@Test public void getAllCredentialsShouldBeAbleToMigrateCredentialsWithoutSDLC() { 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 fakeCred2 = new DBCredential(); fakeCred2.setName("APP.dev.testKey2"); fakeCred2.setVersion("0001"); fakeCred2.setUpdatedBy("Ned Stark"); fakeCred2.setUpdatedDate("2018-04-04T12:51:37.803Z"); DBCredential fakeCred3 = new DBCredential(); fakeCred3.setName("APP.dev.testKey3.extra"); fakeCred3.setVersion("0001"); fakeCred3.setUpdatedBy("Ned Stark"); fakeCred3.setUpdatedDate("2018-04-04T12:51:37.803Z"); DBCredential fakeCred4 = new DBCredential(); fakeCred4.setName("APP.TestComponent.dev.testKey"); fakeCred4.setComponent("TestComponent"); fakeCred4.setSdlc("dev"); fakeCred4.setVersion("0001"); fakeCred4.setUpdatedBy("Ned Stark"); fakeCred4.setUpdatedDate("2018-04-04T12:51:37.803Z"); DBCredential fakeCred5 = new DBCredential(); fakeCred5.setName("APP.dev.testKey2"); fakeCred5.setSdlc("dev"); fakeCred5.setVersion("0001"); fakeCred5.setUpdatedBy("Ned Stark"); fakeCred5.setUpdatedDate("2018-04-04T12:51:37.803Z"); DBCredential fakeCred6 = new DBCredential(); fakeCred6.setName("APP.dev.testKey3.extra"); fakeCred6.setSdlc("testKey3"); fakeCred6.setComponent("dev"); fakeCred6.setVersion("0001"); fakeCred6.setUpdatedBy("Ned Stark"); fakeCred6.setUpdatedDate("2018-04-04T12:51:37.803Z"); fakeData.add(fakeCred1); fakeData.add(fakeCred2); fakeData.add(fakeCred3); when(dynamoDBService.scanDynamoDB(any(), eq(DBCredential.class), any())).thenReturn(fakeData); when(migrateService.guessCredentialProperties(fakeCred1)).thenReturn(fakeCred4); when(migrateService.guessCredentialProperties(fakeCred2)).thenReturn(fakeCred5); when(migrateService.guessCredentialProperties(fakeCred3)).thenReturn(fakeCred6); List<Credential> expectedCreds = new ArrayList<>(); expectedCreds.add(new Credential("testKey2", "APP.dev.testKey2", "some-account","region", "APP", "dev", null, "Ned Stark", "2018-04-04T12:51:37.803Z")); expectedCreds.add(new Credential("testKey", "APP.TestComponent.dev.testKey", "some-account", "region", "APP", "dev", "TestComponent", "Ned Stark", "2018-04-04T12:51:37.803Z")); expectedCreds.add(new Credential("extra", "APP.dev.testKey3.extra", "some-account", "region", "APP", "testKey3", "dev", "Ned Stark", "2018-04-04T12:51:37.803Z")); List<Credential> results = credentialsService.getAllCredentials("table", "some-account", "region", "APP"); assertEquals(results, expectedCreds); }
@PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") public List<Credential> getAllCredentials(String tableName, String account, String region, String application) throws FideliusException{ logger.info(String.format("Getting all credentials for app %s using account %s and region %s.", application, account, region)); List<Credential> results = new ArrayList<>(); 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(application + ".")); StringBuilder sb = new StringBuilder(); sb.append("begins_with (#tempname, :key)"); DynamoDBScanExpression queryExp = new DynamoDBScanExpression() .withFilterExpression(sb.toString()) .withExpressionAttributeValues(eav) .withExpressionAttributeNames(ean); List<DBCredential> queryResults = dynamoDBService.scanDynamoDB(queryExp, DBCredential.class, mapper); Map<String, DBCredential> credentials = getLatestCredentialVersion(queryResults); for (DBCredential dbCredential : credentials.values()) { if(dbCredential.getSdlc() == null){ logger.info(String.format("Credential %s missing attributes. Attempting to add missing attributes: ", dbCredential.getName())); dbCredential = migrateService.guessCredentialProperties(dbCredential); } try { Credential credential = new Credential(dbCredential.getShortKey(), dbCredential.getName(), account, region, application, dbCredential.getSdlc(), dbCredential.getComponent(), splitRoleARN(dbCredential.getUpdatedBy()), dbCredential.getUpdatedDate()); if(credential.getEnvironment() != null) results.add(credential); }catch (Exception e){ logger.error("Error parsing key " + dbCredential.getName(), e); } } logger.info(String.format("%2d credentials for application %s successfully retrieved.",results.size(), application)); return results .stream() .sorted(Comparator.comparing(Credential::getLastUpdatedDate, Comparator.nullsLast(Comparator.reverseOrder()))) .collect(Collectors.toList()); }
CredentialsService { @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") public List<Credential> getAllCredentials(String tableName, String account, String region, String application) throws FideliusException{ logger.info(String.format("Getting all credentials for app %s using account %s and region %s.", application, account, region)); List<Credential> results = new ArrayList<>(); 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(application + ".")); StringBuilder sb = new StringBuilder(); sb.append("begins_with (#tempname, :key)"); DynamoDBScanExpression queryExp = new DynamoDBScanExpression() .withFilterExpression(sb.toString()) .withExpressionAttributeValues(eav) .withExpressionAttributeNames(ean); List<DBCredential> queryResults = dynamoDBService.scanDynamoDB(queryExp, DBCredential.class, mapper); Map<String, DBCredential> credentials = getLatestCredentialVersion(queryResults); for (DBCredential dbCredential : credentials.values()) { if(dbCredential.getSdlc() == null){ logger.info(String.format("Credential %s missing attributes. Attempting to add missing attributes: ", dbCredential.getName())); dbCredential = migrateService.guessCredentialProperties(dbCredential); } try { Credential credential = new Credential(dbCredential.getShortKey(), dbCredential.getName(), account, region, application, dbCredential.getSdlc(), dbCredential.getComponent(), splitRoleARN(dbCredential.getUpdatedBy()), dbCredential.getUpdatedDate()); if(credential.getEnvironment() != null) results.add(credential); }catch (Exception e){ logger.error("Error parsing key " + dbCredential.getName(), e); } } logger.info(String.format("%2d credentials for application %s successfully retrieved.",results.size(), application)); return results .stream() .sorted(Comparator.comparing(Credential::getLastUpdatedDate, Comparator.nullsLast(Comparator.reverseOrder()))) .collect(Collectors.toList()); } }
CredentialsService { @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") public List<Credential> getAllCredentials(String tableName, String account, String region, String application) throws FideliusException{ logger.info(String.format("Getting all credentials for app %s using account %s and region %s.", application, account, region)); List<Credential> results = new ArrayList<>(); 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(application + ".")); StringBuilder sb = new StringBuilder(); sb.append("begins_with (#tempname, :key)"); DynamoDBScanExpression queryExp = new DynamoDBScanExpression() .withFilterExpression(sb.toString()) .withExpressionAttributeValues(eav) .withExpressionAttributeNames(ean); List<DBCredential> queryResults = dynamoDBService.scanDynamoDB(queryExp, DBCredential.class, mapper); Map<String, DBCredential> credentials = getLatestCredentialVersion(queryResults); for (DBCredential dbCredential : credentials.values()) { if(dbCredential.getSdlc() == null){ logger.info(String.format("Credential %s missing attributes. Attempting to add missing attributes: ", dbCredential.getName())); dbCredential = migrateService.guessCredentialProperties(dbCredential); } try { Credential credential = new Credential(dbCredential.getShortKey(), dbCredential.getName(), account, region, application, dbCredential.getSdlc(), dbCredential.getComponent(), splitRoleARN(dbCredential.getUpdatedBy()), dbCredential.getUpdatedDate()); if(credential.getEnvironment() != null) results.add(credential); }catch (Exception e){ logger.error("Error parsing key " + dbCredential.getName(), e); } } logger.info(String.format("%2d credentials for application %s successfully retrieved.",results.size(), application)); return results .stream() .sorted(Comparator.comparing(Credential::getLastUpdatedDate, Comparator.nullsLast(Comparator.reverseOrder()))) .collect(Collectors.toList()); }  }
CredentialsService { @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") public List<Credential> getAllCredentials(String tableName, String account, String region, String application) throws FideliusException{ logger.info(String.format("Getting all credentials for app %s using account %s and region %s.", application, account, region)); List<Credential> results = new ArrayList<>(); 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(application + ".")); StringBuilder sb = new StringBuilder(); sb.append("begins_with (#tempname, :key)"); DynamoDBScanExpression queryExp = new DynamoDBScanExpression() .withFilterExpression(sb.toString()) .withExpressionAttributeValues(eav) .withExpressionAttributeNames(ean); List<DBCredential> queryResults = dynamoDBService.scanDynamoDB(queryExp, DBCredential.class, mapper); Map<String, DBCredential> credentials = getLatestCredentialVersion(queryResults); for (DBCredential dbCredential : credentials.values()) { if(dbCredential.getSdlc() == null){ logger.info(String.format("Credential %s missing attributes. Attempting to add missing attributes: ", dbCredential.getName())); dbCredential = migrateService.guessCredentialProperties(dbCredential); } try { Credential credential = new Credential(dbCredential.getShortKey(), dbCredential.getName(), account, region, application, dbCredential.getSdlc(), dbCredential.getComponent(), splitRoleARN(dbCredential.getUpdatedBy()), dbCredential.getUpdatedDate()); if(credential.getEnvironment() != null) results.add(credential); }catch (Exception e){ logger.error("Error parsing key " + dbCredential.getName(), e); } } logger.info(String.format("%2d credentials for application %s successfully retrieved.",results.size(), application)); return results .stream() .sorted(Comparator.comparing(Credential::getLastUpdatedDate, Comparator.nullsLast(Comparator.reverseOrder()))) .collect(Collectors.toList()); }  @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 List<Credential> getAllCredentials(String tableName, String account, String region, String application) throws FideliusException{ logger.info(String.format("Getting all credentials for app %s using account %s and region %s.", application, account, region)); List<Credential> results = new ArrayList<>(); 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(application + ".")); StringBuilder sb = new StringBuilder(); sb.append("begins_with (#tempname, :key)"); DynamoDBScanExpression queryExp = new DynamoDBScanExpression() .withFilterExpression(sb.toString()) .withExpressionAttributeValues(eav) .withExpressionAttributeNames(ean); List<DBCredential> queryResults = dynamoDBService.scanDynamoDB(queryExp, DBCredential.class, mapper); Map<String, DBCredential> credentials = getLatestCredentialVersion(queryResults); for (DBCredential dbCredential : credentials.values()) { if(dbCredential.getSdlc() == null){ logger.info(String.format("Credential %s missing attributes. Attempting to add missing attributes: ", dbCredential.getName())); dbCredential = migrateService.guessCredentialProperties(dbCredential); } try { Credential credential = new Credential(dbCredential.getShortKey(), dbCredential.getName(), account, region, application, dbCredential.getSdlc(), dbCredential.getComponent(), splitRoleARN(dbCredential.getUpdatedBy()), dbCredential.getUpdatedDate()); if(credential.getEnvironment() != null) results.add(credential); }catch (Exception e){ logger.error("Error parsing key " + dbCredential.getName(), e); } } logger.info(String.format("%2d credentials for application %s successfully retrieved.",results.size(), application)); return results .stream() .sorted(Comparator.comparing(Credential::getLastUpdatedDate, Comparator.nullsLast(Comparator.reverseOrder()))) .collect(Collectors.toList()); }  @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);  }