本文整理汇总了Java中com.amazonaws.auth.EnvironmentVariableCredentialsProvider.getCredentials方法的典型用法代码示例。如果您正苦于以下问题:Java EnvironmentVariableCredentialsProvider.getCredentials方法的具体用法?Java EnvironmentVariableCredentialsProvider.getCredentials怎么用?Java EnvironmentVariableCredentialsProvider.getCredentials使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.auth.EnvironmentVariableCredentialsProvider
的用法示例。
在下文中一共展示了EnvironmentVariableCredentialsProvider.getCredentials方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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);
}
}
示例3: 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);
}
}
示例4: getAwsCredentialsFromEnvironment
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider; //导入方法依赖的package包/类
public AWSCredentials getAwsCredentialsFromEnvironment() throws IOException {
EnvironmentVariableCredentialsProvider credentials = new EnvironmentVariableCredentialsProvider();
return credentials.getCredentials();
}