本文整理汇总了Java中com.amazonaws.auth.DefaultAWSCredentialsProviderChain类的典型用法代码示例。如果您正苦于以下问题:Java DefaultAWSCredentialsProviderChain类的具体用法?Java DefaultAWSCredentialsProviderChain怎么用?Java DefaultAWSCredentialsProviderChain使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultAWSCredentialsProviderChain类属于com.amazonaws.auth包,在下文中一共展示了DefaultAWSCredentialsProviderChain类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: retrieve
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; //导入依赖的package包/类
@Override
public String retrieve(String file) throws Exception {
LogUtils.debug(LOG_TAG, "Downloading file: " + file);
TransferManager tm = new TransferManager(new DefaultAWSCredentialsProviderChain());
// TransferManager processes all transfers asynchronously,
// so this call will return immediately.
File downloadedFile = new File(Constants.MCSFS_WORKING_DIR + Constants.S3_WORKING_DIR + file + System.currentTimeMillis());
downloadedFile.getParentFile().mkdirs();
downloadedFile.createNewFile();
Download download = tm.download(bucketName, file, downloadedFile);
download.waitForCompletion();
LogUtils.debug(LOG_TAG, "Successfully downloaded file from bucket.\nName: " + file + "\nBucket name: " +
bucketName);
tm.shutdownNow();
return downloadedFile.getAbsolutePath();
}
示例2: createRepository
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; //导入依赖的package包/类
public static ContentRepository createRepository(boolean reset) {
if (isDynamoDBStore()) {
AmazonDynamoDBClient dynamodb = new AmazonDynamoDBClient(new DefaultAWSCredentialsProviderChain());
dynamodb.setEndpoint("http://localhost:8000");
performReset(reset, dynamodb);
NodeStore store = new DocumentMK.Builder()
.setDynamoDB(dynamodb)
.open().getNodeStore();
return new Oak(store)
.with(new InitialContent())
.with(new OpenSecurityProvider())
.createContentRepository();
}
return null;
}
示例3: get
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; //导入依赖的package包/类
@Override
public Credentials get() {
if (getIdentity() == null || getIdentity().trim().isEmpty() || getCredential() == null || getCredential().trim().isEmpty()) {
DefaultAWSCredentialsProviderChain chain = new DefaultAWSCredentialsProviderChain();
AWSCredentials cred = chain.getCredentials();
if (cred instanceof BasicSessionCredentials) {
BasicSessionCredentials sesCred = (BasicSessionCredentials)cred;
return new SessionCredentials.Builder()
.identity(sesCred.getAWSAccessKeyId())
.credential(sesCred.getAWSSecretKey())
.sessionToken(sesCred.getSessionToken())
.build();
} else {
return new Credentials.Builder<>()
.identity(cred.getAWSAccessKeyId())
.credential(cred.getAWSSecretKey())
.build();
}
}
return super.get();
}
示例4: createSQSAsync
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; //导入依赖的package包/类
@Override
public AmazonSQS createSQSAsync(final SQSQueue queue) {
AWSCredentialsProvider credentials = queue.hasCredentials() ? queue.lookupAwsCredentials() : DefaultAWSCredentialsProviderChain.getInstance();
AmazonSQSAsyncClientBuilder sqsAsyncBuilder = createStandardAsyncClientBuilder(queue, credentials);
final QueueBufferConfig queueBufferConfig = this.getQueueBufferConfig(queue);
final AmazonSQSBufferedAsyncClient sqsBufferedAsync = new AmazonSQSBufferedAsyncClient(sqsAsyncBuilder.build(), queueBufferConfig);
return sqsBufferedAsync;
}
示例5: cleanUpFromPreviousRuns
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; //导入依赖的package包/类
public static void cleanUpFromPreviousRuns(Regions testRegion, String groupPrefix) {
LOG.info("Cleaning up from previous test runs...");
// Get time an hour ago to clean up anything that was created more than an hour ago. That should be more than
// enough time for test runs so anything left over by that time will be junk to clean up.
Date createdBeforeThreshold = new Date(System.currentTimeMillis() - (60 * 60 * 1000));
// Resource prefix for the test groups so we only clean up the resources related to the tests.
// TODO is there a method somewhere that will construct this for me so it will always match the
// actual names constructed by the code?
String testResourcePrefix = String.format(
"strongbox_%s_%s", testRegion.getName(),
AWSResourceNameSerialization.encodeSecretsGroupName(groupPrefix));
AWSCredentialsProvider awsCredentials = new DefaultAWSCredentialsProviderChain();
cleanUpDynamoDBTables(testRegion, testResourcePrefix, createdBeforeThreshold, awsCredentials);
cleanUpKMSKeys(testRegion, testResourcePrefix, createdBeforeThreshold, awsCredentials);
cleanUpIAM(testRegion, testResourcePrefix, createdBeforeThreshold, awsCredentials);
}
示例6: remove
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; //导入依赖的package包/类
@Override
public void remove(String accessKey) throws Exception {
LogUtils.debug(LOG_TAG, "Deleting file with access key: " + accessKey);
AmazonS3 s3Client = new AmazonS3Client(new DefaultAWSCredentialsProviderChain());
DeleteObjectsRequest multiObjectDeleteRequest = new DeleteObjectsRequest(bucketName);
List<KeyVersion> keys = new ArrayList<KeyVersion>();
keys.add(new KeyVersion(accessKey));
keys.add(new KeyVersion(accessKey + "_key"));
multiObjectDeleteRequest.setKeys(keys);
s3Client.deleteObjects(multiObjectDeleteRequest);
LogUtils.debug(LOG_TAG, "Deleted file with access key: " + accessKey);
}
示例7: createSnapshotFromTagName
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; //导入依赖的package包/类
public void createSnapshotFromTagName(TagNameRequest tagNameRequest, Context context) {
LambdaLogger logger = context.getLogger();
logger.log("create ebs snapshot from tag name Start. backup target[" + tagNameRequest + "]");
String regionName = System.getenv("AWS_DEFAULT_REGION");
AmazonEC2Async client = RegionUtils.getRegion(regionName).createClient(AmazonEC2AsyncClient.class,
new DefaultAWSCredentialsProviderChain(), cc);
try {
List<Volume> volumes = describeBackupVolumes(client, tagNameRequest);
for (Volume volume : volumes) {
createSnapshot(volume.getVolumeId(), tagNameRequest.getGenerationCount(), context);
}
} finally {
client.shutdown();
}
}
示例8: whenCustomCredentialsSet_theyAreUsed
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; //导入依赖的package包/类
@Test
public void whenCustomCredentialsSet_theyAreUsed() throws Exception {
AWSCredentialsProvider customProvider = spy(new DefaultAWSCredentialsProviderChain());
KmsMasterKeyProvider mkp = KmsMasterKeyProvider.builder()
.withCredentials(customProvider)
.withKeysForEncryption(KMSTestFixtures.TEST_KEY_IDS[0])
.build();
new AwsCrypto().encryptData(mkp, new byte[1]);
verify(customProvider, atLeastOnce()).getCredentials();
AWSCredentials customCredentials = spy(customProvider.getCredentials());
mkp = KmsMasterKeyProvider.builder()
.withCredentials(customCredentials)
.withKeysForEncryption(KMSTestFixtures.TEST_KEY_IDS[0])
.build();
new AwsCrypto().encryptData(mkp, new byte[1]);
verify(customCredentials, atLeastOnce()).getAWSSecretKey();
}
示例9: credentials
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; //导入依赖的package包/类
/** By default, get credentials from the {@link DefaultAWSCredentialsProviderChain} */
@Bean
@ConditionalOnMissingBean
AWSCredentials.Provider credentials() {
return new AWSCredentials.Provider() {
AWSCredentialsProvider delegate = new DefaultAWSCredentialsProviderChain();
@Override public AWSCredentials get() {
com.amazonaws.auth.AWSCredentials result = delegate.getCredentials();
String sessionToken = result instanceof AWSSessionCredentials
? ((AWSSessionCredentials) result).getSessionToken()
: null;
return new AWSCredentials(
result.getAWSAccessKeyId(),
result.getAWSSecretKey(),
sessionToken
);
}
};
}
示例10: setUp
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; //导入依赖的package包/类
@Before
public void setUp() {
PowerMockito.mockStatic(CredentialsMatchers.class);
PowerMockito.mockStatic(SystemCredentialsProvider.class);
PowerMockito.mockStatic(DefaultAWSCredentialsProviderChain.class);
when(CredentialsMatchers.firstOrNull(any(Iterable.class), any(CredentialsMatcher.class))).thenReturn(mockCBCreds);
when(mockCBCreds.getCredentials()).thenReturn(mockAWSCreds);
when(mockCBCreds.getCredentialsDescriptor()).thenReturn(codeBuildDescriptor);
when(mockCBCreds.getProxyHost()).thenReturn(proxyHost);
when(mockCBCreds.getProxyPort()).thenReturn(proxyPort);
when(mockAWSCreds.getAWSAccessKeyId()).thenReturn("a");
when(mockAWSCreds.getAWSSecretKey()).thenReturn("s");
when(SystemCredentialsProvider.getInstance()).thenReturn(mockSysCreds);
when(DefaultAWSCredentialsProviderChain.getInstance()).thenReturn(cpChain);
}
示例11: setup
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; //导入依赖的package包/类
public void setup() {
AWSCredentialsProvider awsCredentialsProvider = new DefaultAWSCredentialsProviderChain();
try {
awsCredentialsProvider.getCredentials();
s3Bucket = System.getenv("CLOUDKEEPER_S3_TEST_BUCKET");
if (s3Bucket == null) {
s3Bucket = System.getProperty("xyz.cloudkeeper.s3.testbucket");
}
if (s3Bucket != null) {
executorService = Executors.newScheduledThreadPool(4);
AmazonS3 s3Client = new AmazonS3Client(awsCredentialsProvider);
s3Connection = new S3ConnectionBuilder(s3Client, executorService).build();
skipTest = false;
cleanS3(s3Connection, s3Bucket);
}
} catch (AmazonClientException exception) {
credentialsException = exception;
}
}
示例12: initEncryptedConfigStoreService
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; //导入依赖的package包/类
private void initEncryptedConfigStoreService() {
if (encryptedConfigStoreService == null) {
final Environment environment = getEnvironmentData();
KMSEncryptionMaterialsProvider materialProvider =
new KMSEncryptionMaterialsProvider(environment.getConfigKeyId());
AmazonS3EncryptionClient encryptionClient =
new AmazonS3EncryptionClient(
new DefaultAWSCredentialsProviderChain(),
materialProvider,
new CryptoConfiguration()
.withAwsKmsRegion(Region.getRegion(environmentMetadata.getRegions())))
.withRegion(Region.getRegion(environmentMetadata.getRegions()));
encryptedConfigStoreService = new S3StoreService(encryptionClient, environmentMetadata.getBucketName(), "");
}
}
示例13: sendDataToKinesis
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; //导入依赖的package包/类
private void sendDataToKinesis() {
AWSCredentialsProvider credentialsProvider = new
DefaultAWSCredentialsProviderChain();
AmazonKinesisClient amazonKinesisClient = new AmazonKinesisClient(credentialsProvider);
amazonKinesisClient.setRegion(Region.getRegion(Regions.fromName("eu-west-1")));
PutRecordsRequest putRecordsRequest = new PutRecordsRequest();
putRecordsRequest.setStreamName(TestConstants.stream);
List<PutRecordsRequestEntry> putRecordsRequestEntryList = new ArrayList<>();
PutRecordsRequestEntry putRecordsRequestEntry = new PutRecordsRequestEntry();
putRecordsRequestEntry.setData(ByteBuffer.wrap(String.valueOf("This is just a test").getBytes()));
putRecordsRequestEntry.setPartitionKey("partitionKey-1");
putRecordsRequestEntryList.add(putRecordsRequestEntry);
putRecordsRequest.setRecords(putRecordsRequestEntryList);
PutRecordsResult putRecordsResult = amazonKinesisClient.putRecords(putRecordsRequest);
logger.info("Put Result" + putRecordsResult);
}
示例14: startKinesisConsumer
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; //导入依赖的package包/类
private void startKinesisConsumer() throws Exception {
AWSCredentialsProvider credentialsProvider = new
DefaultAWSCredentialsProviderChain();
String region = "eu-west-1";
logger.info("Starting in Region " + region);
String workerId = InetAddress.getLocalHost().getCanonicalHostName() + ":" + UUID.randomUUID();
KinesisClientLibConfiguration kinesisClientLibConfiguration = new KinesisClientLibConfiguration(
this.getClass().getName(), TestConstants.stream, credentialsProvider, workerId)
.withInitialPositionInStream(InitialPositionInStream.LATEST).withRegionName(region);
IRecordProcessorFactory recordProcessorFactory = new
RecordFactory();
worker = new Worker(recordProcessorFactory,
kinesisClientLibConfiguration);
es = Executors.newSingleThreadExecutor();
es.execute(worker);
}
示例15: deleteKinesisStream
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; //导入依赖的package包/类
private void deleteKinesisStream() {
AWSCredentialsProvider credentialsProvider = new
DefaultAWSCredentialsProviderChain();
AmazonKinesisClient amazonKinesisClient = new AmazonKinesisClient(credentialsProvider);
amazonKinesisClient.setRegion(Region.getRegion(Regions.fromName("eu-west-1")));
DeleteStreamRequest createStreamRequest = new DeleteStreamRequest();
createStreamRequest.setStreamName(TestConstants.stream);
amazonKinesisClient.deleteStream(createStreamRequest);
DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest();
describeStreamRequest.setStreamName(TestConstants.stream);
logger.info("Stream " + TestConstants.stream + " deleted");
}