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");
}
}
Aggregations