All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.distelli.aws.CredProviderAws Maven / Gradle / Ivy

There is a newer version: 3.8.16
Show newest version
package com.distelli.aws;

import com.distelli.cred.CredProvider;
import com.distelli.cred.CredPair;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicSessionCredentials;


import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;

public class CredProviderAws implements CredProvider {
    private AWSCredentialsProvider _credProvider;

    public CredProviderAws(String profileName) {
        _credProvider = new ProfileCredentialsProvider(profileName);
    }

    public CredProviderAws() {
        _credProvider = new DefaultAWSCredentialsProviderChain();
    }

    @Override
    public CredPair getCredPair() {
        AWSCredentials awsCreds = _credProvider.getCredentials();
        String keyId = awsCreds.getAWSAccessKeyId();
        String secret = awsCreds.getAWSSecretKey();
        if ( awsCreds instanceof BasicSessionCredentials ) {
            secret = secret + "\u001E" + ((BasicSessionCredentials)awsCreds).getSessionToken();
        }
        return new CredPair()
            .withKeyId(keyId)
            .withSecret(secret);
    }

    @Override
    public void refresh() {
        if ( null == _credProvider ) return;
        _credProvider.refresh();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy