@Test public void testPutExists() throws Exception { when(persistentEngine.isExists(anyString())).thenReturn(true); thrown.expect(InvalidKeyException.class); try { underTest.put("key", "value"); } catch (InvalidKeyException e) { verify(metricService, times(1)).submit(eq(MetricType.VAULT_READ), anyDouble()); throw e; } }
public String put(String key, String value) throws Exception { long start = System.currentTimeMillis(); boolean exists = vaultRetryService.tryReadingVault(() -> persistentEngine.isExists(key)); long duration = System.currentTimeMillis() - start; metricService.submit(MetricType.VAULT_READ, duration); LOGGER.trace("Secret read took {} ms", duration); if (exists) { throw new InvalidKeyException(format("Key: %s already exists!", key)); } start = System.currentTimeMillis(); String secret = vaultRetryService.tryWritingVault(() -> persistentEngine.put(key, value)); duration = System.currentTimeMillis() - start; metricService.submit(MetricType.VAULT_WRITE, duration); LOGGER.trace("Secret write took {} ms", duration); metricService.incrementMetricCounter(() -> "secret.write." + convertSecretToMetric(secret)); return secret; }
SecretService { public String put(String key, String value) throws Exception { long start = System.currentTimeMillis(); boolean exists = vaultRetryService.tryReadingVault(() -> persistentEngine.isExists(key)); long duration = System.currentTimeMillis() - start; metricService.submit(MetricType.VAULT_READ, duration); LOGGER.trace("Secret read took {} ms", duration); if (exists) { throw new InvalidKeyException(format("Key: %s already exists!", key)); } start = System.currentTimeMillis(); String secret = vaultRetryService.tryWritingVault(() -> persistentEngine.put(key, value)); duration = System.currentTimeMillis() - start; metricService.submit(MetricType.VAULT_WRITE, duration); LOGGER.trace("Secret write took {} ms", duration); metricService.incrementMetricCounter(() -> "secret.write." + convertSecretToMetric(secret)); return secret; } }
SecretService { public String put(String key, String value) throws Exception { long start = System.currentTimeMillis(); boolean exists = vaultRetryService.tryReadingVault(() -> persistentEngine.isExists(key)); long duration = System.currentTimeMillis() - start; metricService.submit(MetricType.VAULT_READ, duration); LOGGER.trace("Secret read took {} ms", duration); if (exists) { throw new InvalidKeyException(format("Key: %s already exists!", key)); } start = System.currentTimeMillis(); String secret = vaultRetryService.tryWritingVault(() -> persistentEngine.put(key, value)); duration = System.currentTimeMillis() - start; metricService.submit(MetricType.VAULT_WRITE, duration); LOGGER.trace("Secret write took {} ms", duration); metricService.incrementMetricCounter(() -> "secret.write." + convertSecretToMetric(secret)); return secret; } SecretService(MetricService metricService, List<SecretEngine> engines, VaultRetryService vaultRetryService); }
SecretService { public String put(String key, String value) throws Exception { long start = System.currentTimeMillis(); boolean exists = vaultRetryService.tryReadingVault(() -> persistentEngine.isExists(key)); long duration = System.currentTimeMillis() - start; metricService.submit(MetricType.VAULT_READ, duration); LOGGER.trace("Secret read took {} ms", duration); if (exists) { throw new InvalidKeyException(format("Key: %s already exists!", key)); } start = System.currentTimeMillis(); String secret = vaultRetryService.tryWritingVault(() -> persistentEngine.put(key, value)); duration = System.currentTimeMillis() - start; metricService.submit(MetricType.VAULT_WRITE, duration); LOGGER.trace("Secret write took {} ms", duration); metricService.incrementMetricCounter(() -> "secret.write." + convertSecretToMetric(secret)); return secret; } SecretService(MetricService metricService, List<SecretEngine> engines, VaultRetryService vaultRetryService); @PostConstruct void init(); String put(String key, String value); String get(String secret); String getByResponse(SecretResponse secretResponse); void delete(String secret); List<String> listEntries(String secretPathPrefix); void cleanup(String pathPrefix); boolean isSecret(String secret); SecretResponse convertToExternal(String secret); }
SecretService { public String put(String key, String value) throws Exception { long start = System.currentTimeMillis(); boolean exists = vaultRetryService.tryReadingVault(() -> persistentEngine.isExists(key)); long duration = System.currentTimeMillis() - start; metricService.submit(MetricType.VAULT_READ, duration); LOGGER.trace("Secret read took {} ms", duration); if (exists) { throw new InvalidKeyException(format("Key: %s already exists!", key)); } start = System.currentTimeMillis(); String secret = vaultRetryService.tryWritingVault(() -> persistentEngine.put(key, value)); duration = System.currentTimeMillis() - start; metricService.submit(MetricType.VAULT_WRITE, duration); LOGGER.trace("Secret write took {} ms", duration); metricService.incrementMetricCounter(() -> "secret.write." + convertSecretToMetric(secret)); return secret; } SecretService(MetricService metricService, List<SecretEngine> engines, VaultRetryService vaultRetryService); @PostConstruct void init(); String put(String key, String value); String get(String secret); String getByResponse(SecretResponse secretResponse); void delete(String secret); List<String> listEntries(String secretPathPrefix); void cleanup(String pathPrefix); boolean isSecret(String secret); SecretResponse convertToExternal(String secret);  }