Skip to content

Commit

Permalink
PR review
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Ho <[email protected]>
  • Loading branch information
derek-ho committed Dec 16, 2024
1 parent 58cf8ca commit 45fe5c1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,6 @@ public static ApiToken fromXContent(XContentParser parser) throws IOException {
}
}

if (name == null) {
throw new IllegalArgumentException(NAME_FIELD + " is required");
}
if (jti == null) {
throw new IllegalArgumentException(JTI_FIELD + " is required");
}
if (creationTime == null) {
throw new IllegalArgumentException(CREATION_TIME_FIELD + " is required");
}

return new ApiToken(name, jti, clusterPermissions, indexPermissions, creationTime);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ApiTokenAction(ClusterService clusterService, ThreadPool threadPool, Clie

@Override
public String getName() {
return "Actions to get and create API tokens.";
return "api_token_action";
}

@Override
Expand Down Expand Up @@ -99,7 +99,7 @@ private RestChannelConsumer handleGet(RestRequest request, NodeClient client) {

response = new BytesRestResponse(RestStatus.OK, builder);
} catch (final Exception exception) {
builder.startObject().field("error", "An unexpected error occurred. Please check the input and try again.").endObject();
builder.startObject().field("error", exception.getMessage()).endObject();
response = new BytesRestResponse(RestStatus.INTERNAL_SERVER_ERROR, builder);
}
builder.close();
Expand Down Expand Up @@ -275,7 +275,7 @@ private RestChannelConsumer handleDelete(RestRequest request, NodeClient client)
builder.startObject().field("error", exception.getMessage()).endObject();
response = new BytesRestResponse(RestStatus.NOT_FOUND, builder);
} catch (final Exception exception) {
builder.startObject().field("error", "An unexpected error occurred. Please check the input and try again.").endObject();
builder.startObject().field("error", exception.getMessage()).endObject();
response = new BytesRestResponse(RestStatus.INTERNAL_SERVER_ERROR, builder);
}
builder.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.opensearch.client.Client;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.index.IndexNotFoundException;

public class ApiTokenRepository {
private final ApiTokenIndexHandler apiTokenIndexHandler;
Expand All @@ -31,13 +32,11 @@ public String createApiToken(String name, List<String> clusterPermissions, List<
return apiTokenIndexHandler.indexTokenMetadata(new ApiToken(name, "test-token", clusterPermissions, indexPermissions));
}

public void deleteApiToken(String name) throws ApiTokenException {
apiTokenIndexHandler.createApiTokenIndexIfAbsent();
public void deleteApiToken(String name) throws ApiTokenException, IndexNotFoundException {
apiTokenIndexHandler.deleteToken(name);
}

public Map<String, ApiToken> getApiTokens() {
apiTokenIndexHandler.createApiTokenIndexIfAbsent();
public Map<String, ApiToken> getApiTokens() throws IndexNotFoundException {
return apiTokenIndexHandler.getTokenMetadatas();
}

Expand Down

0 comments on commit 45fe5c1

Please sign in to comment.