當前位置: 首頁>>代碼示例>>Java>>正文


Java AmazonS3ClientBuilder.withCredentials方法代碼示例

本文整理匯總了Java中com.amazonaws.services.s3.AmazonS3ClientBuilder.withCredentials方法的典型用法代碼示例。如果您正苦於以下問題:Java AmazonS3ClientBuilder.withCredentials方法的具體用法?Java AmazonS3ClientBuilder.withCredentials怎麽用?Java AmazonS3ClientBuilder.withCredentials使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.amazonaws.services.s3.AmazonS3ClientBuilder的用法示例。


在下文中一共展示了AmazonS3ClientBuilder.withCredentials方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildAmazonS3ForRegion

import com.amazonaws.services.s3.AmazonS3ClientBuilder; //導入方法依賴的package包/類
private AmazonS3ClientBuilder buildAmazonS3ForRegion(AmazonS3 prototype, String region) {
    AmazonS3ClientBuilder clientBuilder = AmazonS3ClientBuilder.standard();

    AmazonS3Client target = getAmazonS3ClientFromProxy(prototype);
    if (target != null) {
        AWSCredentialsProvider awsCredentialsProvider = (AWSCredentialsProvider) ReflectionUtils.getField(this.credentialsProviderField, target);
        clientBuilder.withCredentials(awsCredentialsProvider);
    }

    return clientBuilder.withRegion(region);
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-aws,代碼行數:12,代碼來源:AmazonS3ClientFactory.java

示例2: S3Reader

import com.amazonaws.services.s3.AmazonS3ClientBuilder; //導入方法依賴的package包/類
public S3Reader(Region region, String accessKey, String secretKey) {
    AmazonS3ClientBuilder clientBuilder = AmazonS3ClientBuilder.standard();
    clientBuilder.setRegion(region.getName());

    if (!accessKey.isEmpty() && !secretKey.isEmpty()) {
        clientBuilder.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)));
    }

    this.s3Client = clientBuilder.build();
}
 
開發者ID:sherzberg,項目名稱:graylog-plugin-s3,代碼行數:11,代碼來源:S3Reader.java

示例3: create

import com.amazonaws.services.s3.AmazonS3ClientBuilder; //導入方法依賴的package包/類
public AmazonS3 create(final BlobStoreConfiguration blobStoreConfiguration) {
  AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();

  String accessKeyId = blobStoreConfiguration.attributes(CONFIG_KEY).get(ACCESS_KEY_ID_KEY, String.class);
  String secretAccessKey = blobStoreConfiguration.attributes(CONFIG_KEY).get(SECRET_ACCESS_KEY_KEY, String.class);
  String region = blobStoreConfiguration.attributes(CONFIG_KEY).get(REGION_KEY, String.class);

  if (!isNullOrEmpty(accessKeyId) && !isNullOrEmpty(secretAccessKey)) {
    String sessionToken = blobStoreConfiguration.attributes(CONFIG_KEY).get(SESSION_TOKEN_KEY, String.class);
    AWSCredentials credentials = buildCredentials(accessKeyId, secretAccessKey, sessionToken);

    String assumeRole = blobStoreConfiguration.attributes(CONFIG_KEY).get(ASSUME_ROLE_KEY, String.class);
    AWSCredentialsProvider credentialsProvider = buildCredentialsProvider(credentials, region, assumeRole);

    builder = builder.withCredentials(credentialsProvider);
  }

  if (!isNullOrEmpty(region)) {
    String endpoint = blobStoreConfiguration.attributes(CONFIG_KEY).get(ENDPOINT_KEY, String.class);
    if (!isNullOrEmpty(endpoint)) {
      builder = builder.withEndpointConfiguration(new AmazonS3ClientBuilder.EndpointConfiguration(endpoint, region));
    } else {
      builder = builder.withRegion(region);
    }
  }

  return builder.build();
}
 
開發者ID:sonatype,項目名稱:nexus-public,代碼行數:29,代碼來源:AmazonS3Factory.java

示例4: configureTokenAuthentication

import com.amazonaws.services.s3.AmazonS3ClientBuilder; //導入方法依賴的package包/類
private static AmazonS3ClientBuilder configureTokenAuthentication(Environment environment, AmazonS3ClientBuilder builder) {
    LOGGER.info("Using Token authentication");
    final String key = environment.getProperty("content-service.store.s3.accessKey");
    final String secret = environment.getProperty("content-service.store.s3.secretKey");
    AWSCredentials awsCredentials = new BasicAWSCredentials(key, secret);
    return builder.withCredentials(new StaticCredentialsProvider(awsCredentials));
}
 
開發者ID:Talend,項目名稱:daikon,代碼行數:8,代碼來源:S3ContentServiceConfiguration.java

示例5: getS3client

import com.amazonaws.services.s3.AmazonS3ClientBuilder; //導入方法依賴的package包/類
public static AmazonS3 getS3client(GoEnvironment env) {
    AmazonS3ClientBuilder amazonS3ClientBuilder = AmazonS3ClientBuilder.standard();

    if (env.has(AWS_REGION)) {
        amazonS3ClientBuilder.withRegion(env.get(AWS_REGION));
    }
    if (env.hasAWSUseIamRole()) {
        amazonS3ClientBuilder.withCredentials(new InstanceProfileCredentialsProvider(false));
    } else if (env.has(AWS_ACCESS_KEY_ID) && env.has(AWS_SECRET_ACCESS_KEY)) {
        BasicAWSCredentials basicCreds = new BasicAWSCredentials(env.get(AWS_ACCESS_KEY_ID), env.get(AWS_SECRET_ACCESS_KEY));
        amazonS3ClientBuilder.withCredentials(new AWSStaticCredentialsProvider(basicCreds));
    }

    return amazonS3ClientBuilder.build();
}
 
開發者ID:indix,項目名稱:gocd-s3-artifacts,代碼行數:16,代碼來源:S3ArtifactStore.java

示例6: initClient

import com.amazonaws.services.s3.AmazonS3ClientBuilder; //導入方法依賴的package包/類
public static AmazonS3 initClient(String s3AccessKey, String s3SecretKey, String s3BucketRegion)
{
    // equivalent to "defaultClient" (unless credentials &/or region are overridden)
    AmazonS3ClientBuilder s3ClientBuilder = AmazonS3ClientBuilder.standard();

    if ((s3AccessKey != null) || (s3SecretKey != null))
    {
        // override default credentials
        s3ClientBuilder.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(s3AccessKey, s3SecretKey)));
    }

    if (s3BucketRegion != null)
    {
        // override default region
        s3ClientBuilder.withRegion(s3BucketRegion);
    }

    AmazonS3 s3 = null;
    
    try
    {
        s3 = s3ClientBuilder.build();
    }
    catch (AmazonClientException e)
    {
        if (e.getMessage().contains("Unable to find a region via the region provider chain"))
        {
            s3ClientBuilder.withRegion(DEFAULT_BUCKET_REGION);
            s3 = s3ClientBuilder.build();
        }
    }
    
    return s3;
}
 
開發者ID:Alfresco,項目名稱:gytheio,代碼行數:35,代碼來源:S3ContentReferenceHandlerImpl.java

示例7: configureEC2Authentication

import com.amazonaws.services.s3.AmazonS3ClientBuilder; //導入方法依賴的package包/類
private static AmazonS3ClientBuilder configureEC2Authentication(AmazonS3ClientBuilder builder) {
    LOGGER.info("Using EC2 authentication");
    return builder.withCredentials(new EC2ContainerCredentialsProviderWrapper());
}
 
開發者ID:Talend,項目名稱:daikon,代碼行數:5,代碼來源:S3ContentServiceConfiguration.java

示例8: S3Filer

import com.amazonaws.services.s3.AmazonS3ClientBuilder; //導入方法依賴的package包/類
public S3Filer(@Nonnull Config config, @Nonnull Access access) {
	checkNotNull(config);
	checkNotNull(access);

	String url = config.getString("url");
	int index = url.indexOf("://");
	if (index > -1) {
		index = url.indexOf("/", index + 3);
		if (index > -1) {
			url = url.substring(0, index);
		}
	}
	uri = URI.create(url);

	bucket = uri.getHost();
	partSize = config.getInt("s3.partSize", 5 * 1024 * 1024);
	tempDir = new File(config.getString("s3.tempDir", System.getProperty("java.io.tmpdir")));
	service = Executors.newFixedThreadPool(config.getInt("s3.threads", 1));

	AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();

	String region = config.getString("aws.region", null);
	if (region != null) {
		builder.withRegion(region);
	}

	String key = config.getString("aws.key", null);
	if (key != null) {
		AmazonS3Exception exception = null;
		int retries = config.getInt("aws.retries", 3);

		for (int i = 0; i < retries + 1; i++) {
			Response response = access.prompt(key + ".secret", key + ".secret: ", Type.MASKED);
			try {
				String secret = response.value();
				builder.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(key, secret)));

				AmazonS3 testS3 = builder.build();
				testS3.listObjects(new ListObjectsRequest().withBucketName(bucket));
				response.accept();
				break;
			} catch (AmazonS3Exception e) {
				exception = e;
				response.reject();
			}
		}

		if (exception != null) {
			throw exception;
		}
	}

	s3 = builder.build();
}
 
開發者ID:lithiumtech,項目名稱:flow,代碼行數:55,代碼來源:S3Filer.java


注:本文中的com.amazonaws.services.s3.AmazonS3ClientBuilder.withCredentials方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。