com.microsoft.azure.keyvault.models.SecretItem Java Examples

The following examples show how to use com.microsoft.azure.keyvault.models.SecretItem. 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: SecretsImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
private SecretImpl wrapModel(SecretItem inner) {
    if (inner == null) {
        return null;
    }
    SerializerAdapter<?> serializer = vault.manager().inner().restClient().serializerAdapter();
    try {
        return wrapModel(serializer.<SecretBundle>deserialize(serializer.serialize(inner), SecretBundle.class));
    } catch (IOException e) {
        return null;
    }
}
 
Example #2
Source File: SecretsImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public Observable<Secret> listAsync() {
    return new KeyVaultFutures.ListCallbackObserver<SecretItem, Secret>() {
        @Override
        protected void list(ListOperationCallback<SecretItem> callback) {
            inner.listSecretsAsync(vault.vaultUri(), callback);
        }

        @Override
        protected Observable<Secret> typeConvertAsync(SecretItem secretItem) {
            return Observable.just((Secret) SecretsImpl.this.wrapModel(secretItem));
        }
    }.toObservable();
}
 
Example #3
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 #4
Source File: SecretsImpl.java    From azure-libraries-for-java with MIT License 4 votes vote down vote up
@Override
public Observable<Secret> typeConvertAsync(SecretItem inner) {
    return Observable.just((Secret) wrapModel(inner));
}
 
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: KeyVaultClientCustom.java    From azure-keyvault-java with MIT License 2 votes vote down vote up
/**
 * List secrets in the specified vault.
 *
 * @param vaultBaseUrl
 *            The vault name, e.g. https://myvault.vault.azure.net
 * @param maxresults
 *            Maximum number of results to return in a page. If not specified
 *            the service will return up to 25 results.
 *
 * @return the PagedList&lt;SecretItem&gt; if successful.
 */
PagedList<SecretItem> listSecrets(final String vaultBaseUrl, final Integer maxresults);
 
Example #7
Source File: KeyVaultClientCustom.java    From azure-keyvault-java with MIT License 2 votes vote down vote up
/**
 * List secrets in the specified vault.
 *
 * @param vaultBaseUrl
 *            The vault name, e.g. https://myvault.vault.azure.net
 * @param maxresults
 *            Maximum number of results to return in a page. If not specified
 *            the service will return up to 25 results.
 * @param serviceCallback
 *            the async ServiceCallback to handle successful and failed
 *            responses.
 * @return the {@link ServiceFuture} object
 */
ServiceFuture<List<SecretItem>> listSecretsAsync(final String vaultBaseUrl, final Integer maxresults,
        final ListOperationCallback<SecretItem> serviceCallback);
 
Example #8
Source File: KeyVaultClientCustom.java    From azure-keyvault-java with MIT License 2 votes vote down vote up
/**
 * List the versions of the specified secret.
 *
 * @param vaultBaseUrl
 *            The vault name, e.g. https://myvault.vault.azure.net
 * @param secretName
 *            The name of the secret in the given vault
 *
 * @return the PagedList&lt;SecretItem&gt; if successful.
 */
PagedList<SecretItem> listSecretVersions(final String vaultBaseUrl, final String secretName);
 
Example #9
Source File: KeyVaultClientCustom.java    From azure-keyvault-java with MIT License 2 votes vote down vote up
/**
 * List the versions of the specified secret.
 *
 * @param vaultBaseUrl
 *            The vault name, e.g. https://myvault.vault.azure.net
 * @param secretName
 *            The name of the secret in the given vault
 * @param serviceCallback
 *            the async ServiceCallback to handle successful and failed
 *            responses.
 * @return the {@link ServiceFuture} object
 */
ServiceFuture<List<SecretItem>> listSecretVersionsAsync(final String vaultBaseUrl, final String secretName,
        final ListOperationCallback<SecretItem> serviceCallback);
 
Example #10
Source File: KeyVaultClientCustom.java    From azure-keyvault-java with MIT License 2 votes vote down vote up
/**
 * List the versions of the specified secret.
 *
 * @param vaultBaseUrl
 *            The vault name, e.g. https://myvault.vault.azure.net
 * @param secretName
 *            The name of the secret in the given vault
 * @param maxresults
 *            Maximum number of results to return in a page. If not specified
 *            the service will return up to 25 results.
 *
 * @return the PagedList&lt;SecretItem&gt; if successful.
 */
PagedList<SecretItem> listSecretVersions(final String vaultBaseUrl, final String secretName,
        final Integer maxresults);
 
Example #11
Source File: KeyVaultClientCustom.java    From azure-keyvault-java with MIT License 2 votes vote down vote up
/**
 * List the versions of the specified secret.
 *
 * @param vaultBaseUrl
 *            The vault name, e.g. https://myvault.vault.azure.net
 * @param secretName
 *            The name of the secret in the given vault
 * @param maxresults
 *            Maximum number of results to return in a page. If not specified
 *            the service will return up to 25 results.
 * @param serviceCallback
 *            the async ServiceCallback to handle successful and failed
 *            responses.
 * @return the {@link ServiceFuture} object
 */
ServiceFuture<List<SecretItem>> listSecretVersionsAsync(final String vaultBaseUrl, final String secretName,
        final Integer maxresults, final ListOperationCallback<SecretItem> serviceCallback);
 
Example #12
Source File: KeyVaultClientCustomImpl.java    From azure-keyvault-java with MIT License 2 votes vote down vote up
/**
 * List secrets in the specified vault.
 *
 * @param vaultBaseUrl
 *            The vault name, e.g. https://myvault.vault.azure.net
 * @return the PagedList&lt;SecretItem&gt; if successful.
 */
public PagedList<SecretItem> listSecrets(final String vaultBaseUrl) {
    return getSecrets(vaultBaseUrl);
}
 
Example #13
Source File: KeyVaultClientCustomImpl.java    From azure-keyvault-java with MIT License 2 votes vote down vote up
/**
 * List secrets in the specified vault.
 *
 * @param vaultBaseUrl
 *            The vault name, e.g. https://myvault.vault.azure.net
 * @param serviceCallback
 *            the async ServiceCallback to handle successful and failed
 *            responses.
 * @return the {@link ServiceFuture} object
 */
public ServiceFuture<List<SecretItem>> listSecretsAsync(final String vaultBaseUrl,
        final ListOperationCallback<SecretItem> serviceCallback) {
    return getSecretsAsync(vaultBaseUrl, serviceCallback);
}
 
Example #14
Source File: KeyVaultClientCustomImpl.java    From azure-keyvault-java with MIT License 2 votes vote down vote up
/**
 * List secrets in the specified vault.
 *
 * @param vaultBaseUrl
 *            The vault name, e.g. https://myvault.vault.azure.net
 * @param maxresults
 *            Maximum number of results to return in a page. If not specified
 *            the service will return up to 25 results.
 * @return the PagedList&lt;SecretItem&gt; if successful.
 */
public PagedList<SecretItem> listSecrets(final String vaultBaseUrl, final Integer maxresults) {
    return getSecrets(vaultBaseUrl, maxresults);
}
 
Example #15
Source File: KeyVaultClientCustomImpl.java    From azure-keyvault-java with MIT License 2 votes vote down vote up
/**
 * List secrets in the specified vault.
 *
 * @param vaultBaseUrl
 *            The vault name, e.g. https://myvault.vault.azure.net
 * @param maxresults
 *            Maximum number of results to return in a page. If not specified
 *            the service will return up to 25 results.
 * @param serviceCallback
 *            the async ServiceCallback to handle successful and failed
 *            responses.
 * @return the {@link ServiceFuture} object
 */
public ServiceFuture<List<SecretItem>> listSecretsAsync(final String vaultBaseUrl, final Integer maxresults,
        final ListOperationCallback<SecretItem> serviceCallback) {
    return getSecretsAsync(vaultBaseUrl, maxresults, serviceCallback);
}
 
Example #16
Source File: KeyVaultClientCustomImpl.java    From azure-keyvault-java with MIT License 2 votes vote down vote up
/**
 * List the versions of the specified secret.
 *
 * @param vaultBaseUrl
 *            The vault name, e.g. https://myvault.vault.azure.net
 * @param secretName
 *            The name of the secret in the given vault
 * @return the PagedList&lt;SecretItem&gt; if successful.
 */
public PagedList<SecretItem> listSecretVersions(final String vaultBaseUrl, final String secretName) {
    return getSecretVersions(vaultBaseUrl, secretName);
}
 
Example #17
Source File: KeyVaultClientCustomImpl.java    From azure-keyvault-java with MIT License 2 votes vote down vote up
/**
 * List the versions of the specified secret.
 *
 * @param vaultBaseUrl
 *            The vault name, e.g. https://myvault.vault.azure.net
 * @param secretName
 *            The name of the secret in the given vault
 * @param serviceCallback
 *            the async ServiceCallback to handle successful and failed
 *            responses.
 * @return the {@link ServiceFuture} object
 */
public ServiceFuture<List<SecretItem>> listSecretVersionsAsync(final String vaultBaseUrl, final String secretName,
        final ListOperationCallback<SecretItem> serviceCallback) {
    return getSecretVersionsAsync(vaultBaseUrl, secretName, serviceCallback);
}
 
Example #18
Source File: KeyVaultClientCustomImpl.java    From azure-keyvault-java with MIT License 2 votes vote down vote up
/**
 * List the versions of the specified secret.
 *
 * @param vaultBaseUrl
 *            The vault name, e.g. https://myvault.vault.azure.net
 * @param secretName
 *            The name of the secret in the given vault
 * @param maxresults
 *            Maximum number of results to return in a page. If not specified
 *            the service will return up to 25 results.
 * @return the PagedList&lt;SecretItem&gt; if successful.
 */
public PagedList<SecretItem> listSecretVersions(final String vaultBaseUrl, final String secretName,
        final Integer maxresults) {
    return getSecretVersions(vaultBaseUrl, secretName, maxresults);
}
 
Example #19
Source File: KeyVaultClientCustomImpl.java    From azure-keyvault-java with MIT License 2 votes vote down vote up
/**
 * List the versions of the specified secret.
 *
 * @param vaultBaseUrl
 *            The vault name, e.g. https://myvault.vault.azure.net
 * @param secretName
 *            The name of the secret in the given vault
 * @param maxresults
 *            Maximum number of results to return in a page. If not specified
 *            the service will return up to 25 results.
 * @param serviceCallback
 *            the async ServiceCallback to handle successful and failed
 *            responses.
 * @return the {@link ServiceFuture} object
 */
public ServiceFuture<List<SecretItem>> listSecretVersionsAsync(final String vaultBaseUrl, final String secretName,
        final Integer maxresults, final ListOperationCallback<SecretItem> serviceCallback) {
    return getSecretVersionsAsync(vaultBaseUrl, secretName, maxresults, serviceCallback);
}
 
Example #20
Source File: KeyVaultClientCustom.java    From azure-keyvault-java with MIT License 2 votes vote down vote up
/**
 * List secrets in the specified vault.
 *
 * @param vaultBaseUrl
 *            The vault name, e.g. https://myvault.vault.azure.net
 * @param serviceCallback
 *            the async ServiceCallback to handle successful and failed
 *            responses.
 * @return the {@link ServiceFuture} object
 */
ServiceFuture<List<SecretItem>> listSecretsAsync(final String vaultBaseUrl,
        final ListOperationCallback<SecretItem> serviceCallback);
 
Example #21
Source File: KeyVaultClientCustom.java    From azure-keyvault-java with MIT License 2 votes vote down vote up
/**
 * List secrets in the specified vault.
 *
 * @param vaultBaseUrl
 *            The vault name, e.g. https://myvault.vault.azure.net
 *
 * @return the PagedList&lt;SecretItem&gt; if successful.
 */
PagedList<SecretItem> listSecrets(final String vaultBaseUrl);