-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Remove deprecated convenient methods from GetApiKeyRequest #89360
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
Remove deprecated convenient methods from GetApiKeyRequest #89360
Conversation
A builder class for GetApiKeyRequest is added as part of elastic#89273. As a result, the existing convenient methods got deprecated in favour of the builder. This PR removes the deprecated methods and replaces all usages with the builder.
Pinging @elastic/es-security (Team:Security) |
{ | ||
final GetApiKeyRequest getApiKeyRequest2 = GetApiKeyRequest.builder() | ||
.apiKeyName(apiKeyId) | ||
.ownedByAuthenticatedUser(true) | ||
.withLimitedBy(true) | ||
.build(); | ||
ByteArrayOutputStream outBuffer = new ByteArrayOutputStream(); | ||
OutputStreamStreamOutput out = new OutputStreamStreamOutput(outBuffer); | ||
out.setVersion(randomVersionBetween(random(), Version.V_7_4_0, Version.V_8_4_0)); | ||
getApiKeyRequest2.writeTo(out); | ||
|
||
InputStreamStreamInput inputStreamStreamInput = new InputStreamStreamInput(new ByteArrayInputStream(outBuffer.toByteArray())); | ||
inputStreamStreamInput.setVersion(randomVersionBetween(random(), Version.V_7_4_0, Version.V_8_4_0)); | ||
GetApiKeyRequest requestFromInputStream = new GetApiKeyRequest(inputStreamStreamInput); | ||
|
||
assertThat(requestFromInputStream.getApiKeyId(), equalTo(getApiKeyRequest2.getApiKeyId())); | ||
assertThat(requestFromInputStream.ownedByAuthenticatedUser(), is(true)); | ||
// old version so the default for `withLimitedBy` is false | ||
assertThat(requestFromInputStream.withLimitedBy(), is(false)); | ||
} | ||
{ | ||
final GetApiKeyRequest getApiKeyRequest3 = GetApiKeyRequest.builder() | ||
.apiKeyName(apiKeyId) | ||
.withLimitedBy(randomBoolean()) | ||
.build(); | ||
ByteArrayOutputStream outBuffer = new ByteArrayOutputStream(); | ||
OutputStreamStreamOutput out = new OutputStreamStreamOutput(outBuffer); | ||
out.setVersion(randomVersionBetween(random(), Version.V_7_4_0, Version.CURRENT)); | ||
getApiKeyRequest.writeTo(out); | ||
out.setVersion(randomVersionBetween(random(), Version.V_8_5_0, Version.CURRENT)); | ||
getApiKeyRequest3.writeTo(out); | ||
|
||
InputStreamStreamInput inputStreamStreamInput = new InputStreamStreamInput(new ByteArrayInputStream(outBuffer.toByteArray())); | ||
inputStreamStreamInput.setVersion(randomVersionBetween(random(), Version.V_7_4_0, Version.CURRENT)); | ||
inputStreamStreamInput.setVersion(randomVersionBetween(random(), Version.V_8_5_0, Version.CURRENT)); | ||
GetApiKeyRequest requestFromInputStream = new GetApiKeyRequest(inputStreamStreamInput); | ||
|
||
assertThat(requestFromInputStream, equalTo(getApiKeyRequest)); | ||
assertThat(requestFromInputStream, equalTo(getApiKeyRequest3)); |
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.
This change is actually a bug fix for test. It can fail because the new with_limited_by
field is not available in version before v8.5.0.
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.
LGTM, pending one typo fix (apiKeyName()
-> apiKeyId()
-- see my inline comment). Didn't want to block since it's only a very small change and everything else looks good.
{ | ||
final GetApiKeyRequest getApiKeyRequest1 = GetApiKeyRequest.builder() |
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: since this is in its own scope, getApiKeyRequest
(without the numerical suffix) still works here, and further down.
assertThat(requestFromInputStream.getApiKeyId(), equalTo(getApiKeyRequest2.getApiKeyId())); | ||
assertThat(requestFromInputStream.ownedByAuthenticatedUser(), is(true)); | ||
// old version so the default for `withLimitedBy` is false | ||
assertThat(requestFromInputStream.withLimitedBy(), is(false)); |
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.
Nice catch!
...src/test/java/org/elasticsearch/xpack/core/security/action/apikey/GetApiKeyRequestTests.java
Outdated
Show resolved
Hide resolved
...src/test/java/org/elasticsearch/xpack/core/security/action/apikey/GetApiKeyRequestTests.java
Outdated
Show resolved
Hide resolved
…security/action/apikey/GetApiKeyRequestTests.java Co-authored-by: Nikolaj Volgushev <[email protected]>
…security/action/apikey/GetApiKeyRequestTests.java Co-authored-by: Nikolaj Volgushev <[email protected]>
A builder class for GetApiKeyRequest is added as part of #89273. As a
result, the existing convenient methods got deprecated in favour of the
builder. This PR removes the deprecated methods and replaces all usages
with the builder.