@Test public void getSecretWithScope() throws Exception { String[] scopes = { SecretScopes.PROJECT, SecretScopes.PROJECT_DEFAULT, "foobar"}; for (String setScope : scopes) { factory.autoCommit(() -> secretControlStore.setProjectSecret(projectId, setScope, KEY1, VALUE1)); assertThat(secretStore.getSecret(projectId, setScope, KEY1), is(Optional.of(VALUE1))); for (String getScope : scopes) { if (getScope.equals(setScope)) { continue; } assertThat("set: " + setScope + ", get: " + getScope, secretStore.getSecret(projectId, getScope, KEY1), is(Optional.absent())); } factory.autoCommit(() -> secretControlStore.deleteProjectSecret(storedProject.getId(), setScope, KEY1)); } }
@Override public Optional<String> getSecret(int projectId, String scope, String key) { EncryptedSecret secret = tm.begin(() -> autoCommit((handle, dao) -> dao.getProjectSecret(siteId, projectId, scope, key))); if (secret == null) { return Optional.absent(); } if (!crypto.getName().equals(secret.engine)) { throw new AssertionError(String.format(ENGLISH, "Crypto engine mismatch. Expected '%s' but got '%s'", secret.engine, crypto.getName())); } String decrypted = crypto.decryptSecret(secret.value); return Optional.of(decrypted); }
DatabaseSecretStore extends BasicDatabaseStoreManager<DatabaseSecretStore.Dao> implements SecretStore { @Override public Optional<String> getSecret(int projectId, String scope, String key) { EncryptedSecret secret = tm.begin(() -> autoCommit((handle, dao) -> dao.getProjectSecret(siteId, projectId, scope, key))); if (secret == null) { return Optional.absent(); } if (!crypto.getName().equals(secret.engine)) { throw new AssertionError(String.format(ENGLISH, "Crypto engine mismatch. Expected '%s' but got '%s'", secret.engine, crypto.getName())); } String decrypted = crypto.decryptSecret(secret.value); return Optional.of(decrypted); } }
DatabaseSecretStore extends BasicDatabaseStoreManager<DatabaseSecretStore.Dao> implements SecretStore { @Override public Optional<String> getSecret(int projectId, String scope, String key) { EncryptedSecret secret = tm.begin(() -> autoCommit((handle, dao) -> dao.getProjectSecret(siteId, projectId, scope, key))); if (secret == null) { return Optional.absent(); } if (!crypto.getName().equals(secret.engine)) { throw new AssertionError(String.format(ENGLISH, "Crypto engine mismatch. Expected '%s' but got '%s'", secret.engine, crypto.getName())); } String decrypted = crypto.decryptSecret(secret.value); return Optional.of(decrypted); } DatabaseSecretStore(DatabaseConfig config, TransactionManager tm, ConfigMapper cfm, int siteId, SecretCrypto crypto); }
DatabaseSecretStore extends BasicDatabaseStoreManager<DatabaseSecretStore.Dao> implements SecretStore { @Override public Optional<String> getSecret(int projectId, String scope, String key) { EncryptedSecret secret = tm.begin(() -> autoCommit((handle, dao) -> dao.getProjectSecret(siteId, projectId, scope, key))); if (secret == null) { return Optional.absent(); } if (!crypto.getName().equals(secret.engine)) { throw new AssertionError(String.format(ENGLISH, "Crypto engine mismatch. Expected '%s' but got '%s'", secret.engine, crypto.getName())); } String decrypted = crypto.decryptSecret(secret.value); return Optional.of(decrypted); } DatabaseSecretStore(DatabaseConfig config, TransactionManager tm, ConfigMapper cfm, int siteId, SecretCrypto crypto); @Override Optional<String> getSecret(int projectId, String scope, String key); }
DatabaseSecretStore extends BasicDatabaseStoreManager<DatabaseSecretStore.Dao> implements SecretStore { @Override public Optional<String> getSecret(int projectId, String scope, String key) { EncryptedSecret secret = tm.begin(() -> autoCommit((handle, dao) -> dao.getProjectSecret(siteId, projectId, scope, key))); if (secret == null) { return Optional.absent(); } if (!crypto.getName().equals(secret.engine)) { throw new AssertionError(String.format(ENGLISH, "Crypto engine mismatch. Expected '%s' but got '%s'", secret.engine, crypto.getName())); } String decrypted = crypto.decryptSecret(secret.value); return Optional.of(decrypted); } DatabaseSecretStore(DatabaseConfig config, TransactionManager tm, ConfigMapper cfm, int siteId, SecretCrypto crypto); @Override Optional<String> getSecret(int projectId, String scope, String key);  }