software.amazon.awssdk.auth.credentials.SystemPropertyCredentialsProvider Java Examples
The following examples show how to use
software.amazon.awssdk.auth.credentials.SystemPropertyCredentialsProvider.
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: S3PinotFS.java From incubator-pinot with Apache License 2.0 | 7 votes |
@Override public void init(Configuration config) { Preconditions.checkArgument(!isNullOrEmpty(config.getString(REGION))); String region = config.getString(REGION); AwsCredentialsProvider awsCredentialsProvider; try { if (!isNullOrEmpty(config.getString(ACCESS_KEY)) && !isNullOrEmpty(config.getString(SECRET_KEY))) { String accessKey = config.getString(ACCESS_KEY); String secretKey = config.getString(SECRET_KEY); AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create(accessKey, secretKey); awsCredentialsProvider = StaticCredentialsProvider.create(awsBasicCredentials); } else { awsCredentialsProvider = AwsCredentialsProviderChain.builder().addCredentialsProvider(SystemPropertyCredentialsProvider.create()) .addCredentialsProvider(EnvironmentVariableCredentialsProvider.create()).build(); } _s3Client = S3Client.builder().region(Region.of(region)).credentialsProvider(awsCredentialsProvider).build(); } catch (S3Exception e) { throw new RuntimeException("Could not initialize S3PinotFS", e); } }
Example #2
Source File: ProfileCredentialsUtils.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private AwsCredentialsProvider credentialSourceCredentialProvider(CredentialSourceType credentialSource) { switch (credentialSource) { case ECS_CONTAINER: return ContainerCredentialsProvider.builder().build(); case EC2_INSTANCE_METADATA: return InstanceProfileCredentialsProvider.create(); case ENVIRONMENT: return AwsCredentialsProviderChain.builder() .addCredentialsProvider(SystemPropertyCredentialsProvider.create()) .addCredentialsProvider(EnvironmentVariableCredentialsProvider.create()) .build(); default: throw noSourceCredentialsException(); } }
Example #3
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(StaticCredentialsProvider.class.getSimpleName())) { return StaticCredentialsProvider.create( AwsBasicCredentials.create(asMap.get(ACCESS_KEY_ID), asMap.get(SECRET_ACCESS_KEY))); } else if (typeName.equals(DefaultCredentialsProvider.class.getSimpleName())) { return DefaultCredentialsProvider.create(); } else if (typeName.equals(EnvironmentVariableCredentialsProvider.class.getSimpleName())) { return EnvironmentVariableCredentialsProvider.create(); } else if (typeName.equals(SystemPropertyCredentialsProvider.class.getSimpleName())) { return SystemPropertyCredentialsProvider.create(); } else if (typeName.equals(ProfileCredentialsProvider.class.getSimpleName())) { return ProfileCredentialsProvider.create(); } else if (typeName.equals(ContainerCredentialsProvider.class.getSimpleName())) { return ContainerCredentialsProvider.builder().build(); } else { throw new IOException( String.format("AWS credential provider type '%s' is not supported", typeName)); } }
Example #4
Source File: AwsModuleTest.java From beam with Apache License 2.0 | 5 votes |
@Test public void testAwsCredentialsProviderSerializationDeserialization() throws Exception { AwsCredentialsProvider credentialsProvider = DefaultCredentialsProvider.create(); String serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider); AwsCredentialsProvider deserializedCredentialsProvider = objectMapper.readValue(serializedCredentialsProvider, DefaultCredentialsProvider.class); assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass()); credentialsProvider = EnvironmentVariableCredentialsProvider.create(); serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider); deserializedCredentialsProvider = objectMapper.readValue(serializedCredentialsProvider, AwsCredentialsProvider.class); assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass()); credentialsProvider = SystemPropertyCredentialsProvider.create(); serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider); deserializedCredentialsProvider = objectMapper.readValue(serializedCredentialsProvider, AwsCredentialsProvider.class); assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass()); credentialsProvider = ProfileCredentialsProvider.create(); serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider); deserializedCredentialsProvider = objectMapper.readValue(serializedCredentialsProvider, AwsCredentialsProvider.class); assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass()); credentialsProvider = ContainerCredentialsProvider.builder().build(); serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider); deserializedCredentialsProvider = objectMapper.readValue(serializedCredentialsProvider, AwsCredentialsProvider.class); assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass()); }