-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for IAM task role credentials, and AWS session credentials.
- Loading branch information
Martin Charlesworth
committed
Aug 29, 2021
1 parent
e52f6f0
commit 9450a83
Showing
8 changed files
with
145 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
AmazonSQS/AmazonSQSExample/src/main/resources/META-INF/microprofile-config.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
awsSecretKey= | ||
awsAccessKeyId= | ||
awsSessionToken= | ||
region=us-east-1 | ||
profileName= |
48 changes: 48 additions & 0 deletions
48
...src/main/java/fish/payara/cloud/connectors/amazonsqs/api/AwsCredentialsProviderUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package fish.payara.cloud.connectors.amazonsqs.api; | ||
|
||
import com.amazonaws.auth.*; | ||
import com.amazonaws.auth.profile.ProfileCredentialsProvider; | ||
import com.amazonaws.util.StringUtils; | ||
|
||
/** | ||
* @author Martin Charlesworth | ||
*/ | ||
public class AwsCredentialsProviderUtils { | ||
|
||
/** | ||
* Creates the appropriate type of {@link AWSCredentialsProvider} depending on the configuration provided. | ||
*/ | ||
public static AWSCredentialsProvider getProvider(String accessKey, | ||
String secretKey, | ||
String sessionToken, | ||
String profileName) { | ||
AWSCredentialsProvider awsCredentialsProvider = null; | ||
if (isValidParam(profileName)) { | ||
// uses specified credentials profile | ||
awsCredentialsProvider = new ProfileCredentialsProvider(profileName); | ||
|
||
} else { | ||
if (isValidParam(accessKey) && isValidParam(secretKey)) { | ||
if (isValidParam(sessionToken)) { | ||
// uses temporary session based credentials | ||
awsCredentialsProvider = new AWSStaticCredentialsProvider(new BasicSessionCredentials(accessKey, secretKey, sessionToken)); | ||
} else { | ||
// uses basic access key + secret key credentials | ||
awsCredentialsProvider = new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)); | ||
} | ||
} | ||
} | ||
if (awsCredentialsProvider == null) { | ||
// if neither credentials nor profile are provided, fall back on the default provider chain, which will | ||
// eventually give us a EC2ContainerCredentialsProviderWrapper, if running in ECS. | ||
awsCredentialsProvider = DefaultAWSCredentialsProviderChain.getInstance(); | ||
} | ||
|
||
return awsCredentialsProvider; | ||
} | ||
|
||
private static boolean isValidParam(String value) { | ||
return !StringUtils.isNullOrEmpty(value) && !value.startsWith("${ENV"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters