com.microsoft.azure.keyvault.requests.SetSecretRequest Java Examples

The following examples show how to use com.microsoft.azure.keyvault.requests.SetSecretRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AzureKeyVaultServiceTest.java    From tessera with Apache License 2.0 6 votes vote down vote up
@Test
public void setSecret() {
    AzureSetSecretData setSecretData = mock(AzureSetSecretData.class);
    String secretName = "id";
    String secret = "secret";
    when(setSecretData.getSecretName()).thenReturn(secretName);
    when(setSecretData.getSecret()).thenReturn(secret);

    keyVaultService.setSecret(setSecretData);

    SetSecretRequest expected = new SetSecretRequest.Builder(vaultUrl, secretName, secret).build();

    ArgumentCaptor<SetSecretRequest> argument = ArgumentCaptor.forClass(SetSecretRequest.class);
    verify(azureKeyVaultClientDelegate).setSecret(argument.capture());

    assertThat(argument.getValue()).isEqualToComparingFieldByField(expected);
}
 
Example #2
Source File: AzureKeyVaultService.java    From tessera with Apache License 2.0 4 votes vote down vote up
@Override
public Object setSecret(AzureSetSecretData azureSetSecretData) {
    SetSecretRequest setSecretRequest = new SetSecretRequest.Builder(vaultUrl, azureSetSecretData.getSecretName(), azureSetSecretData.getSecret()).build();

    return this.azureKeyVaultClientDelegate.setSecret(setSecretRequest);
}
 
Example #3
Source File: AzureKeyVaultClientDelegate.java    From tessera with Apache License 2.0 4 votes vote down vote up
SecretBundle setSecret(SetSecretRequest setSecretRequest) {
    return keyVaultClient.setSecret(setSecretRequest);
}
 
Example #4
Source File: SecretImpl.java    From azure-libraries-for-java with MIT License 4 votes vote down vote up
@Override
public SecretImpl withValue(String value) {
    setSecretRequest = new SetSecretRequest.Builder(vault.vaultUri(), name(), value);
    return this;
}
 
Example #5
Source File: AsyncOperationsTest.java    From azure-keyvault-java with MIT License 4 votes vote down vote up
@Test
public void secretAsyncForAsyncOperationsTest() throws Exception {

	String vault = getVaultUri();
	String secretname = "mySecret";
	String password = "password";

	SetSecretRequest setSecretRequest = new SetSecretRequest.Builder(vault, secretname, password).build();
	SecretBundle secretBundle = keyVaultClient.setSecretAsync(setSecretRequest, null).get();
	Assert.assertNotNull(secretBundle);

	UpdateSecretRequest updateSecretRequest = new UpdateSecretRequest.Builder(secretBundle.id()).build();
	secretBundle = keyVaultClient.updateSecretAsync(updateSecretRequest, null).get();
	Assert.assertNotNull(secretBundle);

	secretBundle = keyVaultClient.getSecretAsync(secretBundle.id(), null).get();
	Assert.assertNotNull(secretBundle);

	List<SecretItem> secretItems = keyVaultClient.listSecretsAsync(vault, 2, null).get();
	Assert.assertNotNull(secretItems);

	List<SecretItem> secretVersionItems = keyVaultClient.listSecretVersionsAsync(vault, secretname, 2, null).get();
	Assert.assertNotNull(secretVersionItems);

	secretBundle = keyVaultClient.deleteSecretAsync(vault, secretname, null).get();
	Assert.assertNotNull(secretBundle);

	try {
		keyVaultClient.deleteSecretAsync(vault, secretname, null).get();

	} catch (ExecutionException ex) {

		Throwable t = ex.getCause();
		if (t instanceof KeyVaultErrorException) {
			Assert.assertEquals("SecretNotFound", ((KeyVaultErrorException) t).body().error().code());
		} else
			throw ex;
	}
	pollOnSecretDeletion(vault, secretname);
	keyVaultClient.purgeDeletedSecretAsync(vault, secretname, null).get();
	Thread.sleep(20000);
}
 
Example #6
Source File: SecretOperationsTest.java    From azure-keyvault-java with MIT License 4 votes vote down vote up
@Test
public void listSecretVersionsForSecretOperationsTest() throws Exception {
	final String listVersionSecretName = "javaSecretVersions";
	HashSet<String> secrets = new HashSet<String>();
	for (int i = 0; i < MAX_SECRETS; ++i) {
		int failureCount = 0;
		for (;;) {
			try {
				SecretBundle secret = keyVaultClient
						.setSecret(new SetSecretRequest.Builder(getVaultUri(), listVersionSecretName, SECRET_VALUE).build());
				secrets.add(secret.id());
				break;
			} catch (KeyVaultErrorException e) {
				++failureCount;
				if (e.body().error().code().equals("Throttled")) {
					System.out.println("Throttled!");
					if (isRecordMode()) {
						Thread.sleep(failureCount * 1500);
					}
					continue;
				}
				throw e;
			}
		}
	}

	PagedList<SecretItem> listResult = keyVaultClient.listSecretVersions(getVaultUri(), listVersionSecretName,
			PAGELIST_MAX_SECRETS);
	Assert.assertTrue(PAGELIST_MAX_SECRETS >= listResult.currentPage().items().size());

	listResult = keyVaultClient.listSecretVersions(getVaultUri(), listVersionSecretName);
	for (SecretItem item : listResult) {
		if (item != null) {
			secrets.remove(item.id());
		}
	}

	Assert.assertEquals(0, secrets.size());

	keyVaultClient.deleteSecret(getVaultUri(), listVersionSecretName);
	pollOnSecretDeletion(getVaultUri(), listVersionSecretName);
	keyVaultClient.purgeDeletedSecret(getVaultUri(), listVersionSecretName);

}
 
Example #7
Source File: KeyVaultClientCustomImpl.java    From azure-keyvault-java with MIT License 3 votes vote down vote up
/**
 * Sets a secret in the specified vault.
 *
 * @param setSecretRequest
 *            the grouped properties for setting a secret request
 * @param serviceCallback
 *            the async ServiceCallback to handle successful and failed
 *            responses.
 * @return the {@link ServiceFuture} object
 */
public ServiceFuture<SecretBundle> setSecretAsync(SetSecretRequest setSecretRequest,
        final ServiceCallback<SecretBundle> serviceCallback) {
    return setSecretAsync(setSecretRequest.vaultBaseUrl(), setSecretRequest.secretName(), setSecretRequest.value(),
            setSecretRequest.tags(), setSecretRequest.contentType(), setSecretRequest.secretAttributes(),
            serviceCallback);
}
 
Example #8
Source File: KeyVaultClientCustom.java    From azure-keyvault-java with MIT License 2 votes vote down vote up
/**
 * Sets a secret in the specified vault.
 *
 * @param setSecretRequest
 *            the grouped properties for setting a secret request
 *
 * @return the SecretBundle if successful.
 */
SecretBundle setSecret(SetSecretRequest setSecretRequest);
 
Example #9
Source File: KeyVaultClientCustom.java    From azure-keyvault-java with MIT License 2 votes vote down vote up
/**
 * Sets a secret in the specified vault.
 *
 * @param setSecretRequest
 *            the grouped properties for setting a secret request
 *
 * @param serviceCallback
 *            the async ServiceCallback to handle successful and failed
 *            responses.
 * @return the {@link ServiceFuture} object
 */
ServiceFuture<SecretBundle> setSecretAsync(SetSecretRequest setSecretRequest,
        final ServiceCallback<SecretBundle> serviceCallback);
 
Example #10
Source File: KeyVaultClientCustomImpl.java    From azure-keyvault-java with MIT License 2 votes vote down vote up
/**
 * Sets a secret in the specified vault.
 *
 * @param setSecretRequest
 *            the grouped properties for setting a secret request
 * @return the SecretBundle if successful.
 */
public SecretBundle setSecret(SetSecretRequest setSecretRequest) {
    return setSecret(setSecretRequest.vaultBaseUrl(), setSecretRequest.secretName(), setSecretRequest.value(),
            setSecretRequest.tags(), setSecretRequest.contentType(), setSecretRequest.secretAttributes());
}