@Test public void validInstanceProfile() { String instanceProfileArn = "account/validInstanceProfile"; InstanceProfile expectedInstanceProfile = new InstanceProfile().withArn(instanceProfileArn); GetInstanceProfileResult getInstanceProfileResult = mock(GetInstanceProfileResult.class); when(getInstanceProfileResult.getInstanceProfile()).thenReturn(expectedInstanceProfile); when(iam.getInstanceProfile(any(GetInstanceProfileRequest.class))).thenReturn(getInstanceProfileResult); ValidationResultBuilder validationRequestBuilder = new ValidationResultBuilder(); InstanceProfile instanceProfile = awsIamService.getInstanceProfile(iam, instanceProfileArn, validationRequestBuilder); assertThat(instanceProfile.getArn()).isEqualTo(instanceProfileArn); assertThat(validationRequestBuilder.build().hasError()).isFalse(); }
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; }
AwsIamService { 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; } }
AwsIamService { 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; }  }
AwsIamService { 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; }  InstanceProfile getInstanceProfile(AmazonIdentityManagement iam, String instanceProfileArn,
            ValidationResultBuilder validationResultBuilder); Set<Role> getValidRoles(AmazonIdentityManagement iam, Set<String> roleArns,
            ValidationResultBuilder validationResultBuilder); Role getRole(AmazonIdentityManagement iam, String roleArn,
            ValidationResultBuilder validationResultBuilder); Policy getAssumeRolePolicy(Role role); Policy getPolicy(String policyFileName, Map<String, String> replacements); SortedSet<String> getStatementActions(Statement statement); SortedSet<String> getStatementResources(Statement statement); List<EvaluationResult> simulatePrincipalPolicy(AmazonIdentityManagement iam,
            String policySourceArn, Collection<String> actionNames, Collection<String> resourceArns); List<EvaluationResult> validateRolePolicies(AmazonIdentityManagement iam, Role role,
            Collection<Policy> policies); }
AwsIamService { 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; }  InstanceProfile getInstanceProfile(AmazonIdentityManagement iam, String instanceProfileArn,
            ValidationResultBuilder validationResultBuilder); Set<Role> getValidRoles(AmazonIdentityManagement iam, Set<String> roleArns,
            ValidationResultBuilder validationResultBuilder); Role getRole(AmazonIdentityManagement iam, String roleArn,
            ValidationResultBuilder validationResultBuilder); Policy getAssumeRolePolicy(Role role); Policy getPolicy(String policyFileName, Map<String, String> replacements); SortedSet<String> getStatementActions(Statement statement); SortedSet<String> getStatementResources(Statement statement); List<EvaluationResult> simulatePrincipalPolicy(AmazonIdentityManagement iam,
            String policySourceArn, Collection<String> actionNames, Collection<String> resourceArns); List<EvaluationResult> validateRolePolicies(AmazonIdentityManagement iam, Role role,
            Collection<Policy> policies);  }