Skip to content

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

Conversation

ywangd
Copy link
Member

@ywangd ywangd commented Aug 16, 2022

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.

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.
@ywangd ywangd added >refactoring :Security/Security Security issues without another label v8.5.0 labels Aug 16, 2022
@ywangd ywangd requested a review from n1v0lg August 16, 2022 00:26
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-security (Team:Security)

@elasticsearchmachine elasticsearchmachine added the Team:Security Meta label for security team label Aug 16, 2022
Comment on lines 144 to 178
{
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));
Copy link
Member Author

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.

Copy link
Contributor

@n1v0lg n1v0lg left a 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()
Copy link
Contributor

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));
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch!

ywangd and others added 3 commits August 16, 2022 20:02
…security/action/apikey/GetApiKeyRequestTests.java

Co-authored-by: Nikolaj Volgushev <[email protected]>
…security/action/apikey/GetApiKeyRequestTests.java

Co-authored-by: Nikolaj Volgushev <[email protected]>
@ywangd ywangd added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Aug 16, 2022
@elasticsearchmachine elasticsearchmachine merged commit e7a84b1 into elastic:main Aug 16, 2022
@ywangd ywangd deleted the remove-deprecated-methods-get-api-key-request branch August 16, 2022 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) >refactoring :Security/Security Security issues without another label Team:Security Meta label for security team v8.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants