@Test public void multipleSecrets() throws Exception { factory.begin(() -> { secretControlStore.setProjectSecret(projectId, SecretScopes.PROJECT, KEY1, VALUE1); secretControlStore.setProjectSecret(projectId, SecretScopes.PROJECT, KEY2, VALUE2); secretControlStore.setProjectSecret(projectId, SecretScopes.PROJECT_DEFAULT, KEY2, VALUE3); return null; }); assertThat(secretStore.getSecret(projectId, SecretScopes.PROJECT, KEY1), is(Optional.of(VALUE1))); assertThat(secretStore.getSecret(projectId, SecretScopes.PROJECT, KEY2), is(Optional.of(VALUE2))); assertThat(secretStore.getSecret(projectId, SecretScopes.PROJECT_DEFAULT, KEY2), is(Optional.of(VALUE3))); factory.autoCommit(() -> secretControlStore.deleteProjectSecret(projectId, SecretScopes.PROJECT_DEFAULT, KEY1)); assertThat(secretStore.getSecret(projectId, SecretScopes.PROJECT, KEY1), is(Optional.of(VALUE1))); assertThat(secretStore.getSecret(projectId, SecretScopes.PROJECT, KEY2), is(Optional.of(VALUE2))); assertThat(secretStore.getSecret(projectId, SecretScopes.PROJECT_DEFAULT, KEY2), is(Optional.of(VALUE3))); factory.autoCommit(() -> secretControlStore.deleteProjectSecret(projectId, SecretScopes.PROJECT, KEY1)); assertThat(secretStore.getSecret(projectId, SecretScopes.PROJECT, KEY1), is(Optional.absent())); assertThat(secretStore.getSecret(projectId, SecretScopes.PROJECT, KEY2), is(Optional.of(VALUE2))); assertThat(secretStore.getSecret(projectId, SecretScopes.PROJECT_DEFAULT, KEY2), is(Optional.of(VALUE3))); factory.autoCommit(() -> secretControlStore.deleteProjectSecret(projectId, SecretScopes.PROJECT, KEY2)); assertThat(secretStore.getSecret(projectId, SecretScopes.PROJECT, KEY2), is(Optional.absent())); assertThat(secretStore.getSecret(projectId, SecretScopes.PROJECT_DEFAULT, KEY2), is(Optional.of(VALUE3))); }
@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);  }