本文整理汇总了Java中com.amazonaws.auth.EnvironmentVariableCredentialsProvider类的典型用法代码示例。如果您正苦于以下问题:Java EnvironmentVariableCredentialsProvider类的具体用法?Java EnvironmentVariableCredentialsProvider怎么用?Java EnvironmentVariableCredentialsProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EnvironmentVariableCredentialsProvider类属于com.amazonaws.auth包,在下文中一共展示了EnvironmentVariableCredentialsProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCredentialProviderC
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider; //导入依赖的package包/类
public static AWSCredentialsProvider getCredentialProviderC(Parameters config){
List<AWSCredentialsProvider> providers = new ArrayList<AWSCredentialsProvider>();
if ("YES".equals(config.get("aws.credentials.instaneProfile")))
providers.add(new InstanceProfileCredentialsProvider());
if ("YES".equals(config.get("aws.credentials.environmentVariable")))
providers.add(new EnvironmentVariableCredentialsProvider());
if ("YES".equals(config.get("aws.credentials.systemProperties")))
providers.add(new SystemPropertiesCredentialsProvider());
String accessKey = config.get("aws.credentials.accessKey").toString();
String secretKey = config.get("aws.credentials.secretKey").toString();
if (accessKey != null && accessKey.length() > 0){
providers.add(new AWSCredentialsConfigFileProvider(accessKey, secretKey));
}
return new AWSCredentialsProviderChain(providers.toArray(new AWSCredentialsProvider[0]));
}
示例2: getAWSCredentialsProviderChain
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider; //导入依赖的package包/类
public static AWSCredentialsProviderChain getAWSCredentialsProviderChain() {
String cerberusRoleToAssume = System.getenv(CERBERUS_ASSUME_ROLE_ARN) != null ?
System.getenv(CERBERUS_ASSUME_ROLE_ARN) : "";
String cerberusRoleToAssumeExternalId = System.getenv(CERBERUS_ASSUME_ROLE_EXTERNAL_ID) != null ?
System.getenv(CERBERUS_ASSUME_ROLE_EXTERNAL_ID) : "";
STSAssumeRoleSessionCredentialsProvider sTSAssumeRoleSessionCredentialsProvider =
new STSAssumeRoleSessionCredentialsProvider
.Builder(cerberusRoleToAssume, UUID.randomUUID().toString())
.withExternalId(cerberusRoleToAssumeExternalId)
.build();
AWSCredentialsProviderChain chain = new AWSCredentialsProviderChain(
new EnvironmentVariableCredentialsProvider(),
new SystemPropertiesCredentialsProvider(),
new ProfileCredentialsProvider(),
sTSAssumeRoleSessionCredentialsProvider,
new InstanceProfileCredentialsProvider());
return chain;
}
示例3: handleRequest
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider; //导入依赖的package包/类
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
String apiIntputStream = new Scanner(inputStream).useDelimiter("\\A").next();
JsonNode rootNode = (new ObjectMapper(new JsonFactory())).readTree(apiIntputStream);
String myApiId = rootNode.path("requestContext").path("apiId").asText();
if (myApiId.isEmpty()) { myApiId = "TODO"; } // Not called from API Gateway
final GenericApiGatewayClient client = new GenericApiGatewayClientBuilder()
.withClientConfiguration(new ClientConfiguration())
.withCredentials(new EnvironmentVariableCredentialsProvider())
.withEndpoint("https://" + myApiId + ".execute-api.us-west-2.amazonaws.com") // your API ID
.withRegion(Region.getRegion(Regions.fromName("us-west-2")))
.build();
GenericApiGatewayResponse apiResponse;
ProxyResponse resp;
try {
apiResponse = client.execute( // throws exception for non-2xx response
new GenericApiGatewayRequestBuilder()
.withHttpMethod(HttpMethodName.GET)
.withResourcePath("/Prod/hello").build());
System.out.println("Response: " + apiResponse.getBody());
System.out.println("Status: " + apiResponse.getHttpResponse().getStatusCode());
resp = new ProxyResponse("200", apiResponse.getBody());
} catch (GenericApiGatewayException e) {
System.out.println("Client threw exception " + e);
resp = new ProxyResponse("400", e.getMessage());
}
String responseString = new ObjectMapper(new JsonFactory()).writeValueAsString(resp);
OutputStreamWriter writer = new OutputStreamWriter(outputStream, "UTF-8");
writer.write(responseString);
writer.close();
}
示例4: ApiImporter
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public ApiImporter(String profile, String accessKey, String secret) {
if (accessKey != null && secret != null) {
credentialsProvider=new AWSCredentialsProvider() {
@Override
public void refresh() {
}
@Override
public AWSCredentials getCredentials() {
return new AWSCredentials() {
@Override
public String getAWSSecretKey() {
return secret;
}
@Override
public String getAWSAccessKeyId() {
return accessKey;
}
};
}
};
} else {
credentialsProvider = new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(),
new SystemPropertiesCredentialsProvider(), new ProfileCredentialsProvider(profile),
new InstanceProfileCredentialsProvider());
}
amazonApiGatewayClient = new AmazonApiGatewayClient(credentialsProvider);
}
示例5: MyCredentialsProvider
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider; //导入依赖的package包/类
MyCredentialsProvider() {
super(new EnvironmentVariableCredentialsProvider(),
new SystemPropertiesCredentialsProvider(),
// Removed due to ElasticBeanstalk environment not being setup with a profile dir
// new ProfileCredentialsProvider(),
new InstanceProfileCredentialsProvider(),
new ClasspathPropertiesFileCredentialsProvider());
}
示例6: getFromAWSS3Storage
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider; //导入依赖的package包/类
public byte[] getFromAWSS3Storage(String name) throws Exception {
AmazonS3 s3Client = new AmazonS3Client(new EnvironmentVariableCredentialsProvider());
S3Object object = s3Client.getObject(
new GetObjectRequest(containerName, name));
InputStream objectData = object.getObjectContent();
return IOUtils.toByteArray(objectData);
}
示例7: AuthenticationInfoAWSCredentialsProviderChain
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider; //导入依赖的package包/类
AuthenticationInfoAWSCredentialsProviderChain(AuthenticationInfo authenticationInfo) {
super(
new InstanceProfileCredentialsProvider(),
new ProfileCredentialsProvider(),
new EnvironmentVariableCredentialsProvider(),
new SystemPropertiesCredentialsProvider(),
new InstanceProfileCredentialsProvider());
}
开发者ID:lambadaframework,项目名称:lambadaframework,代码行数:9,代码来源:AuthenticationInfoAWSCredentialsProviderChain.java
示例8: getS3Client
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider; //导入依赖的package包/类
private AmazonS3Client getS3Client() {
Optional<AWSCredentials> credentials = getCredentials();
if (credentials.isPresent()) {
return new AmazonS3Client(credentials.get());
} else {
return new AmazonS3Client(new EnvironmentVariableCredentialsProvider());
}
}
示例9: getSNSClient
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider; //导入依赖的package包/类
private AmazonSNSClient getSNSClient() {
Optional<AWSCredentials> credentials = getCredentials();
if (credentials.isPresent()) {
return new AmazonSNSClient(credentials.get());
} else {
return new AmazonSNSClient(new EnvironmentVariableCredentialsProvider());
}
}
示例10: shouldPerformUploadToS3Bucket
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider; //导入依赖的package包/类
@Test
@Ignore
public void shouldPerformUploadToS3Bucket() throws Exception {
File testFile = FileGenerator.generate(temporaryFolder.getRoot(), (1024 * 1024 * 1));
ByteRange byteRange = new ByteRange(0, testFile.length() - 1);
ImmutableList<HashStrategy> hashStrategies = ImmutableList.of(Hashes.getHashStrategy(Hashes.SHA256, byteRange), Hashes.getHashStrategy(Hashes.MD5_BASE64, byteRange));
List<Hash> hashes;
try (FileInputStream fileInputStream = new FileInputStream(testFile)) {
hashes = ByteStreams.readBytes(fileInputStream, new HashByteProcessor(hashStrategies));
}
Comparator<Hash> hashComparator = (o1, o2) -> o1.getOffset().compareTo(o2.getOffset());
List<Hash> signingHashes = hashes.stream().filter(hash -> hash.getAlgorithm().equals(Hashes.SHA256)).sorted(hashComparator).collect(ImmutableListCollector.toImmutableList());
List<Hash> partHashes = hashes.stream().filter(hash -> hash.getAlgorithm().equals(Hashes.MD5_BASE64)).sorted(hashComparator).collect(ImmutableListCollector.toImmutableList());
EnvironmentVariableCredentialsProvider credentialsProvider = new EnvironmentVariableCredentialsProvider();
AWSCredentials credentials = credentialsProvider.getCredentials();
S3Upload s3Upload = new S3Upload(credentials, HOST, "us-west-1", "/" + KEY, BUCKET, KEY, null);
try (FileInputStream fileInputStream = new FileInputStream(testFile)) {
s3Client.uploadObject(s3Upload, "testing", signingHashes.get(0).getValue(), partHashes.get(0).getValue(), testFile.length(), fileInputStream);
} catch (Exception e) {
LOGGER.error(e, e);
}
}
示例11: shouldPerformMultipartUploadToS3Bucket
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider; //导入依赖的package包/类
@Test
@Ignore
public void shouldPerformMultipartUploadToS3Bucket() throws Exception {
File testFile = FileGenerator.generate(temporaryFolder.getRoot(), (1024 * 1024 * 10));
ImmutableList<HashStrategy> hashStrategies = Hashes.createByteRanges(PART_SIZE, testFile.length()).stream()
.map(byteRange -> ImmutableList.of(Hashes.getHashStrategy(Hashes.SHA256, byteRange), Hashes.getHashStrategy(Hashes.MD5_BASE64, byteRange))).collect(ImmutableListsCollector.toImmutableList());
List<Hash> hashes;
try (FileInputStream fileInputStream = new FileInputStream(testFile)) {
hashes = ByteStreams.readBytes(fileInputStream, new HashByteProcessor(hashStrategies));
}
Comparator<Hash> hashComparator = (o1, o2) -> o1.getOffset().compareTo(o2.getOffset());
List<Hash> signingHashes = hashes.stream().filter(hash -> hash.getAlgorithm().equals(Hashes.SHA256)).sorted(hashComparator).collect(ImmutableListCollector.toImmutableList());
List<Hash> partHashes = hashes.stream().filter(hash -> hash.getAlgorithm().equals(Hashes.MD5_BASE64)).sorted(hashComparator).collect(ImmutableListCollector.toImmutableList());
List<AWSUploadPart> uploadParts = IntStream.range(0, signingHashes.size()).mapToObj(index -> {
Hash signingHash = signingHashes.get(index);
Hash partHash = partHashes.get(index);
return new AWSUploadPart(index, signingHash.getOffset(), signingHash.getLength().get(), signingHash.getValue(), partHash.getValue());
}).collect(ImmutableListCollector.toImmutableList());
EnvironmentVariableCredentialsProvider credentialsProvider = new EnvironmentVariableCredentialsProvider();
AWSCredentials credentials = credentialsProvider.getCredentials();
S3Upload initS3Upload = new S3Upload(credentials, HOST, "us-west-1", "/" + KEY, BUCKET, KEY, null);
String uploadId = s3Client.initiateMultipartUpload(initS3Upload, testFile.getName());
S3Upload s3Upload = new S3Upload(credentials, HOST, "us-west-1", "/" + KEY, BUCKET, KEY, uploadId);
try (FileInputStream fileInputStream = new FileInputStream(testFile)) {
List<S3Part> s3Parts = uploadParts.stream().map(uploadPart -> s3Client.uploadMultipartPart(s3Upload, uploadPart, PART_SIZE, fileInputStream)).collect(Collectors.toList());
s3Client.completeMultipartUpload(s3Upload, s3Parts);
} catch (Exception e) {
LOGGER.error(e, e);
s3Client.abortMultipartUpload(s3Upload);
}
}
示例12: shouldUploadToGlacierVault
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider; //导入依赖的package包/类
@Test
@Ignore
public void shouldUploadToGlacierVault() throws Exception {
File testFile = FileGenerator.generate(temporaryFolder.getRoot(), (1024 * 1024 * 10));
// create SHA-256 and MD5 hashes for each part
EnvironmentVariableCredentialsProvider credentialsProvider = new EnvironmentVariableCredentialsProvider();
AWSCredentials credentials = credentialsProvider.getCredentials();
String uploadId = glacierClient.initiateMultipartUpload(credentials, "us-west-1", "dev", "testing", 4194304);
try (FileInputStream fileInputStream = new FileInputStream(testFile)) {
URI destination =
new URI("glacier://" + credentials.getAWSAccessKeyId() + ":" + credentials.getAWSSecretKey() + "@glacier.us-west-1.amazonaws.com/-/vaults/dev/multipart-uploads/" + uploadId);
GlacierUpload glacierUpload = AWSClients.glacierUploadFromURI(destination);
ImmutableList.Builder<AWSUploadPart> uploadPartBuilder = ImmutableList.builder();
uploadPartBuilder
.add(new AWSUploadPart(0, 0, 4194304, "c72bed74619a0238b707f13fd6ee8bec14cc7779caca89248350ebc1ac9725ec", "ec9364f600b5e47c533056a548fda46affb964198244fe9d08540ad3884aa89f"));
uploadPartBuilder.add(new AWSUploadPart(1, 4194304, 8388608, "dfc5f7fead60530c8f6155ef3405e7b1f21bdabf2dc2a7dc26573ad6dd44251e",
"9deb0b59576f96e20efb79d09c274b6db16533314d37d1f1b74145283550031f"));
uploadPartBuilder.add(new AWSUploadPart(2, 8388608, 10486525, "1da69b95fc1a32b26957c70b39fd3adf88c4726f77cf338fbeecf43bf50c0067",
"1e7d14612ffb9cb4dae4dcedb8fd24dbd4d916fbf93677e782074dfc5986f54c"));
uploadPartBuilder.build().forEach(uploadPart -> glacierClient.uploadMultipartPart(glacierUpload, uploadPart, 4194304, fileInputStream));
String archiveId = glacierClient.completeMultipartUpload(credentials, "us-west-1", "dev", uploadId, testFile.length(), "2b30a705e4dcfd60c89a5596c6d4d1ddf5c1a1576271fbada358a319175020cd");
} catch (Exception e) {
LOGGER.error(e);
glacierClient.abortMultipartUpload(credentials, "us-west-1", "dev", uploadId);
}
}
示例13: deploy
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider; //导入依赖的package包/类
@TaskAction
protected void deploy() {
String versionLabel = getVersionLabel();
AWSCredentialsProviderChain credentialsProvider = new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new ProfileCredentialsProvider(beanstalk.getProfile()));
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);
}
示例14: getCredentials
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider; //导入依赖的package包/类
/**
*
* @return
*/
private AWSCredentialsProvider getCredentials() {
return new AWSCredentialsProviderChain(new StaticCredentialsProvider(
new AppenderCredentials()), new SystemPropertiesCredentialsProvider(),
new EnvironmentVariableCredentialsProvider(),
new ProfileCredentialsProvider(),
new InstanceProfileCredentialsProvider());
}
示例15: getEnvironmentVariableCredentialsProvider
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider; //导入依赖的package包/类
private static AWSCredentialsProvider getEnvironmentVariableCredentialsProvider() {
AWSCredentialsProvider provider = new EnvironmentVariableCredentialsProvider();
try {
AWSCredentials credentials = provider.getCredentials();
if (credentials != null && credentials.getAWSAccessKeyId() != null && credentials.getAWSSecretKey() != null) {
return provider;
}
} catch (Throwable t) {
//Ignore
}
return null;
}