Skip to content

Commit

Permalink
Add api key metadata version check in ApiKeyService
Browse files Browse the repository at this point in the history
  • Loading branch information
ywangd committed Mar 29, 2021
1 parent a16e649 commit f4ff07d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void writeTo(StreamOutput out) throws IOException {
if (metadata != null && false == metadata.isEmpty()) {
if (out.getVersion().before(Version.V_7_13_0)) {
throw new IllegalArgumentException(
"api key metadata requires minimum node version to be [7.13.0], got: [" + out.getVersion() + "]");
"api key metadata requires minimum node version to be [7.13], got: [" + out.getVersion() + "]");
} else {
out.writeMap(metadata);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private void createApiKeyAndIndexIt(Authentication authentication, CreateApiKeyR
indexResponse -> listener.onResponse(
new CreateApiKeyResponse(request.getName(), indexResponse.getId(), apiKey, expiration)),
listener::onFailure))));
} catch (IOException e) {
} catch (Exception e) {
listener.onFailure(e);
}
}
Expand Down Expand Up @@ -334,8 +334,17 @@ XContentBuilder newDocument(SecureString apiKey, String name, Authentication aut
builder.endObject();

builder.field("name", name)
.field("version", version.id)
.field("metadata_flattened", metadata)
.field("version", version.id);
final Version masterNodeVersion = clusterService.state().nodes().getMasterNode().getVersion();
if (masterNodeVersion.onOrAfter(Version.V_7_13_0)) {
builder.field("metadata_flattened", metadata);
} else {
if (metadata != null && false == metadata.isEmpty()) {
throw new IllegalArgumentException(
"api key metadata requires master node to be on version [7.13] or later, got [" + masterNodeVersion + "]");
}
}
builder
.startObject("creator")
.field("principal", authentication.getUser().principal())
.field("full_name", authentication.getUser().fullName())
Expand Down

0 comments on commit f4ff07d

Please sign in to comment.