use of com.amazonaws.auth.AWSCredentialsProvider in project hadoop by apache.
the class TestS3AAWSCredentialsProvider method assertCredentialProviders.
/**
* Asserts expected provider classes in list.
* @param expectedClasses expected provider classes
* @param list providers to check
*/
private static void assertCredentialProviders(List<Class<? extends AWSCredentialsProvider>> expectedClasses, AWSCredentialProviderList list) {
assertNotNull(list);
List<AWSCredentialsProvider> providers = list.getProviders();
assertEquals(expectedClasses.size(), providers.size());
for (int i = 0; i < expectedClasses.size(); ++i) {
Class<? extends AWSCredentialsProvider> expectedClass = expectedClasses.get(i);
AWSCredentialsProvider provider = providers.get(i);
assertNotNull(String.format("At position %d, expected class is %s, but found null.", i, expectedClass), provider);
assertTrue(String.format("At position %d, expected class is %s, but found %s.", i, expectedClass, provider.getClass()), expectedClass.isAssignableFrom(provider.getClass()));
}
}
use of com.amazonaws.auth.AWSCredentialsProvider in project hadoop by apache.
the class TestS3AAWSCredentialsProvider method testInstantiationChain.
@Test
public void testInstantiationChain() throws Throwable {
Configuration conf = new Configuration();
conf.set(AWS_CREDENTIALS_PROVIDER, TemporaryAWSCredentialsProvider.NAME + ", \t" + SimpleAWSCredentialsProvider.NAME + " ,\n " + AnonymousAWSCredentialsProvider.NAME);
Path testFile = new Path(conf.getTrimmed(KEY_CSVTEST_FILE, DEFAULT_CSVTEST_FILE));
URI uri = testFile.toUri();
AWSCredentialProviderList list = S3AUtils.createAWSCredentialProviderSet(uri, conf, uri);
List<Class<? extends AWSCredentialsProvider>> expectedClasses = Arrays.asList(TemporaryAWSCredentialsProvider.class, SimpleAWSCredentialsProvider.class, AnonymousAWSCredentialsProvider.class);
assertCredentialProviders(expectedClasses, list);
}
use of com.amazonaws.auth.AWSCredentialsProvider in project cas by apereo.
the class ChainingAWSCredentialsProvider method getInstance.
/**
* Gets instance.
*
* @param credentialAccessKey the credential access key
* @param credentialSecretKey the credential secret key
* @param credentialPropertiesFile the credential properties file
* @param profilePath the profile path
* @param profileName the profile name
* @return the instance
*/
public static AWSCredentialsProvider getInstance(final String credentialAccessKey, final String credentialSecretKey, final Resource credentialPropertiesFile, final String profilePath, final String profileName) {
LOGGER.debug("Attempting to locate AWS credentials...");
final List<AWSCredentialsProvider> chain = new ArrayList<>();
chain.add(new InstanceProfileCredentialsProvider(false));
if (credentialPropertiesFile != null) {
try {
final File f = credentialPropertiesFile.getFile();
chain.add(new PropertiesFileCredentialsProvider(f.getCanonicalPath()));
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
}
if (StringUtils.isNotBlank(profilePath) && StringUtils.isNotBlank(profileName)) {
chain.add(new ProfileCredentialsProvider(profilePath, profileName));
}
chain.add(new SystemPropertiesCredentialsProvider());
chain.add(new EnvironmentVariableCredentialsProvider());
chain.add(new ClasspathPropertiesFileCredentialsProvider("awscredentials.properties"));
if (StringUtils.isNotBlank(credentialAccessKey) && StringUtils.isNotBlank(credentialSecretKey)) {
final BasicAWSCredentials credentials = new BasicAWSCredentials(credentialAccessKey, credentialSecretKey);
chain.add(new AWSStaticCredentialsProvider(credentials));
}
LOGGER.debug("AWS chained credential providers are configured as [{}]", chain);
return new ChainingAWSCredentialsProvider(chain);
}
use of com.amazonaws.auth.AWSCredentialsProvider in project nifi by apache.
the class CredentialsProviderFactory method getCredentialsProvider.
/**
* Produces the AWSCredentialsProvider according to the given property set and the strategies configured in
* the factory.
* @return AWSCredentialsProvider implementation
*/
public AWSCredentialsProvider getCredentialsProvider(final Map<PropertyDescriptor, String> properties) {
final CredentialsStrategy primaryStrategy = selectPrimaryStrategy(properties);
AWSCredentialsProvider primaryCredentialsProvider = primaryStrategy.getCredentialsProvider(properties);
AWSCredentialsProvider derivedCredentialsProvider = null;
for (CredentialsStrategy strategy : strategies) {
if (strategy.canCreateDerivedCredential(properties)) {
derivedCredentialsProvider = strategy.getDerivedCredentialsProvider(properties, primaryCredentialsProvider);
break;
}
}
if (derivedCredentialsProvider != null) {
return derivedCredentialsProvider;
} else {
return primaryCredentialsProvider;
}
}
use of com.amazonaws.auth.AWSCredentialsProvider in project nifi by apache.
the class TestAWSCredentials method setUp.
@Before
public void setUp() {
mockAwsProcessor = new AbstractAWSCredentialsProviderProcessor<AmazonS3Client>() {
protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
return Arrays.asList(AbstractAWSCredentialsProviderProcessor.AWS_CREDENTIALS_PROVIDER_SERVICE, AbstractAWSProcessor.CREDENTIALS_FILE, AbstractAWSProcessor.ACCESS_KEY, AbstractAWSProcessor.SECRET_KEY, AbstractAWSProcessor.TIMEOUT);
}
@Override
protected AmazonS3Client createClient(final ProcessContext context, final AWSCredentials credentials, final ClientConfiguration config) {
awsCredentials = credentials;
clientConfiguration = config;
final AmazonS3Client s3 = new AmazonS3Client(credentials, config);
return s3;
}
@Override
protected AmazonS3Client createClient(final ProcessContext context, final AWSCredentialsProvider credentialsProvider, final ClientConfiguration config) {
awsCredentialsProvider = credentialsProvider;
clientConfiguration = config;
final AmazonS3Client s3 = new AmazonS3Client(credentialsProvider, config);
return s3;
}
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) {
}
};
runner = TestRunners.newTestRunner(mockAwsProcessor);
}
Aggregations