@Test(expected = Exception.class) public void getCredentialFaliureToMigrate()throws Exception { List<DBCredential> fakeData = new ArrayList<>(); DBCredential fakeCred1 = new DBCredential(); fakeCred1.setName("APP.TestComponent.dev.testKey"); fakeCred1.setVersion("0001"); fakeCred1.setUpdatedBy("Jon Snow"); fakeCred1.setUpdatedDate("2018-04-04T12:51:37.803Z"); DBCredential fakeCred4 = new DBCredential(); fakeCred4.setName("APP.TestComponent.dev.testKey"); fakeCred4.setVersion("0001"); fakeCred4.setUpdatedBy("Ned Stark"); fakeCred4.setUpdatedDate("2018-04-04T12:51:37.803Z"); fakeData.add(fakeCred1); when(dynamoDBService.queryDynamoDB(any(), eq(DBCredential.class), any())).thenReturn(fakeData); when(migrateService.migrateCredential(any(), any())).thenReturn(null); Credential expectedCreds = new Credential("testKey", "APP.TestComponent.dev.testKey", "some-account", "region", "APP", "dev", "TestComponent", "Ned Stark", "2018-04-04T12:51:37.803Z"); Credential result = credentialsService.getCredential("some-account", "region", "APP", "APP.TestComponent.dev.testKey"); assertEquals(null, result); }
@PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") public Credential getCredential(String account, String region, String application, String longKey) throws FideliusException { DynamoDBMapper mapper = dynamoDBService.createMapper(account, region, tableName); setFideliusEnvironment(account, region); Map<String, String> ean = new HashMap<>(); ean.put("#tempname", "name"); Map<String, AttributeValue> eav = new HashMap<>(); eav.put(":key", new AttributeValue().withS(longKey)); DynamoDBQueryExpression<DBCredential> queryExpression = new DynamoDBQueryExpression<DBCredential>() .withExpressionAttributeNames(ean) .withKeyConditionExpression("#tempname = :key") .withExpressionAttributeValues(eav); List<DBCredential> queryResults = dynamoDBService.queryDynamoDB(queryExpression, DBCredential.class, mapper); Map<String, DBCredential> credentials = getLatestCredentialVersion(queryResults); try { DBCredential dbCredential = credentials.values().stream().findFirst().get(); if(dbCredential.getSdlc() == null) { dbCredential = migrateService.migrateCredential(dbCredential, fideliusService); } try { return (new Credential(dbCredential.getShortKey(), dbCredential.getName(), account, region, application, dbCredential.getSdlc(), dbCredential.getComponent(), splitRoleARN(dbCredential.getUpdatedBy()), dbCredential.getUpdatedDate())); }catch (Exception e){ logger.error("Error parsing key " + dbCredential.getName(), e); } } catch (NoSuchElementException e) { logger.error("Credential " + longKey + " not found" , e); return null; } return null; }
CredentialsService { @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") public Credential getCredential(String account, String region, String application, String longKey) throws FideliusException { DynamoDBMapper mapper = dynamoDBService.createMapper(account, region, tableName); setFideliusEnvironment(account, region); Map<String, String> ean = new HashMap<>(); ean.put("#tempname", "name"); Map<String, AttributeValue> eav = new HashMap<>(); eav.put(":key", new AttributeValue().withS(longKey)); DynamoDBQueryExpression<DBCredential> queryExpression = new DynamoDBQueryExpression<DBCredential>() .withExpressionAttributeNames(ean) .withKeyConditionExpression("#tempname = :key") .withExpressionAttributeValues(eav); List<DBCredential> queryResults = dynamoDBService.queryDynamoDB(queryExpression, DBCredential.class, mapper); Map<String, DBCredential> credentials = getLatestCredentialVersion(queryResults); try { DBCredential dbCredential = credentials.values().stream().findFirst().get(); if(dbCredential.getSdlc() == null) { dbCredential = migrateService.migrateCredential(dbCredential, fideliusService); } try { return (new Credential(dbCredential.getShortKey(), dbCredential.getName(), account, region, application, dbCredential.getSdlc(), dbCredential.getComponent(), splitRoleARN(dbCredential.getUpdatedBy()), dbCredential.getUpdatedDate())); }catch (Exception e){ logger.error("Error parsing key " + dbCredential.getName(), e); } } catch (NoSuchElementException e) { logger.error("Credential " + longKey + " not found" , e); return null; } return null; } }
CredentialsService { @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") public Credential getCredential(String account, String region, String application, String longKey) throws FideliusException { DynamoDBMapper mapper = dynamoDBService.createMapper(account, region, tableName); setFideliusEnvironment(account, region); Map<String, String> ean = new HashMap<>(); ean.put("#tempname", "name"); Map<String, AttributeValue> eav = new HashMap<>(); eav.put(":key", new AttributeValue().withS(longKey)); DynamoDBQueryExpression<DBCredential> queryExpression = new DynamoDBQueryExpression<DBCredential>() .withExpressionAttributeNames(ean) .withKeyConditionExpression("#tempname = :key") .withExpressionAttributeValues(eav); List<DBCredential> queryResults = dynamoDBService.queryDynamoDB(queryExpression, DBCredential.class, mapper); Map<String, DBCredential> credentials = getLatestCredentialVersion(queryResults); try { DBCredential dbCredential = credentials.values().stream().findFirst().get(); if(dbCredential.getSdlc() == null) { dbCredential = migrateService.migrateCredential(dbCredential, fideliusService); } try { return (new Credential(dbCredential.getShortKey(), dbCredential.getName(), account, region, application, dbCredential.getSdlc(), dbCredential.getComponent(), splitRoleARN(dbCredential.getUpdatedBy()), dbCredential.getUpdatedDate())); }catch (Exception e){ logger.error("Error parsing key " + dbCredential.getName(), e); } } catch (NoSuchElementException e) { logger.error("Credential " + longKey + " not found" , e); return null; } return null; }  }
CredentialsService { @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") public Credential getCredential(String account, String region, String application, String longKey) throws FideliusException { DynamoDBMapper mapper = dynamoDBService.createMapper(account, region, tableName); setFideliusEnvironment(account, region); Map<String, String> ean = new HashMap<>(); ean.put("#tempname", "name"); Map<String, AttributeValue> eav = new HashMap<>(); eav.put(":key", new AttributeValue().withS(longKey)); DynamoDBQueryExpression<DBCredential> queryExpression = new DynamoDBQueryExpression<DBCredential>() .withExpressionAttributeNames(ean) .withKeyConditionExpression("#tempname = :key") .withExpressionAttributeValues(eav); List<DBCredential> queryResults = dynamoDBService.queryDynamoDB(queryExpression, DBCredential.class, mapper); Map<String, DBCredential> credentials = getLatestCredentialVersion(queryResults); try { DBCredential dbCredential = credentials.values().stream().findFirst().get(); if(dbCredential.getSdlc() == null) { dbCredential = migrateService.migrateCredential(dbCredential, fideliusService); } try { return (new Credential(dbCredential.getShortKey(), dbCredential.getName(), account, region, application, dbCredential.getSdlc(), dbCredential.getComponent(), splitRoleARN(dbCredential.getUpdatedBy()), dbCredential.getUpdatedDate())); }catch (Exception e){ logger.error("Error parsing key " + dbCredential.getName(), e); } } catch (NoSuchElementException e) { logger.error("Credential " + longKey + " not found" , e); return null; } return null; }  @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") List<Credential> getAllCredentials(String tableName, String account, String region, String application); @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") Credential getCredential(String account, String region, String application, String longKey); @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") List<HistoryEntry> getCredentialHistory(String tableName, String account, String region, String application, String environment, String component, String key); @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account)") Credential getCredentialSecret(String account, String region, String application, String environment,
                                      String component, String shortKey); @PreAuthorize("@fideliusRoleService.isAuthorized(#credential.application, #credential.account)") Credential putCredential(Credential credential); @PreAuthorize("@fideliusRoleService.isAuthorized(#credential.application, #credential.account)") Credential createCredential(Credential credential); @PreAuthorize("@fideliusRoleService.isAuthorizedToDelete(#credential.getApplication(), #credential.getAccount())") Credential deleteCredential(Credential credential); }
CredentialsService { @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") public Credential getCredential(String account, String region, String application, String longKey) throws FideliusException { DynamoDBMapper mapper = dynamoDBService.createMapper(account, region, tableName); setFideliusEnvironment(account, region); Map<String, String> ean = new HashMap<>(); ean.put("#tempname", "name"); Map<String, AttributeValue> eav = new HashMap<>(); eav.put(":key", new AttributeValue().withS(longKey)); DynamoDBQueryExpression<DBCredential> queryExpression = new DynamoDBQueryExpression<DBCredential>() .withExpressionAttributeNames(ean) .withKeyConditionExpression("#tempname = :key") .withExpressionAttributeValues(eav); List<DBCredential> queryResults = dynamoDBService.queryDynamoDB(queryExpression, DBCredential.class, mapper); Map<String, DBCredential> credentials = getLatestCredentialVersion(queryResults); try { DBCredential dbCredential = credentials.values().stream().findFirst().get(); if(dbCredential.getSdlc() == null) { dbCredential = migrateService.migrateCredential(dbCredential, fideliusService); } try { return (new Credential(dbCredential.getShortKey(), dbCredential.getName(), account, region, application, dbCredential.getSdlc(), dbCredential.getComponent(), splitRoleARN(dbCredential.getUpdatedBy()), dbCredential.getUpdatedDate())); }catch (Exception e){ logger.error("Error parsing key " + dbCredential.getName(), e); } } catch (NoSuchElementException e) { logger.error("Credential " + longKey + " not found" , e); return null; } return null; }  @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") List<Credential> getAllCredentials(String tableName, String account, String region, String application); @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") Credential getCredential(String account, String region, String application, String longKey); @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") List<HistoryEntry> getCredentialHistory(String tableName, String account, String region, String application, String environment, String component, String key); @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account)") Credential getCredentialSecret(String account, String region, String application, String environment,
                                      String component, String shortKey); @PreAuthorize("@fideliusRoleService.isAuthorized(#credential.application, #credential.account)") Credential putCredential(Credential credential); @PreAuthorize("@fideliusRoleService.isAuthorized(#credential.application, #credential.account)") Credential createCredential(Credential credential); @PreAuthorize("@fideliusRoleService.isAuthorizedToDelete(#credential.getApplication(), #credential.getAccount())") Credential deleteCredential(Credential credential);  }