com.amazonaws.services.identitymanagement.model.GetRoleRequest Java Examples

The following examples show how to use com.amazonaws.services.identitymanagement.model.GetRoleRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpsWorksDeploymentTests.java    From aws-ant-tasks with Apache License 2.0 6 votes vote down vote up
private CreateStackTask readyStackTask() {
    CreateStackTask stackTask = new CreateStackTask();
    stackTask.setProject(project);
    stackTask.setName("AntTaskTestStack");
    stackTask.setRegion("us-east-1");
    stackTask
            .setDefaultInstanceProfileArn(iamClient
                    .getInstanceProfile(
                            new GetInstanceProfileRequest()
                                    .withInstanceProfileName("aws-opsworks-ec2-role"))
                    .getInstanceProfile().getArn());
    stackTask.setServiceRoleArn(iamClient
            .getRole(
                    new GetRoleRequest()
                            .withRoleName("aws-opsworks-service-role"))
            .getRole().getArn());

    return stackTask;
}
 
Example #2
Source File: SetUpOpsWorksTestsTask.java    From aws-ant-tasks with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the "instanceProfile" and "serviceRole" properties according to the
 * set parameters.
 */
public void execute() {
    checkParams();
    AmazonIdentityManagementClient iamClient = getOrCreateClient(AmazonIdentityManagementClient.class);
    getProject()
            .setProperty(
                    "instanceProfileArn",
                    iamClient
                            .getInstanceProfile(
                                    new GetInstanceProfileRequest()
                                            .withInstanceProfileName(instanceProfile))
                            .getInstanceProfile().getArn());
    getProject()
            .setProperty(
                    "serviceRoleArn",
                    iamClient
                            .getRole(
                                    new GetRoleRequest()
                                            .withRoleName(serviceRole))
                            .getRole().getArn());

}
 
Example #3
Source File: AwsIamService.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
/**
 * Validates role ARN and returns an Role object if valid
 *
 * @param iam                     AmazonIdentityManagement client
 * @param roleArn                 role ARN
 * @param validationResultBuilder builder for any errors encountered
 * @return Role if role ARN is valid otherwise null
 */
public Role getRole(AmazonIdentityManagement iam, String roleArn,
        ValidationResultBuilder validationResultBuilder) {
    Role role = null;
    if (roleArn != null && roleArn.contains("/")) {
        String roleName = roleArn.split("/", 2)[1];
        GetRoleRequest roleRequest = new GetRoleRequest().withRoleName(roleName);
        try {
            role = iam.getRole(roleRequest).getRole();
        } catch (NoSuchEntityException | ServiceFailureException e) {
            String msg = String.format("Role (%s) doesn't exist.", roleArn);
            LOGGER.debug(msg, e);
            validationResultBuilder.error(msg);
        }
    }
    return role;
}
 
Example #4
Source File: AwsIamServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void missingRole() {
    when(iam.getRole(any(GetRoleRequest.class))).thenThrow(NoSuchEntityException.class);

    String roleArn = "account/missingRole";
    ValidationResultBuilder validationRequestBuilder = new ValidationResultBuilder();
    Role role = awsIamService.getRole(iam, roleArn, validationRequestBuilder);

    assertThat(role).isNull();
    ValidationResult validationResult = validationRequestBuilder.build();
    assertThat(validationResult.hasError()).isTrue();
    assertThat(validationResult.getErrors()).isEqualTo(
            Collections.singletonList(String.format("Role (%s) doesn't exist.", roleArn)));
}
 
Example #5
Source File: AwsIamServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void roleServiceFailureException() {
    when(iam.getRole(any(GetRoleRequest.class))).thenThrow(ServiceFailureException.class);

    String roleArn = "account/potentialRole";
    ValidationResultBuilder validationRequestBuilder = new ValidationResultBuilder();
    Role role = awsIamService.getRole(iam, roleArn, validationRequestBuilder);

    assertThat(role).isNull();
    ValidationResult validationResult = validationRequestBuilder.build();
    assertThat(validationResult.hasError()).isTrue();
    assertThat(validationResult.getErrors()).isEqualTo(
            Collections.singletonList(String.format("Role (%s) doesn't exist.", roleArn)));
}
 
Example #6
Source File: AwsIamServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void validRole() {
    String roleArn = "account/validRole";

    Role expectedRole = new Role().withArn(roleArn);
    GetRoleResult getRoleResult = mock(GetRoleResult.class);
    when(getRoleResult.getRole()).thenReturn(expectedRole);
    when(iam.getRole(any(GetRoleRequest.class))).thenReturn(getRoleResult);

    ValidationResultBuilder validationRequestBuilder = new ValidationResultBuilder();
    Role role = awsIamService.getRole(iam, roleArn, validationRequestBuilder);

    assertThat(role.getArn()).isEqualTo(roleArn);
    assertThat(validationRequestBuilder.build().hasError()).isFalse();
}
 
Example #7
Source File: AwsIamConnector.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
private Mono<GetRoleResult> getAwsIamRole(String iamRoleName) {
    GetRoleRequest request = new GetRoleRequest().withRoleName(iamRoleName);
    return AwsReactorExt.toMono(request, iamClient::getRoleAsync);
}
 
Example #8
Source File: RoleImpl.java    From aws-sdk-java-resources with Apache License 2.0 4 votes vote down vote up
@Override
public boolean load(GetRoleRequest request) {
    return load(request, null);
}
 
Example #9
Source File: RoleImpl.java    From aws-sdk-java-resources with Apache License 2.0 4 votes vote down vote up
@Override
public boolean load(GetRoleRequest request, ResultCapture<GetRoleResult>
        extractor) {

    return resource.load(request, extractor);
}
 
Example #10
Source File: Role.java    From aws-sdk-java-resources with Apache License 2.0 2 votes vote down vote up
/**
 * Makes a call to the service to load this resource's attributes if they
 * are not loaded yet.
 * The following request parameters will be populated from the data of this
 * <code>Role</code> resource, and any conflicting parameter value set in
 * the request will be overridden:
 * <ul>
 *   <li>
 *     <b><code>RoleName</code></b>
 *         - mapped from the <code>Name</code> identifier.
 *   </li>
 * </ul>
 *
 * <p>
 *
 * @return Returns {@code true} if the resource is not yet loaded when this
 *         method was invoked, which indicates that a service call has been
 *         made to retrieve the attributes.
 * @see GetRoleRequest
 */
boolean load(GetRoleRequest request);
 
Example #11
Source File: Role.java    From aws-sdk-java-resources with Apache License 2.0 2 votes vote down vote up
/**
 * Makes a call to the service to load this resource's attributes if they
 * are not loaded yet, and use a ResultCapture to retrieve the low-level
 * client response
 * The following request parameters will be populated from the data of this
 * <code>Role</code> resource, and any conflicting parameter value set in
 * the request will be overridden:
 * <ul>
 *   <li>
 *     <b><code>RoleName</code></b>
 *         - mapped from the <code>Name</code> identifier.
 *   </li>
 * </ul>
 *
 * <p>
 *
 * @return Returns {@code true} if the resource is not yet loaded when this
 *         method was invoked, which indicates that a service call has been
 *         made to retrieve the attributes.
 * @see GetRoleRequest
 */
boolean load(GetRoleRequest request, ResultCapture<GetRoleResult> extractor)
        ;