@Test public void getSecret() { HashicorpGetSecretData getSecretData = mock(HashicorpGetSecretData.class); when(getSecretData.getSecretEngineName()).thenReturn("secretEngine"); when(getSecretData.getSecretName()).thenReturn("secretName"); when(getSecretData.getValueId()).thenReturn("keyId"); Versioned versionedResponse = mock(Versioned.class); when(delegate.get(any(HashicorpGetSecretData.class))).thenReturn(versionedResponse); when(versionedResponse.hasData()).thenReturn(true); Map responseData = mock(Map.class); when(versionedResponse.getData()).thenReturn(responseData); when(responseData.containsKey("keyId")).thenReturn(true); String keyValue = "keyvalue"; when(responseData.get("keyId")).thenReturn(keyValue); String result = keyVaultService.getSecret(getSecretData); assertThat(result).isEqualTo(keyValue); }
@Override public String getSecret(HashicorpGetSecretData hashicorpGetSecretData) { KeyValueOperationsDelegate keyValueOperationsDelegate = keyValueOperationsDelegateFactory.create(hashicorpGetSecretData.getSecretEngineName()); Versioned<Map<String, Object>> versionedResponse = keyValueOperationsDelegate.get(hashicorpGetSecretData); if (versionedResponse == null || !versionedResponse.hasData()) { throw new HashicorpVaultException("No data found at " + hashicorpGetSecretData.getSecretEngineName() + "/" + hashicorpGetSecretData.getSecretName()); } if (!versionedResponse.getData().containsKey(hashicorpGetSecretData.getValueId())) { throw new HashicorpVaultException("No value with id " + hashicorpGetSecretData.getValueId() + " found at " + hashicorpGetSecretData.getSecretEngineName() + "/" + hashicorpGetSecretData.getSecretName()); } return versionedResponse.getData().get(hashicorpGetSecretData.getValueId()).toString(); }
HashicorpKeyVaultService implements KeyVaultService<HashicorpSetSecretData, HashicorpGetSecretData> { @Override public String getSecret(HashicorpGetSecretData hashicorpGetSecretData) { KeyValueOperationsDelegate keyValueOperationsDelegate = keyValueOperationsDelegateFactory.create(hashicorpGetSecretData.getSecretEngineName()); Versioned<Map<String, Object>> versionedResponse = keyValueOperationsDelegate.get(hashicorpGetSecretData); if (versionedResponse == null || !versionedResponse.hasData()) { throw new HashicorpVaultException("No data found at " + hashicorpGetSecretData.getSecretEngineName() + "/" + hashicorpGetSecretData.getSecretName()); } if (!versionedResponse.getData().containsKey(hashicorpGetSecretData.getValueId())) { throw new HashicorpVaultException("No value with id " + hashicorpGetSecretData.getValueId() + " found at " + hashicorpGetSecretData.getSecretEngineName() + "/" + hashicorpGetSecretData.getSecretName()); } return versionedResponse.getData().get(hashicorpGetSecretData.getValueId()).toString(); } }
HashicorpKeyVaultService implements KeyVaultService<HashicorpSetSecretData, HashicorpGetSecretData> { @Override public String getSecret(HashicorpGetSecretData hashicorpGetSecretData) { KeyValueOperationsDelegate keyValueOperationsDelegate = keyValueOperationsDelegateFactory.create(hashicorpGetSecretData.getSecretEngineName()); Versioned<Map<String, Object>> versionedResponse = keyValueOperationsDelegate.get(hashicorpGetSecretData); if (versionedResponse == null || !versionedResponse.hasData()) { throw new HashicorpVaultException("No data found at " + hashicorpGetSecretData.getSecretEngineName() + "/" + hashicorpGetSecretData.getSecretName()); } if (!versionedResponse.getData().containsKey(hashicorpGetSecretData.getValueId())) { throw new HashicorpVaultException("No value with id " + hashicorpGetSecretData.getValueId() + " found at " + hashicorpGetSecretData.getSecretEngineName() + "/" + hashicorpGetSecretData.getSecretName()); } return versionedResponse.getData().get(hashicorpGetSecretData.getValueId()).toString(); } HashicorpKeyVaultService(KeyValueOperationsDelegateFactory keyValueOperationsDelegateFactory); }
HashicorpKeyVaultService implements KeyVaultService<HashicorpSetSecretData, HashicorpGetSecretData> { @Override public String getSecret(HashicorpGetSecretData hashicorpGetSecretData) { KeyValueOperationsDelegate keyValueOperationsDelegate = keyValueOperationsDelegateFactory.create(hashicorpGetSecretData.getSecretEngineName()); Versioned<Map<String, Object>> versionedResponse = keyValueOperationsDelegate.get(hashicorpGetSecretData); if (versionedResponse == null || !versionedResponse.hasData()) { throw new HashicorpVaultException("No data found at " + hashicorpGetSecretData.getSecretEngineName() + "/" + hashicorpGetSecretData.getSecretName()); } if (!versionedResponse.getData().containsKey(hashicorpGetSecretData.getValueId())) { throw new HashicorpVaultException("No value with id " + hashicorpGetSecretData.getValueId() + " found at " + hashicorpGetSecretData.getSecretEngineName() + "/" + hashicorpGetSecretData.getSecretName()); } return versionedResponse.getData().get(hashicorpGetSecretData.getValueId()).toString(); } HashicorpKeyVaultService(KeyValueOperationsDelegateFactory keyValueOperationsDelegateFactory); @Override String getSecret(HashicorpGetSecretData hashicorpGetSecretData); @Override Object setSecret(HashicorpSetSecretData hashicorpSetSecretData); }
HashicorpKeyVaultService implements KeyVaultService<HashicorpSetSecretData, HashicorpGetSecretData> { @Override public String getSecret(HashicorpGetSecretData hashicorpGetSecretData) { KeyValueOperationsDelegate keyValueOperationsDelegate = keyValueOperationsDelegateFactory.create(hashicorpGetSecretData.getSecretEngineName()); Versioned<Map<String, Object>> versionedResponse = keyValueOperationsDelegate.get(hashicorpGetSecretData); if (versionedResponse == null || !versionedResponse.hasData()) { throw new HashicorpVaultException("No data found at " + hashicorpGetSecretData.getSecretEngineName() + "/" + hashicorpGetSecretData.getSecretName()); } if (!versionedResponse.getData().containsKey(hashicorpGetSecretData.getValueId())) { throw new HashicorpVaultException("No value with id " + hashicorpGetSecretData.getValueId() + " found at " + hashicorpGetSecretData.getSecretEngineName() + "/" + hashicorpGetSecretData.getSecretName()); } return versionedResponse.getData().get(hashicorpGetSecretData.getValueId()).toString(); } HashicorpKeyVaultService(KeyValueOperationsDelegateFactory keyValueOperationsDelegateFactory); @Override String getSecret(HashicorpGetSecretData hashicorpGetSecretData); @Override Object setSecret(HashicorpSetSecretData hashicorpSetSecretData);  }