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

Commit

Permalink
Fixed credential provider spamming with errors when not configured (#118
Browse files Browse the repository at this point in the history
)
  • Loading branch information
musketyr authored May 17, 2021
1 parent 3390f65 commit 3fa87b2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,24 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_ACTOR: ${{ secrets.GITHUB_ACTOR }}
DEPLOYER_PASSWORD: ${{ secrets.DEPLOYER_PASSWORD }}
ping:
name: Notify Upstream Repositories
runs-on: ubuntu-latest
needs: [release]
strategy:
matrix:
repository:
- agorapulse/agorapulse-bom
- agorapulse/agorapulse-oss
steps:
- uses: actions/checkout@v1
- name: Semantic Version
id: version
uses: ncipollo/semantic-version-action@v1
- name: Dispatch to ${{ matrix.repository }}
uses: peter-evans/repository-dispatch@v1
with:
token: ${{ secrets.AGORAPULSE_BOT_PERSONAL_TOKEN }}
repository: ${{ matrix.repository }}
event-type: ap-new-version-released-event
client-payload: '{ "group": "com.agorapulse", "module": "grails-aws-sdk", "version": "${{ steps.version.outputs.tag }}", "property": "grails.aws.sdk.version", "github" : ${{ toJson(github) }} }'
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
AWS SDK Grails Plugin
=====================

[![Build Status](https://travis-ci.org/agorapulse/grails-aws-sdk.svg)](https://travis-ci.org/agorapulse/grails-aws-sdk) [ ![Download](https://api.bintray.com/packages/agorapulse/plugins/aws-sdk-dynamodb/images/download.svg?version=2.2.12) ](https://bintray.com/agorapulse/plugins/aws-sdk-dynamodb/2.2.12/link)

# Introduction

The [AWS SDK Plugins for Grails3](https://medium.com/@benorama/aws-sdk-plugins-for-grails-3-cc7f910fdc0d#.5gdwdxei3) are a suite of plugins that adds support for the [Amazon Web Services](http://aws.amazon.com/) infrastructure services.
Expand All @@ -22,6 +20,12 @@ The following services are currently supported:

Please check each README for usage info.

# Installation

After the Bintray sunset, the packages are hosted on GitHub.

See https://github.com/orgs/agorapulse/packages?repo_name=grails-aws-sdk

# Testing

[How to Unit Test AWS Services with LocalStack and Testcontainers](https://medium.com/agorapulse-stories/how-to-unit-test-aws-services-with-localstack-and-testcontainers-1d39fe5dc6c2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ 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 @@ -159,7 +166,15 @@ class AwsClientUtil {
}

if (!config.accessKey || !config.secretKey) {
new DefaultAWSCredentialsProviderChain()
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())
}
} else {
new AWSStaticCredentialsProvider(new BasicAWSCredentials(config.accessKey, config.secretKey))
}
Expand Down

0 comments on commit 3fa87b2

Please sign in to comment.