com.amazonaws.services.identitymanagement.model.NoSuchEntityException Java Examples
The following examples show how to use
com.amazonaws.services.identitymanagement.model.NoSuchEntityException.
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: AwsIamConnector.java From titus-control-plane with Apache License 2.0 | 6 votes |
private Mono<IamRole> getIamRoleFromAws(String iamRoleName) { long startTime = registry.clock().wallTime(); return getAwsIamRole(iamRoleName) .timeout(Duration.ofMillis(configuration.getAwsRequestTimeoutMs())) .map(getRoleResult -> { connectorMetrics.success(IamConnectorMetrics.IamMethods.GetIamRole, startTime); return IamRole.newBuilder() .withRoleId(getRoleResult.getRole().getRoleId()) .withRoleName(getRoleResult.getRole().getRoleName()) .withResourceName(getRoleResult.getRole().getArn()) .withPolicyDoc(getRoleResult.getRole().getAssumeRolePolicyDocument()) .build(); } ) .onErrorMap(throwable -> { // Remap to specific Exception if we got rate limited if (throwable.getMessage().contains("Rate exceeded")) { throwable = new AwsIamRateLimitException(throwable); } connectorMetrics.failure(IamConnectorMetrics.IamMethods.GetIamRole, throwable, startTime); if (throwable instanceof NoSuchEntityException) { return IamConnectorException.iamRoleNotFound(iamRoleName); } return IamConnectorException.iamRoleUnexpectedError(iamRoleName, throwable.getMessage()); }); }
Example #2
Source File: AwsIamService.java From cloudbreak with Apache License 2.0 | 6 votes |
/** * Validates instance profile ARN and returns an InstanceProfile object if valid * * @param iam AmazonIdentityManagement client * @param instanceProfileArn instance profile ARN * @param validationResultBuilder builder for any errors encountered * @return InstanceProfile if instance profile ARN is valid otherwise null */ public InstanceProfile getInstanceProfile(AmazonIdentityManagement iam, String instanceProfileArn, ValidationResultBuilder validationResultBuilder) { InstanceProfile instanceProfile = null; if (instanceProfileArn != null && instanceProfileArn.contains("/")) { String instanceProfileName = instanceProfileArn.split("/", 2)[1]; GetInstanceProfileRequest instanceProfileRequest = new GetInstanceProfileRequest() .withInstanceProfileName(instanceProfileName); try { instanceProfile = iam.getInstanceProfile(instanceProfileRequest).getInstanceProfile(); } catch (NoSuchEntityException | ServiceFailureException e) { String msg = String.format("Instance profile (%s) doesn't exist.", instanceProfileArn); LOGGER.error(msg, e); validationResultBuilder.error(msg); } } return instanceProfile; }
Example #3
Source File: AwsIamService.java From cloudbreak with Apache License 2.0 | 6 votes |
/** * 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 | 6 votes |
@Test public void missingInstanceProfile() { when(iam.getInstanceProfile(any(GetInstanceProfileRequest.class))).thenThrow(NoSuchEntityException.class); String instanceProfileArn = "account/missingInstanceProfile"; ValidationResultBuilder validationRequestBuilder = new ValidationResultBuilder(); InstanceProfile instanceProfile = awsIamService.getInstanceProfile(iam, instanceProfileArn, validationRequestBuilder); assertThat(instanceProfile).isNull(); ValidationResult validationResult = validationRequestBuilder.build(); assertThat(validationResult.hasError()).isTrue(); assertThat(validationResult.getErrors()).isEqualTo( Collections.singletonList(String.format("Instance profile (%s) doesn't exist.", instanceProfileArn))); }
Example #5
Source File: IntegrationTestHelper.java From strongbox with Apache License 2.0 | 5 votes |
public static boolean groupExists(SecretsGroupManager secretsGroupManager, SecretsGroupIdentifier identifier) { try { secretsGroupManager.info(identifier); return true; } catch (NoSuchElementException | ResourceNotFoundException | NoSuchEntityException e) { return false; } }
Example #6
Source File: AwsIamServiceTest.java From cloudbreak with Apache License 2.0 | 5 votes |
@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))); }