com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper Java Examples
The following examples show how to use
com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContextCredentialsAutoConfiguration.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
private List<AWSCredentialsProvider> resolveCredentialsProviders( AwsCredentialsProperties properties) { List<AWSCredentialsProvider> providers = new ArrayList<>(); if (StringUtils.hasText(properties.getAccessKey()) && StringUtils.hasText(properties.getSecretKey())) { providers.add(new AWSStaticCredentialsProvider(new BasicAWSCredentials( properties.getAccessKey(), properties.getSecretKey()))); } if (properties.isInstanceProfile()) { providers.add(new EC2ContainerCredentialsProviderWrapper()); } if (properties.getProfileName() != null) { providers.add(properties.getProfilePath() != null ? new ProfileCredentialsProvider(properties.getProfilePath(), properties.getProfileName()) : new ProfileCredentialsProvider(properties.getProfileName())); } return providers; }
Example #2
Source File: ContextCredentialsAutoConfigurationTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void credentialsProvider_instanceProfileConfigured_configuresInstanceProfileCredentialsProvider() { this.contextRunner.withPropertyValues( "cloud.aws.credentials.use-default-aws-credentials-chain:false", "cloud.aws.credentials.instance-profile:true").run((context) -> { AWSCredentialsProvider awsCredentialsProvider = context.getBean( AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, AWSCredentialsProvider.class); assertThat(awsCredentialsProvider).isNotNull(); @SuppressWarnings("unchecked") List<CredentialsProvider> credentialsProviders = (List<CredentialsProvider>) ReflectionTestUtils .getField(awsCredentialsProvider, "credentialsProviders"); assertThat(credentialsProviders).hasSize(1).hasOnlyElementsOfType( EC2ContainerCredentialsProviderWrapper.class); }); }
Example #3
Source File: ContextCredentialsConfigurationRegistrarTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void credentialsProvider_configWithAccessAndSecretKeyAndInstanceProfile_staticAwsCredentialsProviderConfiguredWithInstanceProfile() throws Exception { // @checkstyle:on // Arrange this.context = new AnnotationConfigApplicationContext( ApplicationConfigurationWithAccessKeyAndSecretKeyAndInstanceProfile.class); // Act AWSCredentialsProvider awsCredentialsProvider = this.context .getBean(AWSCredentialsProvider.class); // Assert assertThat(awsCredentialsProvider).isNotNull(); @SuppressWarnings("unchecked") List<CredentialsProvider> credentialsProviders = (List<CredentialsProvider>) ReflectionTestUtils .getField(awsCredentialsProvider, "credentialsProviders"); assertThat(credentialsProviders.size()).isEqualTo(2); assertThat(AWSStaticCredentialsProvider.class .isInstance(credentialsProviders.get(0))).isTrue(); assertThat(EC2ContainerCredentialsProviderWrapper.class .isInstance(credentialsProviders.get(1))).isTrue(); }
Example #4
Source File: ContextCredentialsConfigurationRegistrarTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void credentialsProvider_configWithInstanceProfile_instanceProfileCredentialsProviderConfigured() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext( ApplicationConfigurationWithInstanceProfileOnly.class); // Act AWSCredentialsProvider awsCredentialsProvider = this.context .getBean(AWSCredentialsProvider.class); // Assert assertThat(awsCredentialsProvider).isNotNull(); @SuppressWarnings("unchecked") List<CredentialsProvider> credentialsProviders = (List<CredentialsProvider>) ReflectionTestUtils .getField(awsCredentialsProvider, "credentialsProviders"); assertThat(credentialsProviders.size()).isEqualTo(1); assertThat(EC2ContainerCredentialsProviderWrapper.class .isInstance(credentialsProviders.get(0))).isTrue(); }
Example #5
Source File: ContextCredentialsConfigurationRegistrarTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void credentialsProvider_configWithAllProviders_allCredentialsProvidersConfigured() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext( ApplicationConfigurationWithAllProviders.class); // Act AWSCredentialsProvider awsCredentialsProvider = this.context .getBean(AWSCredentialsProvider.class); // Assert assertThat(awsCredentialsProvider).isNotNull(); @SuppressWarnings("unchecked") List<CredentialsProvider> credentialsProviders = (List<CredentialsProvider>) ReflectionTestUtils .getField(awsCredentialsProvider, "credentialsProviders"); assertThat(credentialsProviders.size()).isEqualTo(3); assertThat(AWSStaticCredentialsProvider.class .isInstance(credentialsProviders.get(0))).isTrue(); assertThat(EC2ContainerCredentialsProviderWrapper.class .isInstance(credentialsProviders.get(1))).isTrue(); assertThat( ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(2))) .isTrue(); }
Example #6
Source File: S3Service.java From crate with Apache License 2.0 | 6 votes |
static AWSCredentialsProvider buildCredentials(Logger logger, S3ClientSettings clientSettings) { final AWSCredentials credentials = clientSettings.credentials; if (credentials == null) { logger.debug("Using instance profile credentials"); var ec2ContainerCredentialsProviderWrapper = new EC2ContainerCredentialsProviderWrapper(); try { // Check if credentials are available ec2ContainerCredentialsProviderWrapper.getCredentials(); return ec2ContainerCredentialsProviderWrapper; } catch (SdkClientException e) { throw new InvalidArgumentException( "Cannot find required credentials to create a repository of type s3. " + "Credentials must be provided either as repository options access_key and secret_key or AWS IAM roles." ); } } else { logger.debug("Using basic key/secret credentials"); return new AWSStaticCredentialsProvider(credentials); } }
Example #7
Source File: AWSLambdaConfiguration.java From micronaut-aws with Apache License 2.0 | 5 votes |
/** * Constructor. * @param clientConfiguration clientConfiguration * @param environment environment */ public AWSLambdaConfiguration(AWSClientConfiguration clientConfiguration, Environment environment) { this.clientConfiguration = clientConfiguration; this.builder.setCredentials(new AWSCredentialsProviderChain( new EnvironmentAWSCredentialsProvider(environment), new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new ProfileCredentialsProvider(), new EC2ContainerCredentialsProviderWrapper() )); }
Example #8
Source File: AwsModule.java From beam with Apache License 2.0 | 5 votes |
@Override public AWSCredentialsProvider deserializeWithType( JsonParser jsonParser, DeserializationContext context, TypeDeserializer typeDeserializer) throws IOException { Map<String, String> asMap = jsonParser.readValueAs(new TypeReference<Map<String, String>>() {}); String typeNameKey = typeDeserializer.getPropertyName(); String typeName = asMap.get(typeNameKey); if (typeName == null) { throw new IOException( String.format("AWS credentials provider type name key '%s' not found", typeNameKey)); } if (typeName.equals(AWSStaticCredentialsProvider.class.getSimpleName())) { return new AWSStaticCredentialsProvider( new BasicAWSCredentials(asMap.get(AWS_ACCESS_KEY_ID), asMap.get(AWS_SECRET_KEY))); } else if (typeName.equals(PropertiesFileCredentialsProvider.class.getSimpleName())) { return new PropertiesFileCredentialsProvider(asMap.get(CREDENTIALS_FILE_PATH)); } else if (typeName.equals( ClasspathPropertiesFileCredentialsProvider.class.getSimpleName())) { return new ClasspathPropertiesFileCredentialsProvider(asMap.get(CREDENTIALS_FILE_PATH)); } else if (typeName.equals(DefaultAWSCredentialsProviderChain.class.getSimpleName())) { return new DefaultAWSCredentialsProviderChain(); } else if (typeName.equals(EnvironmentVariableCredentialsProvider.class.getSimpleName())) { return new EnvironmentVariableCredentialsProvider(); } else if (typeName.equals(SystemPropertiesCredentialsProvider.class.getSimpleName())) { return new SystemPropertiesCredentialsProvider(); } else if (typeName.equals(ProfileCredentialsProvider.class.getSimpleName())) { return new ProfileCredentialsProvider(); } else if (typeName.equals(EC2ContainerCredentialsProviderWrapper.class.getSimpleName())) { return new EC2ContainerCredentialsProviderWrapper(); } else { throw new IOException( String.format("AWS credential provider type '%s' is not supported", typeName)); } }
Example #9
Source File: DeployTask.java From gradle-beanstalk-plugin with MIT License | 5 votes |
@TaskAction protected void deploy() { String versionLabel = getVersionLabel(); AWSCredentialsProviderChain credentialsProvider = new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new ProfileCredentialsProvider(beanstalk.getProfile()), new EC2ContainerCredentialsProviderWrapper()); BeanstalkDeployer deployer = new BeanstalkDeployer(beanstalk.getS3Endpoint(), beanstalk.getBeanstalkEndpoint(), credentialsProvider); File warFile = getProject().files(war).getSingleFile(); deployer.deploy(warFile, deployment.getApplication(), deployment.getEnvironment(), deployment.getTemplate(), versionLabel); }
Example #10
Source File: HadoopAWSCredentialProviderChain.java From circus-train with Apache License 2.0 | 4 votes |
public HadoopAWSCredentialProviderChain() { super(new EC2ContainerCredentialsProviderWrapper()); }
Example #11
Source File: HadoopAWSCredentialProviderChain.java From circus-train with Apache License 2.0 | 4 votes |
public HadoopAWSCredentialProviderChain(Configuration conf) { // note that the order of these providers is significant as they will be tried in the order passed in super(new JceksAWSCredentialProvider(conf), new AssumeRoleCredentialProvider(conf), new EC2ContainerCredentialsProviderWrapper()); }
Example #12
Source File: CustomCredentialsProviderChain.java From strongbox with Apache License 2.0 | 4 votes |
public CustomCredentialsProviderChain(ClientConfiguration clientConfiguration, ProfileIdentifier profile, Supplier<MFAToken> mfaTokenSupplier) { super(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new ProfileCredentialProvider(clientConfiguration, profile, mfaTokenSupplier), new EC2ContainerCredentialsProviderWrapper()); }
Example #13
Source File: ContextConfigurationUtils.java From spring-cloud-aws with Apache License 2.0 | 4 votes |
public static void registerCredentialsProvider(BeanDefinitionRegistry registry, String accessKey, String secretKey, boolean instanceProfile, String profileName, String profilePath) { BeanDefinitionBuilder factoryBeanBuilder = BeanDefinitionBuilder .genericBeanDefinition(CredentialsProviderFactoryBean.class); ManagedList<BeanDefinition> awsCredentialsProviders = new ManagedList<>(); if (StringUtils.hasText(accessKey)) { BeanDefinitionBuilder credentials = BeanDefinitionBuilder .rootBeanDefinition(BasicAWSCredentials.class); credentials.addConstructorArgValue(accessKey); credentials.addConstructorArgValue(secretKey); BeanDefinitionBuilder provider = BeanDefinitionBuilder .rootBeanDefinition(AWSStaticCredentialsProvider.class); provider.addConstructorArgValue(credentials.getBeanDefinition()); awsCredentialsProviders.add(provider.getBeanDefinition()); } if (instanceProfile) { awsCredentialsProviders.add(BeanDefinitionBuilder .rootBeanDefinition(EC2ContainerCredentialsProviderWrapper.class) .getBeanDefinition()); } if (StringUtils.hasText(profileName)) { BeanDefinitionBuilder builder = BeanDefinitionBuilder .genericBeanDefinition(ProfileCredentialsProvider.class); if (StringUtils.hasText(profilePath)) { builder.addConstructorArgValue(profilePath); } builder.addConstructorArgValue(profileName); awsCredentialsProviders.add(builder.getBeanDefinition()); } factoryBeanBuilder.addConstructorArgValue(awsCredentialsProviders); registry.registerBeanDefinition( CredentialsProviderFactoryBean.CREDENTIALS_PROVIDER_BEAN_NAME, factoryBeanBuilder.getBeanDefinition()); AmazonWebserviceClientConfigurationUtils.replaceDefaultCredentialsProvider( registry, CredentialsProviderFactoryBean.CREDENTIALS_PROVIDER_BEAN_NAME); }