@Test public void getSecretGetsLatestVersionOfSecretIfNoVersionProvided() { String secretName = "name"; AzureGetSecretData getSecretData = mock(AzureGetSecretData.class); when(getSecretData.getSecretName()).thenReturn(secretName); when(getSecretData.getSecretVersion()).thenReturn(null); SecretBundle secretBundle = mock(SecretBundle.class); when(azureKeyVaultClientDelegate.getSecret(anyString(), anyString())).thenReturn(secretBundle); when(secretBundle.value()).thenReturn("value"); keyVaultService.getSecret(getSecretData); verify(azureKeyVaultClientDelegate).getSecret(vaultUrl, secretName); }
@Override public String getSecret(AzureGetSecretData azureGetSecretData) { SecretBundle secretBundle; if (azureGetSecretData.getSecretVersion() != null) { secretBundle = azureKeyVaultClientDelegate.getSecret(vaultUrl, azureGetSecretData.getSecretName(), azureGetSecretData.getSecretVersion()); } else { secretBundle = azureKeyVaultClientDelegate.getSecret(vaultUrl, azureGetSecretData.getSecretName()); } if (secretBundle == null) { throw new VaultSecretNotFoundException("Azure Key Vault secret " + azureGetSecretData.getSecretName() + " was not found in vault " + vaultUrl); } return secretBundle.value(); }
AzureKeyVaultService implements KeyVaultService<AzureSetSecretData, AzureGetSecretData> { @Override public String getSecret(AzureGetSecretData azureGetSecretData) { SecretBundle secretBundle; if (azureGetSecretData.getSecretVersion() != null) { secretBundle = azureKeyVaultClientDelegate.getSecret(vaultUrl, azureGetSecretData.getSecretName(), azureGetSecretData.getSecretVersion()); } else { secretBundle = azureKeyVaultClientDelegate.getSecret(vaultUrl, azureGetSecretData.getSecretName()); } if (secretBundle == null) { throw new VaultSecretNotFoundException("Azure Key Vault secret " + azureGetSecretData.getSecretName() + " was not found in vault " + vaultUrl); } return secretBundle.value(); } }
AzureKeyVaultService implements KeyVaultService<AzureSetSecretData, AzureGetSecretData> { @Override public String getSecret(AzureGetSecretData azureGetSecretData) { SecretBundle secretBundle; if (azureGetSecretData.getSecretVersion() != null) { secretBundle = azureKeyVaultClientDelegate.getSecret(vaultUrl, azureGetSecretData.getSecretName(), azureGetSecretData.getSecretVersion()); } else { secretBundle = azureKeyVaultClientDelegate.getSecret(vaultUrl, azureGetSecretData.getSecretName()); } if (secretBundle == null) { throw new VaultSecretNotFoundException("Azure Key Vault secret " + azureGetSecretData.getSecretName() + " was not found in vault " + vaultUrl); } return secretBundle.value(); } AzureKeyVaultService(KeyVaultConfig keyVaultConfig, AzureKeyVaultClientDelegate azureKeyVaultClientDelegate);   AzureKeyVaultService(String vaultUrl, AzureKeyVaultClientDelegate azureKeyVaultClientDelegate); }
AzureKeyVaultService implements KeyVaultService<AzureSetSecretData, AzureGetSecretData> { @Override public String getSecret(AzureGetSecretData azureGetSecretData) { SecretBundle secretBundle; if (azureGetSecretData.getSecretVersion() != null) { secretBundle = azureKeyVaultClientDelegate.getSecret(vaultUrl, azureGetSecretData.getSecretName(), azureGetSecretData.getSecretVersion()); } else { secretBundle = azureKeyVaultClientDelegate.getSecret(vaultUrl, azureGetSecretData.getSecretName()); } if (secretBundle == null) { throw new VaultSecretNotFoundException("Azure Key Vault secret " + azureGetSecretData.getSecretName() + " was not found in vault " + vaultUrl); } return secretBundle.value(); } AzureKeyVaultService(KeyVaultConfig keyVaultConfig, AzureKeyVaultClientDelegate azureKeyVaultClientDelegate);   AzureKeyVaultService(String vaultUrl, AzureKeyVaultClientDelegate azureKeyVaultClientDelegate); @Override String getSecret(AzureGetSecretData azureGetSecretData); @Override Object setSecret(AzureSetSecretData azureSetSecretData); }
AzureKeyVaultService implements KeyVaultService<AzureSetSecretData, AzureGetSecretData> { @Override public String getSecret(AzureGetSecretData azureGetSecretData) { SecretBundle secretBundle; if (azureGetSecretData.getSecretVersion() != null) { secretBundle = azureKeyVaultClientDelegate.getSecret(vaultUrl, azureGetSecretData.getSecretName(), azureGetSecretData.getSecretVersion()); } else { secretBundle = azureKeyVaultClientDelegate.getSecret(vaultUrl, azureGetSecretData.getSecretName()); } if (secretBundle == null) { throw new VaultSecretNotFoundException("Azure Key Vault secret " + azureGetSecretData.getSecretName() + " was not found in vault " + vaultUrl); } return secretBundle.value(); } AzureKeyVaultService(KeyVaultConfig keyVaultConfig, AzureKeyVaultClientDelegate azureKeyVaultClientDelegate);   AzureKeyVaultService(String vaultUrl, AzureKeyVaultClientDelegate azureKeyVaultClientDelegate); @Override String getSecret(AzureGetSecretData azureGetSecretData); @Override Object setSecret(AzureSetSecretData azureSetSecretData);  }