-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* create tif source config api implementation Signed-off-by: Joanne Wang <[email protected]> * clean up Signed-off-by: Joanne Wang <[email protected]> * getTIFSourceConfig API Signed-off-by: Joanne Wang <[email protected]> * clean up Signed-off-by: Joanne Wang <[email protected]> * more cleanup Signed-off-by: Joanne Wang <[email protected]> * remove runner Signed-off-by: Joanne Wang <[email protected]> * add unit serialization tests Signed-off-by: Joanne Wang <[email protected]> --------- Signed-off-by: Joanne Wang <[email protected]>
- Loading branch information
1 parent
1935ed2
commit 243a0ca
Showing
23 changed files
with
918 additions
and
68 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
22 changes: 22 additions & 0 deletions
22
.../java/org/opensearch/securityanalytics/threatIntel/action/SAGetTIFSourceConfigAction.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,22 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.securityanalytics.threatIntel.action; | ||
|
||
import org.opensearch.action.ActionType; | ||
|
||
import static org.opensearch.securityanalytics.threatIntel.sacommons.IndexTIFSourceConfigAction.GET_TIF_SOURCE_CONFIG_ACTION_NAME; | ||
|
||
/** | ||
* Get TIF Source Config Action | ||
*/ | ||
public class SAGetTIFSourceConfigAction extends ActionType<SAGetTIFSourceConfigResponse> { | ||
|
||
public static final SAGetTIFSourceConfigAction INSTANCE = new SAGetTIFSourceConfigAction(); | ||
public static final String NAME = GET_TIF_SOURCE_CONFIG_ACTION_NAME; | ||
private SAGetTIFSourceConfigAction() { | ||
super(NAME, SAGetTIFSourceConfigResponse::new); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...java/org/opensearch/securityanalytics/threatIntel/action/SAGetTIFSourceConfigRequest.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,61 @@ | ||
/* | ||
* 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.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
import java.util.Locale; | ||
|
||
import static org.opensearch.action.ValidateActions.addValidationError; | ||
|
||
/** | ||
* Get threat intel feed source config request | ||
*/ | ||
public class SAGetTIFSourceConfigRequest extends ActionRequest { | ||
private final String id; | ||
private final Long version; | ||
public static final String TIF_SOURCE_CONFIG_ID = "tif_source_config_id"; | ||
|
||
public SAGetTIFSourceConfigRequest(String id, Long version) { | ||
super(); | ||
this.id = id; | ||
this.version = version; | ||
} | ||
|
||
public SAGetTIFSourceConfigRequest(StreamInput sin) throws IOException { | ||
this(sin.readString(), // id | ||
sin.readLong()); // version | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(id); | ||
out.writeLong(version); | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public Long getVersion() { | ||
return version; | ||
} | ||
|
||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
ActionRequestValidationException validationException = null; | ||
if (id == null || id.isEmpty()) { | ||
validationException = addValidationError(String.format(Locale.getDefault(), "%s is missing", TIF_SOURCE_CONFIG_ID), validationException); | ||
} | ||
return validationException; | ||
} | ||
|
||
} |
101 changes: 101 additions & 0 deletions
101
...ava/org/opensearch/securityanalytics/threatIntel/action/SAGetTIFSourceConfigResponse.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,101 @@ | ||
/* | ||
* 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.rest.RestStatus; | ||
import org.opensearch.core.xcontent.ToXContentObject; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.securityanalytics.threatIntel.model.SATIFSourceConfigDto; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.opensearch.securityanalytics.util.RestHandlerUtils._ID; | ||
import static org.opensearch.securityanalytics.util.RestHandlerUtils._VERSION; | ||
|
||
public class SAGetTIFSourceConfigResponse extends ActionResponse implements ToXContentObject { | ||
private final String id; | ||
|
||
private final Long version; | ||
|
||
private final RestStatus status; | ||
|
||
private final SATIFSourceConfigDto SaTifSourceConfigDto; | ||
|
||
|
||
public SAGetTIFSourceConfigResponse(String id, Long version, RestStatus status, SATIFSourceConfigDto SaTifSourceConfigDto) { | ||
super(); | ||
this.id = id; | ||
this.version = version; | ||
this.status = status; | ||
this.SaTifSourceConfigDto = SaTifSourceConfigDto; | ||
} | ||
|
||
public SAGetTIFSourceConfigResponse(StreamInput sin) throws IOException { | ||
this( | ||
sin.readString(), // id | ||
sin.readLong(), // version | ||
sin.readEnum(RestStatus.class), // status | ||
sin.readBoolean()? SATIFSourceConfigDto.readFrom(sin) : null // SA tif config dto | ||
); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(id); | ||
out.writeLong(version); | ||
out.writeEnum(status); | ||
if (SaTifSourceConfigDto != null) { | ||
out.writeBoolean((true)); | ||
SaTifSourceConfigDto.writeTo(out); | ||
} else { | ||
out.writeBoolean(false); | ||
} | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject() | ||
.field(_ID, id) | ||
.field(_VERSION, version); | ||
builder.startObject("tif_config") | ||
.field(SATIFSourceConfigDto.FEED_NAME_FIELD, SaTifSourceConfigDto.getName()) | ||
.field(SATIFSourceConfigDto.FEED_FORMAT_FIELD, SaTifSourceConfigDto.getFeedFormat()) | ||
.field(SATIFSourceConfigDto.FEED_TYPE_FIELD, SaTifSourceConfigDto.getFeedType()) | ||
.field(SATIFSourceConfigDto.STATE_FIELD, SaTifSourceConfigDto.getState()) | ||
.field(SATIFSourceConfigDto.ENABLED_TIME_FIELD, SaTifSourceConfigDto.getEnabledTime()) | ||
.field(SATIFSourceConfigDto.ENABLED_FIELD, SaTifSourceConfigDto.isEnabled()) | ||
.field(SATIFSourceConfigDto.CREATED_AT_FIELD, SaTifSourceConfigDto.getCreatedAt()) | ||
.field(SATIFSourceConfigDto.LAST_UPDATE_TIME_FIELD, SaTifSourceConfigDto.getLastUpdateTime()) | ||
.field(SATIFSourceConfigDto.LAST_REFRESHED_TIME_FIELD, SaTifSourceConfigDto.getLastRefreshedTime()) | ||
.field(SATIFSourceConfigDto.REFRESH_TYPE_FIELD, SaTifSourceConfigDto.getRefreshType()) | ||
.field(SATIFSourceConfigDto.LAST_REFRESHED_USER_FIELD, SaTifSourceConfigDto.getLastRefreshedUser()) | ||
.field(SATIFSourceConfigDto.SCHEDULE_FIELD, SaTifSourceConfigDto.getSchedule()) | ||
// source | ||
.field(SATIFSourceConfigDto.CREATED_BY_USER_FIELD, SaTifSourceConfigDto.getCreatedByUser()) | ||
.field(SATIFSourceConfigDto.IOC_MAP_STORE_FIELD, SaTifSourceConfigDto.getIocMapStore()) | ||
.field(SATIFSourceConfigDto.IOC_TYPES_FIELD, SaTifSourceConfigDto.getIocTypes()) | ||
.endObject(); | ||
return builder.endObject(); | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public Long getVersion() { | ||
return version; | ||
} | ||
|
||
public RestStatus getStatus() { | ||
return status; | ||
} | ||
|
||
public SATIFSourceConfigDto getSaTifSourceConfigDto() { | ||
return SaTifSourceConfigDto; | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
src/main/java/org/opensearch/securityanalytics/threatIntel/common/RefreshType.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,15 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.securityanalytics.threatIntel.common; | ||
|
||
/** | ||
* Refresh Types: Full | ||
* TODO: Add other refresh types such as the delta | ||
*/ | ||
public enum RefreshType { | ||
|
||
FULL | ||
} |
Oops, something went wrong.