Search in sources :

Example 86 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)

Example 87 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project kylo by Teradata.

the class S3FileSystemProvider method createS3Client.

/**
 * Creates an S3 client with the standard credential providers.
 */
@VisibleForTesting
protected AmazonS3 createS3Client(@Nonnull final URI uri, @Nonnull final Configuration conf) {
    // Create list of credential providers
    final List<AWSCredentialsProvider> credentials = new ArrayList<>();
    getCustomCredentialsProvider(uri, conf).ifPresent(credentials::add);
    getBasicCredentialsProvider(uri, conf).ifPresent(credentials::add);
    credentials.add(InstanceProfileCredentialsProvider.getInstance());
    // Create client
    final AWSCredentialsProviderChain chain = new AWSCredentialsProviderChain(credentials);
    chain.setReuseLastProvider(true);
    return AmazonS3ClientBuilder.standard().withCredentials(chain).build();
}
Also used : ArrayList(java.util.ArrayList) BasicAWSCredentialsProvider(org.apache.hadoop.fs.s3a.BasicAWSCredentialsProvider) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) AWSCredentialsProviderChain(com.amazonaws.auth.AWSCredentialsProviderChain) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 88 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project kylo by Teradata.

the class S3FileSystemProviderTest method getCustomCredentialsProvider.

/**
 * Verify creating a custom credentials provider.
 */
@Test
@SuppressWarnings("squid:S3655")
public void getCustomCredentialsProvider() {
    // Test empty configuration
    final S3FileSystemProvider provider = new S3FileSystemProvider();
    Assert.assertFalse("Expected empty credentials", provider.getCustomCredentialsProvider(S3N, new Configuration(false)).isPresent());
    // Test with custom credentials provider
    final Configuration conf = new Configuration(false);
    conf.setClass("fs.s3.customAWSCredentialsProvider", EnvironmentVariableCredentialsProvider.class, AWSCredentialsProvider.class);
    final Optional<AWSCredentialsProvider> credentials = provider.getCustomCredentialsProvider(S3N, conf);
    Assert.assertTrue("Expected custom credentials", credentials.isPresent());
    Assert.assertTrue("Expected EnvironmentVariableCredentialsProvider", credentials.get() instanceof EnvironmentVariableCredentialsProvider);
}
Also used : EnvironmentVariableCredentialsProvider(com.amazonaws.auth.EnvironmentVariableCredentialsProvider) Configuration(org.apache.hadoop.conf.Configuration) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 89 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project kylo by Teradata.

the class S3FileSystemProviderTest method getBasicCredentialsProvider.

/**
 * Verify reading basic credentials.
 */
@Test
@SuppressWarnings("squid:S3655")
public void getBasicCredentialsProvider() {
    // Test empty configuration
    final S3FileSystemProvider provider = new S3FileSystemProvider();
    Assert.assertFalse("Expected empty credentials", provider.getBasicCredentialsProvider(S3N, new Configuration(false)).isPresent());
    // Test configuration credentials
    final Configuration conf = new Configuration(false);
    conf.set("fs.s3n.awsAccessKeyId", "S3N_ACCESS_KEY");
    conf.set("fs.s3n.awsSecretAccessKey", "S3N_SECRET_KEY");
    final Optional<AWSCredentialsProvider> credentialsProvider = provider.getBasicCredentialsProvider(S3N, conf);
    Assert.assertTrue("Expected URI credentials", credentialsProvider.isPresent());
    final AWSCredentials credentials = credentialsProvider.get().getCredentials();
    Assert.assertEquals("S3N_ACCESS_KEY", credentials.getAWSAccessKeyId());
    Assert.assertEquals("S3N_SECRET_KEY", credentials.getAWSSecretKey());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 90 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project ignite by apache.

the class DiscoveryInTheCloud method awsExample2.

public static void awsExample2() {
    // tag::aws2[]
    TcpDiscoverySpi spi = new TcpDiscoverySpi();
    AWSCredentialsProvider instanceProfileCreds = new InstanceProfileCredentialsProvider(false);
    TcpDiscoveryS3IpFinder ipFinder = new TcpDiscoveryS3IpFinder();
    ipFinder.setAwsCredentialsProvider(instanceProfileCreds);
    ipFinder.setBucketName("yourBucketName");
    spi.setIpFinder(ipFinder);
    IgniteConfiguration cfg = new IgniteConfiguration();
    // Override default discovery SPI.
    cfg.setDiscoverySpi(spi);
    // Start a node.
    Ignition.start(cfg);
// end::aws2[]
}
Also used : InstanceProfileCredentialsProvider(com.amazonaws.auth.InstanceProfileCredentialsProvider) TcpDiscoveryS3IpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.s3.TcpDiscoveryS3IpFinder) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Aggregations

AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)125 Test (org.junit.Test)75 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)26 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)20 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)19 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