ChainProvider breaks on AwsEnvironmentProvider
I'm trying to use a ChainedProvider such that it tries both the aws env variables and the aws config file. If I have the provider setup like this,
ChainedProvider(
new AwsConfigProvider(null, null),
new AwsEnvironmentProvider(),
),
It works just fine (i.e. if I have a config file it reads that otherwise picks up the env secrets). However if I swap the order then I get an exception because it doesn't fall back to the config file...
ChainedProvider(
new AwsEnvironmentProvider(),
new AwsConfigProvider(null, null),
),
throws
[error] java.lang.RuntimeException: java.lang.NullPointerException: AccessKey must not be null
[error] at io.minio.S3Base.throwEncapsulatedException(S3Base.java:308)
[error] at io.minio.MinioClient.listBuckets(MinioClient.java:782)
[error] Caused by: java.lang.NullPointerException: AccessKey must not be null
[error] at java.base/java.util.Objects.requireNonNull(Objects.java:259)
[error] at io.minio.credentials.Credentials.<init>(Credentials.java:55)
[error] at io.minio.credentials.AwsEnvironmentProvider.fetch(AwsEnvironmentProvider.java:35)
[error] at io.minio.credentials.ChainedProvider.fetch(ChainedProvider.java:51)
[error] at io.minio.S3Base.executeAsync(S3Base.java:586)
[error] at io.minio.S3Base.lambda$executeAsync$1(S3Base.java:828)
[error] at java.base/java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1187)
[error] at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2341)
[error] at io.minio.S3Base.executeAsync(S3Base.java:825)
[error] at io.minio.S3Base.executeGetAsync(S3Base.java:988)
[error] at io.minio.MinioAsyncClient.listBuckets(MinioAsyncClient.java:1355)
[error] at io.minio.MinioAsyncClient.listBuckets(MinioAsyncClient.java:1333)
[error] at io.minio.MinioClient.listBuckets(MinioClient.java:778)
Not sure if I'm just using something incorrectly or if it's a bug. I haven't tested any other providers FYI.
@lespea Feel free to send a PR to AwsEnvironmentProvider.java
I started looking at this, and it seems the solution to catch this and future/other problems would be to modify the Credentials constructor so that itseld throws a ProviderException if the access/secret key are null/empty. However that would change the signature of the exception which I'm not sure you want to do? I could also modify the ChainedProvider so that it just tries each provider for any exception type but I'm not 100% sure if that's desired either? Otherwise just modifying the individual Providers to throw the correct exception type is probably the least invasive.
Fixed by https://github.com/minio/minio-java/pull/1621