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

KV-Keys code update #7075

Merged
merged 3 commits into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class CryptographyAsyncClient {
private LocalKeyCryptographyClient localKeyCryptographyClient;
private final ClientLogger logger = new ClientLogger(CryptographyAsyncClient.class);
private String keyCollection;
private final String keyId;

/**
* Creates a CryptographyAsyncClient that uses {@code pipeline} to service requests
Expand All @@ -83,6 +84,7 @@ public class CryptographyAsyncClient {
throw new IllegalArgumentException("Json Web Key's key type property is not configured");
}
this.key = key;
this.keyId = key.getId();
service = RestProxy.create(CryptographyService.class, pipeline);
if (!Strings.isNullOrEmpty(key.getId())) {
unpackAndValidateId(key.getId());
Expand All @@ -102,6 +104,7 @@ public class CryptographyAsyncClient {
*/
CryptographyAsyncClient(String keyId, HttpPipeline pipeline, CryptographyServiceVersion version) {
unpackAndValidateId(keyId);
this.keyId = keyId;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't this constructor initializeCryptoClients() while the other constructor does (line 95)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other constructor, JWK key is passed into the constructor. Key is available to initialize crypto clients.
While in this constructor only key id is available at constructor time. In this scenario the Key gets fetched from the service and crypto clients are initialized on demand when user invokes a crypto operation on the client.

service = RestProxy.create(CryptographyService.class, pipeline);
cryptographyServiceClient = new CryptographyServiceClient(keyId, service);
this.key = null;
Expand All @@ -123,6 +126,10 @@ private void initializeCryptoClients() {
}
}

Mono<String> getKeyId() {
return Mono.defer(() -> Mono.just(keyId));
}

/**
* Gets the public part of the configured key. The get key operation is applicable to all key types and it requires
* the {@code keys/get} permission.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ public final class KeyEncryptionKeyAsyncClient extends CryptographyAsyncClient i
}

/**
* {@inheritDoc}
* Get the identifier of the key to use for cryptography operations.
*
* @return A {@link Mono} containing the key identifier.
*/
@Override
public Mono<String> getKeyId() {
try {
return Mono.just(key.getId());
} catch (RuntimeException ex) {
return monoError(logger, ex);
}
return super.getKeyId();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public final class KeyEncryptionKeyClient implements KeyEncryptionKey {
}

/**
* {@inheritDoc}
* Get the identifier of the key to use for cryptography operations.
*
* @return The key identifier.
*/
@Override
public String getKeyId() {
Expand Down