Skip to content

Conversation

kessplas
Copy link
Contributor

@kessplas kessplas commented Sep 11, 2024

Issue #, if available: n/a

Description of changes: When getting an instruction file, the S3EC creates a default client. This client cannot be configured, so unless the environment has the correct creds, the instruction file GET will fail. This change uses the same async client that GetObject uses to avoid issues with configuration.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Check any applicable:

  • Were any files moved? Moving files changes their URL, which breaks all hyperlinks to the files.

@kessplas kessplas marked this pull request as ready for review September 16, 2024 22:14
@kessplas kessplas requested a review from a team as a code owner September 16, 2024 22:14
@kessplas kessplas marked this pull request as draft September 16, 2024 22:16
@kessplas kessplas marked this pull request as ready for review September 16, 2024 22:35
Copy link
Contributor

@lucasmcdonald3 lucasmcdonald3 left a comment

Choose a reason for hiding this comment

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

Are you running into character count limits in the PR title?
Maybe just
fix: use the configured async client to get the instruction file

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.*;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have style guidelines around not using * imports?
I like * imports for ease of development. But previous styleguides have suggested that my opinion is wrong. And we haven't used * imports in this file so far, so I'm wondering if there's some implicit styleguide here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we are not entirely consistent,
particularly between repos,
but most of this project prefers explicit imports,
so I'll apply that here.

.build();

ContentMetadata contentMetadata = ContentMetadataStrategy.decode(getObjectRequest, getObjectResponse);
ContentMetadata contentMetadata = new ContentMetadataDecodingStrategy(null).decode(getObjectRequest, getObjectResponse);
Copy link
Contributor

Choose a reason for hiding this comment

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

(nit) Seems this should be a mock S3 client instead of null; if this test were to attempt to call S3 it would result in NPE.
But this test doesn't call S3, so this is a nit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need null checking somewhere?
If I pass in a null S3 client due to being (silly, adversarial, etc.), is this checked/guarded against in the non-internal class level?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The top-level client builders will create a client when there is none provided,
so it is always the case that the client is not null.
That said,
I'll add a null check / mock in the name of robustness.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool -- I think creating a default top-level client is sufficient but more checks never hurt anyone 👍

}

@Test
public void s3EncryptionClientMixedCredentialsInstructionFile() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what the scope of this test is; it looks like both a failure and success test case?
Could you clarify what exactly is being tested in comments here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, I'll break it out into two separate tests

@kessplas kessplas changed the title fix: use the configured async client to get the instruction file inst… fix: use the configured async client to get the instruction file Sep 17, 2024
Comment on lines +59 to +60
S3AsyncClient s3AsyncClient = S3AsyncClient.create();
ContentMetadata contentMetadata = new ContentMetadataDecodingStrategy(s3AsyncClient).decode(getObjectRequest, getObjectResponse);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine too, I originally meant something like

S3AsyncClient s3AsyncClient = mock(S3AsyncClient.class);

@kessplas kessplas merged commit 5249bbf into main Sep 17, 2024
14 checks passed
josecorella pushed a commit that referenced this pull request Sep 18, 2024
## [3.2.2](v3.2.1...v3.2.2) (2024-09-18)

### Fixes

* use the configured async client to get the instruction file ([#366](#366)) ([5249bbf](5249bbf))

### Maintenance

* update upload_artifacts ([#349](#349)) ([a21cc35](a21cc35))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants