Search in sources :

Example 1 with AWSCredentialsProviderImpl

use of com.yahoo.athenz.zts.AWSCredentialsProviderImpl in project athenz by yahoo.

the class ZTSAWSCredsClient method main.

public static void main(String[] args) {
    // parse our command line to retrieve required input
    CommandLine cmd = parseCommandLine(args);
    final String domainName = cmd.getOptionValue("domain").toLowerCase();
    final String roleName = cmd.getOptionValue("role").toLowerCase();
    final String ztsUrl = cmd.getOptionValue("ztsurl");
    final String keyPath = cmd.getOptionValue("key");
    final String certPath = cmd.getOptionValue("cert");
    final String trustStorePath = cmd.getOptionValue("trustStorePath");
    final String trustStorePassword = cmd.getOptionValue("trustStorePassword");
    try {
        KeyRefresher keyRefresher = Utils.generateKeyRefresher(trustStorePath, trustStorePassword, certPath, keyPath);
        SSLContext sslContext = Utils.buildSSLContext(keyRefresher.getKeyManagerProxy(), keyRefresher.getTrustManagerProxy());
        // obtain temporary credential provider for our domain and role
        AWSCredentialsProviderImpl awsCredProvider = new AWSCredentialsProviderImpl(ztsUrl, sslContext, domainName, roleName);
        // retrieve and display aws temporary creds. Typically you just pass
        // the AWSCredentialsProvider object to any AWS api that requires it.
        // for example, when creating an AWS S3 client
        // AmazonS3 s3client = AmazonS3ClientBuilder.standard()
        // .withCredentials(awsCredProvider).withClientConfiguration(cltConf)
        // .withRegion(getRegion()).build();
        retrieveAWSTempCreds(awsCredProvider);
        // once we're done with our api and we no longer need our
        // provider we need to make sure to close it
        awsCredProvider.close();
    } catch (Exception ex) {
        System.out.println("Exception: " + ex.getMessage());
        ex.printStackTrace();
        System.exit(1);
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) AWSCredentialsProviderImpl(com.yahoo.athenz.zts.AWSCredentialsProviderImpl) SSLContext(javax.net.ssl.SSLContext) KeyRefresher(com.oath.auth.KeyRefresher) ZTSClientException(com.yahoo.athenz.zts.ZTSClientException) ParseException(org.apache.commons.cli.ParseException)

Aggregations

KeyRefresher (com.oath.auth.KeyRefresher)1 AWSCredentialsProviderImpl (com.yahoo.athenz.zts.AWSCredentialsProviderImpl)1 ZTSClientException (com.yahoo.athenz.zts.ZTSClientException)1 SSLContext (javax.net.ssl.SSLContext)1 CommandLine (org.apache.commons.cli.CommandLine)1 ParseException (org.apache.commons.cli.ParseException)1