Example usage for com.amazonaws.services.identitymanagement.model GetInstanceProfileRequest GetInstanceProfileRequest

List of usage examples for com.amazonaws.services.identitymanagement.model GetInstanceProfileRequest GetInstanceProfileRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.identitymanagement.model GetInstanceProfileRequest GetInstanceProfileRequest.

Prototype

GetInstanceProfileRequest

Source Link

Usage

From source file:com.cloudera.director.aws.ec2.EC2InstanceTemplateConfigurationValidator.java

License:Apache License

/**
 * Validates the configured IAM profile.
 *
 * @param configuration       the configuration to be validated
 * @param accumulator         the exception condition accumulator
 * @param localizationContext the localization context
 *//*from w  w  w .  j  ava 2  s  .c o  m*/
@VisibleForTesting
void checkIamProfileName(Configured configuration, PluginExceptionConditionAccumulator accumulator,
        LocalizationContext localizationContext) {

    String iamProfileName = configuration.getConfigurationValue(IAM_PROFILE_NAME, localizationContext);

    if (iamProfileName != null) {
        AmazonIdentityManagementClient iamClient = provider.getIdentityManagementClient();

        try {
            iamClient.getInstanceProfile(
                    new GetInstanceProfileRequest().withInstanceProfileName(iamProfileName));

        } catch (NoSuchEntityException e) {
            addError(accumulator, IAM_PROFILE_NAME, localizationContext, null, INVALID_IAM_PROFILE_NAME_MSG,
                    iamProfileName);
        }
    }
}

From source file:com.cloudera.director.aws.ec2.EC2Provider.java

License:Apache License

/**
 * Configures the specified IAM client.//from  w  w w . j  a v  a  2s  . c om
 *
 * @param configuration               the provider configuration
 * @param accumulator                 the exception accumulator
 * @param identityManagementClient    the IAM client
 * @param providerLocalizationContext the resource provider localization context
 * @param verify                      whether to verify the configuration by making an API call
 * @return the configured client
 * @throws InvalidCredentialsException    if the supplied credentials are invalid
 * @throws TransientProviderException     if a transient exception occurs communicating with the
 *                                        provider
 * @throws UnrecoverableProviderException if an unrecoverable exception occurs communicating with
 *                                        the provider
 */
@SuppressWarnings("PMD.EmptyCatchBlock")
protected static AmazonIdentityManagementClient configureIAMClient(Configured configuration,
        PluginExceptionConditionAccumulator accumulator,
        AmazonIdentityManagementClient identityManagementClient,
        LocalizationContext providerLocalizationContext, boolean verify) {
    checkNotNull(identityManagementClient, "identityManagementClient is null");

    try {
        String iamEndpoint = configuration.getConfigurationValue(IAM_ENDPOINT, providerLocalizationContext);
        if (iamEndpoint != null) {
            LOG.info("<< Using configured IAM endpoint: {}", iamEndpoint);
            identityManagementClient.setEndpoint(iamEndpoint);
        }
        // else use the single default endpoint for all of AWS (outside GovCloud)

        if (verify) {
            // Attempt to use client, to validate credentials and connectivity
            try {
                identityManagementClient
                        .getInstanceProfile(new GetInstanceProfileRequest().withInstanceProfileName("test"));
            } catch (NoSuchEntityException e) {
                /* call succeeded */
            }
        }

    } catch (AmazonClientException e) {
        throw AWSExceptions.propagate(e);
    } catch (IllegalArgumentException e) {
        accumulator.addError(IAM_ENDPOINT.unwrap().getConfigKey(), e.getMessage());
    }
    return identityManagementClient;
}