Search in sources :

Example 81 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project hippo by NHS-digital-website.

the class S3ConnectorServiceRegistrationModule method getAmazonS3.

private AmazonS3 getAmazonS3() {
    AWSCredentialsProvider provider = new SystemPropertiesCredentialsProvider();
    AmazonS3ClientBuilder s3Builder = AmazonS3ClientBuilder.standard().withCredentials(provider).withRegion(Regions.fromName(s3Region));
    if (!s3Endpoint.isEmpty()) {
        s3Builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(s3Endpoint, s3Region));
    }
    return s3Builder.build();
}
Also used : SystemPropertiesCredentialsProvider(com.amazonaws.auth.SystemPropertiesCredentialsProvider) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 82 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project kafka-connect-storage-cloud by confluentinc.

the class TestWithMockedS3 method newS3Client.

@Override
public AmazonS3 newS3Client(S3SinkConnectorConfig config) {
    final AWSCredentialsProvider provider = new AWSCredentialsProvider() {

        private final AnonymousAWSCredentials credentials = new AnonymousAWSCredentials();

        @Override
        public AWSCredentials getCredentials() {
            return credentials;
        }

        @Override
        public void refresh() {
        }
    };
    AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard().withAccelerateModeEnabled(config.getBoolean(S3SinkConnectorConfig.WAN_MODE_CONFIG)).withPathStyleAccessEnabled(true).withCredentials(provider);
    builder = url == null ? builder.withRegion(config.getString(S3SinkConnectorConfig.REGION_CONFIG)) : builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(url, ""));
    return builder.build();
}
Also used : AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) AnonymousAWSCredentials(com.amazonaws.auth.AnonymousAWSCredentials) AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 83 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project herd by FINRAOS.

the class S3DaoTest method testGetAWSCredentialsProviderAssertStaticCredentialsIsNotSetWhenAccessKeyIsNull.

@Test
public void testGetAWSCredentialsProviderAssertStaticCredentialsIsNotSetWhenAccessKeyIsNull() {
    S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations");
    S3Operations mockS3Operations = mock(S3Operations.class);
    ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations);
    try {
        String s3BucketName = "s3BucketName";
        String s3KeyPrefix = "s3KeyPrefix";
        String s3AccessKey = null;
        String s3SecretKey = "s3SecretKey";
        S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
        s3FileTransferRequestParamsDto.setS3BucketName(s3BucketName);
        s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix);
        s3FileTransferRequestParamsDto.setAwsAccessKeyId(s3AccessKey);
        s3FileTransferRequestParamsDto.setAwsSecretKey(s3SecretKey);
        when(mockS3Operations.putObject(any(), any())).then(new Answer<PutObjectResult>() {

            @SuppressWarnings("unchecked")
            @Override
            public PutObjectResult answer(InvocationOnMock invocation) throws Throwable {
                AmazonS3Client amazonS3Client = invocation.getArgument(1);
                AWSCredentialsProviderChain awsCredentialsProviderChain = (AWSCredentialsProviderChain) ReflectionTestUtils.getField(amazonS3Client, "awsCredentialsProvider");
                List<AWSCredentialsProvider> credentialsProviders = (List<AWSCredentialsProvider>) ReflectionTestUtils.getField(awsCredentialsProviderChain, "credentialsProviders");
                assertEquals(1, credentialsProviders.size());
                assertEquals(DefaultAWSCredentialsProviderChain.class, credentialsProviders.get(0).getClass());
                return new PutObjectResult();
            }
        });
        s3Dao.createDirectory(s3FileTransferRequestParamsDto);
    } finally {
        ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations);
    }
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) PutObjectResult(com.amazonaws.services.s3.model.PutObjectResult) DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) AWSCredentialsProviderChain(com.amazonaws.auth.AWSCredentialsProviderChain) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) InvocationOnMock(org.mockito.invocation.InvocationOnMock) List(java.util.List) ArrayList(java.util.ArrayList) HerdAWSCredentialsProvider(org.finra.herd.model.dto.HerdAWSCredentialsProvider) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 84 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project halyard by spinnaker.

the class S3Validator method validate.

@Override
public void validate(ConfigProblemSetBuilder ps, S3PersistentStore n) {
    if (!StringUtils.isEmpty(n.getEndpoint())) {
        return;
    }
    try {
        AWSCredentialsProvider credentialsProvider = AwsAccountValidator.getAwsCredentialsProvider(n.getAccessKeyId(), n.getSecretAccessKey());
        S3Config s3Config = new S3Config();
        S3Properties s3Properties = new S3Properties();
        s3Properties.setBucket(n.getBucket());
        s3Properties.setRootFolder(n.getRootFolder());
        s3Properties.setRegion(n.getRegion());
        AmazonS3 s3Client = s3Config.awsS3Client(credentialsProvider, s3Properties);
        new S3Config().s3StorageService(s3Client, s3Properties);
    } catch (Exception e) {
        ps.addProblem(Problem.Severity.ERROR, "Failed to ensure the required bucket \"" + n.getBucket() + "\" exists: " + e.getMessage());
    }
}
Also used : S3Config(com.netflix.spinnaker.front50.config.S3Config) AmazonS3(com.amazonaws.services.s3.AmazonS3) S3Properties(com.netflix.spinnaker.front50.config.S3Properties) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 85 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project opencast by opencast.

the class AwsS3DistributionServiceImpl method activate.

@Override
public void activate(ComponentContext cc) {
    // Get the configuration
    if (cc != null) {
        if (!Boolean.valueOf(getAWSConfigKey(cc, AWS_S3_DISTRIBUTION_ENABLE))) {
            logger.info("AWS S3 distribution disabled");
            return;
        }
        // AWS S3 bucket name
        bucketName = getAWSConfigKey(cc, AWS_S3_BUCKET_CONFIG);
        logger.info("AWS S3 bucket name is {}", bucketName);
        // AWS region
        String regionStr = getAWSConfigKey(cc, AWS_S3_REGION_CONFIG);
        logger.info("AWS region is {}", regionStr);
        opencastDistributionUrl = getAWSConfigKey(cc, AWS_S3_DISTRIBUTION_BASE_CONFIG);
        if (!opencastDistributionUrl.endsWith("/")) {
            opencastDistributionUrl = opencastDistributionUrl + "/";
        }
        logger.info("AWS distribution url is {}", opencastDistributionUrl);
        // Explicit credentials are optional.
        AWSCredentialsProvider provider = null;
        Option<String> accessKeyIdOpt = OsgiUtil.getOptCfg(cc.getProperties(), AWS_S3_ACCESS_KEY_ID_CONFIG);
        Option<String> accessKeySecretOpt = OsgiUtil.getOptCfg(cc.getProperties(), AWS_S3_SECRET_ACCESS_KEY_CONFIG);
        // profile credentials
        if (accessKeyIdOpt.isNone() && accessKeySecretOpt.isNone())
            provider = new DefaultAWSCredentialsProviderChain();
        else
            provider = new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKeyIdOpt.get(), accessKeySecretOpt.get()));
        // Create AWS client.
        s3 = AmazonS3ClientBuilder.standard().withRegion(regionStr).withCredentials(provider).build();
        s3TransferManager = new TransferManager(s3);
        // Create AWS S3 bucket if not there yet
        createAWSBucket();
        distributionChannel = OsgiUtil.getComponentContextProperty(cc, CONFIG_KEY_STORE_TYPE);
        logger.info("AwsS3DistributionService activated!");
    }
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) TransferManager(com.amazonaws.services.s3.transfer.TransferManager) AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Aggregations

AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)121 Test (org.junit.Test)73 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)24 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)19 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)17 AWSCredentials (com.amazonaws.auth.AWSCredentials)16 TestRunner (org.apache.nifi.util.TestRunner)15 ClientConfiguration (com.amazonaws.ClientConfiguration)12 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)12 STSAssumeRoleSessionCredentialsProvider (com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider)8 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)8 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)8 AWSCredentialsProviderChain (com.amazonaws.auth.AWSCredentialsProviderChain)7 ClasspathPropertiesFileCredentialsProvider (com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider)7 EnvironmentVariableCredentialsProvider (com.amazonaws.auth.EnvironmentVariableCredentialsProvider)7 SystemPropertiesCredentialsProvider (com.amazonaws.auth.SystemPropertiesCredentialsProvider)7 ArrayList (java.util.ArrayList)7 Properties (java.util.Properties)7 Configuration (org.apache.hadoop.conf.Configuration)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7