-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[Connector Secrets] Add delete API endpoint #104815
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
Merged
navarone-feekery
merged 6 commits into
elastic:main
from
navarone-feekery:connector-secrets-delete
Jan 30, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e4314f5
Add delete for connector secrets
navarone-feekery 616f2ce
Add yaml and index service tests
navarone-feekery 57c59c2
Add BWC tests
navarone-feekery 49208d8
Placate linter
navarone-feekery d7d9f2a
Add code review changes
navarone-feekery 0d0a000
Fix styling
navarone-feekery File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
rest-api-spec/src/main/resources/rest-api-spec/api/connector_secret.delete.json
This file contains hidden or 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,28 @@ | ||
| { | ||
| "connector_secret.delete": { | ||
| "documentation": { | ||
| "url": null, | ||
| "description": "Deletes a connector secret." | ||
| }, | ||
| "stability": "experimental", | ||
| "visibility":"private", | ||
| "headers":{ | ||
| "accept": [ "application/json"] | ||
| }, | ||
| "url":{ | ||
| "paths":[ | ||
| { | ||
| "path":"/_connector/_secret/{id}", | ||
| "methods":[ "DELETE" ], | ||
| "parts":{ | ||
| "id":{ | ||
| "type":"string", | ||
| "description":"The ID of the secret" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "params":{} | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
71 changes: 71 additions & 0 deletions
71
...t/src/yamlRestTest/resources/rest-api-spec/test/entsearch/520_connector_secret_delete.yml
This file contains hidden or 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,71 @@ | ||
| setup: | ||
| - skip: | ||
| version: " - 8.12.99" | ||
| reason: Introduced in 8.13.0 | ||
|
|
||
| --- | ||
| 'Delete connector secret - admin': | ||
| - do: | ||
| connector_secret.post: | ||
| body: | ||
| value: my-secret | ||
| - set: { id: id } | ||
| - match: { id: $id } | ||
|
|
||
| - do: | ||
| connector_secret.delete: | ||
| id: $id | ||
| - match: { deleted: true } | ||
|
|
||
| - do: | ||
| connector_secret.get: | ||
| id: $id | ||
| catch: missing | ||
|
|
||
| --- | ||
| 'Delete connector secret - user with privileges': | ||
| - skip: | ||
| features: headers | ||
|
|
||
| - do: | ||
| headers: { Authorization: "Basic ZW50c2VhcmNoLXVzZXI6ZW50c2VhcmNoLXVzZXItcGFzc3dvcmQ=" } # user | ||
| connector_secret.post: | ||
| body: | ||
| value: my-secret | ||
| - set: { id: id } | ||
| - match: { id: $id } | ||
| - do: | ||
| headers: { Authorization: "Basic ZW50c2VhcmNoLXVzZXI6ZW50c2VhcmNoLXVzZXItcGFzc3dvcmQ=" } # user | ||
| connector_secret.delete: | ||
| id: $id | ||
| - match: { deleted: true } | ||
| - do: | ||
| headers: { Authorization: "Basic ZW50c2VhcmNoLXVzZXI6ZW50c2VhcmNoLXVzZXItcGFzc3dvcmQ=" } # user | ||
| connector_secret.get: | ||
| id: $id | ||
| catch: missing | ||
|
|
||
| --- | ||
| 'Delete connector secret - user without privileges': | ||
| - skip: | ||
| features: headers | ||
|
|
||
| - do: | ||
| headers: { Authorization: "Basic ZW50c2VhcmNoLXVzZXI6ZW50c2VhcmNoLXVzZXItcGFzc3dvcmQ=" } # user | ||
| connector_secret.post: | ||
| body: | ||
| value: my-secret | ||
| - set: { id: id } | ||
| - match: { id: $id } | ||
| - do: | ||
| headers: { Authorization: "Basic ZW50c2VhcmNoLXVucHJpdmlsZWdlZDplbnRzZWFyY2gtdW5wcml2aWxlZ2VkLXVzZXI=" } # unprivileged | ||
| connector_secret.delete: | ||
| id: $id | ||
| catch: unauthorized | ||
|
|
||
| --- | ||
| 'Delete connector secret - Secret does not exist': | ||
| - do: | ||
| connector_secret.delete: | ||
| id: non-existing-secret-id | ||
| catch: missing |
This file contains hidden or 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 hidden or 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
19 changes: 19 additions & 0 deletions
19
...elasticsearch/xpack/application/connector/secrets/action/DeleteConnectorSecretAction.java
This file contains hidden or 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,19 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.application.connector.secrets.action; | ||
|
|
||
| import org.elasticsearch.action.ActionType; | ||
|
|
||
| public class DeleteConnectorSecretAction { | ||
|
|
||
| public static final String NAME = "cluster:admin/xpack/connector/secret/delete"; | ||
|
|
||
| public static final ActionType<DeleteConnectorSecretResponse> INSTANCE = new ActionType<>(NAME); | ||
|
|
||
| private DeleteConnectorSecretAction() {/* no instances */} | ||
| } |
67 changes: 67 additions & 0 deletions
67
...lasticsearch/xpack/application/connector/secrets/action/DeleteConnectorSecretRequest.java
This file contains hidden or 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,67 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.application.connector.secrets.action; | ||
|
|
||
| import org.elasticsearch.action.ActionRequest; | ||
| import org.elasticsearch.action.ActionRequestValidationException; | ||
| import org.elasticsearch.common.Strings; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Objects; | ||
|
|
||
| import static org.elasticsearch.action.ValidateActions.addValidationError; | ||
|
|
||
| public class DeleteConnectorSecretRequest extends ActionRequest { | ||
|
|
||
| private final String id; | ||
|
|
||
| public DeleteConnectorSecretRequest(String id) { | ||
| this.id = Objects.requireNonNull(id); | ||
| } | ||
|
|
||
| public DeleteConnectorSecretRequest(StreamInput in) throws IOException { | ||
| super(in); | ||
| this.id = in.readString(); | ||
| } | ||
|
|
||
| public String id() { | ||
| return id; | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| super.writeTo(out); | ||
| out.writeString(id); | ||
| } | ||
|
|
||
| @Override | ||
| public ActionRequestValidationException validate() { | ||
| ActionRequestValidationException validationException = null; | ||
|
|
||
| if (Strings.isNullOrEmpty(id)) { | ||
| validationException = addValidationError("id missing", validationException); | ||
| } | ||
|
|
||
| return validationException; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| DeleteConnectorSecretRequest that = (DeleteConnectorSecretRequest) o; | ||
| return Objects.equals(id, that.id); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(id); | ||
| } | ||
| } | ||
60 changes: 60 additions & 0 deletions
60
...asticsearch/xpack/application/connector/secrets/action/DeleteConnectorSecretResponse.java
This file contains hidden or 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,60 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.application.connector.secrets.action; | ||
|
|
||
| import org.elasticsearch.action.ActionResponse; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.xcontent.ToXContentObject; | ||
| import org.elasticsearch.xcontent.XContentBuilder; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Objects; | ||
|
|
||
| public class DeleteConnectorSecretResponse extends ActionResponse implements ToXContentObject { | ||
|
|
||
| private final boolean deleted; | ||
|
|
||
| public DeleteConnectorSecretResponse(boolean deleted) { | ||
| this.deleted = deleted; | ||
| } | ||
|
|
||
| public DeleteConnectorSecretResponse(StreamInput in) throws IOException { | ||
| super(in); | ||
| this.deleted = in.readBoolean(); | ||
| } | ||
|
|
||
| public boolean isDeleted() { | ||
| return deleted; | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| out.writeBoolean(deleted); | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| builder.startObject(); | ||
| builder.field("deleted", deleted); | ||
| return builder.endObject(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| DeleteConnectorSecretResponse that = (DeleteConnectorSecretResponse) o; | ||
| return deleted == that.deleted; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(deleted); | ||
| } | ||
| } |
42 changes: 42 additions & 0 deletions
42
...ticsearch/xpack/application/connector/secrets/action/RestDeleteConnectorSecretAction.java
This file contains hidden or 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,42 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.application.connector.secrets.action; | ||
|
|
||
| import org.elasticsearch.client.internal.node.NodeClient; | ||
| import org.elasticsearch.rest.BaseRestHandler; | ||
| import org.elasticsearch.rest.RestRequest; | ||
| import org.elasticsearch.rest.Scope; | ||
| import org.elasticsearch.rest.ServerlessScope; | ||
| import org.elasticsearch.rest.action.RestToXContentListener; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| @ServerlessScope(Scope.INTERNAL) | ||
| public class RestDeleteConnectorSecretAction extends BaseRestHandler { | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return "connector_delete_secret"; | ||
| } | ||
|
|
||
| @Override | ||
| public List<Route> routes() { | ||
| return List.of(new Route(RestRequest.Method.DELETE, "/_connector/_secret/{id}")); | ||
| } | ||
|
|
||
| @Override | ||
| protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { | ||
| final String id = request.param("id"); | ||
| return restChannel -> client.execute( | ||
| DeleteConnectorSecretAction.INSTANCE, | ||
| new DeleteConnectorSecretRequest(id), | ||
| new RestToXContentListener<>(restChannel) | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: can we test for this edge case in yaml tests?