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.
Signed-off-by: Subhobrata Dey <[email protected]>
- Loading branch information
Showing
15 changed files
with
585 additions
and
75 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
17 changes: 17 additions & 0 deletions
17
src/main/java/org/opensearch/securityanalytics/threatIntel/action/GetIocFindingsAction.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.threatIntel.action; | ||
|
||
import org.opensearch.action.ActionType; | ||
|
||
public class GetIocFindingsAction extends ActionType<GetIocFindingsResponse> { | ||
|
||
public static final GetIocFindingsAction INSTANCE = new GetIocFindingsAction(); | ||
public static final String NAME = "cluster:admin/opensearch/securityanalytics/ioc/findings/get"; | ||
|
||
public GetIocFindingsAction() { | ||
super(NAME, GetIocFindingsResponse::new); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
src/main/java/org/opensearch/securityanalytics/threatIntel/action/GetIocFindingsRequest.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,81 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.securityanalytics.threatIntel.action; | ||
|
||
import org.opensearch.action.ActionRequest; | ||
import org.opensearch.action.ActionRequestValidationException; | ||
import org.opensearch.action.ValidateActions; | ||
import org.opensearch.commons.alerting.model.Table; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
import java.time.Instant; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
public class GetIocFindingsRequest extends ActionRequest { | ||
|
||
private List<String> findingIds; | ||
|
||
private Instant startTime; | ||
|
||
private Instant endTime; | ||
|
||
private Table table; | ||
|
||
public GetIocFindingsRequest(StreamInput sin) throws IOException { | ||
this( | ||
sin.readOptionalStringList(), | ||
sin.readOptionalInstant(), | ||
sin.readOptionalInstant(), | ||
Table.readFrom(sin) | ||
); | ||
} | ||
|
||
public GetIocFindingsRequest(List<String> findingIds, | ||
Instant startTime, | ||
Instant endTime, | ||
Table table) { | ||
this.findingIds = findingIds; | ||
this.startTime = startTime; | ||
this.endTime = endTime; | ||
this.table = table; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
ActionRequestValidationException validationException = null; | ||
if (startTime != null && endTime != null && startTime.isAfter(endTime)) { | ||
validationException = ValidateActions.addValidationError(String.format(Locale.getDefault(), | ||
"startTime should be less than endTime"), validationException); | ||
} | ||
return validationException; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeOptionalStringCollection(findingIds); | ||
out.writeOptionalInstant(startTime); | ||
out.writeOptionalInstant(endTime); | ||
table.writeTo(out); | ||
} | ||
|
||
public List<String> getFindingIds() { | ||
return findingIds; | ||
} | ||
|
||
public Instant getStartTime() { | ||
return startTime; | ||
} | ||
|
||
public Instant getEndTime() { | ||
return endTime; | ||
} | ||
|
||
public Table getTable() { | ||
return table; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...main/java/org/opensearch/securityanalytics/threatIntel/action/GetIocFindingsResponse.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,62 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.securityanalytics.threatIntel.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.xcontent.ToXContentObject; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.securityanalytics.model.threatintel.IocFinding; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class GetIocFindingsResponse extends ActionResponse implements ToXContentObject { | ||
|
||
private static final String TOTAL_IOC_FINDINGS_FIELD = "total_findings"; | ||
|
||
private static final String IOC_FINDINGS_FIELD = "ioc_findings"; | ||
|
||
private Integer totalFindings; | ||
|
||
private List<IocFinding> iocFindings; | ||
|
||
public GetIocFindingsResponse(Integer totalFindings, List<IocFinding> iocFindings) { | ||
super(); | ||
this.totalFindings = totalFindings; | ||
this.iocFindings = iocFindings; | ||
} | ||
|
||
public GetIocFindingsResponse(StreamInput sin) throws IOException { | ||
this( | ||
sin.readInt(), | ||
Collections.unmodifiableList(sin.readList(IocFinding::new)) | ||
); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeInt(totalFindings); | ||
out.writeCollection(iocFindings); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject() | ||
.field(TOTAL_IOC_FINDINGS_FIELD, totalFindings) | ||
.field(IOC_FINDINGS_FIELD, iocFindings); | ||
return builder.endObject(); | ||
} | ||
|
||
public Integer getTotalFindings() { | ||
return totalFindings; | ||
} | ||
|
||
public List<IocFinding> getIocFindings() { | ||
return iocFindings; | ||
} | ||
} |
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
Oops, something went wrong.