Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete threat intel source config API #1066

Merged

Conversation

jowg-amazon
Copy link
Collaborator

Description

Architecture for delete threat intel source config API

Issues Resolved

[List any issues this PR will resolve]

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Joanne Wang <[email protected]>
Signed-off-by: Joanne Wang <[email protected]>
Signed-off-by: Joanne Wang <[email protected]>

@Override
public ActionRequestValidationException validate() {
return null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a check here to assert that the id is not null or empty?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a check to ensure id exists

@@ -158,7 +159,8 @@ public void deleteTIFSourceConfig(
SATIFSourceConfig SaTifSourceConfig = convertToSATIFConfig(SaTifSourceConfigDto);
SaTifSourceConfigService.deleteTIFSourceConfig(SaTifSourceConfig, ActionListener.wrap(
deleteResponse -> {
log.debug("Successfully deleted threat intel source config");
log.debug("Successfully deleted threat intel source config [{}]", SaTifSourceConfig.getId());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking, but should we consider making this an info-level log?

@@ -248,7 +246,7 @@ public void deleteTIFSourceConfig(
client.delete(request, ActionListener.wrap(
deleteResponse -> {
if (deleteResponse.status().equals(RestStatus.OK)) {
log.info("Deleted threat intel source config [{}] successfully", SaTifSourceConfig.getId());
log.debug("Deleted threat intel source config [{}] successfully", SaTifSourceConfig.getId());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as above.

Signed-off-by: Joanne Wang <[email protected]>

public class SADeleteTIFSourceConfigResponse extends ActionResponse implements ToXContentObject {
private final String id;
private final RestStatus status;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what status implies deleted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the delete response is OK then the document is deleted successfully.

@@ -10,4 +10,6 @@
public class Constants {
public static final String USER_AGENT_KEY = "User-Agent";
public static final String USER_AGENT_VALUE = String.format(Locale.ROOT, "OpenSearch/%s vanilla", Version.CURRENT.toString());
public static final String SOURCE_CONFIG_ID = "source_config_id";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEGA-NIT: threat_intel_source_config_id?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to threat_intel_source_config_id


@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
String SaTifSourceConfigId = request.param(SOURCE_CONFIG_ID, SATIFSourceConfigDto.NO_ID);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lower case letter to begin variable name

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
String SaTifSourceConfigId = request.param(SOURCE_CONFIG_ID, SATIFSourceConfigDto.NO_ID);

if (SaTifSourceConfigId == null || SaTifSourceConfigId.isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Stringutils.isBlank() instead

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

Copy link
Member

@eirsep eirsep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is only one config and it it's being deleted we need to ensure there are no jobs
Fail the delete request of the config saying plz delete all threat intel monitors before deleting the last config

Signed-off-by: Joanne Wang <[email protected]>
@jowg-amazon
Copy link
Collaborator Author

if there is only one config and it it's being deleted we need to ensure there are no jobs Fail the delete request of the config saying plz delete all threat intel monitors before deleting the last config

Added a method checkAndEnsureThreatIntelMonitorsDeleted that checks if the source config to be deleted is the last one and if so, makes sure that all threat intel monitors have been deleted. Otherwise it throws an exception.

@jowg-amazon jowg-amazon merged commit 686d317 into opensearch-project:feature/threat_intel Jun 13, 2024
2 checks passed
AWSHurneyt pushed a commit to AWSHurneyt/security-analytics that referenced this pull request Jun 25, 2024
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants