Skip to content

Commit

Permalink
adding withResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
samvaity committed Jul 24, 2019
1 parent ea5b286 commit cc610fb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,16 @@
<Bug pattern="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"/>
</Match>

<!-- Incorrect flagging, if the response is null a HttpResponseException should be thrown
https://github.com/azure/azure-sdk-for-java/issues/4556 -->
<Match>
<Or>
<Class name="com.azure.security.keyvault.keys.KeyClient"/>
<Class name="com.azure.security.keyvault.keys.SecretClient"/>
</Or>
<Bug pattern="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"/>
</Match>

<!-- Super doesn't need to be cloned since it is Object -->
<Match>
<Class name="com.azure.core.util.configuration.Configuration"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public final class SecretAsyncClient {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Secret> setSecret(Secret secret) {
return withContext(context -> setSecret(secret, context))
return withContext(context -> setSecretWithResponse(secret))
.flatMap(response -> Mono.justOrEmpty(response.value()));
}

Expand Down Expand Up @@ -140,14 +140,14 @@ Mono<Response<Secret>> setSecret(Secret secret, Context context) {
*
* @param name The name of the secret. It is required and cannot be null.
* @param value The value of the secret. It is required and cannot be null.
* @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value}
* contains the {@link Secret created secret}.
* @return A {@link Mono} containing the {@link Secret created secret}.
* @throws ResourceModifiedException if invalid {@code name} or {@code value} are specified.
* @throws HttpRequestException if {@code name} or {@code value} is empty string.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Secret>> setSecret(String name, String value) {
return withContext(context -> setSecret(name, value, context));
public Mono<Secret> setSecret(String name, String value) {
return withContext(context -> setSecret(name, value, context))
.flatMap(response -> Mono.justOrEmpty(response.value()));
}

Mono<Response<Secret>> setSecret(String name, String value, Context context) {
Expand Down Expand Up @@ -181,7 +181,7 @@ Mono<Response<Secret>> setSecret(String name, String value, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Secret> getSecret(String name, String version) {
return withContext(context -> getSecret(name, version, context))
return withContext(context -> getSecretWithResponse(name, version))
.flatMap(response -> Mono.justOrEmpty(response.value()));
}

Expand Down Expand Up @@ -236,8 +236,7 @@ Mono<Response<Secret>> getSecret(String name, String version, Context context) {
*
* @param secretBase The {@link SecretBase base secret} secret base holding attributes of the
* secret being requested.
* @return A {@link Response} whose {@link Response#value() value} contains the requested {@link
* Secret secret}.
* @return A {@link Mono} containing the requested {@link Secret secret}.
* @throws ResourceNotFoundException when a secret with {@link SecretBase#name() name} and {@link
* SecretBase#version() version} doesn't exist in the key vault.
* @throws HttpRequestException if {@link SecretBase#name()} name} or {@link SecretBase#version()
Expand All @@ -249,7 +248,8 @@ public Mono<Secret> getSecret(SecretBase secretBase) {
if (secretBase.version() == null) {
return getSecret(secretBase.name());
}
return getSecret(secretBase.name(), secretBase.version());
return getSecretWithResponse(secretBase.name(), secretBase.version())
.flatMap(response -> Mono.justOrEmpty(response.value()));
}

/**
Expand Down Expand Up @@ -302,11 +302,12 @@ Mono<Response<Secret>> getSecret(SecretBase secretBase, Context context) {
* @param name The name of the secret.
* @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault.
* @throws HttpRequestException if {@code name} is empty string.
* @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the requested {@link Secret secret}.
* @return A {@link Mono} containing the requested {@link Secret secret}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Secret> getSecret(String name) {
return getSecret(name, "");
return getSecretWithResponse(name, "")
.flatMap(response -> Mono.justOrEmpty(response.value()));
}

Mono<Response<Secret>> getSecret(String name, Context context) {
Expand All @@ -333,7 +334,7 @@ Mono<Response<Secret>> getSecret(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<SecretBase> updateSecret(SecretBase secret) {
return withContext(context -> updateSecret(secret, context))
return withContext(context -> updateSecretWithResponse(secret))
.flatMap(response -> Mono.justOrEmpty(response.value()));
}

Expand Down Expand Up @@ -390,7 +391,7 @@ Mono<Response<SecretBase>> updateSecret(SecretBase secret, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<DeletedSecret> deleteSecret(String name) {
return withContext(context -> deleteSecret(name, context))
return withContext(context -> deleteSecretWithResponse(name))
.flatMap(response -> Mono.justOrEmpty(response.value()));
}

Expand Down Expand Up @@ -441,7 +442,7 @@ Mono<Response<DeletedSecret>> deleteSecret(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<DeletedSecret> getDeletedSecret(String name) {
return withContext(context -> getDeletedSecret(name, context))
return withContext(context -> getDeletedSecretWithResponse(name))
.flatMap(response -> Mono.justOrEmpty(response.value()));
}

Expand Down Expand Up @@ -525,7 +526,7 @@ Mono<VoidResponse> purgeDeletedSecret(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Secret> recoverDeletedSecret(String name) {
return withContext(context -> recoverDeletedSecret(name, context))
return withContext(context -> recoverDeletedSecretWithResponse(name))
.flatMap(response -> Mono.justOrEmpty(response.value()));
}

Expand Down Expand Up @@ -576,7 +577,7 @@ Mono<Response<Secret>> recoverDeletedSecret(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<byte[]> backupSecret(String name) {
return withContext(context -> backupSecret(name, context))
return withContext(context -> backupSecretWithResponse(name))
.flatMap(response -> Mono.justOrEmpty(response.value()));
}

Expand Down Expand Up @@ -629,7 +630,7 @@ Mono<Response<byte[]>> backupSecret(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Secret> restoreSecret(byte[] backup) {
return withContext(context -> restoreSecret(backup, context))
return withContext(context -> restoreSecretWithResponse(backup))
.flatMap(response -> Mono.justOrEmpty(response.value()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static void main(String[] args) throws InterruptedException {
// To achieve this, we need to create a new version of the secret in the key vault. The update operation cannot
// change the value of the secret.
secretAsyncClient.setSecret("BankAccountPassword", "bhjd4DDgsa").subscribe(secretResponse ->
System.out.printf("Secret is created with name %s and value %s \n", secretResponse.value().name(), secretResponse.value().value()));
System.out.printf("Secret is created with name %s and value %s \n", secretResponse.name(), secretResponse.value()));

Thread.sleep(2000);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void setSecretCodeSnippets() {
.subscriberContext(Context.of(key1, value1, key2, value2))
.subscribe(secretResponse ->
System.out.printf("Secret is created with name %s and value %s \n",
secretResponse.value().name(), secretResponse.value().value()));
secretResponse.name(), secretResponse.value()));
// END: com.azure.keyvault.secrets.secretclient.setSecret#string-string
}

Expand Down

0 comments on commit cc610fb

Please sign in to comment.