List of usage examples for com.amazonaws.internal StaticCredentialsProvider StaticCredentialsProvider
public StaticCredentialsProvider(AWSCredentials credentials)
From source file:hudson.plugins.ec2.EC2Cloud.java
License:Open Source License
public static AWSCredentialsProvider createCredentialsProvider(final boolean useInstanceProfileForCredentials, final String accessId, final Secret secretKey) { if (useInstanceProfileForCredentials) { return new InstanceProfileCredentialsProvider(); }/*from ww w. j av a2 s . co m*/ BasicAWSCredentials credentials = new BasicAWSCredentials(accessId, Secret.toString(secretKey)); return new StaticCredentialsProvider(credentials); }
From source file:io.radiowitness.kinesis.consumer.KclConfigFactory.java
License:Open Source License
private AWSCredentialsProvider credentials() { return new StaticCredentialsProvider( new BasicAWSCredentials(config.getAccessKeyId(), config.getSecretKey())); }
From source file:ohnosequences.ivy.S3Repository.java
License:Apache License
public S3Repository(String accessKey, String secretKey, boolean overwrite, Region region, CannedAccessControlList acl, boolean serverSideEncryption) { AWSCredentialsProvider provider = new InstanceProfileCredentialsProvider(); try {/*from www. jav a2 s . co m*/ provider.getCredentials(); } catch (AmazonClientException e1) { provider = new StaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)); } s3Client = new AmazonS3Client(provider); this.overwrite = overwrite; this.region = region; this.acl = acl; this.serverSideEncryption = serverSideEncryption; }
From source file:org.alfresco.provision.AWSService.java
License:Open Source License
private static AWSCredentialsProvider getCredentials(String accessKeyId, String secretAccessKey) { AWSCredentialsProvider credentials = new StaticCredentialsProvider( new BasicAWSCredentials(accessKeyId, secretAccessKey)); return credentials; }
From source file:org.apache.beam.sdk.io.kinesis.KinesisUploader.java
License:Apache License
public static void uploadAll(List<String> data, KinesisTestOptions options) { AmazonKinesisClient client = new AmazonKinesisClient(new StaticCredentialsProvider( new BasicAWSCredentials(options.getAwsAccessKey(), options.getAwsSecretKey()))) .withRegion(Regions.fromName(options.getAwsKinesisRegion())); List<List<String>> partitions = Lists.partition(data, MAX_NUMBER_OF_RECORDS_IN_BATCH); for (List<String> partition : partitions) { List<PutRecordsRequestEntry> allRecords = newArrayList(); for (String row : partition) { allRecords.add(new PutRecordsRequestEntry().withData(ByteBuffer.wrap(row.getBytes(Charsets.UTF_8))) .withPartitionKey(Integer.toString(row.hashCode())) );/*from www . j a v a 2 s. c om*/ } PutRecordsResult result; do { result = client.putRecords(new PutRecordsRequest().withStreamName(options.getAwsKinesisStream()) .withRecords(allRecords)); List<PutRecordsRequestEntry> failedRecords = newArrayList(); int i = 0; for (PutRecordsResultEntry row : result.getRecords()) { if (row.getErrorCode() != null) { failedRecords.add(allRecords.get(i)); } ++i; } allRecords = failedRecords; } while (result.getFailedRecordCount() > 0); } }
From source file:org.apache.nifi.processors.aws.credentials.provider.factory.strategies.AccessKeyPairCredentialsStrategy.java
License:Apache License
@Override public AWSCredentialsProvider getCredentialsProvider(Map<PropertyDescriptor, String> properties) { String accessKey = properties.get(CredentialPropertyDescriptors.ACCESS_KEY); String secretKey = properties.get(CredentialPropertyDescriptors.SECRET_KEY); BasicAWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey); return new StaticCredentialsProvider(creds); }
From source file:org.apache.nifi.processors.aws.credentials.provider.factory.strategies.AnonymousCredentialsStrategy.java
License:Apache License
@Override public AWSCredentialsProvider getCredentialsProvider(Map<PropertyDescriptor, String> properties) { AnonymousAWSCredentials creds = new AnonymousAWSCredentials(); return new StaticCredentialsProvider(creds); }
From source file:org.apache.usergrid.chop.api.store.amazon.AmazonUtils.java
License:Apache License
/** * @param accessKey//from w w w.ja v a 2s .com * @param secretKey * @return */ public static AmazonEC2Client getEC2Client(String accessKey, String secretKey) { AWSCredentialsProvider provider; if (accessKey != null && secretKey != null) { AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); provider = new StaticCredentialsProvider(credentials); } else { provider = new DefaultAWSCredentialsProviderChain(); } AmazonEC2Client client = new AmazonEC2Client(provider); ClientConfiguration configuration = new ClientConfiguration(); configuration.setProtocol(Protocol.HTTPS); client.setConfiguration(configuration); return client; }
From source file:org.elasticsearch.cloud.aws.AwsEc2Service.java
License:Apache License
public synchronized AmazonEC2 client() { if (client != null) { return client; }//from w w w . ja v a 2s . com ClientConfiguration clientConfiguration = new ClientConfiguration(); String protocol = componentSettings.get("protocol", "http").toLowerCase(); if ("http".equals(protocol)) { clientConfiguration.setProtocol(Protocol.HTTP); } else if ("https".equals(protocol)) { clientConfiguration.setProtocol(Protocol.HTTPS); } else { throw new ElasticsearchIllegalArgumentException( "No protocol supported [" + protocol + "], can either be [http] or [https]"); } String account = componentSettings.get("access_key", settings.get("cloud.account")); String key = componentSettings.get("secret_key", settings.get("cloud.key")); String proxyHost = componentSettings.get("proxy_host"); if (proxyHost != null) { String portString = componentSettings.get("proxy_port", "80"); Integer proxyPort; try { proxyPort = Integer.parseInt(portString, 10); } catch (NumberFormatException ex) { throw new ElasticsearchIllegalArgumentException( "The configured proxy port value [" + portString + "] is invalid", ex); } clientConfiguration.withProxyHost(proxyHost).setProxyPort(proxyPort); } AWSCredentialsProvider credentials; if (account == null && key == null) { credentials = new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new InstanceProfileCredentialsProvider()); } else { credentials = new AWSCredentialsProviderChain( new StaticCredentialsProvider(new BasicAWSCredentials(account, key))); } this.client = new AmazonEC2Client(credentials, clientConfiguration); if (componentSettings.get("ec2.endpoint") != null) { String endpoint = componentSettings.get("ec2.endpoint"); logger.debug("using explicit ec2 endpoint [{}]", endpoint); client.setEndpoint(endpoint); } else if (componentSettings.get("region") != null) { String region = componentSettings.get("region").toLowerCase(); String endpoint; if (region.equals("us-east-1") || region.equals("us-east")) { endpoint = "ec2.us-east-1.amazonaws.com"; } else if (region.equals("us-west") || region.equals("us-west-1")) { endpoint = "ec2.us-west-1.amazonaws.com"; } else if (region.equals("us-west-2")) { endpoint = "ec2.us-west-2.amazonaws.com"; } else if (region.equals("ap-southeast") || region.equals("ap-southeast-1")) { endpoint = "ec2.ap-southeast-1.amazonaws.com"; } else if (region.equals("ap-southeast-2")) { endpoint = "ec2.ap-southeast-2.amazonaws.com"; } else if (region.equals("ap-northeast") || region.equals("ap-northeast-1")) { endpoint = "ec2.ap-northeast-1.amazonaws.com"; } else if (region.equals("eu-west") || region.equals("eu-west-1")) { endpoint = "ec2.eu-west-1.amazonaws.com"; } else if (region.equals("sa-east") || region.equals("sa-east-1")) { endpoint = "ec2.sa-east-1.amazonaws.com"; } else { throw new ElasticsearchIllegalArgumentException( "No automatic endpoint could be derived from region [" + region + "]"); } if (endpoint != null) { logger.debug("using ec2 region [{}], with endpoint [{}]", region, endpoint); client.setEndpoint(endpoint); } } return this.client; }
From source file:org.elasticsearch.cloud.aws.AwsEc2ServiceImpl.java
License:Apache License
protected static AWSCredentialsProvider buildCredentials(Logger logger, Settings settings) { AWSCredentialsProvider credentials;/*w w w . java 2 s . co m*/ String key = CLOUD_EC2.KEY_SETTING.get(settings); String secret = CLOUD_EC2.SECRET_SETTING.get(settings); if (key.isEmpty() && secret.isEmpty()) { logger.debug("Using either environment variables, system properties or instance profile credentials"); credentials = new DefaultAWSCredentialsProviderChain(); } else { logger.debug("Using basic key/secret credentials"); credentials = new StaticCredentialsProvider(new BasicAWSCredentials(key, secret)); } return credentials; }