@Test public void getDynamicDbCredentials() { credentials.data = new VaultDatabaseCredentialsData(); credentials.data.username = "bob"; credentials.data.password = "sinclair1"; credentials.leaseId = mylease; credentials.leaseDurationSecs = 10; credentials.renewable = true; vaultRenewLease.leaseId = mylease; vaultRenewLease.leaseDurationSecs = 10; vaultRenewLease.renewable = true; Map<String, String> properties = vaultDbManager.getDynamicDbCredentials(mydbrole); assertEquals("bob", properties.get(USER_PROPERTY_NAME)); assertEquals("sinclair1", properties.get(PASSWORD_PROPERTY_NAME)); VaultDynamicDatabaseCredentials vaultDynamicDatabaseCredentials = vaultDbManager.credentialsCache.get(mydbrole); vaultDynamicDatabaseCredentials.created = EPOCH; vaultDynamicDatabaseCredentials.nowSupplier = () -> EPOCH.plusSeconds(1); credentials.data.password = "sinclair2"; properties = vaultDbManager.getDynamicDbCredentials(mydbrole); assertEquals("sinclair1", properties.get(PASSWORD_PROPERTY_NAME), "returned from cache"); lookupLeaseShouldReturn400.set(true); properties = vaultDbManager.getDynamicDbCredentials(mydbrole); assertEquals("sinclair2", properties.get(PASSWORD_PROPERTY_NAME), "fetched again because of 400"); lookupLeaseShouldReturn400.set(false); vaultDynamicDatabaseCredentials = vaultDbManager.credentialsCache.get(mydbrole); vaultDynamicDatabaseCredentials.created = EPOCH; vaultDynamicDatabaseCredentials.password = "sinclair3"; vaultDynamicDatabaseCredentials.nowSupplier = () -> EPOCH.plusSeconds(8); properties = vaultDbManager.getDynamicDbCredentials(mydbrole); assertEquals("sinclair3", properties.get(PASSWORD_PROPERTY_NAME), "extended"); vaultDynamicDatabaseCredentials = vaultDbManager.credentialsCache.get(mydbrole); vaultDynamicDatabaseCredentials.created = EPOCH; vaultDynamicDatabaseCredentials.nowSupplier = () -> EPOCH.plusSeconds(12); credentials.data.password = "sinclair4"; properties = vaultDbManager.getDynamicDbCredentials(mydbrole); assertEquals("sinclair4", properties.get(PASSWORD_PROPERTY_NAME), "recreated"); vaultDynamicDatabaseCredentials = vaultDbManager.credentialsCache.get(mydbrole); vaultDynamicDatabaseCredentials.created = EPOCH; vaultDynamicDatabaseCredentials.nowSupplier = () -> EPOCH.plusSeconds(8); vaultDynamicDatabaseCredentials.leaseDurationSecs = 2; credentials.data.password = "sinclair5"; properties = vaultDbManager.getDynamicDbCredentials(mydbrole); assertEquals("sinclair5", properties.get(PASSWORD_PROPERTY_NAME), "reaching max-ttl"); }
public Map<String, String> getDynamicDbCredentials(String databaseCredentialsRole) { String clientToken = vaultAuthManager.getClientToken(); VaultDynamicDatabaseCredentials currentCredentials = credentialsCache.get(databaseCredentialsRole); VaultDynamicDatabaseCredentials credentials = getCredentials(currentCredentials, clientToken, databaseCredentialsRole); credentialsCache.put(databaseCredentialsRole, credentials); Map<String, String> properties = new HashMap<>(); properties.put(USER_PROPERTY_NAME, credentials.username); properties.put(PASSWORD_PROPERTY_NAME, credentials.password); return properties; }
VaultDbManager { public Map<String, String> getDynamicDbCredentials(String databaseCredentialsRole) { String clientToken = vaultAuthManager.getClientToken(); VaultDynamicDatabaseCredentials currentCredentials = credentialsCache.get(databaseCredentialsRole); VaultDynamicDatabaseCredentials credentials = getCredentials(currentCredentials, clientToken, databaseCredentialsRole); credentialsCache.put(databaseCredentialsRole, credentials); Map<String, String> properties = new HashMap<>(); properties.put(USER_PROPERTY_NAME, credentials.username); properties.put(PASSWORD_PROPERTY_NAME, credentials.password); return properties; } }
VaultDbManager { public Map<String, String> getDynamicDbCredentials(String databaseCredentialsRole) { String clientToken = vaultAuthManager.getClientToken(); VaultDynamicDatabaseCredentials currentCredentials = credentialsCache.get(databaseCredentialsRole); VaultDynamicDatabaseCredentials credentials = getCredentials(currentCredentials, clientToken, databaseCredentialsRole); credentialsCache.put(databaseCredentialsRole, credentials); Map<String, String> properties = new HashMap<>(); properties.put(USER_PROPERTY_NAME, credentials.username); properties.put(PASSWORD_PROPERTY_NAME, credentials.password); return properties; } VaultDbManager(VaultAuthManager vaultAuthManager, VaultClient vaultClient, VaultRuntimeConfig serverConfig); }
VaultDbManager { public Map<String, String> getDynamicDbCredentials(String databaseCredentialsRole) { String clientToken = vaultAuthManager.getClientToken(); VaultDynamicDatabaseCredentials currentCredentials = credentialsCache.get(databaseCredentialsRole); VaultDynamicDatabaseCredentials credentials = getCredentials(currentCredentials, clientToken, databaseCredentialsRole); credentialsCache.put(databaseCredentialsRole, credentials); Map<String, String> properties = new HashMap<>(); properties.put(USER_PROPERTY_NAME, credentials.username); properties.put(PASSWORD_PROPERTY_NAME, credentials.password); return properties; } VaultDbManager(VaultAuthManager vaultAuthManager, VaultClient vaultClient, VaultRuntimeConfig serverConfig); Map<String, String> getDynamicDbCredentials(String databaseCredentialsRole); VaultDynamicDatabaseCredentials getCredentials(VaultDynamicDatabaseCredentials currentCredentials,
            String clientToken,
            String databaseCredentialsRole); }
VaultDbManager { public Map<String, String> getDynamicDbCredentials(String databaseCredentialsRole) { String clientToken = vaultAuthManager.getClientToken(); VaultDynamicDatabaseCredentials currentCredentials = credentialsCache.get(databaseCredentialsRole); VaultDynamicDatabaseCredentials credentials = getCredentials(currentCredentials, clientToken, databaseCredentialsRole); credentialsCache.put(databaseCredentialsRole, credentials); Map<String, String> properties = new HashMap<>(); properties.put(USER_PROPERTY_NAME, credentials.username); properties.put(PASSWORD_PROPERTY_NAME, credentials.password); return properties; } VaultDbManager(VaultAuthManager vaultAuthManager, VaultClient vaultClient, VaultRuntimeConfig serverConfig); Map<String, String> getDynamicDbCredentials(String databaseCredentialsRole); VaultDynamicDatabaseCredentials getCredentials(VaultDynamicDatabaseCredentials currentCredentials,
            String clientToken,
            String databaseCredentialsRole);  }