Skip to content

Commit

Permalink
Updated the ci.yml for publishing the new Key Vault Administration pa…
Browse files Browse the repository at this point in the history
…ckage (#14914)

* Updated the ci.yml file for publishing the new Key Vault Administration package.

* Fixed Javadoc issue.

* Fixed checkstyle and spotbugs errors.
  • Loading branch information
vcolin7 authored Sep 8, 2020
1 parent 259e63f commit eee7889
Show file tree
Hide file tree
Showing 18 changed files with 198 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@

<!-- Public API already exposed: Common vocabulary errors, refer to Java Spec: https://azure.github.io/azure-sdk/java_introduction.html,
issue link: https://github.com/Azure/azure-sdk-for-java/issues/5145 -->
<suppress checks="com.azure.tools.checkstyle.checks.ServiceClientCheck"
files="com.azure.security.keyvault.administration.KeyVaultBackupAsyncClient"/>
<suppress checks="com.azure.tools.checkstyle.checks.ServiceClientCheck"
files="com.azure.security.keyvault.administration.KeyVaultBackupClient"/>
<suppress checks="com.azure.tools.checkstyle.checks.ServiceClientCheck"
files="com.azure.security.keyvault.secrets.SecretAsyncClient.java"/>
<suppress checks="com.azure.tools.checkstyle.checks.ServiceClientCheck"
Expand Down Expand Up @@ -359,9 +363,10 @@
<!-- Allows the HttpPipelinePolicy derived class in Implementation folder -->
<suppress checks="com.azure.tools.checkstyle.checks.HttpPipelinePolicy" files="com.azure.messaging.servicebus.implementation.ServiceBusTokenCredentialHttpPolicy.java"/>
<suppress checks="com.azure.tools.checkstyle.checks.HttpPipelinePolicy" files="com.azure.storage.common.implementation.policy.SasTokenCredentialPolicy.java"/>
<suppress checks="com.azure.tools.checkstyle.checks.HttpPipelinePolicy" files="com.azure.security.keyvault.secrets.implementation.KeyVaultCredentialPolicy.java"/>
<suppress checks="com.azure.tools.checkstyle.checks.HttpPipelinePolicy" files="com.azure.security.keyvault.administration.implementation.KeyVaultCredentialPolicy.java"/>
<suppress checks="com.azure.tools.checkstyle.checks.HttpPipelinePolicy" files="com.azure.security.keyvault.certificates.implementation.KeyVaultCredentialPolicy.java"/>
<suppress checks="com.azure.tools.checkstyle.checks.HttpPipelinePolicy" files="com.azure.security.keyvault.keys.implementation.KeyVaultCredentialPolicy.java"/>
<suppress checks="com.azure.tools.checkstyle.checks.HttpPipelinePolicy" files="com.azure.security.keyvault.secrets.implementation.KeyVaultCredentialPolicy.java"/>

<!-- Empty while loop waiting for Reactor stream completion -->
<suppress checks="EmptyBlock" files="com.azure.storage.blob.batch.BlobBatch.java"/>
Expand Down Expand Up @@ -420,6 +425,8 @@
<suppress checks="LineLength" files="com.azure.ai.formrecognizer.Transforms.java"/>

<suppress checks="Indentation" files="com.azure.ai.formrecognizer.implementation.FormRecognizerClientImpl" />
<suppress checks="Indentation" files="com.azure.security.keyvault.administration.implementation.RoleAssignmentsImpl" />
<suppress checks="Indentation" files="com.azure.security.keyvault.administration.implementation.RoleDefinitionsImpl" />

<suppress checks="GoodLoggingCheck" files="com.azure.ai.formrecognizer.models.FieldValueType.java" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@
import com.azure.security.keyvault.administration.implementation.KeyVaultAccessControlClientImpl;
import com.azure.security.keyvault.administration.implementation.KeyVaultAccessControlClientImplBuilder;
import com.azure.security.keyvault.administration.implementation.KeyVaultErrorCodeStrings;
import com.azure.security.keyvault.administration.implementation.models.*;
import com.azure.security.keyvault.administration.models.*;
import com.azure.security.keyvault.administration.implementation.models.Permission;
import com.azure.security.keyvault.administration.implementation.models.RoleAssignment;
import com.azure.security.keyvault.administration.implementation.models.RoleAssignmentCreateParameters;
import com.azure.security.keyvault.administration.implementation.models.RoleAssignmentProperties;
import com.azure.security.keyvault.administration.implementation.models.RoleAssignmentPropertiesWithScope;
import com.azure.security.keyvault.administration.implementation.models.RoleDefinition;
import com.azure.security.keyvault.administration.models.KeyVaultPermission;
import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignment;
import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignmentProperties;
import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignmentScope;
import com.azure.security.keyvault.administration.models.KeyVaultRoleDefinition;
import com.azure.security.keyvault.administration.models.KeyVaultRoleDefinitionProperties;
import reactor.core.publisher.Mono;

import java.io.IOException;
Expand Down Expand Up @@ -142,7 +152,7 @@ Mono<PagedResponse<KeyVaultRoleDefinition>> listRoleDefinitionsFirstPage(String
.doOnSuccess(response -> logger.info("Listed role definitions for roleScope - {}", roleScope))
.doOnError(error -> logger.warning(String.format("Failed to list role definitions for roleScope - %s",
roleScope), error))
.map(this::transformRoleDefinitionsPagedResponse);
.map(KeyVaultAccessControlAsyncClient::transformRoleDefinitionsPagedResponse);
} catch (RuntimeException e) {
return monoError(logger, e);
}
Expand All @@ -168,7 +178,7 @@ Mono<PagedResponse<KeyVaultRoleDefinition>> listRoleDefinitionsNextPage(String c
.doOnSuccess(response -> logger.info("Listed next role definitions page - Page {}", continuationToken))
.doOnError(error -> logger.warning("Failed to list next role definitions page - Page {}",
continuationToken, error))
.map(this::transformRoleDefinitionsPagedResponse);
.map(KeyVaultAccessControlAsyncClient::transformRoleDefinitionsPagedResponse);
} catch (RuntimeException e) {
return monoError(logger, e);
}
Expand Down Expand Up @@ -230,7 +240,7 @@ Mono<PagedResponse<KeyVaultRoleAssignment>> listRoleAssignmentsFirstPage(String
.doOnSuccess(response -> logger.info("Listed role assignments for roleScope - {}", roleScope))
.doOnError(error -> logger.warning(String.format("Failed to list role assignments for roleScope - %s",
roleScope), error))
.map(this::transformRoleAssignmentsPagedResponse);
.map(KeyVaultAccessControlAsyncClient::transformRoleAssignmentsPagedResponse);
} catch (RuntimeException e) {
return monoError(logger, e);
}
Expand All @@ -256,7 +266,7 @@ Mono<PagedResponse<KeyVaultRoleAssignment>> listRoleAssignmentsNextPage(String c
.doOnSuccess(response -> logger.info("Listed next role assignments page - Page {}", continuationToken))
.doOnError(error -> logger.warning("Failed to list next role assignments page - Page {}",
continuationToken, error))
.map(this::transformRoleAssignmentsPagedResponse);
.map(KeyVaultAccessControlAsyncClient::transformRoleAssignmentsPagedResponse);
} catch (RuntimeException e) {
return monoError(logger, e);
}
Expand Down Expand Up @@ -364,7 +374,7 @@ Mono<Response<KeyVaultRoleAssignment>> createRoleAssignmentWithResponse(KeyVault
.doOnRequest(ignored -> logger.info("Creating role assignment - {}", name))
.doOnSuccess(response -> logger.info("Created role assignment - {}", response.getValue().getName()))
.doOnError(error -> logger.warning("Failed to create role assignment - {}", name, error))
.map(this::transformRoleAssignmentResponse);
.map(KeyVaultAccessControlAsyncClient::transformRoleAssignmentResponse);
}

/**
Expand Down Expand Up @@ -422,7 +432,7 @@ Mono<Response<KeyVaultRoleAssignment>> getRoleAssignmentWithResponse(KeyVaultRol
.doOnRequest(ignored -> logger.info("Retrieving role assignment - {}", name))
.doOnSuccess(response -> logger.info("Retrieved role assignment - {}", response.getValue().getName()))
.doOnError(error -> logger.warning("Failed to retrieved role assignment - {}", name, error))
.map(this::transformRoleAssignmentResponse);
.map(KeyVaultAccessControlAsyncClient::transformRoleAssignmentResponse);
} catch (RuntimeException e) {
return monoError(logger, e);
}
Expand Down Expand Up @@ -483,83 +493,30 @@ Mono<Response<KeyVaultRoleAssignment>> deleteRoleAssignmentWithResponse(KeyVault
.doOnRequest(ignored -> logger.info("Deleting role assignment - {}", name))
.doOnSuccess(response -> logger.info("Deleted role assignment - {}", response.getValue().getName()))
.doOnError(error -> logger.warning("Failed to delete role assignment - {}", name, error))
.map(this::transformRoleAssignmentResponse);
.map(KeyVaultAccessControlAsyncClient::transformRoleAssignmentResponse);
} catch (RuntimeException e) {
return monoError(logger, e);
}
}

private PagedResponse<KeyVaultRoleDefinition> transformRoleDefinitionsPagedResponse(PagedResponse<RoleDefinition> pagedResponse) {
@SuppressWarnings("BoundedWildcard")
private static PagedResponse<KeyVaultRoleDefinition> transformRoleDefinitionsPagedResponse(PagedResponse<RoleDefinition> pagedResponse) {
List<KeyVaultRoleDefinition> keyVaultRoleDefinitions = new ArrayList<>();

for (RoleDefinition roleDefinition : pagedResponse.getValue()) {
keyVaultRoleDefinitions.add(roleDefinitionToKeyVaultRoleDefinition(roleDefinition));
}

return new PagedResponse<KeyVaultRoleDefinition>() {
@Override
public void close() throws IOException {
}

@Override
public IterableStream<KeyVaultRoleDefinition> getElements() {
return new IterableStream<>(keyVaultRoleDefinitions);
}

@Override
public String getContinuationToken() {
return pagedResponse.getContinuationToken();
}

@Override
public int getStatusCode() {
return pagedResponse.getStatusCode();
}

@Override
public HttpHeaders getHeaders() {
return pagedResponse.getHeaders();
}

@Override
public HttpRequest getRequest() {
return pagedResponse.getRequest();
}

@Override
public List<KeyVaultRoleDefinition> getValue() {
return keyVaultRoleDefinitions;
}
};
return new TransformedPagedResponse<>(keyVaultRoleDefinitions, pagedResponse);
}

private Response<KeyVaultRoleAssignment> transformRoleAssignmentResponse(Response<RoleAssignment> response) {
private static Response<KeyVaultRoleAssignment> transformRoleAssignmentResponse(Response<RoleAssignment> response) {
KeyVaultRoleAssignment keyVaultRoleAssignment = roleAssignmentToKeyVaultRoleAssignment(response.getValue());

return new Response<KeyVaultRoleAssignment>() {
@Override
public int getStatusCode() {
return response.getStatusCode();
}

@Override
public HttpHeaders getHeaders() {
return response.getHeaders();
}

@Override
public HttpRequest getRequest() {
return response.getRequest();
}

@Override
public KeyVaultRoleAssignment getValue() {
return keyVaultRoleAssignment;
}
};
return new TransformedResponse<>(keyVaultRoleAssignment, response);
}

private KeyVaultRoleDefinition roleDefinitionToKeyVaultRoleDefinition(RoleDefinition roleDefinition) {
private static KeyVaultRoleDefinition roleDefinitionToKeyVaultRoleDefinition(RoleDefinition roleDefinition) {
List<KeyVaultPermission> keyVaultPermissions = new ArrayList<>();

for (Permission permission : roleDefinition.getPermissions()) {
Expand All @@ -574,55 +531,95 @@ private KeyVaultRoleDefinition roleDefinitionToKeyVaultRoleDefinition(RoleDefini
roleDefinition.getAssignableScopes()));
}

private PagedResponse<KeyVaultRoleAssignment> transformRoleAssignmentsPagedResponse(PagedResponse<RoleAssignment> pagedResponse) {
private static PagedResponse<KeyVaultRoleAssignment> transformRoleAssignmentsPagedResponse(PagedResponse<RoleAssignment> pagedResponse) {
List<KeyVaultRoleAssignment> keyVaultRoleAssignments = new ArrayList<>();

for (RoleAssignment roleAssignment : pagedResponse.getValue()) {
keyVaultRoleAssignments.add(roleAssignmentToKeyVaultRoleAssignment(roleAssignment));
}

return new PagedResponse<KeyVaultRoleAssignment>() {
@Override
public void close() throws IOException {
}

@Override
public IterableStream<KeyVaultRoleAssignment> getElements() {
return new IterableStream<>(keyVaultRoleAssignments);
}

@Override
public String getContinuationToken() {
return pagedResponse.getContinuationToken();
}

@Override
public int getStatusCode() {
return pagedResponse.getStatusCode();
}

@Override
public HttpHeaders getHeaders() {
return pagedResponse.getHeaders();
}

@Override
public HttpRequest getRequest() {
return pagedResponse.getRequest();
}

@Override
public List<KeyVaultRoleAssignment> getValue() {
return keyVaultRoleAssignments;
}
};
return new TransformedPagedResponse<>(keyVaultRoleAssignments, pagedResponse);
}

private KeyVaultRoleAssignment roleAssignmentToKeyVaultRoleAssignment(RoleAssignment roleAssignment) {
private static KeyVaultRoleAssignment roleAssignmentToKeyVaultRoleAssignment(RoleAssignment roleAssignment) {
RoleAssignmentPropertiesWithScope propertiesWithScope = roleAssignment.getProperties();

return new KeyVaultRoleAssignment(roleAssignment.getId(), roleAssignment.getName(), roleAssignment.getType(),
new KeyVaultRoleAssignmentProperties(propertiesWithScope.getRoleDefinitionId(),
propertiesWithScope.getPrincipalId()), KeyVaultRoleAssignmentScope.fromString(propertiesWithScope.getScope()));
}

private static final class TransformedPagedResponse<L extends List<T>, T, U> implements PagedResponse<T> {
private final L output;
private final PagedResponse<U> pagedResponse;

TransformedPagedResponse(L output, PagedResponse<U> inputPagedResponse) {
this.output = output;
this.pagedResponse = inputPagedResponse;
}

@Override
public void close() throws IOException {
}

@Override
public IterableStream<T> getElements() {
return new IterableStream<>(output);
}

@Override
public String getContinuationToken() {
return pagedResponse.getContinuationToken();
}

@Override
public int getStatusCode() {
return pagedResponse.getStatusCode();
}

@Override
public HttpHeaders getHeaders() {
return pagedResponse.getHeaders();
}

@Override
public HttpRequest getRequest() {
return pagedResponse.getRequest();
}

@Override
public List<T> getValue() {
return output;
}
}

private static final class TransformedResponse<T, U> implements Response<T> {
private final T output;
private final Response<U> response;

TransformedResponse(T output, Response<U> response) {
this.output = output;
this.response = response;
}

@Override
public int getStatusCode() {
return response.getStatusCode();
}

@Override
public HttpHeaders getHeaders() {
return response.getHeaders();
}

@Override
public HttpRequest getRequest() {
return response.getRequest();
}

@Override
public T getValue() {
return output;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
import com.azure.security.keyvault.administration.models.*;
import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignment;
import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignmentProperties;
import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignmentScope;
import com.azure.security.keyvault.administration.models.KeyVaultRoleDefinition;
import reactor.core.publisher.Mono;

import java.util.UUID;
Expand Down Expand Up @@ -170,6 +173,7 @@ public KeyVaultRoleAssignment getRoleAssignment(KeyVaultRoleAssignmentScope role
*
* @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment}.
* @param name The name of the {@link KeyVaultRoleAssignment}.
* @param context Additional context that is passed through the HTTP pipeline during the service call.
* @return The {@link KeyVaultRoleAssignment}.
* @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} or {@link UUID name} are
* {@code null}.
Expand Down Expand Up @@ -198,6 +202,7 @@ public KeyVaultRoleAssignment deleteRoleAssignment(KeyVaultRoleAssignmentScope r
*
* @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment}.
* @param name The name of the {@link KeyVaultRoleAssignment}.
* @param context Additional context that is passed through the HTTP pipeline during the service call.
* @return The {@link KeyVaultRoleAssignment}.
* @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} or {@link UUID name} are
* {@code null}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpPipelineBuilder;
import com.azure.core.http.policy.*;
import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpLoggingPolicy;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.http.policy.HttpPolicyProviders;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.logging.ClientLogger;
Expand Down
Loading

0 comments on commit eee7889

Please sign in to comment.