Search in sources :

Example 1 with CustomConnectorProfileCredentials

use of com.amazonaws.services.appflow.model.CustomConnectorProfileCredentials in project aws-appflow-custom-connector-java by awslabs.

the class CredentialsProvider method getCustomConnectorProfileCredentials.

/**
 * Builds the credentials by reading the data fetched from secret manager.
 *
 * @return- CustomConnectorProfileCredentials
 */
public static CustomConnectorProfileCredentials getCustomConnectorProfileCredentials(final CustomConnectorProfileConfiguration profileConfiguration) {
    CustomConnectorProfileCredentials customConnectorProfileCredentials = new CustomConnectorProfileCredentials();
    if (profileConfiguration.authenticationType().equals(AuthenticationType.NO_AUTH) || !profileConfiguration.secretsManagerArn().isPresent()) {
        return customConnectorProfileCredentials;
    }
    AWSSecretsManager secretsManager = ServiceProvider.getSecretsManager();
    GetSecretValueResult secretValueResult = secretsManager.getSecretValue(new GetSecretValueRequest().withSecretId(profileConfiguration.secretsManagerArn().get()));
    try {
        switch(profileConfiguration.authenticationType()) {
            case API_KEY:
                return customConnectorProfileCredentials.withAuthenticationType(com.amazonaws.services.appflow.model.AuthenticationType.APIKEY).withApiKey(OBJECT_MAPPER.readValue(secretValueResult.getSecretString(), ApiKeyCredentials.class));
            case BASIC:
                return customConnectorProfileCredentials.withAuthenticationType(com.amazonaws.services.appflow.model.AuthenticationType.BASIC).withBasic(OBJECT_MAPPER.readValue(secretValueResult.getSecretString(), BasicAuthCredentials.class));
            case OAUTH2:
                return customConnectorProfileCredentials.withAuthenticationType(com.amazonaws.services.appflow.model.AuthenticationType.OAUTH2).withOauth2(OBJECT_MAPPER.readValue(secretValueResult.getSecretString(), OAuth2Credentials.class));
            case CUSTOM:
                return customConnectorProfileCredentials.withAuthenticationType(com.amazonaws.services.appflow.model.AuthenticationType.CUSTOM).withCustom(OBJECT_MAPPER.readValue(secretValueResult.getSecretString(), CustomAuthCredentials.class));
            default:
                throw new IllegalStateException("AuthenticationType is not defined");
        }
    } catch (JsonProcessingException e) {
        throw new RuntimeException("Unable to Serialize secrets value. Secret String must be a valid json");
    }
}
Also used : ApiKeyCredentials(com.amazonaws.services.appflow.model.ApiKeyCredentials) GetSecretValueResult(com.amazonaws.services.secretsmanager.model.GetSecretValueResult) BasicAuthCredentials(com.amazonaws.services.appflow.model.BasicAuthCredentials) CustomAuthCredentials(com.amazonaws.services.appflow.model.CustomAuthCredentials) CustomConnectorProfileCredentials(com.amazonaws.services.appflow.model.CustomConnectorProfileCredentials) AWSSecretsManager(com.amazonaws.services.secretsmanager.AWSSecretsManager) GetSecretValueRequest(com.amazonaws.services.secretsmanager.model.GetSecretValueRequest) OAuth2Credentials(com.amazonaws.services.appflow.model.OAuth2Credentials) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

ApiKeyCredentials (com.amazonaws.services.appflow.model.ApiKeyCredentials)1 BasicAuthCredentials (com.amazonaws.services.appflow.model.BasicAuthCredentials)1 CustomAuthCredentials (com.amazonaws.services.appflow.model.CustomAuthCredentials)1 CustomConnectorProfileCredentials (com.amazonaws.services.appflow.model.CustomConnectorProfileCredentials)1 OAuth2Credentials (com.amazonaws.services.appflow.model.OAuth2Credentials)1 AWSSecretsManager (com.amazonaws.services.secretsmanager.AWSSecretsManager)1 GetSecretValueRequest (com.amazonaws.services.secretsmanager.model.GetSecretValueRequest)1 GetSecretValueResult (com.amazonaws.services.secretsmanager.model.GetSecretValueResult)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1