forked from opensearch-project/security-analytics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/threat_intel' into ioc_findings
Signed-off-by: Subhobrata Dey <sbcd90@gmail.com>
- Loading branch information
Showing
39 changed files
with
1,757 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/org/opensearch/securityanalytics/action/TestS3ConnectionAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.securityanalytics.action; | ||
|
||
import org.opensearch.action.ActionType; | ||
|
||
public class TestS3ConnectionAction extends ActionType<TestS3ConnectionResponse> { | ||
public static final String NAME = "cluster:admin/opensearch/securityanalytics/connections/test/s3"; | ||
public static final TestS3ConnectionAction INSTANCE = new TestS3ConnectionAction(); | ||
|
||
public TestS3ConnectionAction() { | ||
super(NAME, TestS3ConnectionResponse::new); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/org/opensearch/securityanalytics/action/TestS3ConnectionRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.securityanalytics.action; | ||
|
||
import org.opensearch.action.ActionRequest; | ||
import org.opensearch.action.ActionRequestValidationException; | ||
import org.opensearch.action.ValidateActions; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.xcontent.ToXContentObject; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.core.xcontent.XContentParser; | ||
import org.opensearch.securityanalytics.commons.connector.model.S3ConnectorConfig; | ||
import org.opensearch.securityanalytics.threatIntel.model.S3Source; | ||
|
||
import java.io.IOException; | ||
|
||
public class TestS3ConnectionRequest extends ActionRequest implements ToXContentObject { | ||
private final S3Source s3Source; | ||
|
||
public TestS3ConnectionRequest(S3Source s3Source) { | ||
super(); | ||
this.s3Source = s3Source; | ||
} | ||
|
||
public TestS3ConnectionRequest(String bucketName, String objectKey, String region, String roleArn) { | ||
this(new S3Source(bucketName, objectKey, region, roleArn)); | ||
} | ||
|
||
public TestS3ConnectionRequest(StreamInput sin) throws IOException { | ||
this(new S3Source(sin)); | ||
} | ||
|
||
public void writeTo(StreamOutput out) throws IOException { | ||
s3Source.writeTo(out); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
ActionRequestValidationException validationException = null; | ||
if (s3Source.getBucketName() == null || s3Source.getBucketName().isEmpty()) { | ||
validationException = ValidateActions.addValidationError("Must provide bucket name.", validationException); | ||
} | ||
if (s3Source.getObjectKey() == null || s3Source.getObjectKey().isEmpty()) { | ||
validationException = ValidateActions.addValidationError("Must provide object key.", validationException); | ||
} | ||
if (s3Source.getObjectKey() == null || s3Source.getObjectKey().isEmpty()) { | ||
validationException = ValidateActions.addValidationError("Must provide region.", validationException); | ||
} | ||
if (s3Source.getRoleArn() == null || s3Source.getRoleArn().isEmpty()) { | ||
validationException = ValidateActions.addValidationError("Must provide role ARN.", validationException); | ||
} | ||
return validationException; | ||
} | ||
|
||
public static TestS3ConnectionRequest parse(XContentParser xcp) throws IOException { | ||
return new TestS3ConnectionRequest(S3Source.parse(xcp)); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
return s3Source.toXContent(builder, params); | ||
} | ||
|
||
public S3ConnectorConfig constructS3ConnectorConfig() { | ||
return new S3ConnectorConfig( | ||
s3Source.getBucketName(), | ||
s3Source.getObjectKey(), | ||
s3Source.getRegion(), | ||
s3Source.getRoleArn() | ||
); | ||
} | ||
|
||
public S3Source getS3Source() { | ||
return s3Source; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/org/opensearch/securityanalytics/action/TestS3ConnectionResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.securityanalytics.action; | ||
|
||
import org.opensearch.core.action.ActionResponse; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.rest.RestStatus; | ||
import org.opensearch.core.xcontent.ToXContentObject; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
|
||
public class TestS3ConnectionResponse extends ActionResponse implements ToXContentObject { | ||
public static final String STATUS_FIELD = "status"; | ||
public static final String ERROR_FIELD = "error"; | ||
|
||
private RestStatus status; | ||
private String error; | ||
|
||
public TestS3ConnectionResponse(RestStatus status, String error) { | ||
super(); | ||
this.status = status; | ||
this.error = error; | ||
} | ||
|
||
public TestS3ConnectionResponse(StreamInput sin) throws IOException { | ||
this(sin.readEnum(RestStatus.class), sin.readOptionalString()); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeEnum(status); | ||
out.writeOptionalString(error); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
return builder.startObject() | ||
.field(STATUS_FIELD, status) | ||
.field(ERROR_FIELD, error) | ||
.endObject(); | ||
} | ||
|
||
public RestStatus getStatus() { | ||
return status; | ||
} | ||
|
||
public String getError() { | ||
return error; | ||
} | ||
} |
Oops, something went wrong.