Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tracing context in Key Vault secrets package #4549

Merged
merged 15 commits into from
Jul 31, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@
<Match>
<Or>
<Class name="com.azure.security.keyvault.keys.KeyClient"/>
<Class name="com.azure.security.keyvault.keys.SecretClient"/>
<Class name="com.azure.security.keyvault.secrets.SecretClient"/>
</Or>
<Bug pattern="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"/>
</Match>
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

package com.azure.security.keyvault.keys;

import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
import com.azure.identity.credential.DefaultAzureCredential;
import com.azure.security.keyvault.keys.models.Key;
import com.azure.security.keyvault.keys.models.RsaKeyCreateOptions;
Expand Down Expand Up @@ -33,9 +35,12 @@ public static void main(String[] args) throws InterruptedException, IllegalArgum

// Let's create a Rsa key valid for 1 year. if the key
// already exists in the key vault, then a new version of the key is created.
keyClient.createRsaKey(new RsaKeyCreateOptions("CloudRsaKey")
.expires(OffsetDateTime.now().plusYears(1))
.keySize(2048));
Response<Key> createKeyResponse = keyClient.createRsaKeyWithResponse(new RsaKeyCreateOptions("CloudRsaKey")
.expires(OffsetDateTime.now().plusYears(1))
.keySize(2048), new Context("key1", "value1"));

// Let's validate create key operation succeeded using the status code information in the response.
System.out.printf("Create Key operation succeeded with status code %s \n", createKeyResponse.statusCode());

// Let's Get the Cloud Rsa Key from the key vault.
Key cloudRsaKey = keyClient.getKey("CloudRsaKey");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

package com.azure.security.keyvault.keys;

import com.azure.core.http.rest.Response;
import com.azure.identity.credential.DefaultAzureCredential;
import com.azure.security.keyvault.keys.models.Key;
import com.azure.security.keyvault.keys.models.RsaKeyCreateOptions;
import reactor.core.Disposable;

import java.time.OffsetDateTime;

Expand All @@ -32,11 +34,13 @@ public static void main(String[] args) throws InterruptedException {

// Let's create Cloud Rsa key valid for 1 year. if the key
// already exists in the key vault, then a new version of the key is created.
keyAsyncClient.createRsaKey(new RsaKeyCreateOptions("CloudRsaKey")
.expires(OffsetDateTime.now().plusYears(1))
.keySize(2048))
.subscribe(keyResponse ->
System.out.printf("Key is created with name %s and type %s \n", keyResponse.name(), keyResponse.keyMaterial().kty()));
Response<Key> createKeyResponse = keyAsyncClient.createRsaKeyWithResponse(new RsaKeyCreateOptions("CloudRsaKey")
.expires(OffsetDateTime.now().plusYears(1))
.keySize(2048)).block();

// Let's validate create key operation succeeded using the status code information in the response.
System.out.printf("Create Key operation succeeded with status code %s \n", createKeyResponse.statusCode());
System.out.printf("Key is created with name %s and type %s \n", createKeyResponse.value().name(), createKeyResponse.value().keyMaterial().kty());

Thread.sleep(2000);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.azure.core.test.policy.RecordNetworkCallPolicy;
import com.azure.identity.credential.DefaultAzureCredential;
import com.azure.security.keyvault.keys.models.EcKeyCreateOptions;
import com.azure.security.keyvault.keys.models.Key;
import com.azure.security.keyvault.keys.models.KeyBase;
import com.azure.security.keyvault.keys.models.KeyCreateOptions;
import com.azure.security.keyvault.keys.models.RsaKeyCreateOptions;
Expand Down Expand Up @@ -209,14 +208,6 @@ public void getKeyWithResponseSnippets() {
keyResponse.value().name(), keyResponse.value().id()));
// END: com.azure.security.keyvault.keys.async.keyclient.getKeyWithResponse#string-string

// BEGIN: com.azure.security.keyvault.keys.async.keyclient.getKeyWithResponse#string
keyAsyncClient.getKeyWithResponse("keyName")
.subscriberContext(Context.of(key1, value1, key2, value2))
.subscribe(keyResponse ->
System.out.printf("Key is created with name %s and id %s \n",
keyResponse.value().name(), keyResponse.value().id()));
// END: com.azure.security.keyvault.keys.async.keyclient.getKeyWithResponse#string

// BEGIN: com.azure.security.keyvault.keys.async.keyclient.getKeyWithResponse#KeyBase
keyAsyncClient.listKeys().subscribe(keyBase ->
keyAsyncClient.getKeyWithResponse(keyBase)
Expand Down Expand Up @@ -263,12 +254,11 @@ public void updateKeyWithResponseSnippets() {
KeyAsyncClient keyAsyncClient = createAsyncClient();

// BEGIN: com.azure.security.keyvault.keys.async.keyclient.updateKeyWithResponse#KeyBase-keyOperations
keyAsyncClient.getKeyWithResponse("keyName")
keyAsyncClient.getKey("keyName")
.subscribe(keyResponse -> {
Key key = keyResponse.value();
//Update the not before time of the key.
key.notBefore(OffsetDateTime.now().plusDays(50));
keyAsyncClient.updateKeyWithResponse(key, KeyOperation.ENCRYPT, KeyOperation.DECRYPT)
keyResponse.notBefore(OffsetDateTime.now().plusDays(50));
keyAsyncClient.updateKeyWithResponse(keyResponse, KeyOperation.ENCRYPT, KeyOperation.DECRYPT)
.subscriberContext(Context.of(key1, value1, key2, value2))
.subscribe(updatedKeyResponse ->
System.out.printf("Key's updated not before time %s \n",
Expand All @@ -277,12 +267,11 @@ public void updateKeyWithResponseSnippets() {
// END: com.azure.security.keyvault.keys.async.keyclient.updateKeyWithResponse#KeyBase-keyOperations

// BEGIN: com.azure.security.keyvault.keys.async.keyclient.updateKeyWithResponse#KeyBase
keyAsyncClient.getKeyWithResponse("keyName")
keyAsyncClient.getKey("keyName")
.subscribe(keyResponse -> {
Key key = keyResponse.value();
//Update the not before time of the key.
key.notBefore(OffsetDateTime.now().plusDays(50));
keyAsyncClient.updateKeyWithResponse(key)
keyResponse.notBefore(OffsetDateTime.now().plusDays(50));
keyAsyncClient.updateKeyWithResponse(keyResponse)
.subscriberContext(Context.of(key1, value1, key2, value2))
.subscribe(updatedKeyResponse ->
System.out.printf("Key's updated not before time %s \n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
package com.azure.security.keyvault.keys;

import com.azure.core.credentials.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpPipelineBuilder;
import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.VoidResponse;
import com.azure.core.util.Context;
Expand Down Expand Up @@ -123,23 +119,23 @@ public void createKeyWithResponses() {
System.out.printf("Key is created with name %s and id %s \n", optionsKey.name(), optionsKey.id());
// END: com.azure.keyvault.keys.keyclient.createKeyWithResponse#keyCreateOptions-Context

// BEGIN: com.azure.keyvault.keys.keyclient.createRsaKeyWithResponse#keyOptions
// BEGIN: com.azure.keyvault.keys.keyclient.createRsaKeyWithResponse#keyOptions-Context
RsaKeyCreateOptions rsaKeyCreateOptions = new RsaKeyCreateOptions("keyName")
.keySize(2048)
.notBefore(OffsetDateTime.now().plusDays(1))
.expires(OffsetDateTime.now().plusYears(1));
Key rsaKey = keyClient.createRsaKeyWithResponse(rsaKeyCreateOptions, new Context(key1, value1)).value();
System.out.printf("Key is created with name %s and id %s \n", rsaKey.name(), rsaKey.id());
// END: com.azure.keyvault.keys.keyclient.createRsaKeyWithResponse#keyOptions
// END: com.azure.keyvault.keys.keyclient.createRsaKeyWithResponse#keyOptions-Context

// BEGIN: com.azure.keyvault.keys.keyclient.createEcKeyWithResponse#keyOptions
// BEGIN: com.azure.keyvault.keys.keyclient.createEcKeyWithResponse#keyOptions-Context
EcKeyCreateOptions ecKeyCreateOptions = new EcKeyCreateOptions("keyName")
.curve(KeyCurveName.P_384)
.notBefore(OffsetDateTime.now().plusDays(1))
.expires(OffsetDateTime.now().plusYears(1));
Key ecKey = keyClient.createEcKeyWithResponse(ecKeyCreateOptions, new Context(key1, value1)).value();
System.out.printf("Key is created with name %s and id %s \n", ecKey.name(), ecKey.id());
// END: com.azure.keyvault.keys.keyclient.createEcKeyWithResponse#keyOptions
// END: com.azure.keyvault.keys.keyclient.createEcKeyWithResponse#keyOptions-Context
}

/**
Expand All @@ -153,6 +149,14 @@ public void getKeyWithResponseSnippets() {
new Context(key1, value1)).value();
System.out.printf("Key is returned with name %s and id %s \n", keyWithVersion.name(), keyWithVersion.id());
// END: com.azure.keyvault.keys.keyclient.getKeyWithResponse#string-string-Context

// BEGIN: com.azure.keyvault.keys.keyclient.getKeyWithResponse#KeyBase-Context
for (KeyBase key : keyClient.listKeys()) {
Key keyResponse = keyClient.getKeyWithResponse(key, new Context(key1, value1)).value();
System.out.printf("Received key with name %s and type %s", keyResponse.name(),
keyResponse.keyMaterial().kty());
}
// END: com.azure.keyvault.keys.keyclient.getKeyWithResponse#KeyBase-Context
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public static void main(String[] args) throws InterruptedException {

Thread.sleep(2000);

keyAsyncClient.createRsaKeyWithResponse(new RsaKeyCreateOptions("CloudRsaKey")
keyAsyncClient.createRsaKey(new RsaKeyCreateOptions("CloudRsaKey")
.expires(OffsetDateTime.now().plusYears(1)))
.subscribe(keyResponse ->
System.out.printf("Key is created with name %s and type %s \n", keyResponse.value().name(), keyResponse.value().keyMaterial().kty()));
System.out.printf("Key is created with name %s and type %s \n", keyResponse.name(), keyResponse.keyMaterial().kty()));

Thread.sleep(2000);

Expand Down
Loading