Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
reverted static credentials usage
Browse files Browse the repository at this point in the history
  • Loading branch information
musketyr committed Jun 7, 2021
1 parent 6b90931 commit 169be60
Showing 1 changed file with 1 addition and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,18 @@ package agorapulse.libs.awssdk.util

import com.amazonaws.ClientConfiguration
import com.amazonaws.Protocol
import com.amazonaws.SdkClientException
import com.amazonaws.auth.AWSCredentials
import com.amazonaws.auth.AWSCredentialsProvider
import com.amazonaws.auth.AWSStaticCredentialsProvider
import com.amazonaws.auth.AnonymousAWSCredentials
import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
import com.amazonaws.client.builder.AwsSyncClientBuilder
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
import com.amazonaws.regions.Region
import com.amazonaws.regions.RegionUtils
import org.slf4j.Logger
import org.slf4j.LoggerFactory

@SuppressWarnings(['FactoryMethodName'])
class AwsClientUtil {

private static final Logger LOGGER = LoggerFactory.getLogger(AwsClientUtil)

static final String DEFAULT_REGION = 'us-east-1'

static <C, B extends AwsSyncClientBuilder<B, C>> B configure(B builder, String serviceName, config, serviceConfig) {
Expand Down Expand Up @@ -166,15 +159,7 @@ class AwsClientUtil {
}

if (!config.accessKey || !config.secretKey) {
try {
// only fetch the credentials once when inititalized
AWSCredentials credentials = new DefaultAWSCredentialsProviderChain().getCredentials()
return new AWSStaticCredentialsProvider(credentials)
} catch(SdkClientException e) {
LOGGER.warn('Failed to obtain credentials from the chain. ' +
'Please, configure grails.plugin.awssdk.accessKey and grails.plugin.awssdk.secretKey ', e)
return new AWSStaticCredentialsProvider(new AnonymousAWSCredentials())
}
new DefaultAWSCredentialsProviderChain()
} else {
new AWSStaticCredentialsProvider(new BasicAWSCredentials(config.accessKey, config.secretKey))
}
Expand Down

0 comments on commit 169be60

Please sign in to comment.