Java 类com.amazonaws.auth.EnvironmentVariableCredentialsProvider 实例源码

项目:detective    文件:AwsUtils.java   
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]));
}
项目:cerberus-lifecycle-cli    文件:CerberusModule.java   
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;
}
项目:apigateway-generic-java-sdk    文件:Main.java   
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();
}
项目:aml    文件:ApiImporter.java   
@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);
}
项目:aws-iot-mqtt-load-generator    文件:MyCredentialsProvider.java   
MyCredentialsProvider() {
    super(new EnvironmentVariableCredentialsProvider(),
            new SystemPropertiesCredentialsProvider(),
            // Removed due to ElasticBeanstalk environment not being setup with a profile dir
            // new ProfileCredentialsProvider(),
            new InstanceProfileCredentialsProvider(),
            new ClasspathPropertiesFileCredentialsProvider());
}
项目:azure-s3proxy-cf-demo    文件:PhotoLibrary.java   
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);
}
项目:lambadaframework    文件:AuthenticationInfoAWSCredentialsProviderChain.java   
AuthenticationInfoAWSCredentialsProviderChain(AuthenticationInfo authenticationInfo) {
    super(
            new InstanceProfileCredentialsProvider(),
            new ProfileCredentialsProvider(),
            new EnvironmentVariableCredentialsProvider(),
            new SystemPropertiesCredentialsProvider(),
            new InstanceProfileCredentialsProvider());
}
项目:aws-iprange-update-checker    文件:RangeCheckHandler.java   
private AmazonS3Client getS3Client() {
  Optional<AWSCredentials> credentials = getCredentials();
  if (credentials.isPresent()) {
    return new AmazonS3Client(credentials.get());
  } else {
    return new AmazonS3Client(new EnvironmentVariableCredentialsProvider());
  }
}
项目:aws-iprange-update-checker    文件:RangeCheckHandler.java   
private AmazonSNSClient getSNSClient() {
  Optional<AWSCredentials> credentials = getCredentials();
  if (credentials.isPresent()) {
    return new AmazonSNSClient(credentials.get());
  } else {
    return new AmazonSNSClient(new EnvironmentVariableCredentialsProvider());
  }
}
项目:omakase    文件:S3ClientTest.java   
@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);
    }
}
项目:omakase    文件:S3ClientTest.java   
@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);
    }
}
项目:omakase    文件:GlacierClientTest.java   
@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);
    }
}
项目:gradle-beanstalk-plugin    文件:DeployTask.java   
@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);
}
项目:logback-sqs    文件:SqsAppender.java   
/**
 * 
 * @return
 */
private AWSCredentialsProvider getCredentials() {
  return new AWSCredentialsProviderChain(new StaticCredentialsProvider(
      new AppenderCredentials()), new SystemPropertiesCredentialsProvider(),
      new EnvironmentVariableCredentialsProvider(),
      new ProfileCredentialsProvider(),
      new InstanceProfileCredentialsProvider());
}
项目:aws-apigateway-swagger-exporter    文件:APIGExporterMain.java   
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;
}
项目:amediamanager    文件:ServerConfig.java   
@Bean
@Scope(WebApplicationContext.SCOPE_APPLICATION)
public AWSCredentialsProvider credentials() {
    return new AWSCredentialsProviderChain(
          new InstanceProfileCredentialsProvider(),
          new EnvironmentVariableCredentialsProvider(),
          new SystemPropertiesCredentialsProvider()
            );
}
项目:detective    文件:AwsServiceImpl.java   
private AWSCredentialsProvider createCredentialsProvider(){
  return new AWSCredentialsProviderChain(
      new InstanceProfileCredentialsProvider(),
      new EnvironmentVariableCredentialsProvider(),
      new SystemPropertiesCredentialsProvider(),
      new AWSCredentialsConfigFileProvider()
      );
}
项目:awsbigdata    文件:KinesisServer.java   
public static void main(String[] args) throws Exception {
       java.security.Security.setProperty("networkaddress.cache.ttl" , "60");

       Server server = new Server();
       ServerConnector connector = new ServerConnector(server);
       connector.setPort(80);
       server.addConnector(connector);

       ResourceHandler resource_handler = new ResourceHandler();
       resource_handler.setResourceBase(".");
       ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
       context.setContextPath("/");
       ServletHolder holderEvents = new ServletHolder("ws-events", MessageProxyServlet.class);
       context.addServlet(holderEvents, "/kinesisapp/*");

       HandlerList handlers = new HandlerList();
       handlers.setHandlers(new Handler[] { resource_handler, context, new DefaultHandler() });
       server.setHandler(handlers);        
       server.start();

       AWSCredentialsProvider credentialsProvider = new EnvironmentVariableCredentialsProvider();
       KinesisClientLibConfiguration kinesisConfig = new KinesisClientLibConfiguration(
            System.getProperty("kinesisapp.name"), 
            System.getProperty("kinesisapp.stream"), 
            credentialsProvider, Long.toString(System.currentTimeMillis()))
            .withKinesisEndpoint(System.getProperty("kinesisapp.endpoint"));

       IRecordProcessorFactory factory = new Factory();
       Worker worker = new Worker(factory, kinesisConfig);
       worker.run();

       /*
    Processor p = new Processor();
    p.test();
    */
}
项目:incubator-gobblin    文件:AWSClusterSecurityManager.java   
DefaultAWSCredentialsProviderChain(Config config) {
  super(new EnvironmentVariableCredentialsProvider(),
          new SystemPropertiesCredentialsProvider(),
          new ConfigurationCredentialsProvider(config),
          new ProfileCredentialsProvider(),
          new InstanceProfileCredentialsProvider());
}
项目:logback-ext    文件:AwsSupport.java   
public AWSCredentialsProvider getCredentials(AWSCredentials credentials) {
    return new AWSCredentialsProviderChain(
            new EnvironmentVariableCredentialsProvider(),
            new SystemPropertiesCredentialsProvider(),
            new StaticCredentialsProvider(credentials == null ? new NullCredentials() : credentials),
            new ProfileCredentialsProvider(),
            new InstanceProfileCredentialsProvider()
    );
}
项目:CrypDist    文件:ServerAccessor.java   
public ServerAccessor(){

        s3client = AmazonS3ClientBuilder.standard()
                .withCredentials(new EnvironmentVariableCredentialsProvider())
                .withRegion(Regions.EU_CENTRAL_1).build();
    }
项目:cyberduck    文件:AWSEnviromentCredentialsConfigurator.java   
public AWSEnviromentCredentialsConfigurator() {
    super(new EnvironmentVariableCredentialsProvider());
}
项目:strongbox    文件:CustomCredentialsProviderChain.java   
public CustomCredentialsProviderChain(ClientConfiguration clientConfiguration, ProfileIdentifier profile, Supplier<MFAToken> mfaTokenSupplier) {
    super(new EnvironmentVariableCredentialsProvider(),
            new SystemPropertiesCredentialsProvider(),
            new ProfileCredentialProvider(clientConfiguration, profile, mfaTokenSupplier),
            new EC2ContainerCredentialsProviderWrapper());
}
项目:ServiceCommons    文件:EnvironmentDynamoDBProvider.java   
@Override
public AWSCredentials getCredentials() {
    return new EnvironmentVariableCredentialsProvider().getCredentials();
}
项目:kinesis-logback-appender    文件:CustomCredentialsProviderChain.java   
public CustomCredentialsProviderChain() {
  super(new ClasspathPropertiesFileCredentialsProvider(), new InstanceProfileCredentialsProvider(),
      new SystemPropertiesCredentialsProvider(), new EnvironmentVariableCredentialsProvider(),
      new ProfileCredentialsProvider());
}
项目:snap2cloud    文件:AwsConn.java   
public AWSCredentials getAwsCredentialsFromEnvironment() throws IOException {
    EnvironmentVariableCredentialsProvider credentials = new EnvironmentVariableCredentialsProvider();
    return credentials.getCredentials();
}
项目:kinesis-log4j-appender    文件:CustomCredentialsProviderChain.java   
public CustomCredentialsProviderChain() {
  super(new ClasspathPropertiesFileCredentialsProvider(), new InstanceProfileCredentialsProvider(),
      new SystemPropertiesCredentialsProvider(), new EnvironmentVariableCredentialsProvider());
}
项目:aws-big-data-blog    文件:CustomCredentialsProviderChain.java   
public CustomCredentialsProviderChain() {
    super(new EnvironmentVariableCredentialsProvider(),
            new SystemPropertiesCredentialsProvider(),
            new ClasspathPropertiesFileCredentialsProvider(),
            new InstanceProfileCredentialsProvider());
}