@Test void testUpdateByAccountId() { Credential result = new Credential(); result.setId(2L); result.setResourceCrn("this"); result.setCloudPlatform(PLATFORM); CREDENTIAL.setId(1L); CREDENTIAL.setResourceCrn("that"); CREDENTIAL.setCloudPlatform(PLATFORM); when(repository.findByNameAndAccountId(eq(CREDENTIAL_NAME), eq(ACCOUNT_ID), anyCollection(), any())) .thenReturn(Optional.of(result)); when(credentialAdapter.verify(any(), anyString())).thenAnswer(i -> new CredentialVerification(i.getArgument(0), true)); when(repository.save(any())).thenAnswer(i -> i.getArgument(0)); when(credentialValidator.validateCredentialUpdate(any(Credential.class), any(Credential.class), any(CredentialType.class))) .thenReturn(ValidationResult.builder().build()); Credential testResult = credentialServiceUnderTest.updateByAccountId(CREDENTIAL, ACCOUNT_ID, ENVIRONMENT); verify(repository).save(CREDENTIAL); assertEquals(2L, testResult.getId()); }
public Credential updateByAccountId(Credential credential, String accountId, CredentialType type) { Credential original = getCredentialAndValidateUpdate(credential, accountId, type); credential.setId(original.getId()); credential.setAccountId(accountId); credential.setResourceCrn(original.getResourceCrn()); credential.setCreator(original.getCreator()); Credential updated = repository.save(credentialAdapter.verify(credential, accountId).getCredential()); secretService.delete(original.getAttributesSecret()); sendCredentialNotification(credential, ResourceEvent.CREDENTIAL_MODIFIED); return updated; }
CredentialService extends AbstractCredentialService implements ResourceBasedCrnProvider { public Credential updateByAccountId(Credential credential, String accountId, CredentialType type) { Credential original = getCredentialAndValidateUpdate(credential, accountId, type); credential.setId(original.getId()); credential.setAccountId(accountId); credential.setResourceCrn(original.getResourceCrn()); credential.setCreator(original.getCreator()); Credential updated = repository.save(credentialAdapter.verify(credential, accountId).getCredential()); secretService.delete(original.getAttributesSecret()); sendCredentialNotification(credential, ResourceEvent.CREDENTIAL_MODIFIED); return updated; } }
CredentialService extends AbstractCredentialService implements ResourceBasedCrnProvider { public Credential updateByAccountId(Credential credential, String accountId, CredentialType type) { Credential original = getCredentialAndValidateUpdate(credential, accountId, type); credential.setId(original.getId()); credential.setAccountId(accountId); credential.setResourceCrn(original.getResourceCrn()); credential.setCreator(original.getCreator()); Credential updated = repository.save(credentialAdapter.verify(credential, accountId).getCredential()); secretService.delete(original.getAttributesSecret()); sendCredentialNotification(credential, ResourceEvent.CREDENTIAL_MODIFIED); return updated; } protected  CredentialService(NotificationSender notificationSender, CloudbreakMessagesService messagesService,
            @Value("${environment.enabledplatforms}") Set<String> enabledPlatforms); }
CredentialService extends AbstractCredentialService implements ResourceBasedCrnProvider { public Credential updateByAccountId(Credential credential, String accountId, CredentialType type) { Credential original = getCredentialAndValidateUpdate(credential, accountId, type); credential.setId(original.getId()); credential.setAccountId(accountId); credential.setResourceCrn(original.getResourceCrn()); credential.setCreator(original.getCreator()); Credential updated = repository.save(credentialAdapter.verify(credential, accountId).getCredential()); secretService.delete(original.getAttributesSecret()); sendCredentialNotification(credential, ResourceEvent.CREDENTIAL_MODIFIED); return updated; } protected  CredentialService(NotificationSender notificationSender, CloudbreakMessagesService messagesService,
            @Value("${environment.enabledplatforms}") Set<String> enabledPlatforms); Set<Credential> listAvailablesByAccountId(String accountId, CredentialType type); @Cacheable(cacheNames = "credentialCloudPlatformCache") Set<String> getValidPlatformsForAccountId(String accountId); Credential getByNameForAccountId(String name, String accountId, CredentialType type); Optional<Credential> getOptionalByNameForAccountId(String name, String accountId, CredentialType type); Credential getByCrnForAccountId(String crn, String accountId, CredentialType type); Optional<Credential> getOptionalByCrnForAccountId(String crn, String accountId, CredentialType type); Credential extractCredential(Optional<Credential> credential, String resourceIdentifier); Credential getByEnvironmentCrnAndAccountId(String environmentCrn, String accountId, CredentialType type); Credential getByEnvironmentNameAndAccountId(String environmentName, String accountId, CredentialType type); Map<String, String> interactiveLogin(String accountId, String userId, Credential credential); Credential verify(Credential credential); Credential updateByAccountId(Credential credential, String accountId, CredentialType type); @Retryable(value = BadRequestException.class, maxAttempts = 30, backoff = @Backoff(delay = 2000)) void createWithRetry(Credential credential, String accountId, String creatorUserCrn); Credential create(Credential credential, @Nonnull String accountId, @Nonnull String creatorUserCrn, CredentialType type); CredentialPrerequisitesResponse getPrerequisites(String cloudPlatform, String deploymentAddress, String userCrn, CredentialType type); String initCodeGrantFlow(String accountId, @Nonnull Credential credential, String creatorUserCrn); String initCodeGrantFlow(String accountId, String name, String userId); Credential authorizeCodeGrantFlow(String code, @Nonnull String state, String accountId, @Nonnull String platform); String getCloudPlatformByCredential(String credentialName, String accountId, CredentialType type); CreateAWSCredentialRequest getCreateAWSCredentialForCli(CredentialRequest credentialRequest); @Override String getResourceCrnByResourceName(String resourceName); @Override List<String> getResourceCrnListByResourceNameList(List<String> resourceNames); @Override List<String> getResourceCrnsInAccount(); @Override AuthorizationResourceType getResourceType(); }
CredentialService extends AbstractCredentialService implements ResourceBasedCrnProvider { public Credential updateByAccountId(Credential credential, String accountId, CredentialType type) { Credential original = getCredentialAndValidateUpdate(credential, accountId, type); credential.setId(original.getId()); credential.setAccountId(accountId); credential.setResourceCrn(original.getResourceCrn()); credential.setCreator(original.getCreator()); Credential updated = repository.save(credentialAdapter.verify(credential, accountId).getCredential()); secretService.delete(original.getAttributesSecret()); sendCredentialNotification(credential, ResourceEvent.CREDENTIAL_MODIFIED); return updated; } protected  CredentialService(NotificationSender notificationSender, CloudbreakMessagesService messagesService,
            @Value("${environment.enabledplatforms}") Set<String> enabledPlatforms); Set<Credential> listAvailablesByAccountId(String accountId, CredentialType type); @Cacheable(cacheNames = "credentialCloudPlatformCache") Set<String> getValidPlatformsForAccountId(String accountId); Credential getByNameForAccountId(String name, String accountId, CredentialType type); Optional<Credential> getOptionalByNameForAccountId(String name, String accountId, CredentialType type); Credential getByCrnForAccountId(String crn, String accountId, CredentialType type); Optional<Credential> getOptionalByCrnForAccountId(String crn, String accountId, CredentialType type); Credential extractCredential(Optional<Credential> credential, String resourceIdentifier); Credential getByEnvironmentCrnAndAccountId(String environmentCrn, String accountId, CredentialType type); Credential getByEnvironmentNameAndAccountId(String environmentName, String accountId, CredentialType type); Map<String, String> interactiveLogin(String accountId, String userId, Credential credential); Credential verify(Credential credential); Credential updateByAccountId(Credential credential, String accountId, CredentialType type); @Retryable(value = BadRequestException.class, maxAttempts = 30, backoff = @Backoff(delay = 2000)) void createWithRetry(Credential credential, String accountId, String creatorUserCrn); Credential create(Credential credential, @Nonnull String accountId, @Nonnull String creatorUserCrn, CredentialType type); CredentialPrerequisitesResponse getPrerequisites(String cloudPlatform, String deploymentAddress, String userCrn, CredentialType type); String initCodeGrantFlow(String accountId, @Nonnull Credential credential, String creatorUserCrn); String initCodeGrantFlow(String accountId, String name, String userId); Credential authorizeCodeGrantFlow(String code, @Nonnull String state, String accountId, @Nonnull String platform); String getCloudPlatformByCredential(String credentialName, String accountId, CredentialType type); CreateAWSCredentialRequest getCreateAWSCredentialForCli(CredentialRequest credentialRequest); @Override String getResourceCrnByResourceName(String resourceName); @Override List<String> getResourceCrnListByResourceNameList(List<String> resourceNames); @Override List<String> getResourceCrnsInAccount(); @Override AuthorizationResourceType getResourceType();  }