-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete threat intel source config API (#1066)
* delete api Signed-off-by: Joanne Wang <[email protected]> * clean up Signed-off-by: Joanne Wang <[email protected]> * delete api integ test Signed-off-by: Joanne Wang <[email protected]> * added validation logic Signed-off-by: Joanne Wang <[email protected]> * respond to comments Signed-off-by: Joanne Wang <[email protected]> * fix merge conflicts Signed-off-by: Joanne Wang <[email protected]> * fix merge conflicts Signed-off-by: Joanne Wang <[email protected]> --------- Signed-off-by: Joanne Wang <[email protected]>
- Loading branch information
1 parent
1997575
commit 686d317
Showing
15 changed files
with
416 additions
and
20 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
...va/org/opensearch/securityanalytics/threatIntel/action/SADeleteTIFSourceConfigAction.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.DELETE_TIF_SOURCE_CONFIG_ACTION_NAME; | ||
|
||
/** | ||
* Delete TIF Source Config Action | ||
*/ | ||
public class SADeleteTIFSourceConfigAction extends ActionType<SADeleteTIFSourceConfigResponse> { | ||
|
||
public static final SADeleteTIFSourceConfigAction INSTANCE = new SADeleteTIFSourceConfigAction(); | ||
public static final String NAME = DELETE_TIF_SOURCE_CONFIG_ACTION_NAME; | ||
private SADeleteTIFSourceConfigAction() { | ||
super(NAME, SADeleteTIFSourceConfigResponse::new); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...a/org/opensearch/securityanalytics/threatIntel/action/SADeleteTIFSourceConfigRequest.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,52 @@ | ||
/* | ||
* 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; | ||
import static org.opensearch.securityanalytics.threatIntel.common.Constants.THREAT_INTEL_SOURCE_CONFIG_ID; | ||
|
||
/** | ||
* Delete threat intel feed source config request | ||
*/ | ||
public class SADeleteTIFSourceConfigRequest extends ActionRequest { | ||
private final String id; | ||
public SADeleteTIFSourceConfigRequest(String id) { | ||
super(); | ||
this.id = id; | ||
} | ||
|
||
public SADeleteTIFSourceConfigRequest(StreamInput sin) throws IOException { | ||
this(sin.readString()); // id | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(id); | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
ActionRequestValidationException validationException = null; | ||
if (id == null || id.isEmpty()) { | ||
validationException = addValidationError(String.format(Locale.getDefault(), "%s is missing", THREAT_INTEL_SOURCE_CONFIG_ID), validationException); | ||
} | ||
return validationException; | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
.../org/opensearch/securityanalytics/threatIntel/action/SADeleteTIFSourceConfigResponse.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,58 @@ | ||
/* | ||
* 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 SADeleteTIFSourceConfigResponse extends ActionResponse implements ToXContentObject { | ||
private final String id; | ||
private final RestStatus status; | ||
|
||
public SADeleteTIFSourceConfigResponse(String id, RestStatus status) { | ||
super(); | ||
this.id = id; | ||
this.status = status; | ||
} | ||
|
||
public SADeleteTIFSourceConfigResponse(StreamInput sin) throws IOException { | ||
this( | ||
sin.readString(), // id | ||
sin.readEnum(RestStatus.class) // status | ||
); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(id); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject() | ||
.field(_ID, id); | ||
return builder.endObject(); | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
|
||
public RestStatus getStatus() { | ||
return status; | ||
} | ||
|
||
} |
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
50 changes: 50 additions & 0 deletions
50
...opensearch/securityanalytics/threatIntel/resthandler/RestDeleteTIFSourceConfigAction.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,50 @@ | ||
package org.opensearch.securityanalytics.threatIntel.resthandler; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.client.node.NodeClient; | ||
import org.opensearch.rest.BaseRestHandler; | ||
import org.opensearch.rest.RestRequest; | ||
import org.opensearch.rest.action.RestToXContentListener; | ||
import org.opensearch.securityanalytics.SecurityAnalyticsPlugin; | ||
import org.opensearch.securityanalytics.threatIntel.action.SADeleteTIFSourceConfigAction; | ||
import org.opensearch.securityanalytics.threatIntel.action.SADeleteTIFSourceConfigRequest; | ||
import org.opensearch.securityanalytics.threatIntel.model.SATIFSourceConfigDto; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
import static org.opensearch.securityanalytics.threatIntel.common.Constants.THREAT_INTEL_SOURCE_CONFIG_ID; | ||
|
||
public class RestDeleteTIFSourceConfigAction extends BaseRestHandler { | ||
|
||
private static final Logger log = LogManager.getLogger(RestDeleteTIFSourceConfigAction.class); | ||
|
||
@Override | ||
public String getName() { | ||
return "delete_tif_config_action"; | ||
} | ||
|
||
@Override | ||
public List<Route> routes() { | ||
return List.of(new Route(RestRequest.Method.DELETE, String.format(Locale.getDefault(), "%s/{%s}", SecurityAnalyticsPlugin.THREAT_INTEL_SOURCE_URI, THREAT_INTEL_SOURCE_CONFIG_ID))); | ||
} | ||
|
||
@Override | ||
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { | ||
String saTifSourceConfigId = request.param(THREAT_INTEL_SOURCE_CONFIG_ID, SATIFSourceConfigDto.NO_ID); | ||
|
||
if (saTifSourceConfigId == null || saTifSourceConfigId.isBlank()) { | ||
throw new IllegalArgumentException("missing id"); | ||
} | ||
|
||
SADeleteTIFSourceConfigRequest req = new SADeleteTIFSourceConfigRequest(saTifSourceConfigId); | ||
|
||
return channel -> client.execute( | ||
SADeleteTIFSourceConfigAction.INSTANCE, | ||
req, | ||
new RestToXContentListener<>(channel) | ||
); | ||
} | ||
} |
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
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.