From 0484ce66e17388acab01e5f5d316190b2a8fa43b Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Mon, 12 Sep 2016 17:35:15 -0700 Subject: [PATCH 01/33] Generate graph and keyvault clients --- .../management/graphrbac/GraphError.java | 71 + .../graphrbac/GraphErrorException.java | 87 ++ .../KeyCredentialsUpdateParameters.java | 43 + .../PasswordCredentialsUpdateParameters.java | 43 + .../implementation/AADObjectInner.java | 20 +- .../implementation/ADGroupInner.java | 10 +- .../ApplicationCreateParametersInner.java | 19 +- .../implementation/ApplicationInner.java | 14 +- .../ApplicationUpdateParametersInner.java | 43 +- .../implementation/ApplicationsInner.java | 973 +++++++++--- .../GraphRbacManagementClientImpl.java | 6 +- .../graphrbac/implementation/GroupsInner.java | 1307 ++++++++++------- .../KeyCredentialInner.java} | 42 +- .../implementation/ObjectsInner.java | 89 +- .../PasswordCredentialInner.java} | 30 +- ...ServicePrincipalCreateParametersInner.java | 53 +- .../implementation/ServicePrincipalInner.java | 10 +- .../ServicePrincipalsInner.java | 1090 ++++++++++---- .../graphrbac/implementation/UserInner.java | 12 +- .../graphrbac/implementation/UsersInner.java | 869 ++++++----- .../keyvault/AccessPolicyEntry.java | 7 +- .../management/keyvault/KeyPermissions.java | 98 ++ .../management/keyvault/Permissions.java | 12 +- .../keyvault/SecretPermissions.java | 68 + .../azure/management/keyvault/Sku.java | 10 +- .../azure/management/keyvault/SkuFamily.java | 20 - .../keyvault/implementation/VaultInner.java | 1 - .../keyvault/implementation/VaultsInner.java | 990 ++++++++----- gulpfile.js | 4 +- 29 files changed, 4090 insertions(+), 1951 deletions(-) create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GraphError.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GraphErrorException.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/KeyCredentialsUpdateParameters.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordCredentialsUpdateParameters.java rename azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/{KeyCredential.java => implementation/KeyCredentialInner.java} (69%) rename azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/{PasswordCredential.java => implementation/PasswordCredentialInner.java} (70%) create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/KeyPermissions.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SecretPermissions.java delete mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SkuFamily.java diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GraphError.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GraphError.java new file mode 100644 index 000000000000..033bb358f3d5 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GraphError.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * Active Directory error information. + */ +@JsonFlatten +public class GraphError { + /** + * Error code. + */ + @JsonProperty(value = "odata\\.error.code") + private String code; + + /** + * Error message value. + */ + @JsonProperty(value = "odata\\.error.message.value") + private String message; + + /** + * Get the code value. + * + * @return the code value + */ + public String code() { + return this.code; + } + + /** + * Set the code value. + * + * @param code the code value to set + * @return the GraphError object itself. + */ + public GraphError withCode(String code) { + this.code = code; + return this; + } + + /** + * Get the message value. + * + * @return the message value + */ + public String message() { + return this.message; + } + + /** + * Set the message value. + * + * @param message the message value to set + * @return the GraphError object itself. + */ + public GraphError withMessage(String message) { + this.message = message; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GraphErrorException.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GraphErrorException.java new file mode 100644 index 000000000000..e6b4aeeeecb8 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GraphErrorException.java @@ -0,0 +1,87 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac; + +import com.microsoft.rest.RestException; +import retrofit2.Response; + +/** + * Exception thrown for an invalid response with GraphError information. + */ +public class GraphErrorException extends RestException { + /** + * Information about the associated HTTP response. + */ + private Response response; + /** + * The actual response body. + */ + private GraphError body; + /** + * Initializes a new instance of the GraphErrorException class. + */ + public GraphErrorException() { } + /** + * Initializes a new instance of the GraphErrorException class. + * + * @param message The exception message. + */ + public GraphErrorException(final String message) { + super(message); + } + /** + * Initializes a new instance of the GraphErrorException class. + * + * @param message the exception message + * @param cause exception that caused this exception to occur + */ + public GraphErrorException(final String message, final Throwable cause) { + super(message, cause); + } + /** + * Initializes a new instance of the GraphErrorException class. + * + * @param cause exception that caused this exception to occur + */ + public GraphErrorException(final Throwable cause) { + super(cause); + } + /** + * Gets information about the associated HTTP response. + * + * @return the HTTP response + */ + public Response getResponse() { + return response; + } + /** + * Gets the HTTP response body. + * + * @return the response body + */ + public GraphError getBody() { + return body; + } + /** + * Sets the HTTP response. + * + * @param response the HTTP response + */ + public void setResponse(Response response) { + this.response = response; + } + /** + * Sets the HTTP response body. + * + * @param body the response body + */ + public void setBody(GraphError body) { + this.body = body; + } +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/KeyCredentialsUpdateParameters.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/KeyCredentialsUpdateParameters.java new file mode 100644 index 000000000000..9fd5ff8b29f5 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/KeyCredentialsUpdateParameters.java @@ -0,0 +1,43 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac; + +import java.util.List; +import com.microsoft.azure.management.graphrbac.implementation.KeyCredentialInner; + +/** + * Request parameters for KeyCredentials update operation. + */ +public class KeyCredentialsUpdateParameters { + /** + * KeyCredential list. + */ + private List value; + + /** + * Get the value value. + * + * @return the value value + */ + public List value() { + return this.value; + } + + /** + * Set the value value. + * + * @param value the value value to set + * @return the KeyCredentialsUpdateParameters object itself. + */ + public KeyCredentialsUpdateParameters withValue(List value) { + this.value = value; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordCredentialsUpdateParameters.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordCredentialsUpdateParameters.java new file mode 100644 index 000000000000..adc5d0ccec51 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordCredentialsUpdateParameters.java @@ -0,0 +1,43 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac; + +import java.util.List; +import com.microsoft.azure.management.graphrbac.implementation.PasswordCredentialInner; + +/** + * Request paramters for PasswordCredentials update operation. + */ +public class PasswordCredentialsUpdateParameters { + /** + * PasswordCredential list. + */ + private List value; + + /** + * Get the value value. + * + * @return the value value + */ + public List value() { + return this.value; + } + + /** + * Set the value value. + * + * @param value the value value to set + * @return the PasswordCredentialsUpdateParameters object itself. + */ + public PasswordCredentialsUpdateParameters withValue(List value) { + this.value = value; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/AADObjectInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/AADObjectInner.java index 87922b8c92fd..79a109bb42d7 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/AADObjectInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/AADObjectInner.java @@ -15,52 +15,52 @@ */ public class AADObjectInner { /** - * Gets or sets object Id. + * object Id. */ private String objectId; /** - * Gets or sets object type. + * object type. */ private String objectType; /** - * Gets or sets object display name. + * object display name. */ private String displayName; /** - * Gets or sets principal name. + * principal name. */ private String userPrincipalName; /** - * Gets or sets mail. + * mail. */ private String mail; /** - * Gets or sets MailEnabled field. + * MailEnabled field. */ private Boolean mailEnabled; /** - * Gets or sets SecurityEnabled field. + * SecurityEnabled field. */ private Boolean securityEnabled; /** - * Gets or sets signIn name. + * signIn name. */ private String signInName; /** - * Gets or sets the list of service principal names. + * the list of service principal names. */ private List servicePrincipalNames; /** - * Gets or sets the user type. + * the user type. */ private String userType; diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ADGroupInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ADGroupInner.java index d2fd0568b922..b5108f421d70 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ADGroupInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ADGroupInner.java @@ -14,27 +14,27 @@ */ public class ADGroupInner { /** - * Gets or sets object Id. + * object Id. */ private String objectId; /** - * Gets or sets object type. + * object type. */ private String objectType; /** - * Gets or sets group display name. + * group display name. */ private String displayName; /** - * Gets or sets security enabled field. + * security enabled field. */ private Boolean securityEnabled; /** - * Gets or sets mail field. + * mail field. */ private String mail; diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationCreateParametersInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationCreateParametersInner.java index 334e0768005b..ac996c9c89fa 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationCreateParametersInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationCreateParametersInner.java @@ -9,8 +9,6 @@ package com.microsoft.azure.management.graphrbac.implementation; import java.util.List; -import com.microsoft.azure.management.graphrbac.KeyCredential; -import com.microsoft.azure.management.graphrbac.PasswordCredential; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -32,7 +30,6 @@ public class ApplicationCreateParametersInner { /** * Application homepage. */ - @JsonProperty(required = true) private String homepage; /** @@ -47,14 +44,14 @@ public class ApplicationCreateParametersInner { private List replyUrls; /** - * Gets or sets the list of KeyCredential objects. + * the list of KeyCredential objects. */ - private List keyCredentials; + private List keyCredentials; /** - * Gets or sets the list of PasswordCredential objects. + * the list of PasswordCredential objects. */ - private List passwordCredentials; + private List passwordCredentials; /** * Get the availableToOtherTenants value. @@ -161,7 +158,7 @@ public ApplicationCreateParametersInner withReplyUrls(List replyUrls) { * * @return the keyCredentials value */ - public List keyCredentials() { + public List keyCredentials() { return this.keyCredentials; } @@ -171,7 +168,7 @@ public List keyCredentials() { * @param keyCredentials the keyCredentials value to set * @return the ApplicationCreateParametersInner object itself. */ - public ApplicationCreateParametersInner withKeyCredentials(List keyCredentials) { + public ApplicationCreateParametersInner withKeyCredentials(List keyCredentials) { this.keyCredentials = keyCredentials; return this; } @@ -181,7 +178,7 @@ public ApplicationCreateParametersInner withKeyCredentials(List k * * @return the passwordCredentials value */ - public List passwordCredentials() { + public List passwordCredentials() { return this.passwordCredentials; } @@ -191,7 +188,7 @@ public List passwordCredentials() { * @param passwordCredentials the passwordCredentials value to set * @return the ApplicationCreateParametersInner object itself. */ - public ApplicationCreateParametersInner withPasswordCredentials(List passwordCredentials) { + public ApplicationCreateParametersInner withPasswordCredentials(List passwordCredentials) { this.passwordCredentials = passwordCredentials; return this; } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationInner.java index 1e4259ec221d..443db8cdc1d1 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationInner.java @@ -15,22 +15,22 @@ */ public class ApplicationInner { /** - * Gets or sets object Id. + * object Id. */ private String objectId; /** - * Gets or sets object type. + * object type. */ private String objectType; /** - * Gets or sets application Id. + * application Id. */ private String appId; /** - * Gets or sets application permissions. + * application permissions. */ private List appPermissions; @@ -40,17 +40,17 @@ public class ApplicationInner { private Boolean availableToOtherTenants; /** - * Gets or sets the displayName. + * the displayName. */ private String displayName; /** - * Gets or sets the application identifier Uris. + * the application identifier Uris. */ private List identifierUris; /** - * Gets or sets the application reply Urls. + * the application reply Urls. */ private List replyUrls; diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationUpdateParametersInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationUpdateParametersInner.java index ea7d6deeb662..759d2d37df6d 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationUpdateParametersInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationUpdateParametersInner.java @@ -9,13 +9,16 @@ package com.microsoft.azure.management.graphrbac.implementation; import java.util.List; -import com.microsoft.azure.management.graphrbac.KeyCredential; -import com.microsoft.azure.management.graphrbac.PasswordCredential; /** * Request parameters for updating an existing application. */ public class ApplicationUpdateParametersInner { + /** + * Indicates if the application will be available to other tenants. + */ + private Boolean availableToOtherTenants; + /** * Application display name. */ @@ -37,14 +40,34 @@ public class ApplicationUpdateParametersInner { private List replyUrls; /** - * Gets or sets the list of KeyCredential objects. + * the list of KeyCredential objects. + */ + private List keyCredentials; + + /** + * the list of PasswordCredential objects. */ - private List keyCredentials; + private List passwordCredentials; /** - * Gets or sets the list of PasswordCredential objects. + * Get the availableToOtherTenants value. + * + * @return the availableToOtherTenants value */ - private List passwordCredentials; + public Boolean availableToOtherTenants() { + return this.availableToOtherTenants; + } + + /** + * Set the availableToOtherTenants value. + * + * @param availableToOtherTenants the availableToOtherTenants value to set + * @return the ApplicationUpdateParametersInner object itself. + */ + public ApplicationUpdateParametersInner withAvailableToOtherTenants(Boolean availableToOtherTenants) { + this.availableToOtherTenants = availableToOtherTenants; + return this; + } /** * Get the displayName value. @@ -131,7 +154,7 @@ public ApplicationUpdateParametersInner withReplyUrls(List replyUrls) { * * @return the keyCredentials value */ - public List keyCredentials() { + public List keyCredentials() { return this.keyCredentials; } @@ -141,7 +164,7 @@ public List keyCredentials() { * @param keyCredentials the keyCredentials value to set * @return the ApplicationUpdateParametersInner object itself. */ - public ApplicationUpdateParametersInner withKeyCredentials(List keyCredentials) { + public ApplicationUpdateParametersInner withKeyCredentials(List keyCredentials) { this.keyCredentials = keyCredentials; return this; } @@ -151,7 +174,7 @@ public ApplicationUpdateParametersInner withKeyCredentials(List k * * @return the passwordCredentials value */ - public List passwordCredentials() { + public List passwordCredentials() { return this.passwordCredentials; } @@ -161,7 +184,7 @@ public List passwordCredentials() { * @param passwordCredentials the passwordCredentials value to set * @return the ApplicationUpdateParametersInner object itself. */ - public ApplicationUpdateParametersInner withPasswordCredentials(List passwordCredentials) { + public ApplicationUpdateParametersInner withPasswordCredentials(List passwordCredentials) { this.passwordCredentials = passwordCredentials; return this; } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationsInner.java index 9c6b519e4ea3..d77097b6d262 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationsInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationsInner.java @@ -11,16 +11,16 @@ import retrofit2.Retrofit; import com.google.common.reflect.TypeToken; import com.microsoft.azure.AzureServiceResponseBuilder; -import com.microsoft.azure.CloudException; +import com.microsoft.azure.management.graphrbac.GraphErrorException; +import com.microsoft.azure.management.graphrbac.KeyCredentialsUpdateParameters; +import com.microsoft.azure.management.graphrbac.PasswordCredentialsUpdateParameters; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; -import com.microsoft.rest.ServiceResponseCallback; import com.microsoft.rest.Validator; import java.io.IOException; import java.util.List; import okhttp3.ResponseBody; -import retrofit2.Call; import retrofit2.http.Body; import retrofit2.http.GET; import retrofit2.http.Header; @@ -31,6 +31,8 @@ import retrofit2.http.POST; import retrofit2.http.Query; import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; /** * An instance of this class provides access to all the operations defined @@ -60,23 +62,39 @@ public ApplicationsInner(Retrofit retrofit, GraphRbacManagementClientImpl client interface ApplicationsService { @Headers("Content-Type: application/json; charset=utf-8") @POST("{tenantID}/applications") - Call create(@Path("tenantID") String tenantID, @Body ApplicationCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> create(@Path("tenantID") String tenantID, @Body ApplicationCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/applications") - Call list(@Path("tenantID") String tenantID, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> list(@Path("tenantID") String tenantID, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @HTTP(path = "{tenantID}/applications/{applicationObjectId}", method = "DELETE", hasBody = true) - Call delete(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> delete(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/applications/{applicationObjectId}") - Call get(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> get(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @PATCH("{tenantID}/applications/{applicationObjectId}") - Call patch(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Body ApplicationUpdateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> patch(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Body ApplicationUpdateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/applications/{applicationObjectId}/keyCredentials") + Observable> listKeyCredentials(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @PATCH("{tenantID}/applications/{applicationObjectId}/keyCredentials") + Observable> updateKeyCredentials(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body KeyCredentialsUpdateParameters parameters, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/applications/{applicationObjectId}/passwordCredentials") + Observable> listPasswordCredentials(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @PATCH("{tenantID}/applications/{applicationObjectId}/passwordCredentials") + Observable> updatePasswordCredentials(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body PasswordCredentialsUpdateParameters parameters, @Header("User-Agent") String userAgent); } @@ -84,24 +102,13 @@ interface ApplicationsService { * Create a new application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. * * @param parameters Parameters to create an application. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the ApplicationInner object wrapped in {@link ServiceResponse} if successful. + * @return the ApplicationInner object if successful. */ - public ServiceResponse create(ApplicationCreateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(parameters); - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return createDelegate(call.execute()); + public ApplicationInner create(ApplicationCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { + return createWithServiceResponseAsync(parameters).toBlocking().single().getBody(); } /** @@ -109,57 +116,107 @@ public ServiceResponse create(ApplicationCreateParametersInner * * @param parameters Parameters to create an application. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall createAsync(ApplicationCreateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall createAsync(ApplicationCreateParametersInner parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(createWithServiceResponseAsync(parameters), serviceCallback); + } + + /** + * Create a new application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param parameters Parameters to create an application. + * @return the observable to the ApplicationInner object + */ + public Observable createAsync(ApplicationCreateParametersInner parameters) { + return createWithServiceResponseAsync(parameters).map(new Func1, ApplicationInner>() { + @Override + public ApplicationInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Create a new application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param parameters Parameters to create an application. + * @return the observable to the ApplicationInner object + */ + public Observable> createWithServiceResponseAsync(ApplicationCreateParametersInner parameters) { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (parameters == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Validator.validate(parameters, serviceCallback); - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(createDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + Validator.validate(parameters); + return service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse createDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse createDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(201, new TypeToken() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } /** * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. * - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<ApplicationInner> object wrapped in {@link ServiceResponse} if successful. + * @return the List<ApplicationInner> object if successful. + */ + public List list() throws GraphErrorException, IOException, IllegalArgumentException { + return listWithServiceResponseAsync().toBlocking().single().getBody(); + } + + /** + * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall> listAsync(final ServiceCallback> serviceCallback) { + return ServiceCall.create(listWithServiceResponseAsync(), serviceCallback); + } + + /** + * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @return the observable to the List<ApplicationInner> object + */ + public Observable> listAsync() { + return listWithServiceResponseAsync().map(new Func1>, List>() { + @Override + public List call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @return the observable to the List<ApplicationInner> object */ - public ServiceResponse> list() throws CloudException, IOException, IllegalArgumentException { + public Observable>> listWithServiceResponseAsync() { if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -167,191 +224,451 @@ public ServiceResponse> list() throws CloudException, IOE throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } final String filter = null; - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - List result = response.getBody().getItems(); - return new ServiceResponse<>(result, response.getResponse()); + return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); } /** * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. * + * @param filter The filters to apply on the operation + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<ApplicationInner> object if successful. + */ + public List list(String filter) throws GraphErrorException, IOException, IllegalArgumentException { + return listWithServiceResponseAsync(filter).toBlocking().single().getBody(); + } + + /** + * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param filter The filters to apply on the operation * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listAsync(final ServiceCallback> serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } - if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; - } - if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; - } - final String filter = null; - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { + public ServiceCall> listAsync(String filter, final ServiceCallback> serviceCallback) { + return ServiceCall.create(listWithServiceResponseAsync(filter), serviceCallback); + } + + /** + * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param filter The filters to apply on the operation + * @return the observable to the List<ApplicationInner> object + */ + public Observable> listAsync(String filter) { + return listWithServiceResponseAsync(filter).map(new Func1>, List>() { @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); - } + public List call(ServiceResponse> response) { + return response.getBody(); } }); - return serviceCall; } /** * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. * * @param filter The filters to apply on the operation - * @throws CloudException exception thrown from REST call - * @throws IOException exception thrown from serialization/deserialization - * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<ApplicationInner> object wrapped in {@link ServiceResponse} if successful. + * @return the observable to the List<ApplicationInner> object */ - public ServiceResponse> list(String filter) throws CloudException, IOException, IllegalArgumentException { + public Observable>> listWithServiceResponseAsync(String filter) { if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - List result = response.getBody().getItems(); - return new ServiceResponse<>(result, response.getResponse()); + return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); } /** - * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * Delete an application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. * - * @param filter The filters to apply on the operation + * @param applicationObjectId Application object id + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + */ + public void delete(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + deleteWithServiceResponseAsync(applicationObjectId).toBlocking().single().getBody(); + } + + /** + * Delete an application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object + */ + public ServiceCall deleteAsync(String applicationObjectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(deleteWithServiceResponseAsync(applicationObjectId), serviceCallback); + } + + /** + * Delete an application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @return the {@link ServiceResponse} object if successful. */ - public ServiceCall listAsync(String filter, final ServiceCallback> serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); + public Observable deleteAsync(String applicationObjectId) { + return deleteWithServiceResponseAsync(applicationObjectId).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Delete an application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deleteWithServiceResponseAsync(String applicationObjectId) { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.delete(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } + }); + } + + private ServiceResponse deleteDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); + } + + /** + * Get an application by object Id. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the ApplicationInner object if successful. + */ + public ApplicationInner get(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + return getWithServiceResponseAsync(applicationObjectId).toBlocking().single().getBody(); + } + + /** + * Get an application by object Id. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall getAsync(String applicationObjectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(getWithServiceResponseAsync(applicationObjectId), serviceCallback); + } + + /** + * Get an application by object Id. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @return the observable to the ApplicationInner object + */ + public Observable getAsync(String applicationObjectId) { + return getWithServiceResponseAsync(applicationObjectId).map(new Func1, ApplicationInner>() { + @Override + public ApplicationInner call(ServiceResponse response) { + return response.getBody(); } }); - return serviceCall; } - private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) - .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + /** + * Get an application by object Id. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @return the observable to the ApplicationInner object + */ + public Observable> getWithServiceResponseAsync(String applicationObjectId) { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.get(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } /** - * Delete an application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * Update existing application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. * * @param applicationObjectId Application object id - * @throws CloudException exception thrown from REST call + * @param parameters Parameters to update an existing application. + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters + */ + public void patch(String applicationObjectId, ApplicationUpdateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { + patchWithServiceResponseAsync(applicationObjectId, parameters).toBlocking().single().getBody(); + } + + /** + * Update existing application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @param parameters Parameters to update an existing application. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall patchAsync(String applicationObjectId, ApplicationUpdateParametersInner parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(patchWithServiceResponseAsync(applicationObjectId, parameters), serviceCallback); + } + + /** + * Update existing application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @param parameters Parameters to update an existing application. * @return the {@link ServiceResponse} object if successful. */ - public ServiceResponse delete(String applicationObjectId) throws CloudException, IOException, IllegalArgumentException { + public Observable patchAsync(String applicationObjectId, ApplicationUpdateParametersInner parameters) { + return patchWithServiceResponseAsync(applicationObjectId, parameters).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Update existing application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @param parameters Parameters to update an existing application. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> patchWithServiceResponseAsync(String applicationObjectId, ApplicationUpdateParametersInner parameters) { if (applicationObjectId == null) { throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.delete(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return deleteDelegate(call.execute()); + Validator.validate(parameters); + return service.patch(applicationObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = patchDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse patchDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); } /** - * Delete an application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * Get keyCredentials associated with the application by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<KeyCredentialInner> object if successful. + */ + public List listKeyCredentials(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + return listKeyCredentialsWithServiceResponseAsync(applicationObjectId).toBlocking().single().getBody(); + } + + /** + * Get keyCredentials associated with the application by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. * * @param applicationObjectId Application object id * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall deleteAsync(String applicationObjectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listKeyCredentialsAsync(String applicationObjectId, final ServiceCallback> serviceCallback) { + return ServiceCall.create(listKeyCredentialsWithServiceResponseAsync(applicationObjectId), serviceCallback); + } + + /** + * Get keyCredentials associated with the application by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @return the observable to the List<KeyCredentialInner> object + */ + public Observable> listKeyCredentialsAsync(String applicationObjectId) { + return listKeyCredentialsWithServiceResponseAsync(applicationObjectId).map(new Func1>, List>() { + @Override + public List call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Get keyCredentials associated with the application by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @return the observable to the List<KeyCredentialInner> object + */ + public Observable>> listKeyCredentialsWithServiceResponseAsync(String applicationObjectId) { if (applicationObjectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.delete(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(deleteDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.listKeyCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listKeyCredentialsDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse deleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) - .register(204, new TypeToken() { }.getType()) + private ServiceResponse> listKeyCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } /** - * Get an application by object Id. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. * * @param applicationObjectId Application object id - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the ApplicationInner object wrapped in {@link ServiceResponse} if successful. */ - public ServiceResponse get(String applicationObjectId) throws CloudException, IOException, IllegalArgumentException { + public void updateKeyCredentials(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + updateKeyCredentialsWithServiceResponseAsync(applicationObjectId).toBlocking().single().getBody(); + } + + /** + * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall updateKeyCredentialsAsync(String applicationObjectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(updateKeyCredentialsWithServiceResponseAsync(applicationObjectId), serviceCallback); + } + + /** + * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @return the {@link ServiceResponse} object if successful. + */ + public Observable updateKeyCredentialsAsync(String applicationObjectId) { + return updateKeyCredentialsWithServiceResponseAsync(applicationObjectId).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updateKeyCredentialsWithServiceResponseAsync(String applicationObjectId) { if (applicationObjectId == null) { throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } @@ -361,132 +678,332 @@ public ServiceResponse get(String applicationObjectId) throws if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.get(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return getDelegate(call.execute()); + final List value = null; + KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); + parameters.withValue(null); + return service.updateKeyCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updateKeyCredentialsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); } /** - * Get an application by object Id. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @param value KeyCredential list. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + */ + public void updateKeyCredentials(String applicationObjectId, List value) throws GraphErrorException, IOException, IllegalArgumentException { + updateKeyCredentialsWithServiceResponseAsync(applicationObjectId, value).toBlocking().single().getBody(); + } + + /** + * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. * * @param applicationObjectId Application object id + * @param value KeyCredential list. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall getAsync(String applicationObjectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall updateKeyCredentialsAsync(String applicationObjectId, List value, final ServiceCallback serviceCallback) { + return ServiceCall.create(updateKeyCredentialsWithServiceResponseAsync(applicationObjectId, value), serviceCallback); + } + + /** + * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @param value KeyCredential list. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable updateKeyCredentialsAsync(String applicationObjectId, List value) { + return updateKeyCredentialsWithServiceResponseAsync(applicationObjectId, value).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @param value KeyCredential list. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updateKeyCredentialsWithServiceResponseAsync(String applicationObjectId, List value) { if (applicationObjectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.get(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(getDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + Validator.validate(value); + KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); + parameters.withValue(value); + return service.updateKeyCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updateKeyCredentialsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } + }); + } + + private ServiceResponse updateKeyCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); + } + + /** + * Gets passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<PasswordCredentialInner> object if successful. + */ + public List listPasswordCredentials(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + return listPasswordCredentialsWithServiceResponseAsync(applicationObjectId).toBlocking().single().getBody(); + } + + /** + * Gets passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall> listPasswordCredentialsAsync(String applicationObjectId, final ServiceCallback> serviceCallback) { + return ServiceCall.create(listPasswordCredentialsWithServiceResponseAsync(applicationObjectId), serviceCallback); + } + + /** + * Gets passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @return the observable to the List<PasswordCredentialInner> object + */ + public Observable> listPasswordCredentialsAsync(String applicationObjectId) { + return listPasswordCredentialsWithServiceResponseAsync(applicationObjectId).map(new Func1>, List>() { + @Override + public List call(ServiceResponse> response) { + return response.getBody(); } }); - return serviceCall; } - private ServiceResponse getDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) - .register(200, new TypeToken() { }.getType()) - .registerError(CloudException.class) + /** + * Gets passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @return the observable to the List<PasswordCredentialInner> object + */ + public Observable>> listPasswordCredentialsWithServiceResponseAsync(String applicationObjectId) { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.listPasswordCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listPasswordCredentialsDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listPasswordCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } /** - * Update existing application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. * * @param applicationObjectId Application object id - * @param parameters Parameters to update an existing application. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters + */ + public void updatePasswordCredentials(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + updatePasswordCredentialsWithServiceResponseAsync(applicationObjectId).toBlocking().single().getBody(); + } + + /** + * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall updatePasswordCredentialsAsync(String applicationObjectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(updatePasswordCredentialsWithServiceResponseAsync(applicationObjectId), serviceCallback); + } + + /** + * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id * @return the {@link ServiceResponse} object if successful. */ - public ServiceResponse patch(String applicationObjectId, ApplicationUpdateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { + public Observable updatePasswordCredentialsAsync(String applicationObjectId) { + return updatePasswordCredentialsWithServiceResponseAsync(applicationObjectId).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updatePasswordCredentialsWithServiceResponseAsync(String applicationObjectId) { if (applicationObjectId == null) { throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Validator.validate(parameters); - Call call = service.patch(applicationObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return patchDelegate(call.execute()); + final List value = null; + PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); + parameters.withValue(null); + return service.updatePasswordCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updatePasswordCredentialsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); } /** - * Update existing application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. * * @param applicationObjectId Application object id - * @param parameters Parameters to update an existing application. + * @param value PasswordCredential list. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + */ + public void updatePasswordCredentials(String applicationObjectId, List value) throws GraphErrorException, IOException, IllegalArgumentException { + updatePasswordCredentialsWithServiceResponseAsync(applicationObjectId, value).toBlocking().single().getBody(); + } + + /** + * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @param value PasswordCredential list. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall patchAsync(String applicationObjectId, ApplicationUpdateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall updatePasswordCredentialsAsync(String applicationObjectId, List value, final ServiceCallback serviceCallback) { + return ServiceCall.create(updatePasswordCredentialsWithServiceResponseAsync(applicationObjectId, value), serviceCallback); + } + + /** + * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @param value PasswordCredential list. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable updatePasswordCredentialsAsync(String applicationObjectId, List value) { + return updatePasswordCredentialsWithServiceResponseAsync(applicationObjectId, value).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @param value PasswordCredential list. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updatePasswordCredentialsWithServiceResponseAsync(String applicationObjectId, List value) { if (applicationObjectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; - } - if (parameters == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Validator.validate(parameters, serviceCallback); - Call call = service.patch(applicationObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(patchDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + Validator.validate(value); + PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); + parameters.withValue(value); + return service.updatePasswordCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updatePasswordCredentialsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse patchDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse updatePasswordCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManagementClientImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManagementClientImpl.java index e95756e1703d..56062b62394e 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManagementClientImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManagementClientImpl.java @@ -40,11 +40,11 @@ public String apiVersion() { return this.apiVersion; } - /** Gets or sets the tenant Id. */ + /** the tenant Id. */ private String tenantID; /** - * Gets Gets or sets the tenant Id. + * Gets the tenant Id. * * @return the tenantID value. */ @@ -53,7 +53,7 @@ public String tenantID() { } /** - * Sets Gets or sets the tenant Id. + * Sets the tenant Id. * * @param tenantID the tenantID value. * @return the service client itself diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java index dc6fb1951e64..909a198bd288 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java @@ -10,22 +10,22 @@ import retrofit2.Retrofit; import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceCall; import com.microsoft.azure.AzureServiceResponseBuilder; -import com.microsoft.azure.CloudException; import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.management.graphrbac.GraphErrorException; import com.microsoft.azure.management.graphrbac.GroupAddMemberParameters; import com.microsoft.azure.management.graphrbac.GroupGetMemberGroupsParameters; import com.microsoft.azure.Page; import com.microsoft.azure.PagedList; +import com.microsoft.rest.RestException; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; -import com.microsoft.rest.ServiceResponseCallback; import com.microsoft.rest.Validator; import java.io.IOException; import java.util.List; import okhttp3.ResponseBody; -import retrofit2.Call; import retrofit2.http.Body; import retrofit2.http.GET; import retrofit2.http.Header; @@ -35,6 +35,8 @@ import retrofit2.http.POST; import retrofit2.http.Query; import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; /** * An instance of this class provides access to all the operations defined @@ -64,47 +66,47 @@ public GroupsInner(Retrofit retrofit, GraphRbacManagementClientImpl client) { interface GroupsService { @Headers("Content-Type: application/json; charset=utf-8") @POST("{tenantID}/isMemberOf") - Call isMemberOf(@Path("tenantID") String tenantID, @Body CheckGroupMembershipParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> isMemberOf(@Path("tenantID") String tenantID, @Body CheckGroupMembershipParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @HTTP(path = "{tenantID}/groups/{groupObjectId}/$links/members/{memberObjectId}", method = "DELETE", hasBody = true) - Call removeMember(@Path(value = "groupObjectId", encoded = true) String groupObjectId, @Path(value = "memberObjectId", encoded = true) String memberObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> removeMember(@Path(value = "groupObjectId", encoded = true) String groupObjectId, @Path(value = "memberObjectId", encoded = true) String memberObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @POST("{tenantID}/groups/{groupObjectId}/$links/members") - Call addMember(@Path(value = "groupObjectId", encoded = true) String groupObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body GroupAddMemberParameters parameters, @Header("User-Agent") String userAgent); + Observable> addMember(@Path(value = "groupObjectId", encoded = true) String groupObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body GroupAddMemberParameters parameters, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @HTTP(path = "{tenantID}/groups/{groupObjectId}", method = "DELETE", hasBody = true) - Call delete(@Path(value = "groupObjectId", encoded = true) String groupObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> delete(@Path(value = "groupObjectId", encoded = true) String groupObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @POST("{tenantID}/groups") - Call create(@Path("tenantID") String tenantID, @Body GroupCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> create(@Path("tenantID") String tenantID, @Body GroupCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/groups") - Call list(@Path("tenantID") String tenantID, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> list(@Path("tenantID") String tenantID, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/groups/{objectId}/members") - Call getGroupMembers(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> getGroupMembers(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/groups/{objectId}") - Call get(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> get(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @POST("{tenantID}/groups/{objectId}/getMemberGroups") - Call getMemberGroups(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body GroupGetMemberGroupsParameters parameters, @Header("User-Agent") String userAgent); + Observable> getMemberGroups(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body GroupGetMemberGroupsParameters parameters, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/{nextLink}") - Call listNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> listNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/{nextLink}") - Call getGroupMembersNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> getGroupMembersNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); } @@ -112,24 +114,13 @@ interface GroupsService { * Checks whether the specified user, group, contact, or service principal is a direct or a transitive member of the specified group. * * @param parameters Check group membership parameters. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the CheckGroupMembershipResultInner object wrapped in {@link ServiceResponse} if successful. + * @return the CheckGroupMembershipResultInner object if successful. */ - public ServiceResponse isMemberOf(CheckGroupMembershipParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(parameters); - Call call = service.isMemberOf(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return isMemberOfDelegate(call.execute()); + public CheckGroupMembershipResultInner isMemberOf(CheckGroupMembershipParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { + return isMemberOfWithServiceResponseAsync(parameters).toBlocking().single().getBody(); } /** @@ -137,45 +128,62 @@ public ServiceResponse isMemberOf(CheckGroupMem * * @param parameters Check group membership parameters. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall isMemberOfAsync(CheckGroupMembershipParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall isMemberOfAsync(CheckGroupMembershipParametersInner parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(isMemberOfWithServiceResponseAsync(parameters), serviceCallback); + } + + /** + * Checks whether the specified user, group, contact, or service principal is a direct or a transitive member of the specified group. + * + * @param parameters Check group membership parameters. + * @return the observable to the CheckGroupMembershipResultInner object + */ + public Observable isMemberOfAsync(CheckGroupMembershipParametersInner parameters) { + return isMemberOfWithServiceResponseAsync(parameters).map(new Func1, CheckGroupMembershipResultInner>() { + @Override + public CheckGroupMembershipResultInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Checks whether the specified user, group, contact, or service principal is a direct or a transitive member of the specified group. + * + * @param parameters Check group membership parameters. + * @return the observable to the CheckGroupMembershipResultInner object + */ + public Observable> isMemberOfWithServiceResponseAsync(CheckGroupMembershipParametersInner parameters) { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (parameters == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Validator.validate(parameters, serviceCallback); - Call call = service.isMemberOf(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(isMemberOfDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + Validator.validate(parameters); + return service.isMemberOf(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = isMemberOfDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse isMemberOfDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse isMemberOfDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(200, new TypeToken() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } @@ -184,26 +192,12 @@ private ServiceResponse isMemberOfDelegate(Resp * * @param groupObjectId Group object id * @param memberObjectId Member Object id - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the {@link ServiceResponse} object if successful. */ - public ServiceResponse removeMember(String groupObjectId, String memberObjectId) throws CloudException, IOException, IllegalArgumentException { - if (groupObjectId == null) { - throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); - } - if (memberObjectId == null) { - throw new IllegalArgumentException("Parameter memberObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.removeMember(groupObjectId, memberObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return removeMemberDelegate(call.execute()); + public void removeMember(String groupObjectId, String memberObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + removeMemberWithServiceResponseAsync(groupObjectId, memberObjectId).toBlocking().single().getBody(); } /** @@ -212,47 +206,66 @@ public ServiceResponse removeMember(String groupObjectId, String memberObj * @param groupObjectId Group object id * @param memberObjectId Member Object id * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall removeMemberAsync(String groupObjectId, String memberObjectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall removeMemberAsync(String groupObjectId, String memberObjectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(removeMemberWithServiceResponseAsync(groupObjectId, memberObjectId), serviceCallback); + } + + /** + * Remove a memeber from a group. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/groups-operations#DeleteGroupMember. + * + * @param groupObjectId Group object id + * @param memberObjectId Member Object id + * @return the {@link ServiceResponse} object if successful. + */ + public Observable removeMemberAsync(String groupObjectId, String memberObjectId) { + return removeMemberWithServiceResponseAsync(groupObjectId, memberObjectId).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Remove a memeber from a group. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/groups-operations#DeleteGroupMember. + * + * @param groupObjectId Group object id + * @param memberObjectId Member Object id + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> removeMemberWithServiceResponseAsync(String groupObjectId, String memberObjectId) { if (groupObjectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter groupObjectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); } if (memberObjectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter memberObjectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter memberObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.removeMember(groupObjectId, memberObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(removeMemberDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.removeMember(groupObjectId, memberObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = removeMemberDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse removeMemberDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse removeMemberDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } @@ -261,28 +274,12 @@ private ServiceResponse removeMemberDelegate(Response respon * * @param groupObjectId Group object id * @param url Member Object Url as "https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd", where "0b1f9851-1bf0-433f-aec3-cb9272f093dc" is the tenantId and "f260bbc4-c254-447b-94cf-293b5ec434dd" is the objectId of the member (user, application, servicePrincipal, group) to be added. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the {@link ServiceResponse} object if successful. */ - public ServiceResponse addMember(String groupObjectId, String url) throws CloudException, IOException, IllegalArgumentException { - if (groupObjectId == null) { - throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - if (url == null) { - throw new IllegalArgumentException("Parameter url is required and cannot be null."); - } - GroupAddMemberParameters parameters = new GroupAddMemberParameters(); - parameters.withUrl(url); - Call call = service.addMember(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - return addMemberDelegate(call.execute()); + public void addMember(String groupObjectId, String url) throws GraphErrorException, IOException, IllegalArgumentException { + addMemberWithServiceResponseAsync(groupObjectId, url).toBlocking().single().getBody(); } /** @@ -291,49 +288,68 @@ public ServiceResponse addMember(String groupObjectId, String url) throws * @param groupObjectId Group object id * @param url Member Object Url as "https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd", where "0b1f9851-1bf0-433f-aec3-cb9272f093dc" is the tenantId and "f260bbc4-c254-447b-94cf-293b5ec434dd" is the objectId of the member (user, application, servicePrincipal, group) to be added. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall addMemberAsync(String groupObjectId, String url, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall addMemberAsync(String groupObjectId, String url, final ServiceCallback serviceCallback) { + return ServiceCall.create(addMemberWithServiceResponseAsync(groupObjectId, url), serviceCallback); + } + + /** + * Add a memeber to a group. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/groups-operations#AddGroupMembers. + * + * @param groupObjectId Group object id + * @param url Member Object Url as "https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd", where "0b1f9851-1bf0-433f-aec3-cb9272f093dc" is the tenantId and "f260bbc4-c254-447b-94cf-293b5ec434dd" is the objectId of the member (user, application, servicePrincipal, group) to be added. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable addMemberAsync(String groupObjectId, String url) { + return addMemberWithServiceResponseAsync(groupObjectId, url).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Add a memeber to a group. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/groups-operations#AddGroupMembers. + * + * @param groupObjectId Group object id + * @param url Member Object Url as "https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd", where "0b1f9851-1bf0-433f-aec3-cb9272f093dc" is the tenantId and "f260bbc4-c254-447b-94cf-293b5ec434dd" is the objectId of the member (user, application, servicePrincipal, group) to be added. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> addMemberWithServiceResponseAsync(String groupObjectId, String url) { if (groupObjectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter groupObjectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } if (url == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter url is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter url is required and cannot be null."); } GroupAddMemberParameters parameters = new GroupAddMemberParameters(); parameters.withUrl(url); - Call call = service.addMember(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(addMemberDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.addMember(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = addMemberDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse addMemberDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse addMemberDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } @@ -341,23 +357,12 @@ private ServiceResponse addMemberDelegate(Response response) * Delete a group in the directory. Reference: http://msdn.microsoft.com/en-us/library/azure/dn151676.aspx. * * @param groupObjectId Object id - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the {@link ServiceResponse} object if successful. */ - public ServiceResponse delete(String groupObjectId) throws CloudException, IOException, IllegalArgumentException { - if (groupObjectId == null) { - throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.delete(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return deleteDelegate(call.execute()); + public void delete(String groupObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + deleteWithServiceResponseAsync(groupObjectId).toBlocking().single().getBody(); } /** @@ -365,43 +370,61 @@ public ServiceResponse delete(String groupObjectId) throws CloudException, * * @param groupObjectId Object id * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall deleteAsync(String groupObjectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall deleteAsync(String groupObjectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(deleteWithServiceResponseAsync(groupObjectId), serviceCallback); + } + + /** + * Delete a group in the directory. Reference: http://msdn.microsoft.com/en-us/library/azure/dn151676.aspx. + * + * @param groupObjectId Object id + * @return the {@link ServiceResponse} object if successful. + */ + public Observable deleteAsync(String groupObjectId) { + return deleteWithServiceResponseAsync(groupObjectId).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Delete a group in the directory. Reference: http://msdn.microsoft.com/en-us/library/azure/dn151676.aspx. + * + * @param groupObjectId Object id + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deleteWithServiceResponseAsync(String groupObjectId) { if (groupObjectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter groupObjectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.delete(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(deleteDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.delete(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse deleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse deleteDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } @@ -409,24 +432,13 @@ private ServiceResponse deleteDelegate(Response response) th * Create a group in the directory. Reference: http://msdn.microsoft.com/en-us/library/azure/dn151676.aspx. * * @param parameters Parameters to create a group - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the ADGroupInner object wrapped in {@link ServiceResponse} if successful. + * @return the ADGroupInner object if successful. */ - public ServiceResponse create(GroupCreateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(parameters); - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return createDelegate(call.execute()); + public ADGroupInner create(GroupCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { + return createWithServiceResponseAsync(parameters).toBlocking().single().getBody(); } /** @@ -434,142 +446,179 @@ public ServiceResponse create(GroupCreateParametersInner parameter * * @param parameters Parameters to create a group * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall createAsync(GroupCreateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall createAsync(GroupCreateParametersInner parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(createWithServiceResponseAsync(parameters), serviceCallback); + } + + /** + * Create a group in the directory. Reference: http://msdn.microsoft.com/en-us/library/azure/dn151676.aspx. + * + * @param parameters Parameters to create a group + * @return the observable to the ADGroupInner object + */ + public Observable createAsync(GroupCreateParametersInner parameters) { + return createWithServiceResponseAsync(parameters).map(new Func1, ADGroupInner>() { + @Override + public ADGroupInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Create a group in the directory. Reference: http://msdn.microsoft.com/en-us/library/azure/dn151676.aspx. + * + * @param parameters Parameters to create a group + * @return the observable to the ADGroupInner object + */ + public Observable> createWithServiceResponseAsync(GroupCreateParametersInner parameters) { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (parameters == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Validator.validate(parameters, serviceCallback); - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(createDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + Validator.validate(parameters); + return service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse createDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse createDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(201, new TypeToken() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } /** * Gets list of groups for the current tenant. * - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<ADGroupInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<ADGroupInner> object if successful. */ - public ServiceResponse> list() throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - final String filter = null; - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList list() throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = listSinglePageAsync().toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextLink) throws CloudException, IOException { - return listNext(nextLink).getBody(); + public Page nextPage(String nextLink) throws RestException, IOException { + return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** * Gets list of groups for the current tenant. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listAsync(final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listAsync(final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listSinglePageAsync(), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return listNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets list of groups for the current tenant. + * + * @return the observable to the PagedList<ADGroupInner> object + */ + public Observable> listAsync() { + return listWithServiceResponseAsync() + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets list of groups for the current tenant. + * + * @return the observable to the PagedList<ADGroupInner> object + */ + public Observable>> listWithServiceResponseAsync() { + return listSinglePageAsync() + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets list of groups for the current tenant. + * + * @return the PagedList<ADGroupInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync() { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } final String filter = null; - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } /** * Gets list of groups for the current tenant. * * @param filter The filter to apply on the operation. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<ADGroupInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<ADGroupInner> object if successful. */ - public ServiceResponse> list(final String filter) throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList list(final String filter) throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = listSinglePageAsync(filter).toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextLink) throws CloudException, IOException { - return listNext(nextLink).getBody(); + public Page nextPage(String nextLink) throws RestException, IOException { + return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** @@ -577,47 +626,87 @@ public Page nextPage(String nextLink) throws CloudException, IOExc * * @param filter The filter to apply on the operation. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listAsync(final String filter, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listAsync(final String filter, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listSinglePageAsync(filter), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return listNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets list of groups for the current tenant. + * + * @param filter The filter to apply on the operation. + * @return the observable to the PagedList<ADGroupInner> object + */ + public Observable> listAsync(final String filter) { + return listWithServiceResponseAsync(filter) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets list of groups for the current tenant. + * + * @param filter The filter to apply on the operation. + * @return the observable to the PagedList<ADGroupInner> object + */ + public Observable>> listWithServiceResponseAsync(final String filter) { + return listSinglePageAsync(filter) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets list of groups for the current tenant. + * + ServiceResponse> * @param filter The filter to apply on the operation. + * @return the PagedList<ADGroupInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync(final String filter) { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } - private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + private ServiceResponse> listDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } @@ -625,30 +714,19 @@ private ServiceResponse> listDelegate(Response> getGroupMembers(final String objectId) throws CloudException, IOException, IllegalArgumentException { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.getGroupMembers(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = getGroupMembersDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList getGroupMembers(final String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = getGroupMembersSinglePageAsync(objectId).toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextLink) throws CloudException, IOException { - return getGroupMembersNext(nextLink).getBody(); + public Page nextPage(String nextLink) throws RestException, IOException { + return getGroupMembersNextSinglePageAsync(nextLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** @@ -656,51 +734,90 @@ public Page nextPage(String nextLink) throws CloudException, IOE * * @param objectId Group object Id who's members should be retrieved. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall getGroupMembersAsync(final String objectId, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> getGroupMembersAsync(final String objectId, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + getGroupMembersSinglePageAsync(objectId), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return getGroupMembersNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets the members of a group. + * + * @param objectId Group object Id who's members should be retrieved. + * @return the observable to the PagedList<AADObjectInner> object + */ + public Observable> getGroupMembersAsync(final String objectId) { + return getGroupMembersWithServiceResponseAsync(objectId) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets the members of a group. + * + * @param objectId Group object Id who's members should be retrieved. + * @return the observable to the PagedList<AADObjectInner> object + */ + public Observable>> getGroupMembersWithServiceResponseAsync(final String objectId) { + return getGroupMembersSinglePageAsync(objectId) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(getGroupMembersNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets the members of a group. + * + ServiceResponse> * @param objectId Group object Id who's members should be retrieved. + * @return the PagedList<AADObjectInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> getGroupMembersSinglePageAsync(final String objectId) { if (objectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter objectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.getGroupMembers(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = getGroupMembersDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - getGroupMembersNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.getGroupMembers(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = getGroupMembersDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } - private ServiceResponse> getGroupMembersDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + private ServiceResponse> getGroupMembersDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } @@ -708,23 +825,13 @@ private ServiceResponse> getGroupMembersDelegate(Respo * Gets group information from the directory. * * @param objectId User objectId to get group information. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the ADGroupInner object wrapped in {@link ServiceResponse} if successful. + * @return the ADGroupInner object if successful. */ - public ServiceResponse get(String objectId) throws CloudException, IOException, IllegalArgumentException { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return getDelegate(call.execute()); + public ADGroupInner get(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + return getWithServiceResponseAsync(objectId).toBlocking().single().getBody(); } /** @@ -732,44 +839,61 @@ public ServiceResponse get(String objectId) throws CloudException, * * @param objectId User objectId to get group information. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall getAsync(String objectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall getAsync(String objectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(getWithServiceResponseAsync(objectId), serviceCallback); + } + + /** + * Gets group information from the directory. + * + * @param objectId User objectId to get group information. + * @return the observable to the ADGroupInner object + */ + public Observable getAsync(String objectId) { + return getWithServiceResponseAsync(objectId).map(new Func1, ADGroupInner>() { + @Override + public ADGroupInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Gets group information from the directory. + * + * @param objectId User objectId to get group information. + * @return the observable to the ADGroupInner object + */ + public Observable> getWithServiceResponseAsync(String objectId) { if (objectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter objectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(getDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse getDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse getDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(200, new TypeToken() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } @@ -778,27 +902,13 @@ private ServiceResponse getDelegate(Response respons * * @param objectId Group filtering parameters. * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<String> object wrapped in {@link ServiceResponse} if successful. + * @return the List<String> object if successful. */ - public ServiceResponse> getMemberGroups(String objectId, boolean securityEnabledOnly) throws CloudException, IOException, IllegalArgumentException { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - GroupGetMemberGroupsParameters parameters = new GroupGetMemberGroupsParameters(); - parameters.withSecurityEnabledOnly(securityEnabledOnly); - Call call = service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - ServiceResponse> response = getMemberGroupsDelegate(call.execute()); - List result = response.getBody().getItems(); - return new ServiceResponse<>(result, response.getResponse()); + public List getMemberGroups(String objectId, boolean securityEnabledOnly) throws GraphErrorException, IOException, IllegalArgumentException { + return getMemberGroupsWithServiceResponseAsync(objectId, securityEnabledOnly).toBlocking().single().getBody(); } /** @@ -807,47 +917,66 @@ public ServiceResponse> getMemberGroups(String objectId, boolean se * @param objectId Group filtering parameters. * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall getMemberGroupsAsync(String objectId, boolean securityEnabledOnly, final ServiceCallback> serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> getMemberGroupsAsync(String objectId, boolean securityEnabledOnly, final ServiceCallback> serviceCallback) { + return ServiceCall.create(getMemberGroupsWithServiceResponseAsync(objectId, securityEnabledOnly), serviceCallback); + } + + /** + * Gets a collection that contains the Object IDs of the groups of which the group is a member. + * + * @param objectId Group filtering parameters. + * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked + * @return the observable to the List<String> object + */ + public Observable> getMemberGroupsAsync(String objectId, boolean securityEnabledOnly) { + return getMemberGroupsWithServiceResponseAsync(objectId, securityEnabledOnly).map(new Func1>, List>() { + @Override + public List call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets a collection that contains the Object IDs of the groups of which the group is a member. + * + * @param objectId Group filtering parameters. + * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked + * @return the observable to the List<String> object + */ + public Observable>> getMemberGroupsWithServiceResponseAsync(String objectId, boolean securityEnabledOnly) { if (objectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter objectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } GroupGetMemberGroupsParameters parameters = new GroupGetMemberGroupsParameters(); parameters.withSecurityEnabledOnly(securityEnabledOnly); - Call call = service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = getMemberGroupsDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = getMemberGroupsDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse> getMemberGroupsDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + private ServiceResponse> getMemberGroupsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } @@ -855,23 +984,19 @@ private ServiceResponse> getMemberGroupsDelegate(Response> listNext(final String nextLink) throws CloudException, IOException, IllegalArgumentException { - if (nextLink == null) { - throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return listNextDelegate(call.execute()); + public PagedList listNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = listNextSinglePageAsync(nextLink).toBlocking().single(); + return new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextLink) throws RestException, IOException { + return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); + } + }; } /** @@ -880,51 +1005,90 @@ public ServiceResponse> listNext(final String nextLink) * @param nextLink Next link for list operation. * @param serviceCall the ServiceCall object tracking the Retrofit calls * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listNextAsync(final String nextLink, final ServiceCall serviceCall, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listNextSinglePageAsync(nextLink), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return listNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets list of groups for the current tenant. + * + * @param nextLink Next link for list operation. + * @return the observable to the PagedList<ADGroupInner> object + */ + public Observable> listNextAsync(final String nextLink) { + return listNextWithServiceResponseAsync(nextLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets list of groups for the current tenant. + * + * @param nextLink Next link for list operation. + * @return the observable to the PagedList<ADGroupInner> object + */ + public Observable>> listNextWithServiceResponseAsync(final String nextLink) { + return listNextSinglePageAsync(nextLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets list of groups for the current tenant. + * + ServiceResponse> * @param nextLink Next link for list operation. + * @return the PagedList<ADGroupInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listNextSinglePageAsync(final String nextLink) { if (nextLink == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - serviceCall.newCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listNextDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listNextDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } - private ServiceResponse> listNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + private ServiceResponse> listNextDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } @@ -932,23 +1096,19 @@ private ServiceResponse> listNextDelegate(Response> getGroupMembersNext(final String nextLink) throws CloudException, IOException, IllegalArgumentException { - if (nextLink == null) { - throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.getGroupMembersNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return getGroupMembersNextDelegate(call.execute()); + public PagedList getGroupMembersNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = getGroupMembersNextSinglePageAsync(nextLink).toBlocking().single(); + return new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextLink) throws RestException, IOException { + return getGroupMembersNextSinglePageAsync(nextLink).toBlocking().single().getBody(); + } + }; } /** @@ -957,51 +1117,90 @@ public ServiceResponse> getGroupMembersNext(final Stri * @param nextLink Next link for list operation. * @param serviceCall the ServiceCall object tracking the Retrofit calls * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall getGroupMembersNextAsync(final String nextLink, final ServiceCall serviceCall, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> getGroupMembersNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + getGroupMembersNextSinglePageAsync(nextLink), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return getGroupMembersNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets the members of a group. + * + * @param nextLink Next link for list operation. + * @return the observable to the PagedList<AADObjectInner> object + */ + public Observable> getGroupMembersNextAsync(final String nextLink) { + return getGroupMembersNextWithServiceResponseAsync(nextLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets the members of a group. + * + * @param nextLink Next link for list operation. + * @return the observable to the PagedList<AADObjectInner> object + */ + public Observable>> getGroupMembersNextWithServiceResponseAsync(final String nextLink) { + return getGroupMembersNextSinglePageAsync(nextLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(getGroupMembersNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets the members of a group. + * + ServiceResponse> * @param nextLink Next link for list operation. + * @return the PagedList<AADObjectInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> getGroupMembersNextSinglePageAsync(final String nextLink) { if (nextLink == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.getGroupMembersNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - serviceCall.newCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = getGroupMembersNextDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - getGroupMembersNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.getGroupMembersNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = getGroupMembersNextDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } - private ServiceResponse> getGroupMembersNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + private ServiceResponse> getGroupMembersNextDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/KeyCredential.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/KeyCredentialInner.java similarity index 69% rename from azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/KeyCredential.java rename to azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/KeyCredentialInner.java index a872fc2465af..9ce3370d8ebf 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/KeyCredential.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/KeyCredentialInner.java @@ -6,41 +6,41 @@ * Code generated by Microsoft (R) AutoRest Code Generator. */ -package com.microsoft.azure.management.graphrbac; +package com.microsoft.azure.management.graphrbac.implementation; import org.joda.time.DateTime; /** - * Active Directory service principal Key Credential information. + * Active Directory Key Credential information. */ -public class KeyCredential { +public class KeyCredentialInner { /** - * Gets or sets start date. + * start date. */ private DateTime startDate; /** - * Gets or sets end date. + * end date. */ private DateTime endDate; /** - * Gets or sets value. + * value. */ private String value; /** - * Gets or sets key Id. + * key Id. */ private String keyId; /** - * Gets or sets usage. + * usage. Acceptable values are 'Verify' and 'Sign'. */ private String usage; /** - * Gets or sets type. + * type. Acceptable values are 'AsymmetricX509Cert' and 'Symmetric'. */ private String type; @@ -57,9 +57,9 @@ public DateTime startDate() { * Set the startDate value. * * @param startDate the startDate value to set - * @return the KeyCredential object itself. + * @return the KeyCredentialInner object itself. */ - public KeyCredential withStartDate(DateTime startDate) { + public KeyCredentialInner withStartDate(DateTime startDate) { this.startDate = startDate; return this; } @@ -77,9 +77,9 @@ public DateTime endDate() { * Set the endDate value. * * @param endDate the endDate value to set - * @return the KeyCredential object itself. + * @return the KeyCredentialInner object itself. */ - public KeyCredential withEndDate(DateTime endDate) { + public KeyCredentialInner withEndDate(DateTime endDate) { this.endDate = endDate; return this; } @@ -97,9 +97,9 @@ public String value() { * Set the value value. * * @param value the value value to set - * @return the KeyCredential object itself. + * @return the KeyCredentialInner object itself. */ - public KeyCredential withValue(String value) { + public KeyCredentialInner withValue(String value) { this.value = value; return this; } @@ -117,9 +117,9 @@ public String keyId() { * Set the keyId value. * * @param keyId the keyId value to set - * @return the KeyCredential object itself. + * @return the KeyCredentialInner object itself. */ - public KeyCredential withKeyId(String keyId) { + public KeyCredentialInner withKeyId(String keyId) { this.keyId = keyId; return this; } @@ -137,9 +137,9 @@ public String usage() { * Set the usage value. * * @param usage the usage value to set - * @return the KeyCredential object itself. + * @return the KeyCredentialInner object itself. */ - public KeyCredential withUsage(String usage) { + public KeyCredentialInner withUsage(String usage) { this.usage = usage; return this; } @@ -157,9 +157,9 @@ public String type() { * Set the type value. * * @param type the type value to set - * @return the KeyCredential object itself. + * @return the KeyCredentialInner object itself. */ - public KeyCredential withType(String type) { + public KeyCredentialInner withType(String type) { this.type = type; return this; } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ObjectsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ObjectsInner.java index 51d87506eece..98ae94a7696e 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ObjectsInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ObjectsInner.java @@ -11,20 +11,20 @@ import retrofit2.Retrofit; import com.google.common.reflect.TypeToken; import com.microsoft.azure.AzureServiceResponseBuilder; -import com.microsoft.azure.CloudException; +import com.microsoft.azure.management.graphrbac.GraphErrorException; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; -import com.microsoft.rest.ServiceResponseCallback; import java.io.IOException; import okhttp3.ResponseBody; -import retrofit2.Call; import retrofit2.http.GET; import retrofit2.http.Header; import retrofit2.http.Headers; import retrofit2.http.Path; import retrofit2.http.Query; import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; /** * An instance of this class provides access to all the operations defined @@ -54,67 +54,76 @@ public ObjectsInner(Retrofit retrofit, GraphRbacManagementClientImpl client) { interface ObjectsService { @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/me") - Call getCurrentUser(@Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> getCurrentUser(@Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); } /** * Gets the details for current logged in user. * - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the AADObjectInner object wrapped in {@link ServiceResponse} if successful. + * @return the AADObjectInner object if successful. */ - public ServiceResponse getCurrentUser() throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.getCurrentUser(this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return getCurrentUserDelegate(call.execute()); + public AADObjectInner getCurrentUser() throws GraphErrorException, IOException, IllegalArgumentException { + return getCurrentUserWithServiceResponseAsync().toBlocking().single().getBody(); } /** * Gets the details for current logged in user. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall getCurrentUserAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall getCurrentUserAsync(final ServiceCallback serviceCallback) { + return ServiceCall.create(getCurrentUserWithServiceResponseAsync(), serviceCallback); + } + + /** + * Gets the details for current logged in user. + * + * @return the observable to the AADObjectInner object + */ + public Observable getCurrentUserAsync() { + return getCurrentUserWithServiceResponseAsync().map(new Func1, AADObjectInner>() { + @Override + public AADObjectInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Gets the details for current logged in user. + * + * @return the observable to the AADObjectInner object + */ + public Observable> getCurrentUserWithServiceResponseAsync() { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.getCurrentUser(this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(getCurrentUserDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.getCurrentUser(this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getCurrentUserDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse getCurrentUserDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse getCurrentUserDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(200, new TypeToken() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordCredential.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/PasswordCredentialInner.java similarity index 70% rename from azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordCredential.java rename to azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/PasswordCredentialInner.java index 67660ebb9d30..c39714365dbf 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordCredential.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/PasswordCredentialInner.java @@ -6,31 +6,31 @@ * Code generated by Microsoft (R) AutoRest Code Generator. */ -package com.microsoft.azure.management.graphrbac; +package com.microsoft.azure.management.graphrbac.implementation; import org.joda.time.DateTime; /** - * Active Directory service principal Password Credential information. + * Active Directory PasswordCredential information. */ -public class PasswordCredential { +public class PasswordCredentialInner { /** - * Gets or sets start date. + * start date. */ private DateTime startDate; /** - * Gets or sets end date. + * end date. */ private DateTime endDate; /** - * Gets or sets key Id. + * key Id. */ private String keyId; /** - * Gets or sets value. + * value. */ private String value; @@ -47,9 +47,9 @@ public DateTime startDate() { * Set the startDate value. * * @param startDate the startDate value to set - * @return the PasswordCredential object itself. + * @return the PasswordCredentialInner object itself. */ - public PasswordCredential withStartDate(DateTime startDate) { + public PasswordCredentialInner withStartDate(DateTime startDate) { this.startDate = startDate; return this; } @@ -67,9 +67,9 @@ public DateTime endDate() { * Set the endDate value. * * @param endDate the endDate value to set - * @return the PasswordCredential object itself. + * @return the PasswordCredentialInner object itself. */ - public PasswordCredential withEndDate(DateTime endDate) { + public PasswordCredentialInner withEndDate(DateTime endDate) { this.endDate = endDate; return this; } @@ -87,9 +87,9 @@ public String keyId() { * Set the keyId value. * * @param keyId the keyId value to set - * @return the PasswordCredential object itself. + * @return the PasswordCredentialInner object itself. */ - public PasswordCredential withKeyId(String keyId) { + public PasswordCredentialInner withKeyId(String keyId) { this.keyId = keyId; return this; } @@ -107,9 +107,9 @@ public String value() { * Set the value value. * * @param value the value value to set - * @return the PasswordCredential object itself. + * @return the PasswordCredentialInner object itself. */ - public PasswordCredential withValue(String value) { + public PasswordCredentialInner withValue(String value) { this.value = value; return this; } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalCreateParametersInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalCreateParametersInner.java index aa4aa749bece..83174b9cb180 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalCreateParametersInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalCreateParametersInner.java @@ -8,6 +8,7 @@ package com.microsoft.azure.management.graphrbac.implementation; +import java.util.List; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -15,7 +16,7 @@ */ public class ServicePrincipalCreateParametersInner { /** - * Gets or sets application Id. + * application Id. */ @JsonProperty(required = true) private String appId; @@ -26,6 +27,16 @@ public class ServicePrincipalCreateParametersInner { @JsonProperty(required = true) private boolean accountEnabled; + /** + * the list of KeyCredential objects. + */ + private List keyCredentials; + + /** + * the list of PasswordCredential objects. + */ + private List passwordCredentials; + /** * Get the appId value. * @@ -66,4 +77,44 @@ public ServicePrincipalCreateParametersInner withAccountEnabled(boolean accountE return this; } + /** + * Get the keyCredentials value. + * + * @return the keyCredentials value + */ + public List keyCredentials() { + return this.keyCredentials; + } + + /** + * Set the keyCredentials value. + * + * @param keyCredentials the keyCredentials value to set + * @return the ServicePrincipalCreateParametersInner object itself. + */ + public ServicePrincipalCreateParametersInner withKeyCredentials(List keyCredentials) { + this.keyCredentials = keyCredentials; + return this; + } + + /** + * Get the passwordCredentials value. + * + * @return the passwordCredentials value + */ + public List passwordCredentials() { + return this.passwordCredentials; + } + + /** + * Set the passwordCredentials value. + * + * @param passwordCredentials the passwordCredentials value to set + * @return the ServicePrincipalCreateParametersInner object itself. + */ + public ServicePrincipalCreateParametersInner withPasswordCredentials(List passwordCredentials) { + this.passwordCredentials = passwordCredentials; + return this; + } + } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalInner.java index c5b41719ebd7..b3c2dd63a739 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalInner.java @@ -15,27 +15,27 @@ */ public class ServicePrincipalInner { /** - * Gets or sets object Id. + * object Id. */ private String objectId; /** - * Gets or sets object type. + * object type. */ private String objectType; /** - * Gets or sets service principal display name. + * service principal display name. */ private String displayName; /** - * Gets or sets app id. + * app id. */ private String appId; /** - * Gets or sets the list of names. + * the list of names. */ private List servicePrincipalNames; diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java index d24ea4be93f1..963ea8bfe284 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java @@ -10,29 +10,34 @@ import retrofit2.Retrofit; import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceCall; import com.microsoft.azure.AzureServiceResponseBuilder; -import com.microsoft.azure.CloudException; import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.management.graphrbac.GraphErrorException; +import com.microsoft.azure.management.graphrbac.KeyCredentialsUpdateParameters; +import com.microsoft.azure.management.graphrbac.PasswordCredentialsUpdateParameters; import com.microsoft.azure.Page; import com.microsoft.azure.PagedList; +import com.microsoft.rest.RestException; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; -import com.microsoft.rest.ServiceResponseCallback; import com.microsoft.rest.Validator; import java.io.IOException; import java.util.List; import okhttp3.ResponseBody; -import retrofit2.Call; import retrofit2.http.Body; import retrofit2.http.GET; import retrofit2.http.Header; import retrofit2.http.Headers; import retrofit2.http.HTTP; +import retrofit2.http.PATCH; import retrofit2.http.Path; import retrofit2.http.POST; import retrofit2.http.Query; import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; /** * An instance of this class provides access to all the operations defined @@ -62,23 +67,39 @@ public ServicePrincipalsInner(Retrofit retrofit, GraphRbacManagementClientImpl c interface ServicePrincipalsService { @Headers("Content-Type: application/json; charset=utf-8") @POST("{tenantID}/servicePrincipals") - Call create(@Path("tenantID") String tenantID, @Body ServicePrincipalCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> create(@Path("tenantID") String tenantID, @Body ServicePrincipalCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/servicePrincipals") - Call list(@Path("tenantID") String tenantID, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> list(@Path("tenantID") String tenantID, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @HTTP(path = "{tenantID}/servicePrincipals/{objectId}", method = "DELETE", hasBody = true) - Call delete(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> delete(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/servicePrincipals/{objectId}") - Call get(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> get(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/servicePrincipals/{objectId}/keyCredentials") + Observable> listKeyCredentials(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @PATCH("{tenantID}/servicePrincipals/{objectId}/keyCredentials") + Observable> updateKeyCredentials(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body KeyCredentialsUpdateParameters parameters, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/servicePrincipals/{objectId}/passwordCredentials") + Observable> listPasswordCredentials(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @PATCH("{tenantID}/servicePrincipals/{objectId}/passwordCredentials") + Observable> updatePasswordCredentials(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body PasswordCredentialsUpdateParameters parameters, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/{nextLink}") - Call listNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> listNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); } @@ -86,24 +107,13 @@ interface ServicePrincipalsService { * Creates a service principal in the directory. * * @param parameters Parameters to create a service principal. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the ServicePrincipalInner object wrapped in {@link ServiceResponse} if successful. + * @return the ServicePrincipalInner object if successful. */ - public ServiceResponse create(ServicePrincipalCreateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(parameters); - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return createDelegate(call.execute()); + public ServicePrincipalInner create(ServicePrincipalCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { + return createWithServiceResponseAsync(parameters).toBlocking().single().getBody(); } /** @@ -111,142 +121,179 @@ public ServiceResponse create(ServicePrincipalCreateParam * * @param parameters Parameters to create a service principal. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall createAsync(ServicePrincipalCreateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall createAsync(ServicePrincipalCreateParametersInner parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(createWithServiceResponseAsync(parameters), serviceCallback); + } + + /** + * Creates a service principal in the directory. + * + * @param parameters Parameters to create a service principal. + * @return the observable to the ServicePrincipalInner object + */ + public Observable createAsync(ServicePrincipalCreateParametersInner parameters) { + return createWithServiceResponseAsync(parameters).map(new Func1, ServicePrincipalInner>() { + @Override + public ServicePrincipalInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Creates a service principal in the directory. + * + * @param parameters Parameters to create a service principal. + * @return the observable to the ServicePrincipalInner object + */ + public Observable> createWithServiceResponseAsync(ServicePrincipalCreateParametersInner parameters) { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (parameters == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Validator.validate(parameters, serviceCallback); - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(createDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + Validator.validate(parameters); + return service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse createDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse createDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(201, new TypeToken() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } /** * Gets list of service principals from the current tenant. * - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<ServicePrincipalInner> object if successful. */ - public ServiceResponse> list() throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - final String filter = null; - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList list() throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = listSinglePageAsync().toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextLink) throws CloudException, IOException { - return listNext(nextLink).getBody(); + public Page nextPage(String nextLink) throws RestException, IOException { + return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** * Gets list of service principals from the current tenant. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listAsync(final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listAsync(final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listSinglePageAsync(), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return listNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets list of service principals from the current tenant. + * + * @return the observable to the PagedList<ServicePrincipalInner> object + */ + public Observable> listAsync() { + return listWithServiceResponseAsync() + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets list of service principals from the current tenant. + * + * @return the observable to the PagedList<ServicePrincipalInner> object + */ + public Observable>> listWithServiceResponseAsync() { + return listSinglePageAsync() + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets list of service principals from the current tenant. + * + * @return the PagedList<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync() { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } final String filter = null; - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } /** * Gets list of service principals from the current tenant. * * @param filter The filter to apply on the operation. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<ServicePrincipalInner> object if successful. */ - public ServiceResponse> list(final String filter) throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList list(final String filter) throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = listSinglePageAsync(filter).toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextLink) throws CloudException, IOException { - return listNext(nextLink).getBody(); + public Page nextPage(String nextLink) throws RestException, IOException { + return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** @@ -254,47 +301,87 @@ public Page nextPage(String nextLink) throws CloudExcepti * * @param filter The filter to apply on the operation. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listAsync(final String filter, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listAsync(final String filter, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listSinglePageAsync(filter), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return listNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets list of service principals from the current tenant. + * + * @param filter The filter to apply on the operation. + * @return the observable to the PagedList<ServicePrincipalInner> object + */ + public Observable> listAsync(final String filter) { + return listWithServiceResponseAsync(filter) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets list of service principals from the current tenant. + * + * @param filter The filter to apply on the operation. + * @return the observable to the PagedList<ServicePrincipalInner> object + */ + public Observable>> listWithServiceResponseAsync(final String filter) { + return listSinglePageAsync(filter) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets list of service principals from the current tenant. + * + ServiceResponse> * @param filter The filter to apply on the operation. + * @return the PagedList<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync(final String filter) { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } - private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + private ServiceResponse> listDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } @@ -302,12 +389,47 @@ private ServiceResponse> listDelegate(Response< * Deletes service principal from the directory. * * @param objectId Object id to delete service principal information. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters + */ + public void delete(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + deleteWithServiceResponseAsync(objectId).toBlocking().single().getBody(); + } + + /** + * Deletes service principal from the directory. + * + * @param objectId Object id to delete service principal information. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall deleteAsync(String objectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(deleteWithServiceResponseAsync(objectId), serviceCallback); + } + + /** + * Deletes service principal from the directory. + * + * @param objectId Object id to delete service principal information. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable deleteAsync(String objectId) { + return deleteWithServiceResponseAsync(objectId).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Deletes service principal from the directory. + * + * @param objectId Object id to delete service principal information. * @return the {@link ServiceResponse} object if successful. */ - public ServiceResponse delete(String objectId) throws CloudException, IOException, IllegalArgumentException { + public Observable> deleteWithServiceResponseAsync(String objectId) { if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -317,65 +439,225 @@ public ServiceResponse delete(String objectId) throws CloudException, IOEx if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.delete(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return deleteDelegate(call.execute()); + return service.delete(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse deleteDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); } /** - * Deletes service principal from the directory. + * Gets service principal information from the directory. * - * @param objectId Object id to delete service principal information. + * @param objectId Object id to get service principal information. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the ServicePrincipalInner object if successful. + */ + public ServicePrincipalInner get(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + return getWithServiceResponseAsync(objectId).toBlocking().single().getBody(); + } + + /** + * Gets service principal information from the directory. + * + * @param objectId Object id to get service principal information. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall deleteAsync(String objectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall getAsync(String objectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(getWithServiceResponseAsync(objectId), serviceCallback); + } + + /** + * Gets service principal information from the directory. + * + * @param objectId Object id to get service principal information. + * @return the observable to the ServicePrincipalInner object + */ + public Observable getAsync(String objectId) { + return getWithServiceResponseAsync(objectId).map(new Func1, ServicePrincipalInner>() { + @Override + public ServicePrincipalInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Gets service principal information from the directory. + * + * @param objectId Object id to get service principal information. + * @return the observable to the ServicePrincipalInner object + */ + public Observable> getWithServiceResponseAsync(String objectId) { if (objectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter objectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.delete(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(deleteDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } + }); + } + + private ServiceResponse getDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); + } + + /** + * Get keyCredentials associated with the service principal by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<KeyCredentialInner> object if successful. + */ + public List listKeyCredentials(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + return listKeyCredentialsWithServiceResponseAsync(objectId).toBlocking().single().getBody(); + } + + /** + * Get keyCredentials associated with the service principal by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall> listKeyCredentialsAsync(String objectId, final ServiceCallback> serviceCallback) { + return ServiceCall.create(listKeyCredentialsWithServiceResponseAsync(objectId), serviceCallback); + } + + /** + * Get keyCredentials associated with the service principal by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @return the observable to the List<KeyCredentialInner> object + */ + public Observable> listKeyCredentialsAsync(String objectId) { + return listKeyCredentialsWithServiceResponseAsync(objectId).map(new Func1>, List>() { + @Override + public List call(ServiceResponse> response) { + return response.getBody(); } }); - return serviceCall; } - private ServiceResponse deleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) - .register(204, new TypeToken() { }.getType()) + /** + * Get keyCredentials associated with the service principal by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @return the observable to the List<KeyCredentialInner> object + */ + public Observable>> listKeyCredentialsWithServiceResponseAsync(String objectId) { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.listKeyCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listKeyCredentialsDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listKeyCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } /** - * Gets service principal information from the directory. + * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. * * @param objectId Object id to get service principal information. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the ServicePrincipalInner object wrapped in {@link ServiceResponse} if successful. */ - public ServiceResponse get(String objectId) throws CloudException, IOException, IllegalArgumentException { + public void updateKeyCredentials(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + updateKeyCredentialsWithServiceResponseAsync(objectId).toBlocking().single().getBody(); + } + + /** + * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall updateKeyCredentialsAsync(String objectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(updateKeyCredentialsWithServiceResponseAsync(objectId), serviceCallback); + } + + /** + * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable updateKeyCredentialsAsync(String objectId) { + return updateKeyCredentialsWithServiceResponseAsync(objectId).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updateKeyCredentialsWithServiceResponseAsync(String objectId) { if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -385,68 +667,229 @@ public ServiceResponse get(String objectId) throws CloudE if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return getDelegate(call.execute()); + final List value = null; + KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); + parameters.withValue(null); + return service.updateKeyCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updateKeyCredentialsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); } /** - * Gets service principal information from the directory. + * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. * * @param objectId Object id to get service principal information. + * @param value KeyCredential list. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + */ + public void updateKeyCredentials(String objectId, List value) throws GraphErrorException, IOException, IllegalArgumentException { + updateKeyCredentialsWithServiceResponseAsync(objectId, value).toBlocking().single().getBody(); + } + + /** + * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @param value KeyCredential list. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall getAsync(String objectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall updateKeyCredentialsAsync(String objectId, List value, final ServiceCallback serviceCallback) { + return ServiceCall.create(updateKeyCredentialsWithServiceResponseAsync(objectId, value), serviceCallback); + } + + /** + * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @param value KeyCredential list. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable updateKeyCredentialsAsync(String objectId, List value) { + return updateKeyCredentialsWithServiceResponseAsync(objectId, value).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @param value KeyCredential list. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updateKeyCredentialsWithServiceResponseAsync(String objectId, List value) { if (objectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter objectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(getDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + Validator.validate(value); + KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); + parameters.withValue(value); + return service.updateKeyCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updateKeyCredentialsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } + }); + } + + private ServiceResponse updateKeyCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); + } + + /** + * Gets passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<PasswordCredentialInner> object if successful. + */ + public List listPasswordCredentials(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + return listPasswordCredentialsWithServiceResponseAsync(objectId).toBlocking().single().getBody(); + } + + /** + * Gets passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall> listPasswordCredentialsAsync(String objectId, final ServiceCallback> serviceCallback) { + return ServiceCall.create(listPasswordCredentialsWithServiceResponseAsync(objectId), serviceCallback); + } + + /** + * Gets passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @return the observable to the List<PasswordCredentialInner> object + */ + public Observable> listPasswordCredentialsAsync(String objectId) { + return listPasswordCredentialsWithServiceResponseAsync(objectId).map(new Func1>, List>() { + @Override + public List call(ServiceResponse> response) { + return response.getBody(); } }); - return serviceCall; } - private ServiceResponse getDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) - .register(200, new TypeToken() { }.getType()) - .registerError(CloudException.class) + /** + * Gets passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @return the observable to the List<PasswordCredentialInner> object + */ + public Observable>> listPasswordCredentialsWithServiceResponseAsync(String objectId) { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.listPasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listPasswordCredentialsDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listPasswordCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } /** - * Gets list of service principals from the current tenant. + * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. * - * @param nextLink Next link for list operation. - * @throws CloudException exception thrown from REST call + * @param objectId Object id to get service principal information. + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. */ - public ServiceResponse> listNext(final String nextLink) throws CloudException, IOException, IllegalArgumentException { - if (nextLink == null) { - throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); + public void updatePasswordCredentials(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + updatePasswordCredentialsWithServiceResponseAsync(objectId).toBlocking().single().getBody(); + } + + /** + * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall updatePasswordCredentialsAsync(String objectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(updatePasswordCredentialsWithServiceResponseAsync(objectId), serviceCallback); + } + + /** + * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable updatePasswordCredentialsAsync(String objectId) { + return updatePasswordCredentialsWithServiceResponseAsync(objectId).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updatePasswordCredentialsWithServiceResponseAsync(String objectId) { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); @@ -454,8 +897,122 @@ public ServiceResponse> listNext(final String n if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return listNextDelegate(call.execute()); + final List value = null; + PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); + parameters.withValue(null); + return service.updatePasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updatePasswordCredentialsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + /** + * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @param value PasswordCredential list. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + */ + public void updatePasswordCredentials(String objectId, List value) throws GraphErrorException, IOException, IllegalArgumentException { + updatePasswordCredentialsWithServiceResponseAsync(objectId, value).toBlocking().single().getBody(); + } + + /** + * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @param value PasswordCredential list. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall updatePasswordCredentialsAsync(String objectId, List value, final ServiceCallback serviceCallback) { + return ServiceCall.create(updatePasswordCredentialsWithServiceResponseAsync(objectId, value), serviceCallback); + } + + /** + * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @param value PasswordCredential list. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable updatePasswordCredentialsAsync(String objectId, List value) { + return updatePasswordCredentialsWithServiceResponseAsync(objectId, value).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @param value PasswordCredential list. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updatePasswordCredentialsWithServiceResponseAsync(String objectId, List value) { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(value); + PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); + parameters.withValue(value); + return service.updatePasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updatePasswordCredentialsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse updatePasswordCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); + } + + /** + * Gets list of service principals from the current tenant. + * + * @param nextLink Next link for list operation. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the PagedList<ServicePrincipalInner> object if successful. + */ + public PagedList listNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = listNextSinglePageAsync(nextLink).toBlocking().single(); + return new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextLink) throws RestException, IOException { + return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); + } + }; } /** @@ -464,51 +1021,90 @@ public ServiceResponse> listNext(final String n * @param nextLink Next link for list operation. * @param serviceCall the ServiceCall object tracking the Retrofit calls * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listNextAsync(final String nextLink, final ServiceCall serviceCall, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listNextSinglePageAsync(nextLink), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return listNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets list of service principals from the current tenant. + * + * @param nextLink Next link for list operation. + * @return the observable to the PagedList<ServicePrincipalInner> object + */ + public Observable> listNextAsync(final String nextLink) { + return listNextWithServiceResponseAsync(nextLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets list of service principals from the current tenant. + * + * @param nextLink Next link for list operation. + * @return the observable to the PagedList<ServicePrincipalInner> object + */ + public Observable>> listNextWithServiceResponseAsync(final String nextLink) { + return listNextSinglePageAsync(nextLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets list of service principals from the current tenant. + * + ServiceResponse> * @param nextLink Next link for list operation. + * @return the PagedList<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listNextSinglePageAsync(final String nextLink) { if (nextLink == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - serviceCall.newCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listNextDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listNextDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } - private ServiceResponse> listNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + private ServiceResponse> listNextDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserInner.java index 33cff51127ea..00785fa6dc3e 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserInner.java @@ -14,32 +14,32 @@ */ public class UserInner { /** - * Gets or sets object Id. + * object Id. */ private String objectId; /** - * Gets or sets object type. + * object type. */ private String objectType; /** - * Gets or sets user principal name. + * user principal name. */ private String userPrincipalName; /** - * Gets or sets user display name. + * user display name. */ private String displayName; /** - * Gets or sets user signIn name. + * user signIn name. */ private String signInName; /** - * Gets or sets user mail. + * user mail. */ private String mail; diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java index d9a3e5da72c7..91499376d8cd 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java @@ -8,34 +8,35 @@ package com.microsoft.azure.management.graphrbac.implementation; +import retrofit2.Retrofit; import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceCall; import com.microsoft.azure.AzureServiceResponseBuilder; -import com.microsoft.azure.CloudException; import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.management.graphrbac.GraphErrorException; +import com.microsoft.azure.management.graphrbac.UserGetMemberGroupsParameters; import com.microsoft.azure.Page; import com.microsoft.azure.PagedList; -import com.microsoft.azure.management.graphrbac.UserGetMemberGroupsParameters; +import com.microsoft.rest.RestException; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; -import com.microsoft.rest.ServiceResponseCallback; import com.microsoft.rest.Validator; +import java.io.IOException; +import java.util.List; import okhttp3.ResponseBody; -import retrofit2.Call; -import retrofit2.Response; -import retrofit2.Retrofit; import retrofit2.http.Body; import retrofit2.http.GET; -import retrofit2.http.HTTP; import retrofit2.http.Header; import retrofit2.http.Headers; +import retrofit2.http.HTTP; import retrofit2.http.PATCH; -import retrofit2.http.POST; import retrofit2.http.Path; +import retrofit2.http.POST; import retrofit2.http.Query; - -import java.io.IOException; -import java.util.List; +import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; /** * An instance of this class provides access to all the operations defined @@ -65,31 +66,31 @@ public UsersInner(Retrofit retrofit, GraphRbacManagementClientImpl client) { interface UsersService { @Headers("Content-Type: application/json; charset=utf-8") @POST("{tenantID}/users") - Call create(@Path("tenantID") String tenantID, @Body UserCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> create(@Path("tenantID") String tenantID, @Body UserCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/users") - Call list(@Path("tenantID") String tenantID, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> list(@Path("tenantID") String tenantID, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/users/{upnOrObjectId}") - Call get(@Path(value = "upnOrObjectId", encoded = true) String upnOrObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> get(@Path(value = "upnOrObjectId", encoded = true) String upnOrObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @PATCH("{tenantID}/users/{upnOrObjectId}") - Call update(@Path(value = "upnOrObjectId", encoded = true) String upnOrObjectId, @Path("tenantID") String tenantID, @Body UserUpdateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> update(@Path(value = "upnOrObjectId", encoded = true) String upnOrObjectId, @Path("tenantID") String tenantID, @Body UserUpdateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @HTTP(path = "{tenantID}/users/{upnOrObjectId}", method = "DELETE", hasBody = true) - Call delete(@Path(value = "upnOrObjectId", encoded = true) String upnOrObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> delete(@Path(value = "upnOrObjectId", encoded = true) String upnOrObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @POST("{tenantID}/users/{objectId}/getMemberGroups") - Call getMemberGroups(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body UserGetMemberGroupsParameters parameters, @Header("User-Agent") String userAgent); + Observable> getMemberGroups(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body UserGetMemberGroupsParameters parameters, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/{nextLink}") - Call listNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> listNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); } @@ -97,24 +98,13 @@ interface UsersService { * Create a new user. Reference: https://msdn.microsoft.com/library/azure/ad/graph/api/users-operations#CreateUser. * * @param parameters Parameters to create a user. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the UserInner object wrapped in {@link ServiceResponse} if successful. + * @return the UserInner object if successful. */ - public ServiceResponse create(UserCreateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(parameters); - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return createDelegate(call.execute()); + public UserInner create(UserCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { + return createWithServiceResponseAsync(parameters).toBlocking().single().getBody(); } /** @@ -122,142 +112,179 @@ public ServiceResponse create(UserCreateParametersInner parameters) t * * @param parameters Parameters to create a user. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall createAsync(UserCreateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall createAsync(UserCreateParametersInner parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(createWithServiceResponseAsync(parameters), serviceCallback); + } + + /** + * Create a new user. Reference: https://msdn.microsoft.com/library/azure/ad/graph/api/users-operations#CreateUser. + * + * @param parameters Parameters to create a user. + * @return the observable to the UserInner object + */ + public Observable createAsync(UserCreateParametersInner parameters) { + return createWithServiceResponseAsync(parameters).map(new Func1, UserInner>() { + @Override + public UserInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Create a new user. Reference: https://msdn.microsoft.com/library/azure/ad/graph/api/users-operations#CreateUser. + * + * @param parameters Parameters to create a user. + * @return the observable to the UserInner object + */ + public Observable> createWithServiceResponseAsync(UserCreateParametersInner parameters) { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (parameters == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Validator.validate(parameters, serviceCallback); - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(createDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + Validator.validate(parameters); + return service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse createDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse createDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(201, new TypeToken() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } /** * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. * - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<UserInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<UserInner> object if successful. */ - public ServiceResponse> list() throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - final String filter = null; - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList list() throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = listSinglePageAsync().toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextLink) throws CloudException, IOException { - return listNext(nextLink).getBody(); + public Page nextPage(String nextLink) throws RestException, IOException { + return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listAsync(final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listAsync(final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listSinglePageAsync(), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return listNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. + * + * @return the observable to the PagedList<UserInner> object + */ + public Observable> listAsync() { + return listWithServiceResponseAsync() + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. + * + * @return the observable to the PagedList<UserInner> object + */ + public Observable>> listWithServiceResponseAsync() { + return listSinglePageAsync() + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. + * + * @return the PagedList<UserInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync() { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } final String filter = null; - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } /** * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. * * @param filter The filter to apply on the operation. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<UserInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<UserInner> object if successful. */ - public ServiceResponse> list(final String filter) throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList list(final String filter) throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = listSinglePageAsync(filter).toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextLink) throws CloudException, IOException { - return listNext(nextLink).getBody(); + public Page nextPage(String nextLink) throws RestException, IOException { + return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** @@ -265,47 +292,87 @@ public Page nextPage(String nextLink) throws CloudException, IOExcept * * @param filter The filter to apply on the operation. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listAsync(final String filter, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listAsync(final String filter, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listSinglePageAsync(filter), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return listNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. + * + * @param filter The filter to apply on the operation. + * @return the observable to the PagedList<UserInner> object + */ + public Observable> listAsync(final String filter) { + return listWithServiceResponseAsync(filter) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. + * + * @param filter The filter to apply on the operation. + * @return the observable to the PagedList<UserInner> object + */ + public Observable>> listWithServiceResponseAsync(final String filter) { + return listSinglePageAsync(filter) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. + * + ServiceResponse> * @param filter The filter to apply on the operation. + * @return the PagedList<UserInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync(final String filter) { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } - private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + private ServiceResponse> listDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } @@ -313,23 +380,13 @@ private ServiceResponse> listDelegate(Response get(String upnOrObjectId) throws CloudException, IOException, IllegalArgumentException { - if (upnOrObjectId == null) { - throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.get(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return getDelegate(call.execute()); + public UserInner get(String upnOrObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + return getWithServiceResponseAsync(upnOrObjectId).toBlocking().single().getBody(); } /** @@ -337,44 +394,61 @@ public ServiceResponse get(String upnOrObjectId) throws CloudExceptio * * @param upnOrObjectId User object Id or user principal name to get user information. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall getAsync(String upnOrObjectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall getAsync(String upnOrObjectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(getWithServiceResponseAsync(upnOrObjectId), serviceCallback); + } + + /** + * Gets user information from the directory. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetAUser. + * + * @param upnOrObjectId User object Id or user principal name to get user information. + * @return the observable to the UserInner object + */ + public Observable getAsync(String upnOrObjectId) { + return getWithServiceResponseAsync(upnOrObjectId).map(new Func1, UserInner>() { + @Override + public UserInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Gets user information from the directory. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetAUser. + * + * @param upnOrObjectId User object Id or user principal name to get user information. + * @return the observable to the UserInner object + */ + public Observable> getWithServiceResponseAsync(String upnOrObjectId) { if (upnOrObjectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.get(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(getDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.get(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse getDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse getDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(200, new TypeToken() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } @@ -383,27 +457,12 @@ private ServiceResponse getDelegate(Response response) * * @param upnOrObjectId User object Id or user principal name to get user information. * @param parameters Parameters to update an exisitng user. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the {@link ServiceResponse} object if successful. */ - public ServiceResponse update(String upnOrObjectId, UserUpdateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { - if (upnOrObjectId == null) { - throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(parameters); - Call call = service.update(upnOrObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return updateDelegate(call.execute()); + public void update(String upnOrObjectId, UserUpdateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { + updateWithServiceResponseAsync(upnOrObjectId, parameters).toBlocking().single().getBody(); } /** @@ -412,48 +471,67 @@ public ServiceResponse update(String upnOrObjectId, UserUpdateParametersIn * @param upnOrObjectId User object Id or user principal name to get user information. * @param parameters Parameters to update an exisitng user. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall updateAsync(String upnOrObjectId, UserUpdateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall updateAsync(String upnOrObjectId, UserUpdateParametersInner parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(updateWithServiceResponseAsync(upnOrObjectId, parameters), serviceCallback); + } + + /** + * Updates an exisitng user. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#UpdateUser. + * + * @param upnOrObjectId User object Id or user principal name to get user information. + * @param parameters Parameters to update an exisitng user. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable updateAsync(String upnOrObjectId, UserUpdateParametersInner parameters) { + return updateWithServiceResponseAsync(upnOrObjectId, parameters).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Updates an exisitng user. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#UpdateUser. + * + * @param upnOrObjectId User object Id or user principal name to get user information. + * @param parameters Parameters to update an exisitng user. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updateWithServiceResponseAsync(String upnOrObjectId, UserUpdateParametersInner parameters) { if (upnOrObjectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (parameters == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Validator.validate(parameters, serviceCallback); - Call call = service.update(upnOrObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(updateDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + Validator.validate(parameters); + return service.update(upnOrObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse updateDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse updateDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } @@ -461,23 +539,12 @@ private ServiceResponse updateDelegate(Response response) th * Delete a user. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#DeleteUser. * * @param upnOrObjectId user object id or user principal name (upn) - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the {@link ServiceResponse} object if successful. */ - public ServiceResponse delete(String upnOrObjectId) throws CloudException, IOException, IllegalArgumentException { - if (upnOrObjectId == null) { - throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.delete(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return deleteDelegate(call.execute()); + public void delete(String upnOrObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + deleteWithServiceResponseAsync(upnOrObjectId).toBlocking().single().getBody(); } /** @@ -485,43 +552,61 @@ public ServiceResponse delete(String upnOrObjectId) throws CloudException, * * @param upnOrObjectId user object id or user principal name (upn) * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall deleteAsync(String upnOrObjectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall deleteAsync(String upnOrObjectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(deleteWithServiceResponseAsync(upnOrObjectId), serviceCallback); + } + + /** + * Delete a user. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#DeleteUser. + * + * @param upnOrObjectId user object id or user principal name (upn) + * @return the {@link ServiceResponse} object if successful. + */ + public Observable deleteAsync(String upnOrObjectId) { + return deleteWithServiceResponseAsync(upnOrObjectId).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Delete a user. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#DeleteUser. + * + * @param upnOrObjectId user object id or user principal name (upn) + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deleteWithServiceResponseAsync(String upnOrObjectId) { if (upnOrObjectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.delete(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(deleteDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.delete(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse deleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse deleteDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } @@ -530,27 +615,13 @@ private ServiceResponse deleteDelegate(Response response) th * * @param objectId User filtering parameters. * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<String> object wrapped in {@link ServiceResponse} if successful. + * @return the List<String> object if successful. */ - public ServiceResponse> getMemberGroups(String objectId, boolean securityEnabledOnly) throws CloudException, IOException, IllegalArgumentException { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - UserGetMemberGroupsParameters parameters = new UserGetMemberGroupsParameters(); - parameters.withSecurityEnabledOnly(securityEnabledOnly); - Call call = service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - ServiceResponse> response = getMemberGroupsDelegate(call.execute()); - List result = response.getBody().getItems(); - return new ServiceResponse<>(result, response.getResponse()); + public List getMemberGroups(String objectId, boolean securityEnabledOnly) throws GraphErrorException, IOException, IllegalArgumentException { + return getMemberGroupsWithServiceResponseAsync(objectId, securityEnabledOnly).toBlocking().single().getBody(); } /** @@ -559,47 +630,66 @@ public ServiceResponse> getMemberGroups(String objectId, boolean se * @param objectId User filtering parameters. * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall getMemberGroupsAsync(String objectId, boolean securityEnabledOnly, final ServiceCallback> serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> getMemberGroupsAsync(String objectId, boolean securityEnabledOnly, final ServiceCallback> serviceCallback) { + return ServiceCall.create(getMemberGroupsWithServiceResponseAsync(objectId, securityEnabledOnly), serviceCallback); + } + + /** + * Gets a collection that contains the Object IDs of the groups of which the user is a member. + * + * @param objectId User filtering parameters. + * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked + * @return the observable to the List<String> object + */ + public Observable> getMemberGroupsAsync(String objectId, boolean securityEnabledOnly) { + return getMemberGroupsWithServiceResponseAsync(objectId, securityEnabledOnly).map(new Func1>, List>() { + @Override + public List call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets a collection that contains the Object IDs of the groups of which the user is a member. + * + * @param objectId User filtering parameters. + * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked + * @return the observable to the List<String> object + */ + public Observable>> getMemberGroupsWithServiceResponseAsync(String objectId, boolean securityEnabledOnly) { if (objectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter objectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } UserGetMemberGroupsParameters parameters = new UserGetMemberGroupsParameters(); parameters.withSecurityEnabledOnly(securityEnabledOnly); - Call call = service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = getMemberGroupsDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = getMemberGroupsDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse> getMemberGroupsDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + private ServiceResponse> getMemberGroupsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } @@ -607,23 +697,19 @@ private ServiceResponse> getMemberGroupsDelegate(Response> listNext(final String nextLink) throws CloudException, IOException, IllegalArgumentException { - if (nextLink == null) { - throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return listNextDelegate(call.execute()); + public PagedList listNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = listNextSinglePageAsync(nextLink).toBlocking().single(); + return new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextLink) throws RestException, IOException { + return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); + } + }; } /** @@ -632,51 +718,90 @@ public ServiceResponse> listNext(final String nextLink) thr * @param nextLink Next link for list operation. * @param serviceCall the ServiceCall object tracking the Retrofit calls * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listNextAsync(final String nextLink, final ServiceCall serviceCall, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listNextSinglePageAsync(nextLink), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return listNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets list of users for the current tenant. + * + * @param nextLink Next link for list operation. + * @return the observable to the PagedList<UserInner> object + */ + public Observable> listNextAsync(final String nextLink) { + return listNextWithServiceResponseAsync(nextLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets list of users for the current tenant. + * + * @param nextLink Next link for list operation. + * @return the observable to the PagedList<UserInner> object + */ + public Observable>> listNextWithServiceResponseAsync(final String nextLink) { + return listNextSinglePageAsync(nextLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets list of users for the current tenant. + * + ServiceResponse> * @param nextLink Next link for list operation. + * @return the PagedList<UserInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listNextSinglePageAsync(final String nextLink) { if (nextLink == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - serviceCall.newCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listNextDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listNextDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } - private ServiceResponse> listNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + private ServiceResponse> listNextDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicyEntry.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicyEntry.java index 1bc9de5052af..65c9e483215b 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicyEntry.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicyEntry.java @@ -9,6 +9,7 @@ package com.microsoft.azure.management.keyvault; import java.util.UUID; +import com.fasterxml.jackson.annotation.JsonProperty; /** * An array of 0 to 16 identities that have access to the key vault. All @@ -20,12 +21,15 @@ public class AccessPolicyEntry { * The Azure Active Directory tenant ID that should be used for * authenticating requests to the key vault. */ + @JsonProperty(required = true) private UUID tenantId; /** * The object ID of a user or service principal in the Azure Active - * Directory tenant for the vault. + * Directory tenant for the vault. The object ID must be unique for the + * list of access policies. */ + @JsonProperty(required = true) private UUID objectId; /** @@ -36,6 +40,7 @@ public class AccessPolicyEntry { /** * Permissions the identity has for keys and secrets. */ + @JsonProperty(required = true) private Permissions permissions; /** diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/KeyPermissions.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/KeyPermissions.java new file mode 100644 index 000000000000..1e9996897691 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/KeyPermissions.java @@ -0,0 +1,98 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.keyvault; + +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Defines values for KeyPermissions. + */ +public final class KeyPermissions { + /** Static value all for KeyPermissions. */ + public static final KeyPermissions ALL = new KeyPermissions("all"); + + /** Static value encrypt for KeyPermissions. */ + public static final KeyPermissions ENCRYPT = new KeyPermissions("encrypt"); + + /** Static value decrypt for KeyPermissions. */ + public static final KeyPermissions DECRYPT = new KeyPermissions("decrypt"); + + /** Static value wrapkey for KeyPermissions. */ + public static final KeyPermissions WRAPKEY = new KeyPermissions("wrapkey"); + + /** Static value unwrapkey for KeyPermissions. */ + public static final KeyPermissions UNWRAPKEY = new KeyPermissions("unwrapkey"); + + /** Static value sign for KeyPermissions. */ + public static final KeyPermissions SIGN = new KeyPermissions("sign"); + + /** Static value verify for KeyPermissions. */ + public static final KeyPermissions VERIFY = new KeyPermissions("verify"); + + /** Static value get for KeyPermissions. */ + public static final KeyPermissions GET = new KeyPermissions("get"); + + /** Static value list for KeyPermissions. */ + public static final KeyPermissions LIST = new KeyPermissions("list"); + + /** Static value create for KeyPermissions. */ + public static final KeyPermissions CREATE = new KeyPermissions("create"); + + /** Static value update for KeyPermissions. */ + public static final KeyPermissions UPDATE = new KeyPermissions("update"); + + /** Static value import for KeyPermissions. */ + public static final KeyPermissions IMPORT = new KeyPermissions("import"); + + /** Static value delete for KeyPermissions. */ + public static final KeyPermissions DELETE = new KeyPermissions("delete"); + + /** Static value backup for KeyPermissions. */ + public static final KeyPermissions BACKUP = new KeyPermissions("backup"); + + /** Static value restore for KeyPermissions. */ + public static final KeyPermissions RESTORE = new KeyPermissions("restore"); + + private String value; + + /** + * Creates a custom value for KeyPermissions. + * @param value the custom value + */ + public KeyPermissions(String value) { + this.value = value; + } + + @JsonValue + @Override + public String toString() { + return value; + } + + @Override + public int hashCode() { + return value.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof KeyPermissions)) { + return false; + } + if (obj == this) { + return true; + } + KeyPermissions rhs = (KeyPermissions) obj; + if (value == null) { + return rhs.value == null; + } else { + return value.equals(rhs.value); + } + } +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Permissions.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Permissions.java index 1db622fd6ac4..b6ef1c6dadda 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Permissions.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Permissions.java @@ -17,19 +17,19 @@ public class Permissions { /** * Permissions to keys. */ - private List keys; + private List keys; /** * Permissions to secrets. */ - private List secrets; + private List secrets; /** * Get the keys value. * * @return the keys value */ - public List keys() { + public List keys() { return this.keys; } @@ -39,7 +39,7 @@ public List keys() { * @param keys the keys value to set * @return the Permissions object itself. */ - public Permissions withKeys(List keys) { + public Permissions withKeys(List keys) { this.keys = keys; return this; } @@ -49,7 +49,7 @@ public Permissions withKeys(List keys) { * * @return the secrets value */ - public List secrets() { + public List secrets() { return this.secrets; } @@ -59,7 +59,7 @@ public List secrets() { * @param secrets the secrets value to set * @return the Permissions object itself. */ - public Permissions withSecrets(List secrets) { + public Permissions withSecrets(List secrets) { this.secrets = secrets; return this; } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SecretPermissions.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SecretPermissions.java new file mode 100644 index 000000000000..4891a939903d --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SecretPermissions.java @@ -0,0 +1,68 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.keyvault; + +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Defines values for SecretPermissions. + */ +public final class SecretPermissions { + /** Static value all for SecretPermissions. */ + public static final SecretPermissions ALL = new SecretPermissions("all"); + + /** Static value get for SecretPermissions. */ + public static final SecretPermissions GET = new SecretPermissions("get"); + + /** Static value list for SecretPermissions. */ + public static final SecretPermissions LIST = new SecretPermissions("list"); + + /** Static value set for SecretPermissions. */ + public static final SecretPermissions SET = new SecretPermissions("set"); + + /** Static value delete for SecretPermissions. */ + public static final SecretPermissions DELETE = new SecretPermissions("delete"); + + private String value; + + /** + * Creates a custom value for SecretPermissions. + * @param value the custom value + */ + public SecretPermissions(String value) { + this.value = value; + } + + @JsonValue + @Override + public String toString() { + return value; + } + + @Override + public int hashCode() { + return value.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof SecretPermissions)) { + return false; + } + if (obj == this) { + return true; + } + SecretPermissions rhs = (SecretPermissions) obj; + if (value == null) { + return rhs.value == null; + } else { + return value.equals(rhs.value); + } + } +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Sku.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Sku.java index 7403d947e9c4..79b8ab8b0e29 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Sku.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Sku.java @@ -15,8 +15,9 @@ */ public class Sku { /** - * SKU family name. Possible values include: 'A'. + * SKU family name. */ + @JsonProperty(required = true) private String family; /** @@ -26,6 +27,13 @@ public class Sku { @JsonProperty(required = true) private SkuName name; + /** + * Creates an instance of Sku class. + */ + public Sku() { + family = "A"; + } + /** * Get the family value. * diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SkuFamily.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SkuFamily.java deleted file mode 100644 index 3b170cc4be9d..000000000000 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SkuFamily.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for - * license information. - * - * Code generated by Microsoft (R) AutoRest Code Generator. - */ - -package com.microsoft.azure.management.keyvault; - -/** - * Defines values for SkuFamily. - */ -public final class SkuFamily { - /** Static value A for SkuFamily. */ - public static final String A = "A"; - - private SkuFamily() { - } -} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultInner.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultInner.java index 7f85bfedae22..89d9902415de 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultInner.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultInner.java @@ -11,7 +11,6 @@ import com.microsoft.azure.management.keyvault.VaultProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.microsoft.azure.Resource; -import com.microsoft.azure.Resource; /** * Resource information with extended details. diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsInner.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsInner.java index 68d2d771e5ee..4f28b7533faf 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsInner.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsInner.java @@ -10,20 +10,20 @@ import retrofit2.Retrofit; import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceCall; import com.microsoft.azure.AzureServiceResponseBuilder; import com.microsoft.azure.CloudException; import com.microsoft.azure.ListOperationCallback; import com.microsoft.azure.Page; import com.microsoft.azure.PagedList; +import com.microsoft.rest.RestException; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; -import com.microsoft.rest.ServiceResponseCallback; import com.microsoft.rest.Validator; import java.io.IOException; import java.util.List; import okhttp3.ResponseBody; -import retrofit2.Call; import retrofit2.http.Body; import retrofit2.http.GET; import retrofit2.http.Header; @@ -32,8 +32,9 @@ import retrofit2.http.Path; import retrofit2.http.PUT; import retrofit2.http.Query; -import retrofit2.http.Url; import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; /** * An instance of this class provides access to all the operations defined @@ -63,31 +64,31 @@ public VaultsInner(Retrofit retrofit, KeyVaultManagementClientImpl client) { interface VaultsService { @Headers("Content-Type: application/json; charset=utf-8") @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.KeyVault/vaults/{vaultName}") - Call createOrUpdate(@Path("resourceGroupName") String resourceGroupName, @Path("vaultName") String vaultName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Body VaultCreateOrUpdateParametersInner parameters, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> createOrUpdate(@Path("resourceGroupName") String resourceGroupName, @Path("vaultName") String vaultName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Body VaultCreateOrUpdateParametersInner parameters, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.KeyVault/vaults/{vaultName}", method = "DELETE", hasBody = true) - Call delete(@Path("resourceGroupName") String resourceGroupName, @Path("vaultName") String vaultName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> delete(@Path("resourceGroupName") String resourceGroupName, @Path("vaultName") String vaultName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.KeyVault/vaults/{vaultName}") - Call get(@Path("resourceGroupName") String resourceGroupName, @Path("vaultName") String vaultName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> get(@Path("resourceGroupName") String resourceGroupName, @Path("vaultName") String vaultName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.KeyVault/vaults") - Call listByResourceGroup(@Path("resourceGroupName") String resourceGroupName, @Path("subscriptionId") String subscriptionId, @Query("$top") Integer top, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> listByResourceGroup(@Path("resourceGroupName") String resourceGroupName, @Path("subscriptionId") String subscriptionId, @Query("$top") Integer top, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("subscriptions/{subscriptionId}/resources") - Call list(@Path("subscriptionId") String subscriptionId, @Query("$filter") String filter, @Query("$top") Integer top, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> list(@Path("subscriptionId") String subscriptionId, @Query("$filter") String filter, @Query("$top") Integer top, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") - @GET - Call listByResourceGroupNext(@Url String nextPageLink, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + @GET("{nextLink}") + Observable> listByResourceGroupNext(@Path(value = "nextLink", encoded = true) String nextPageLink, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") - @GET - Call listNext(@Url String nextPageLink, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + @GET("{nextLink}") + Observable> listNext(@Path(value = "nextLink", encoded = true) String nextPageLink, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); } @@ -100,27 +101,10 @@ interface VaultsService { * @throws CloudException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the VaultInner object wrapped in {@link ServiceResponse} if successful. + * @return the VaultInner object if successful. */ - public ServiceResponse createOrUpdate(String resourceGroupName, String vaultName, VaultCreateOrUpdateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { - if (resourceGroupName == null) { - throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); - } - if (vaultName == null) { - throw new IllegalArgumentException("Parameter vaultName is required and cannot be null."); - } - if (this.client.subscriptionId() == null) { - throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } - Validator.validate(parameters); - Call call = service.createOrUpdate(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), parameters, this.client.acceptLanguage(), this.client.userAgent()); - return createOrUpdateDelegate(call.execute()); + public VaultInner createOrUpdate(String resourceGroupName, String vaultName, VaultCreateOrUpdateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, vaultName, parameters).toBlocking().single().getBody(); } /** @@ -130,47 +114,66 @@ public ServiceResponse createOrUpdate(String resourceGroupName, Stri * @param vaultName Name of the vault * @param parameters Parameters to create or update the vault * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall createOrUpdateAsync(String resourceGroupName, String vaultName, VaultCreateOrUpdateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall createOrUpdateAsync(String resourceGroupName, String vaultName, VaultCreateOrUpdateParametersInner parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(createOrUpdateWithServiceResponseAsync(resourceGroupName, vaultName, parameters), serviceCallback); + } + + /** + * Create or update a key vault in the specified subscription. + * + * @param resourceGroupName The name of the Resource Group to which the server belongs. + * @param vaultName Name of the vault + * @param parameters Parameters to create or update the vault + * @return the observable to the VaultInner object + */ + public Observable createOrUpdateAsync(String resourceGroupName, String vaultName, VaultCreateOrUpdateParametersInner parameters) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, vaultName, parameters).map(new Func1, VaultInner>() { + @Override + public VaultInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Create or update a key vault in the specified subscription. + * + * @param resourceGroupName The name of the Resource Group to which the server belongs. + * @param vaultName Name of the vault + * @param parameters Parameters to create or update the vault + * @return the observable to the VaultInner object + */ + public Observable> createOrUpdateWithServiceResponseAsync(String resourceGroupName, String vaultName, VaultCreateOrUpdateParametersInner parameters) { if (resourceGroupName == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } if (vaultName == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter vaultName is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter vaultName is required and cannot be null."); } if (this.client.subscriptionId() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } if (parameters == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); } - Validator.validate(parameters, serviceCallback); - Call call = service.createOrUpdate(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), parameters, this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(createOrUpdateDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + Validator.validate(parameters); + return service.createOrUpdate(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), parameters, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createOrUpdateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } private ServiceResponse createOrUpdateDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -189,23 +192,9 @@ private ServiceResponse createOrUpdateDelegate(Response delete(String resourceGroupName, String vaultName) throws CloudException, IOException, IllegalArgumentException { - if (resourceGroupName == null) { - throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); - } - if (vaultName == null) { - throw new IllegalArgumentException("Parameter vaultName is required and cannot be null."); - } - if (this.client.subscriptionId() == null) { - throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.delete(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return deleteDelegate(call.execute()); + public void delete(String resourceGroupName, String vaultName) throws CloudException, IOException, IllegalArgumentException { + deleteWithServiceResponseAsync(resourceGroupName, vaultName).toBlocking().single().getBody(); } /** @@ -214,42 +203,60 @@ public ServiceResponse delete(String resourceGroupName, String vaultName) * @param resourceGroupName The name of the Resource Group to which the vault belongs. * @param vaultName The name of the vault to delete * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall deleteAsync(String resourceGroupName, String vaultName, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall deleteAsync(String resourceGroupName, String vaultName, final ServiceCallback serviceCallback) { + return ServiceCall.create(deleteWithServiceResponseAsync(resourceGroupName, vaultName), serviceCallback); + } + + /** + * Deletes the specified Azure key vault. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @param vaultName The name of the vault to delete + * @return the {@link ServiceResponse} object if successful. + */ + public Observable deleteAsync(String resourceGroupName, String vaultName) { + return deleteWithServiceResponseAsync(resourceGroupName, vaultName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Deletes the specified Azure key vault. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @param vaultName The name of the vault to delete + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deleteWithServiceResponseAsync(String resourceGroupName, String vaultName) { if (resourceGroupName == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } if (vaultName == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter vaultName is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter vaultName is required and cannot be null."); } if (this.client.subscriptionId() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.delete(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(deleteDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.delete(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } private ServiceResponse deleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -266,23 +273,10 @@ private ServiceResponse deleteDelegate(Response response) th * @throws CloudException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the VaultInner object wrapped in {@link ServiceResponse} if successful. + * @return the VaultInner object if successful. */ - public ServiceResponse get(String resourceGroupName, String vaultName) throws CloudException, IOException, IllegalArgumentException { - if (resourceGroupName == null) { - throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); - } - if (vaultName == null) { - throw new IllegalArgumentException("Parameter vaultName is required and cannot be null."); - } - if (this.client.subscriptionId() == null) { - throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.get(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return getDelegate(call.execute()); + public VaultInner get(String resourceGroupName, String vaultName) throws CloudException, IOException, IllegalArgumentException { + return getWithServiceResponseAsync(resourceGroupName, vaultName).toBlocking().single().getBody(); } /** @@ -291,42 +285,60 @@ public ServiceResponse get(String resourceGroupName, String vaultNam * @param resourceGroupName The name of the Resource Group to which the vault belongs. * @param vaultName The name of the vault. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall getAsync(String resourceGroupName, String vaultName, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall getAsync(String resourceGroupName, String vaultName, final ServiceCallback serviceCallback) { + return ServiceCall.create(getWithServiceResponseAsync(resourceGroupName, vaultName), serviceCallback); + } + + /** + * Gets the specified Azure key vault. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @param vaultName The name of the vault. + * @return the observable to the VaultInner object + */ + public Observable getAsync(String resourceGroupName, String vaultName) { + return getWithServiceResponseAsync(resourceGroupName, vaultName).map(new Func1, VaultInner>() { + @Override + public VaultInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Gets the specified Azure key vault. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @param vaultName The name of the vault. + * @return the observable to the VaultInner object + */ + public Observable> getWithServiceResponseAsync(String resourceGroupName, String vaultName) { if (resourceGroupName == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } if (vaultName == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter vaultName is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter vaultName is required and cannot be null."); } if (this.client.subscriptionId() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.get(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(getDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.get(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } private ServiceResponse getDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -343,28 +355,16 @@ private ServiceResponse getDelegate(Response response) * @throws CloudException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<VaultInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<VaultInner> object if successful. */ - public ServiceResponse> listByResourceGroup(final String resourceGroupName) throws CloudException, IOException, IllegalArgumentException { - if (resourceGroupName == null) { - throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); - } - if (this.client.subscriptionId() == null) { - throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - final Integer top = null; - Call call = service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), top, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listByResourceGroupDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList listByResourceGroup(final String resourceGroupName) throws CloudException, IOException, IllegalArgumentException { + ServiceResponse> response = listByResourceGroupSinglePageAsync(resourceGroupName).toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextPageLink) throws CloudException, IOException { - return listByResourceGroupNext(nextPageLink).getBody(); + public Page nextPage(String nextPageLink) throws RestException, IOException { + return listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** @@ -372,46 +372,85 @@ public Page nextPage(String nextPageLink) throws CloudException, IOE * * @param resourceGroupName The name of the Resource Group to which the vault belongs. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listByResourceGroupAsync(final String resourceGroupName, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listByResourceGroupAsync(final String resourceGroupName, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listByResourceGroupSinglePageAsync(resourceGroupName), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @return the observable to the PagedList<VaultInner> object + */ + public Observable> listByResourceGroupAsync(final String resourceGroupName) { + return listByResourceGroupWithServiceResponseAsync(resourceGroupName) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @return the observable to the PagedList<VaultInner> object + */ + public Observable>> listByResourceGroupWithServiceResponseAsync(final String resourceGroupName) { + return listByResourceGroupSinglePageAsync(resourceGroupName) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.getBody().getNextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByResourceGroupNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @return the PagedList<VaultInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByResourceGroupSinglePageAsync(final String resourceGroupName) { if (resourceGroupName == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } if (this.client.subscriptionId() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } final Integer top = null; - Call call = service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), top, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listByResourceGroupDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listByResourceGroupNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), top, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByResourceGroupDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } /** @@ -422,27 +461,16 @@ public void onResponse(Call call, Response response) * @throws CloudException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<VaultInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<VaultInner> object if successful. */ - public ServiceResponse> listByResourceGroup(final String resourceGroupName, final Integer top) throws CloudException, IOException, IllegalArgumentException { - if (resourceGroupName == null) { - throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); - } - if (this.client.subscriptionId() == null) { - throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), top, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listByResourceGroupDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList listByResourceGroup(final String resourceGroupName, final Integer top) throws CloudException, IOException, IllegalArgumentException { + ServiceResponse> response = listByResourceGroupSinglePageAsync(resourceGroupName, top).toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextPageLink) throws CloudException, IOException { - return listByResourceGroupNext(nextPageLink).getBody(); + public Page nextPage(String nextPageLink) throws RestException, IOException { + return listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** @@ -451,45 +479,87 @@ public Page nextPage(String nextPageLink) throws CloudException, IOE * @param resourceGroupName The name of the Resource Group to which the vault belongs. * @param top Maximum number of results to return. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listByResourceGroupAsync(final String resourceGroupName, final Integer top, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listByResourceGroupAsync(final String resourceGroupName, final Integer top, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listByResourceGroupSinglePageAsync(resourceGroupName, top), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @param top Maximum number of results to return. + * @return the observable to the PagedList<VaultInner> object + */ + public Observable> listByResourceGroupAsync(final String resourceGroupName, final Integer top) { + return listByResourceGroupWithServiceResponseAsync(resourceGroupName, top) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @param top Maximum number of results to return. + * @return the observable to the PagedList<VaultInner> object + */ + public Observable>> listByResourceGroupWithServiceResponseAsync(final String resourceGroupName, final Integer top) { + return listByResourceGroupSinglePageAsync(resourceGroupName, top) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.getBody().getNextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByResourceGroupNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + ServiceResponse> * @param resourceGroupName The name of the Resource Group to which the vault belongs. + ServiceResponse> * @param top Maximum number of results to return. + * @return the PagedList<VaultInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByResourceGroupSinglePageAsync(final String resourceGroupName, final Integer top) { if (resourceGroupName == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } if (this.client.subscriptionId() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), top, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listByResourceGroupDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listByResourceGroupNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), top, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByResourceGroupDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse> listByResourceGroupDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -505,64 +575,94 @@ private ServiceResponse> listByResourceGroupDelegate(Respon * @throws CloudException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<VaultInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<VaultInner> object if successful. */ - public ServiceResponse> list() throws CloudException, IOException, IllegalArgumentException { - if (this.client.subscriptionId() == null) { - throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); - } - final String filter = "resourceType eq 'Microsoft.KeyVault/vaults'"; - final String apiVersion = "2015-11-01"; - final Integer top = null; - Call call = service.list(this.client.subscriptionId(), filter, top, apiVersion, this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList list() throws CloudException, IOException, IllegalArgumentException { + ServiceResponse> response = listSinglePageAsync().toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextPageLink) throws CloudException, IOException { - return listNext(nextPageLink).getBody(); + public Page nextPage(String nextPageLink) throws RestException, IOException { + return listNextSinglePageAsync(nextPageLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** * The List operation gets information about the vaults associated with the subscription. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listAsync(final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listAsync(final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listSinglePageAsync(), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + * @return the observable to the PagedList<VaultInner> object + */ + public Observable> listAsync() { + return listWithServiceResponseAsync() + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + * @return the observable to the PagedList<VaultInner> object + */ + public Observable>> listWithServiceResponseAsync() { + return listSinglePageAsync() + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.getBody().getNextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + * @return the PagedList<VaultInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync() { if (this.client.subscriptionId() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); } final String filter = "resourceType eq 'Microsoft.KeyVault/vaults'"; final String apiVersion = "2015-11-01"; final Integer top = null; - Call call = service.list(this.client.subscriptionId(), filter, top, apiVersion, this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.list(this.client.subscriptionId(), filter, top, apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } /** @@ -572,23 +672,16 @@ public void onResponse(Call call, Response response) * @throws CloudException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<VaultInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<VaultInner> object if successful. */ - public ServiceResponse> list(final Integer top) throws CloudException, IOException, IllegalArgumentException { - if (this.client.subscriptionId() == null) { - throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); - } - final String filter = "resourceType eq 'Microsoft.KeyVault/vaults'"; - final String apiVersion = "2015-11-01"; - Call call = service.list(this.client.subscriptionId(), filter, top, apiVersion, this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList list(final Integer top) throws CloudException, IOException, IllegalArgumentException { + ServiceResponse> response = listSinglePageAsync(top).toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextPageLink) throws CloudException, IOException { - return listNext(nextPageLink).getBody(); + public Page nextPage(String nextPageLink) throws RestException, IOException { + return listNextSinglePageAsync(nextPageLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** @@ -596,39 +689,80 @@ public Page nextPage(String nextPageLink) throws CloudException, IOE * * @param top Maximum number of results to return. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listAsync(final Integer top, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listAsync(final Integer top, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listSinglePageAsync(top), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + * @param top Maximum number of results to return. + * @return the observable to the PagedList<VaultInner> object + */ + public Observable> listAsync(final Integer top) { + return listWithServiceResponseAsync(top) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + * @param top Maximum number of results to return. + * @return the observable to the PagedList<VaultInner> object + */ + public Observable>> listWithServiceResponseAsync(final Integer top) { + return listSinglePageAsync(top) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.getBody().getNextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + ServiceResponse> * @param top Maximum number of results to return. + * @return the PagedList<VaultInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync(final Integer top) { if (this.client.subscriptionId() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); } final String filter = "resourceType eq 'Microsoft.KeyVault/vaults'"; final String apiVersion = "2015-11-01"; - Call call = service.list(this.client.subscriptionId(), filter, top, apiVersion, this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.list(this.client.subscriptionId(), filter, top, apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -645,14 +779,16 @@ private ServiceResponse> listDelegate(Response> listByResourceGroupNext(final String nextPageLink) throws CloudException, IOException, IllegalArgumentException { - if (nextPageLink == null) { - throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); - } - Call call = service.listByResourceGroupNext(nextPageLink, this.client.acceptLanguage(), this.client.userAgent()); - return listByResourceGroupNextDelegate(call.execute()); + public PagedList listByResourceGroupNext(final String nextPageLink) throws CloudException, IOException, IllegalArgumentException { + ServiceResponse> response = listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single(); + return new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextPageLink) throws RestException, IOException { + return listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single().getBody(); + } + }; } /** @@ -661,37 +797,78 @@ public ServiceResponse> listByResourceGroupNext(final Strin * @param nextPageLink The NextLink from the previous successful call to List operation. * @param serviceCall the ServiceCall object tracking the Retrofit calls * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listByResourceGroupNextAsync(final String nextPageLink, final ServiceCall serviceCall, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listByResourceGroupNextAsync(final String nextPageLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listByResourceGroupNextSinglePageAsync(nextPageLink), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @return the observable to the PagedList<VaultInner> object + */ + public Observable> listByResourceGroupNextAsync(final String nextPageLink) { + return listByResourceGroupNextWithServiceResponseAsync(nextPageLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @return the observable to the PagedList<VaultInner> object + */ + public Observable>> listByResourceGroupNextWithServiceResponseAsync(final String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.getBody().getNextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByResourceGroupNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation. + * @return the PagedList<VaultInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByResourceGroupNextSinglePageAsync(final String nextPageLink) { if (nextPageLink == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter nextPageLink is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); } - Call call = service.listByResourceGroupNext(nextPageLink, this.client.acceptLanguage(), this.client.userAgent()); - serviceCall.newCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listByResourceGroupNextDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listByResourceGroupNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.listByResourceGroupNext(nextPageLink, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByResourceGroupNextDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse> listByResourceGroupNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -708,14 +885,16 @@ private ServiceResponse> listByResourceGroupNextDelegate(Re * @throws CloudException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<VaultInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<VaultInner> object if successful. */ - public ServiceResponse> listNext(final String nextPageLink) throws CloudException, IOException, IllegalArgumentException { - if (nextPageLink == null) { - throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); - } - Call call = service.listNext(nextPageLink, this.client.acceptLanguage(), this.client.userAgent()); - return listNextDelegate(call.execute()); + public PagedList listNext(final String nextPageLink) throws CloudException, IOException, IllegalArgumentException { + ServiceResponse> response = listNextSinglePageAsync(nextPageLink).toBlocking().single(); + return new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextPageLink) throws RestException, IOException { + return listNextSinglePageAsync(nextPageLink).toBlocking().single().getBody(); + } + }; } /** @@ -724,37 +903,78 @@ public ServiceResponse> listNext(final String nextPageLink) * @param nextPageLink The NextLink from the previous successful call to List operation. * @param serviceCall the ServiceCall object tracking the Retrofit calls * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listNextAsync(final String nextPageLink, final ServiceCall serviceCall, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listNextAsync(final String nextPageLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listNextSinglePageAsync(nextPageLink), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @return the observable to the PagedList<VaultInner> object + */ + public Observable> listNextAsync(final String nextPageLink) { + return listNextWithServiceResponseAsync(nextPageLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @return the observable to the PagedList<VaultInner> object + */ + public Observable>> listNextWithServiceResponseAsync(final String nextPageLink) { + return listNextSinglePageAsync(nextPageLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.getBody().getNextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation. + * @return the PagedList<VaultInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listNextSinglePageAsync(final String nextPageLink) { if (nextPageLink == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter nextPageLink is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); } - Call call = service.listNext(nextPageLink, this.client.acceptLanguage(), this.client.userAgent()); - serviceCall.newCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listNextDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.listNext(nextPageLink, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listNextDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse> listNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { diff --git a/gulpfile.js b/gulpfile.js index 387f37e2594a..c24bfbba123d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -11,13 +11,13 @@ var mappings = { 'package': 'com.microsoft.azure.management.compute', 'args': '-FT 1' }, - 'graph': { + 'graphrbac': { 'dir': 'azure-mgmt-graph-rbac', 'source': 'arm-graphrbac/1.6/swagger/graphrbac.json', 'package': 'com.microsoft.azure.management.graphrbac', 'args': '-FT 1' }, - 'keyvault': { + 'arm-keyvault': { 'dir': 'azure-mgmt-keyvault', 'source': 'arm-keyvault/2015-06-01/swagger/keyvault.json', 'package': 'com.microsoft.azure.management.keyvault', From 36616ae219751d14f65f2eb8484e526cd2b09499 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Tue, 26 Jul 2016 17:30:13 -0700 Subject: [PATCH 02/33] Add interfaces for vault & access policy --- azure-mgmt-keyvault/pom.xml | 10 - .../management/keyvault/AccessPolicy.java | 120 ++++++++++++ .../azure/management/keyvault/Vault.java | 151 +++++++++++++++ .../azure/management/keyvault/Vaults.java | 28 +++ .../implementation/AccessPolicyImpl.java | 123 ++++++++++++ .../implementation/KeyVaultManager.java | 101 ++++++++++ .../keyvault/implementation/VaultImpl.java | 180 ++++++++++++++++++ 7 files changed, 703 insertions(+), 10 deletions(-) create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vaults.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java diff --git a/azure-mgmt-keyvault/pom.xml b/azure-mgmt-keyvault/pom.xml index 0b99f6b53562..27dc43d2f31f 100644 --- a/azure-mgmt-keyvault/pom.xml +++ b/azure-mgmt-keyvault/pom.xml @@ -56,16 +56,6 @@ azure-mgmt-resources 1.0.0-SNAPSHOT - - com.microsoft.azure - azure-mgmt-storage - 1.0.0-SNAPSHOT - - - com.microsoft.azure - azure-mgmt-network - 1.0.0-SNAPSHOT - junit junit diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java new file mode 100644 index 000000000000..77500c7b0976 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java @@ -0,0 +1,120 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.keyvault; + +import com.microsoft.azure.management.resources.fluentcore.arm.models.ChildResource; +import com.microsoft.azure.management.resources.fluentcore.model.Attachable; +import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; + +import java.util.List; +import java.util.UUID; + +/** + * An immutable client-side representation of a key vault access policy. + */ +public interface AccessPolicy extends + ChildResource, + Wrapper { + /** + * @return The Azure Active Directory tenant ID that should be used for + * authenticating requests to the key vault. + */ + UUID tenantId(); + + /** + * @return The object ID of a user or service principal in the Azure Active + * Directory tenant for the vault. + */ + UUID objectId(); + + /** + * @return Application ID of the client making request on behalf of a principal. + */ + UUID applicationId(); + + /** + * @return Permissions the identity has for keys and secrets. + */ + Permissions permissions(); + + /************************************************************** + * Fluent interfaces to attach an access policy + **************************************************************/ + + interface Definition extends + DefinitionStages.Blank, + DefinitionStages.WithTenantId, + DefinitionStages.WithApplicationId, + DefinitionStages.WithAttach { + } + + /** + * Grouping of access policy definition stages applicable as part of a key vault creation. + */ + interface DefinitionStages { + /** + * The first stage of an access policy definition. + * + * @param the return type of the final {@link WithAttach#attach()} + */ + interface Blank extends WithTenantId { + } + + /** + * The access policy definition stage allowing tenant ID to be specified. + * @param the return type of the final {@link WithAttach#attach()} + */ + interface WithTenantId { + WithPermissions withTenantId(UUID tenantId); + } + + /** + * The access policy definition stage allowing permissions to be added. + * @param the return type of the final {@link WithAttach#attach()} + */ + interface WithPermissions { + WithAttach withPermissionToKey(String key); + WithAttach withPermissionToKeys(List keys); + WithAttach withPermissionToSecret(String secret); + WithAttach withPermissionToSecrets(List secrets); + } + + /** + * The access policy definition stage allowing application ID to be specified. + * @param the return type of the final {@link WithAttach#attach()} + */ + interface WithApplicationId { + WithAttach withApplicationId(UUID applicationId); + } + + /** The final stage of the access policy definition. + *

+ * At this stage, more permissions can be added or application ID can be specified, + * or the access policy definition can be attached to the parent key vault definition + * using {@link WithAttach#attach()}. + * @param the return type of {@link WithAttach#attach()} + */ + interface WithAttach extends + Attachable.InDefinition, + WithApplicationId, + WithPermissions { + } + } + + /** + * Grouping of all the key vault update stages. + */ + interface UpdateStages { + } + + /** + * The template for a key vault update operation, containing all the settings that can be modified. + */ + interface Update { + } +} + diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java new file mode 100644 index 000000000000..9ae1fa85e029 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java @@ -0,0 +1,151 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.keyvault; + +import com.microsoft.azure.management.keyvault.implementation.VaultInner; +import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource; +import com.microsoft.azure.management.resources.fluentcore.model.Appliable; +import com.microsoft.azure.management.resources.fluentcore.model.Creatable; +import com.microsoft.azure.management.resources.fluentcore.model.Refreshable; +import com.microsoft.azure.management.resources.fluentcore.model.Updatable; +import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; + +import java.util.List; +import java.util.UUID; + +/** + * An immutable client-side representation of an Azure Key Vault. + */ +public interface Vault extends + GroupableResource, + Refreshable, + Updatable, + Wrapper { + /** + * @return The URI of the vault for performing operations on keys and secrets. + */ + String vaultUri(); + + /** + * @return The Azure Active Directory tenant ID that should be used for + * authenticating requests to the key vault. + */ + UUID tenantId(); + + /** + * @return SKU details. + */ + Sku sku(); + + /** + * @return An array of 0 to 16 identities that have access to the key vault. All + * identities in the array must use the same tenant ID as the key vault's + * tenant ID. + */ + List accessPolicies(); + + /** + * @return Property to specify whether Azure Virtual Machines are permitted to + * retrieve certificates stored as secrets from the key vault. + */ + Boolean enabledForDeployment(); + + /** + * @return Property to specify whether Azure Disk Encryption is permitted to + * retrieve secrets from the vault and unwrap keys. + */ + Boolean enabledForDiskEncryption(); + + /** + * @return Property to specify whether Azure Resource Manager is permitted to + * retrieve secrets from the key vault. + */ + Boolean enabledForTemplateDeployment(); + + /************************************************************** + * Fluent interfaces to provision a Vault + **************************************************************/ + + /** + * Container interface for all the definitions that need to be implemented. + */ + interface Definition extends + DefinitionStages.Blank, + DefinitionStages.WithGroup, + DefinitionStages.WithCreate { + } + + /** + * Grouping of all the key vault definition stages. + */ + interface DefinitionStages { + /** + * The first stage of the key vault definition. + */ + interface Blank extends DefinitionWithRegion { + } + + /** + * A key vault definition allowing resource group to be set. + */ + interface WithGroup extends GroupableResource.DefinitionStages.WithGroup { + } + + /** + * A key vault definition allowing the sku to be set. + */ + interface WithSku { + /** + * Specifies the sku of the key vault. + * + * @param skuName the sku + * @return the next stage of key vault definition + */ + WithCreate withSku(SkuName skuName); + } + + interface WithAccessPolicy { + WithCreate withEmptyAccessPolicy(); + WithCreate withAccessPolicy(AccessPolicy accessPolicy); + AccessPolicy.DefinitionStages.Blank defineAccessPolicy(String objectId); + } + + interface WithConfigurations { + WithCreate enabledForDeployment(boolean enabled); + WithCreate enabledForDiskEncryption(boolean enabled); + WithCreate enabledForTemplateDeployment(boolean enabled); + } + + /** + * A key vault definition with sufficient inputs to create a new + * storage account in the cloud, but exposing additional optional inputs to + * specify. + */ + interface WithCreate extends + Creatable, + GroupableResource.DefinitionWithTags, + DefinitionStages.WithSku, + DefinitionStages.WithAccessPolicy, + DefinitionStages.WithConfigurations { + } + } + + /** + * Grouping of all the key vault update stages. + */ + interface UpdateStages { + } + + /** + * The template for a key vault update operation, containing all the settings that can be modified. + */ + interface Update extends + Appliable, + UpdateWithTags { + } +} + diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vaults.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vaults.java new file mode 100644 index 000000000000..6c47f5ed4d75 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vaults.java @@ -0,0 +1,28 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.keyvault; + +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +/** + * Entry point for storage accounts management API. + */ +public interface Vaults extends + SupportsListing, + SupportsCreating, + SupportsDeleting, + SupportsListingByGroup, + SupportsGettingByGroup, + SupportsGettingById, + SupportsDeletingByGroup { +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java new file mode 100644 index 000000000000..57b08544102a --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java @@ -0,0 +1,123 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.keyvault.implementation; + +import com.microsoft.azure.management.keyvault.AccessPolicy; +import com.microsoft.azure.management.keyvault.AccessPolicyEntry; +import com.microsoft.azure.management.keyvault.Permissions; +import com.microsoft.azure.management.keyvault.Vault; +import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.ChildResourceImpl; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + * Implementation for StorageAccount and its parent interfaces. + */ +class AccessPolicyImpl + extends ChildResourceImpl< + AccessPolicyEntry, + VaultImpl> + implements + AccessPolicy, + AccessPolicy.Definition { + protected AccessPolicyImpl(String name, AccessPolicyEntry innerObject, VaultImpl parent) { + super(name, innerObject, parent); + } + + @Override + public UUID tenantId() { + return inner().tenantId(); + } + + @Override + public UUID objectId() { + return inner().objectId(); + } + + @Override + public UUID applicationId() { + return inner().applicationId(); + } + + @Override + public Permissions permissions() { + return inner().permissions(); + } + + @Override + public String name() { + return inner().objectId().toString(); + } + + @Override + public AccessPolicyImpl withApplicationId(UUID applicationId) { + inner().withApplicationId(applicationId); + return this; + } + + @Override + public AccessPolicyImpl withPermissionToKey(String key) { + if (inner().permissions() == null) { + inner().withPermissions(new Permissions()); + } + if (inner().permissions().keys() == null) { + inner().permissions().withKeys(new ArrayList()); + } + inner().permissions().keys().add(key); + return this; + } + + @Override + public AccessPolicyImpl withPermissionToKeys(List keys) { + if (inner().permissions() == null) { + inner().withPermissions(new Permissions()); + } + if (inner().permissions().keys() == null) { + inner().permissions().withKeys(new ArrayList()); + } + inner().permissions().keys().addAll(keys); + return this; + } + + @Override + public AccessPolicyImpl withPermissionToSecret(String secret) { + if (inner().permissions() == null) { + inner().withPermissions(new Permissions()); + } + if (inner().permissions().secrets() == null) { + inner().permissions().withSecrets(new ArrayList()); + } + inner().permissions().secrets().add(secret); + return this; + } + + @Override + public AccessPolicyImpl withPermissionToSecrets(List secrets) { + if (inner().permissions() == null) { + inner().withPermissions(new Permissions()); + } + if (inner().permissions().secrets() == null) { + inner().permissions().withSecrets(new ArrayList()); + } + inner().permissions().secrets().addAll(secrets); + return this; + } + + @Override + public AccessPolicyImpl withTenantId(UUID tenantId) { + inner().withTenantId(tenantId); + return this; + } + + @Override + public VaultImpl attach() { + parent().withAccessPolicy(this); + return parent(); + } +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java new file mode 100644 index 000000000000..3bb7d93bb0a8 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java @@ -0,0 +1,101 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.keyvault.implementation; + +import com.microsoft.azure.AzureEnvironment; +import com.microsoft.azure.RestClient; +import com.microsoft.azure.management.keyvault.Vaults; +import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; +import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; +import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager; +import com.microsoft.azure.management.storage.StorageAccounts; +import com.microsoft.azure.management.storage.implementation.StorageAccountsImpl; +import com.microsoft.azure.management.storage.implementation.StorageManagementClientImpl; +import com.microsoft.rest.credentials.ServiceClientCredentials; + +/** + * Entry point to Azure storage resource management. + */ +public final class KeyVaultManager extends Manager { + // Collections + private Vaults vaults; + + /** + * Get a Configurable instance that can be used to create StorageManager with optional configuration. + * + * @return the instance allowing configurations + */ + public static Configurable configure() { + return new KeyVaultManager.ConfigurableImpl(); + } + + /** + * Creates an instance of StorageManager that exposes storage resource management API entry points. + * + * @param credentials the credentials to use + * @param subscriptionId the subscription UUID + * @return the StorageManager + */ + public static KeyVaultManager authenticate(ServiceClientCredentials credentials, String subscriptionId) { + return new KeyVaultManager(AzureEnvironment.AZURE.newRestClientBuilder() + .withCredentials(credentials) + .build(), subscriptionId); + } + + /** + * Creates an instance of StorageManager that exposes storage resource management API entry points. + * + * @param restClient the RestClient to be used for API calls. + * @param subscriptionId the subscription UUID + * @return the StorageManager + */ + public static KeyVaultManager authenticate(RestClient restClient, String subscriptionId) { + return new KeyVaultManager(restClient, subscriptionId); + } + + /** + * The interface allowing configurations to be set. + */ + public interface Configurable extends AzureConfigurable { + /** + * Creates an instance of StorageManager that exposes storage management API entry points. + * + * @param credentials the credentials to use + * @param subscriptionId the subscription UUID + * @return the interface exposing storage management API entry points that work across subscriptions + */ + KeyVaultManager authenticate(ServiceClientCredentials credentials, String subscriptionId); + } + + /** + * The implementation for Configurable interface. + */ + private static final class ConfigurableImpl extends AzureConfigurableImpl implements Configurable { + public KeyVaultManager authenticate(ServiceClientCredentials credentials, String subscriptionId) { + return KeyVaultManager.authenticate(buildRestClient(credentials), subscriptionId); + } + } + + private KeyVaultManager(RestClient restClient, String subscriptionId) { + super( + restClient, + subscriptionId, + new KeyVaultManagementClientImpl(restClient).withSubscriptionId(subscriptionId)); + } + + /** + * @return the storage account management API entry point + */ + public Vaults vaults() { + if (vaults == null) { + vaults = new VaultsImpl( + super.innerManagementClient.vaults(), + this); + } + return vaults; + } +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java new file mode 100644 index 000000000000..60b5b33d68cc --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java @@ -0,0 +1,180 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.keyvault.implementation; + +import com.microsoft.azure.management.keyvault.AccessPolicy; +import com.microsoft.azure.management.keyvault.AccessPolicyEntry; +import com.microsoft.azure.management.keyvault.Sku; +import com.microsoft.azure.management.keyvault.SkuFamily; +import com.microsoft.azure.management.keyvault.SkuName; +import com.microsoft.azure.management.keyvault.Vault; +import com.microsoft.azure.management.keyvault.VaultProperties; +import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource; +import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + * Implementation for StorageAccount and its parent interfaces. + */ +class VaultImpl + extends GroupableResourceImpl< + Vault, + VaultInner, + VaultImpl, + KeyVaultManager> + implements + Vault, + Vault.Definition, + Vault.Update { + private VaultsInner client; + + protected VaultImpl(String key, VaultInner innerObject, VaultsInner client, KeyVaultManager manager) { + super(key, innerObject, manager); + this.client = client; + } + + @Override + public String vaultUri() { + if (inner().properties() == null) { + return null; + } + return inner().properties().vaultUri(); + } + + @Override + public UUID tenantId() { + if (inner().properties() == null) { + return null; + } + return inner().properties().tenantId(); + } + + @Override + public Sku sku() { + if (inner().properties() == null) { + return null; + } + return inner().properties().sku(); + } + + @Override + public List accessPolicies() { + if (inner().properties() == null) { + return null; + } + return inner().properties().accessPolicies(); + } + + @Override + public Boolean enabledForDeployment() { + if (inner().properties() == null) { + return null; + } + return inner().properties().enabledForDeployment(); + } + + @Override + public Boolean enabledForDiskEncryption() { + if (inner().properties() == null) { + return null; + } + return inner().properties().enabledForDiskEncryption(); + } + + @Override + public Boolean enabledForTemplateDeployment() { + if (inner().properties() == null) { + return null; + } + return inner().properties().enabledForTemplateDeployment(); + } + + @Override + public VaultImpl withEmptyAccessPolicy() { + if (inner().properties() == null) { + inner().withProperties(new VaultProperties()); + } + inner().properties().withAccessPolicies(new ArrayList()); + return this; + } + + @Override + public VaultImpl withAccessPolicy(AccessPolicy accessPolicy) { + if (inner().properties() == null) { + inner().withProperties(new VaultProperties()); + } + if (inner().properties().accessPolicies() == null) { + inner().properties().withAccessPolicies(new ArrayList()); + } + inner().properties().accessPolicies().add(accessPolicy.inner()); + return this; + } + + @Override + public AccessPolicyImpl defineAccessPolicy(String objectId) { + return new AccessPolicyImpl(objectId, new AccessPolicyEntry(), this); + } + + @Override + public VaultImpl enabledForDeployment(boolean enabled) { + inner().properties().withEnabledForDeployment(enabled); + return this; + } + + @Override + public VaultImpl enabledForDiskEncryption(boolean enabled) { + inner().properties().withEnabledForDiskEncryption(enabled); + return this; + } + + @Override + public VaultImpl enabledForTemplateDeployment(boolean enabled) { + inner().properties().withEnabledForTemplateDeployment(enabled); + return this; + } + + @Override + public VaultImpl withSku(SkuName skuName) { + inner().properties().withSku(new Sku().withName(skuName).withFamily(SkuFamily.A)); + return this; + } + + @Override + public VaultImpl apply() throws Exception { + return createResource(); + } + + @Override + public ServiceCall applyAsync(ServiceCallback callback) { + return null; + } + + @Override + public ServiceCall createResourceAsync(ServiceCallback serviceCallback) { + return null; + } + + @Override + public VaultImpl createResource() throws Exception { + VaultCreateOrUpdateParametersInner parameters = new VaultCreateOrUpdateParametersInner(); + parameters.withLocation(regionName()); + parameters.withProperties(inner().properties()); + parameters.withTags(inner().getTags()); + this.setInner(client.createOrUpdate(resourceGroupName(), name(), parameters).getBody()); + return this; + } + + @Override + public VaultImpl refresh() throws Exception { + return null; + } +} From b112eff475bd9a6bec4670635bffb6ec23b2e95d Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 27 Jul 2016 15:11:24 -0700 Subject: [PATCH 03/33] Basic Create --- .../azure/management/keyvault/Vault.java | 10 ++- .../implementation/KeyVaultManager.java | 3 - .../keyvault/implementation/VaultImpl.java | 12 +++ .../keyvault/implementation/VaultsImpl.java | 86 +++++++++++++++++++ .../keyvault/KeyVaultManagementTestBase.java | 42 +++++++++ .../azure/management/keyvault/VaultTests.java | 44 ++++++++++ 6 files changed, 191 insertions(+), 6 deletions(-) create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java create mode 100644 azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java create mode 100644 azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java index 9ae1fa85e029..e421a7f73a0a 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java @@ -76,6 +76,7 @@ public interface Vault extends interface Definition extends DefinitionStages.Blank, DefinitionStages.WithGroup, + DefinitionStages.WithTenantId, DefinitionStages.WithCreate { } @@ -92,7 +93,11 @@ interface Blank extends DefinitionWithRegion { /** * A key vault definition allowing resource group to be set. */ - interface WithGroup extends GroupableResource.DefinitionStages.WithGroup { + interface WithGroup extends GroupableResource.DefinitionStages.WithGroup { + } + + interface WithTenantId { + WithCreate withTenantId(UUID tenantId); } /** @@ -144,8 +149,7 @@ interface UpdateStages { * The template for a key vault update operation, containing all the settings that can be modified. */ interface Update extends - Appliable, - UpdateWithTags { + Appliable { } } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java index 3bb7d93bb0a8..59a7bf6f9077 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java @@ -12,9 +12,6 @@ import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager; -import com.microsoft.azure.management.storage.StorageAccounts; -import com.microsoft.azure.management.storage.implementation.StorageAccountsImpl; -import com.microsoft.azure.management.storage.implementation.StorageManagementClientImpl; import com.microsoft.rest.credentials.ServiceClientCredentials; /** diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java index 60b5b33d68cc..e4a11789202e 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java @@ -144,10 +144,22 @@ public VaultImpl enabledForTemplateDeployment(boolean enabled) { @Override public VaultImpl withSku(SkuName skuName) { + if (inner().properties() == null) { + inner().withProperties(new VaultProperties()); + } inner().properties().withSku(new Sku().withName(skuName).withFamily(SkuFamily.A)); return this; } + @Override + public VaultImpl withTenantId(UUID tenantId) { + if (inner().properties() == null) { + inner().withProperties(new VaultProperties()); + } + inner().properties().withTenantId(tenantId); + return this; + } + @Override public VaultImpl apply() throws Exception { return createResource(); diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java new file mode 100644 index 000000000000..f19965465424 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java @@ -0,0 +1,86 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.keyvault.implementation; + +import com.microsoft.azure.CloudException; +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.keyvault.SkuName; +import com.microsoft.azure.management.keyvault.Vault; +import com.microsoft.azure.management.keyvault.Vaults; +import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; + +import java.io.IOException; + +/** + * The implementation of StorageAccounts and its parent interfaces. + */ +class VaultsImpl + extends GroupableResourcesImpl< + Vault, + VaultImpl, + VaultInner, + VaultsInner, + KeyVaultManager> + implements Vaults { + + VaultsImpl( + final VaultsInner client, + final KeyVaultManager keyVaultManager) { + super(client, keyVaultManager); + } + + @Override + public PagedList list() throws CloudException, IOException { + return wrapList(this.innerCollection.list().getBody()); + } + + @Override + public PagedList listByGroup(String groupName) throws CloudException, IOException { + return wrapList(this.innerCollection.listByResourceGroup(groupName).getBody()); + } + + @Override + public Vault getByGroup(String groupName, String name) throws CloudException, IOException { + return wrapModel(this.innerCollection.get(groupName, name).getBody()); + } + + @Override + public void delete(String id) throws Exception { + delete(ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id)); + } + + @Override + public void delete(String groupName, String name) throws Exception { + this.innerCollection.delete(groupName, name); + } + + @Override + public VaultImpl define(String name) { + return wrapModel(name) + .withSku(SkuName.STANDARD) + .withEmptyAccessPolicy(); + } + + @Override + protected VaultImpl wrapModel(String name) { + return new VaultImpl( + name, + new VaultInner(), + this.innerCollection, + super.myManager); + } + + @Override + protected VaultImpl wrapModel(VaultInner storageAccountInner) { + return new VaultImpl( + storageAccountInner.name(), + storageAccountInner, + this.innerCollection, + super.myManager); + } +} diff --git a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java new file mode 100644 index 000000000000..19ceb7ca66df --- /dev/null +++ b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java @@ -0,0 +1,42 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.keyvault; + +import com.microsoft.azure.AzureEnvironment; +import com.microsoft.azure.RestClient; +import com.microsoft.azure.credentials.ApplicationTokenCredentials; +import com.microsoft.azure.management.keyvault.implementation.KeyVaultManager; +import com.microsoft.azure.management.resources.implementation.ResourceManager; +import okhttp3.logging.HttpLoggingInterceptor; + +/** + * The base for storage manager tests. + */ +public abstract class KeyVaultManagementTestBase { + protected static ResourceManager resourceManager; + protected static KeyVaultManager keyVaultManager; + + protected static void createClients() { + ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( + System.getenv("client-id"), + System.getenv("domain"), + System.getenv("secret"), + null); + + RestClient restClient = AzureEnvironment.AZURE.newRestClientBuilder() + .withCredentials(credentials) + .withLogLevel(HttpLoggingInterceptor.Level.BODY) + .build(); + + resourceManager = ResourceManager + .authenticate(restClient) + .withSubscription(System.getenv("subscription-id")); + + keyVaultManager = KeyVaultManager + .authenticate(restClient, System.getenv("subscription-id")); + } +} diff --git a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java new file mode 100644 index 000000000000..47b6524656ac --- /dev/null +++ b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.keyvault; + +import com.microsoft.azure.management.resources.ResourceGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.Region; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.UUID; + +public class VaultTests extends KeyVaultManagementTestBase { + private static final String RG_NAME = "javacsmrg901"; + private static final String VAULT_NAME = "java-keyvault-901"; + private static ResourceGroup resourceGroup; + + @BeforeClass + public static void setup() throws Exception { + createClients(); + } + + @AfterClass + public static void cleanup() throws Exception { + resourceManager.resourceGroups().delete(RG_NAME); + } + + @Test + public void canCRUDVault() throws Exception { + // CREATE + Vault vault = keyVaultManager.vaults().define(VAULT_NAME) + .withRegion(Region.US_WEST) + .withNewResourceGroup(RG_NAME) + .withTenantId(UUID.fromString("72f988bf-86f1-41af-91ab-2d7cd011db47")) + .create(); + Assert.assertNotNull(vault); + // GET + } +} From 1fe0f3ff6550d3a1e52f7857034264bed08db062 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Mon, 1 Aug 2016 16:10:30 -0700 Subject: [PATCH 04/33] Add graph to key vault flow --- .../GraphRbacManagementTestBase.java | 2 +- azure-mgmt-keyvault/pom.xml | 5 + .../management/keyvault/AccessPolicy.java | 77 +++- .../azure/management/keyvault/Vault.java | 12 +- .../implementation/AccessPolicyImpl.java | 413 ++++++++++++++++-- .../keyvault/implementation/VaultImpl.java | 4 +- .../keyvault/KeyVaultManagementTestBase.java | 15 +- .../azure/management/keyvault/VaultTests.java | 11 +- 8 files changed, 472 insertions(+), 67 deletions(-) diff --git a/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java b/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java index 88f0a8b9d639..b3fb18e2acf4 100644 --- a/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java +++ b/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java @@ -27,6 +27,6 @@ protected static void createClients() { graphRbacManager = GraphRbacManager .configure() .withLogLevel(HttpLoggingInterceptor.Level.BODY) - .authenticate(credentials, credentials.getDomain()); + .authenticate(credentials, "myorganization"); } } diff --git a/azure-mgmt-keyvault/pom.xml b/azure-mgmt-keyvault/pom.xml index 27dc43d2f31f..6b7471bc35ff 100644 --- a/azure-mgmt-keyvault/pom.xml +++ b/azure-mgmt-keyvault/pom.xml @@ -56,6 +56,11 @@ azure-mgmt-resources 1.0.0-SNAPSHOT + + com.microsoft.azure + azure-mgmt-graph-rbac + 1.0.0-SNAPSHOT + junit junit diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java index 77500c7b0976..db46dc0a5071 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java @@ -6,6 +6,8 @@ package com.microsoft.azure.management.keyvault; +import com.microsoft.azure.management.graphrbac.ServicePrincipal; +import com.microsoft.azure.management.graphrbac.User; import com.microsoft.azure.management.resources.fluentcore.arm.models.ChildResource; import com.microsoft.azure.management.resources.fluentcore.model.Attachable; import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; @@ -47,8 +49,6 @@ public interface AccessPolicy extends interface Definition extends DefinitionStages.Blank, - DefinitionStages.WithTenantId, - DefinitionStages.WithApplicationId, DefinitionStages.WithAttach { } @@ -61,15 +61,13 @@ interface DefinitionStages { * * @param the return type of the final {@link WithAttach#attach()} */ - interface Blank extends WithTenantId { + interface Blank extends WithIdentity { } - /** - * The access policy definition stage allowing tenant ID to be specified. - * @param the return type of the final {@link WithAttach#attach()} - */ - interface WithTenantId { - WithPermissions withTenantId(UUID tenantId); + interface WithIdentity { + WithAttach forObjectId(UUID objectId); + WithAttach forUser(User user); + WithAttach forServicePrincipal(ServicePrincipal servicePrincipal); } /** @@ -77,18 +75,54 @@ interface WithTenantId { * @param the return type of the final {@link WithAttach#attach()} */ interface WithPermissions { - WithAttach withPermissionToKey(String key); - WithAttach withPermissionToKeys(List keys); - WithAttach withPermissionToSecret(String secret); - WithAttach withPermissionToSecrets(List secrets); - } - - /** - * The access policy definition stage allowing application ID to be specified. - * @param the return type of the final {@link WithAttach#attach()} - */ - interface WithApplicationId { - WithAttach withApplicationId(UUID applicationId); + WithAttach allowKeyDecrypting(); + WithAttach allowKeyEncrypting(); + WithAttach allowKeyUnwrapping(); + WithAttach allowKeyWrapping(); + WithAttach allowKeyVerifying(); + WithAttach allowKeySigning(); + WithAttach allowKeyGetting(); + WithAttach allowKeyListing(); + WithAttach allowKeyUpdating(); + WithAttach allowKeyCreating(); + WithAttach allowKeyImporting(); + WithAttach allowKeyDeleting(); + WithAttach allowKeyBackingUp(); + WithAttach allowKeyRestoring(); + WithAttach allowKeyAllPermissions(); + WithAttach allowKeyPermission(String permission); + WithAttach allowKeyPermissions(List permissions); + WithAttach disallowKeyDecrypting(); + WithAttach disallowKeyEncrypting(); + WithAttach disallowKeyUnwrapping(); + WithAttach disallowKeyWrapping(); + WithAttach disallowKeyVerifying(); + WithAttach disallowKeySigning(); + WithAttach disallowKeyGetting(); + WithAttach disallowKeyListing(); + WithAttach disallowKeyUpdating(); + WithAttach disallowKeyCreating(); + WithAttach disallowKeyImporting(); + WithAttach disallowKeyDeleting(); + WithAttach disallowKeyBackingUp(); + WithAttach disallowKeyRestoring(); + WithAttach disallowKeyAllPermissions(); + WithAttach disallowKeyPermission(String permission); + WithAttach disallowKeyPermissions(List permissions); + WithAttach allowSecretGetting(); + WithAttach allowSecretListing(); + WithAttach allowSecretSetting(); + WithAttach allowSecretDeleting(); + WithAttach allowSecretAllPermissions(); + WithAttach allowSecretPermission(String permission); + WithAttach allowSecretPermissions(List permissions); + WithAttach disallowSecretGetting(); + WithAttach disallowSecretListing(); + WithAttach disallowSecretSetting(); + WithAttach disallowSecretDeleting(); + WithAttach disallowSecretAllPermissions(); + WithAttach disallowSecretPermission(String permission); + WithAttach disallowSecretPermissions(List permissions); } /** The final stage of the access policy definition. @@ -100,7 +134,6 @@ interface WithApplicationId { */ interface WithAttach extends Attachable.InDefinition, - WithApplicationId, WithPermissions { } } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java index e421a7f73a0a..46b32579bed6 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java @@ -76,7 +76,7 @@ public interface Vault extends interface Definition extends DefinitionStages.Blank, DefinitionStages.WithGroup, - DefinitionStages.WithTenantId, + DefinitionStages.WithTenantIdOrAccessPolicy, DefinitionStages.WithCreate { } @@ -93,11 +93,14 @@ interface Blank extends DefinitionWithRegion { /** * A key vault definition allowing resource group to be set. */ - interface WithGroup extends GroupableResource.DefinitionStages.WithGroup { + interface WithGroup extends GroupableResource.DefinitionStages.WithGroup { + } + + interface WithTenantIdOrAccessPolicy extends WithTenantId, WithAccessPolicy { } interface WithTenantId { - WithCreate withTenantId(UUID tenantId); + WithAccessPolicy withTenantId(UUID tenantId); } /** @@ -116,7 +119,7 @@ interface WithSku { interface WithAccessPolicy { WithCreate withEmptyAccessPolicy(); WithCreate withAccessPolicy(AccessPolicy accessPolicy); - AccessPolicy.DefinitionStages.Blank defineAccessPolicy(String objectId); + AccessPolicy.DefinitionStages.Blank defineAccessPolicy(); } interface WithConfigurations { @@ -134,7 +137,6 @@ interface WithCreate extends Creatable, GroupableResource.DefinitionWithTags, DefinitionStages.WithSku, - DefinitionStages.WithAccessPolicy, DefinitionStages.WithConfigurations { } } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java index 57b08544102a..03db44b39218 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java @@ -6,6 +6,8 @@ package com.microsoft.azure.management.keyvault.implementation; +import com.microsoft.azure.management.graphrbac.ServicePrincipal; +import com.microsoft.azure.management.graphrbac.User; import com.microsoft.azure.management.keyvault.AccessPolicy; import com.microsoft.azure.management.keyvault.AccessPolicyEntry; import com.microsoft.azure.management.keyvault.Permissions; @@ -26,8 +28,32 @@ class AccessPolicyImpl implements AccessPolicy, AccessPolicy.Definition { - protected AccessPolicyImpl(String name, AccessPolicyEntry innerObject, VaultImpl parent) { - super(name, innerObject, parent); + private enum ALLOWED_KEY_PERMISSIONS { + DECRYPT("Decrypt"), ENCRYPT("Encrypt"), UNWRAPKEY("UnwrapKey"), WRAPKEY("WrapKey"), VERIFY("Verify"), SIGN("Sign"), GET("Get"), LIST("List"), UPDATE("Update"), CREATE("Create"), IMPORT("Import"), DELETE("Delete"), BACKUP("Backup"), RESTORE("Restore"), ALL("All"); + private String value; + ALLOWED_KEY_PERMISSIONS(String value) { + this.value = value; + } + @Override + public String toString() { + return value; + } + } + + private enum ALLOWED_SECRET_PERMISSIONS { + GET("Get"), LIST("List"), SET("Set"), DELETE("Delete"), ALL("All"); + private String value; + ALLOWED_SECRET_PERMISSIONS(String value) { + this.value = value; + } + @Override + public String toString() { + return value; + } + } + + AccessPolicyImpl(AccessPolicyEntry innerObject, VaultImpl parent) { + super(null, innerObject, parent); } @Override @@ -55,63 +81,49 @@ public String name() { return inner().objectId().toString(); } - @Override - public AccessPolicyImpl withApplicationId(UUID applicationId) { - inner().withApplicationId(applicationId); - return this; - } - - @Override - public AccessPolicyImpl withPermissionToKey(String key) { + private void initializeKeyPermissions() { if (inner().permissions() == null) { inner().withPermissions(new Permissions()); } if (inner().permissions().keys() == null) { inner().permissions().withKeys(new ArrayList()); } - inner().permissions().keys().add(key); - return this; } - @Override - public AccessPolicyImpl withPermissionToKeys(List keys) { + private void initializeSecretPermissions() { if (inner().permissions() == null) { inner().withPermissions(new Permissions()); } - if (inner().permissions().keys() == null) { - inner().permissions().withKeys(new ArrayList()); + if (inner().permissions().secrets() == null) { + inner().permissions().withSecrets(new ArrayList()); } - inner().permissions().keys().addAll(keys); + } + + @Override + public AccessPolicyImpl allowKeyPermission(String permission) { + initializeKeyPermissions(); + inner().permissions().keys().add(permission); return this; } @Override - public AccessPolicyImpl withPermissionToSecret(String secret) { - if (inner().permissions() == null) { - inner().withPermissions(new Permissions()); - } - if (inner().permissions().secrets() == null) { - inner().permissions().withSecrets(new ArrayList()); - } - inner().permissions().secrets().add(secret); + public AccessPolicyImpl allowKeyPermissions(List permissions) { + initializeKeyPermissions(); + inner().permissions().keys().addAll(permissions); return this; } @Override - public AccessPolicyImpl withPermissionToSecrets(List secrets) { - if (inner().permissions() == null) { - inner().withPermissions(new Permissions()); - } - if (inner().permissions().secrets() == null) { - inner().permissions().withSecrets(new ArrayList()); - } - inner().permissions().secrets().addAll(secrets); + public AccessPolicyImpl allowSecretPermission(String permission) { + initializeSecretPermissions(); + inner().permissions().secrets().add(permission); return this; } @Override - public AccessPolicyImpl withTenantId(UUID tenantId) { - inner().withTenantId(tenantId); + public AccessPolicyImpl allowSecretPermissions(List permissions) { + initializeSecretPermissions(); + inner().permissions().secrets().addAll(permissions); return this; } @@ -120,4 +132,335 @@ public VaultImpl attach() { parent().withAccessPolicy(this); return parent(); } + + @Override + public AccessPolicyImpl forObjectId(UUID objectId) { + inner().withObjectId(objectId); + return this; + } + + @Override + public AccessPolicyImpl forUser(User user) { + inner().withObjectId(UUID.fromString(user.objectId())); + return this; + } + + @Override + public AccessPolicyImpl forServicePrincipal(ServicePrincipal servicePrincipal) { + inner().withObjectId(UUID.fromString(servicePrincipal.objectId())); + return this; + } + + @Override + public AccessPolicyImpl allowKeyDecrypting() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.DECRYPT.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyEncrypting() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.ENCRYPT.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyUnwrapping() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.UNWRAPKEY.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyWrapping() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.WRAPKEY.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyVerifying() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.VERIFY.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeySigning() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.SIGN.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyGetting() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.GET.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyListing() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.LIST.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyUpdating() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.UPDATE.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyCreating() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.CREATE.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyImporting() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.IMPORT.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyDeleting() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.DELETE.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyBackingUp() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.BACKUP.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyRestoring() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.RESTORE.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyAllPermissions() { + initializeKeyPermissions(); + for(ALLOWED_KEY_PERMISSIONS permission : ALLOWED_KEY_PERMISSIONS.values()) { + inner().permissions().keys().add(permission.toString()); + } + return this; + } + + @Override + public AccessPolicyImpl disallowKeyDecrypting() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.DECRYPT.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyEncrypting() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.ENCRYPT.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyUnwrapping() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.UNWRAPKEY.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyWrapping() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.WRAPKEY.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyVerifying() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.VERIFY.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeySigning() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.SIGN.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyGetting() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.GET.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyListing() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.LIST.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyUpdating() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.UPDATE.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyCreating() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.CREATE.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyImporting() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.IMPORT.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyDeleting() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.DELETE.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyBackingUp() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.BACKUP.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyRestoring() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.RESTORE.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyAllPermissions() { + initializeKeyPermissions(); + inner().permissions().keys().clear(); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyPermission(String permission) { + initializeKeyPermissions(); + inner().permissions().keys().remove(permission); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyPermissions(List permissions) { + initializeKeyPermissions(); + inner().permissions().keys().removeAll(permissions); + return this; + } + + @Override + public AccessPolicyImpl allowSecretGetting() { + initializeSecretPermissions(); + inner().permissions().keys().add(ALLOWED_SECRET_PERMISSIONS.GET.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowSecretListing() { + initializeSecretPermissions(); + inner().permissions().keys().add(ALLOWED_SECRET_PERMISSIONS.LIST.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowSecretSetting() { + initializeSecretPermissions(); + inner().permissions().keys().add(ALLOWED_SECRET_PERMISSIONS.SET.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowSecretDeleting() { + initializeSecretPermissions(); + inner().permissions().keys().add(ALLOWED_SECRET_PERMISSIONS.DELETE.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowSecretAllPermissions() { + return null; + } + + @Override + public AccessPolicyImpl disallowSecretGetting() { + initializeSecretPermissions(); + inner().permissions().keys().remove(ALLOWED_SECRET_PERMISSIONS.GET.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowSecretListing() { + initializeSecretPermissions(); + inner().permissions().keys().remove(ALLOWED_SECRET_PERMISSIONS.LIST.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowSecretSetting() { + initializeSecretPermissions(); + inner().permissions().keys().remove(ALLOWED_SECRET_PERMISSIONS.SET.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowSecretDeleting() { + initializeSecretPermissions(); + inner().permissions().keys().remove(ALLOWED_SECRET_PERMISSIONS.DELETE.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowSecretAllPermissions() { + initializeSecretPermissions(); + inner().permissions().keys().clear(); + return this; + } + + @Override + public AccessPolicyImpl disallowSecretPermission(String permission) { + initializeSecretPermissions(); + inner().permissions().keys().remove(permission); + return this; + } + + @Override + public AccessPolicyImpl disallowSecretPermissions(List permissions) { + initializeSecretPermissions(); + inner().permissions().keys().removeAll(permissions); + return this; + } + + @Override + public String key() { + return objectId().toString(); + } } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java index e4a11789202e..e957e2ec6ce5 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java @@ -120,8 +120,8 @@ public VaultImpl withAccessPolicy(AccessPolicy accessPolicy) { } @Override - public AccessPolicyImpl defineAccessPolicy(String objectId) { - return new AccessPolicyImpl(objectId, new AccessPolicyEntry(), this); + public AccessPolicyImpl defineAccessPolicy() { + return new AccessPolicyImpl(new AccessPolicyEntry(), this); } @Override diff --git a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java index 19ceb7ca66df..3e9f9bb9ac14 100644 --- a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java +++ b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java @@ -9,6 +9,7 @@ import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.RestClient; import com.microsoft.azure.credentials.ApplicationTokenCredentials; +import com.microsoft.azure.management.graphrbac.implementation.GraphRbacManager; import com.microsoft.azure.management.keyvault.implementation.KeyVaultManager; import com.microsoft.azure.management.resources.implementation.ResourceManager; import okhttp3.logging.HttpLoggingInterceptor; @@ -18,15 +19,24 @@ */ public abstract class KeyVaultManagementTestBase { protected static ResourceManager resourceManager; + protected static GraphRbacManager graphRbacManager; protected static KeyVaultManager keyVaultManager; + protected static ApplicationTokenCredentials credentials; protected static void createClients() { - ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( + credentials = new ApplicationTokenCredentials( System.getenv("client-id"), System.getenv("domain"), System.getenv("secret"), null); + ApplicationTokenCredentials graphCredentials = new ApplicationTokenCredentials( + System.getenv("client-id"), + System.getenv("domain"), + System.getenv("secret"), + "https://graph.windows.net/", + null); + RestClient restClient = AzureEnvironment.AZURE.newRestClientBuilder() .withCredentials(credentials) .withLogLevel(HttpLoggingInterceptor.Level.BODY) @@ -36,6 +46,9 @@ protected static void createClients() { .authenticate(restClient) .withSubscription(System.getenv("subscription-id")); + graphRbacManager = GraphRbacManager + .authenticate(graphCredentials, System.getenv("domain")); + keyVaultManager = KeyVaultManager .authenticate(restClient, System.getenv("subscription-id")); } diff --git a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java index 47b6524656ac..3782ec8f2647 100644 --- a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java +++ b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java @@ -6,6 +6,7 @@ package com.microsoft.azure.management.keyvault; +import com.microsoft.azure.management.graphrbac.ServicePrincipal; import com.microsoft.azure.management.resources.ResourceGroup; import com.microsoft.azure.management.resources.fluentcore.arm.Region; import org.junit.AfterClass; @@ -33,10 +34,18 @@ public static void cleanup() throws Exception { @Test public void canCRUDVault() throws Exception { // CREATE + ServicePrincipal sp = graphRbacManager.servicePrincipals().getByName(credentials.getClientId()); Vault vault = keyVaultManager.vaults().define(VAULT_NAME) .withRegion(Region.US_WEST) .withNewResourceGroup(RG_NAME) - .withTenantId(UUID.fromString("72f988bf-86f1-41af-91ab-2d7cd011db47")) + .withTenantId(UUID.fromString(credentials.getDomain())) + .defineAccessPolicy() + .forServicePrincipal(sp) + .allowKeyGetting() + .allowKeyListing() + .allowKeyCreating() + .allowSecretAllPermissions() + .attach() .create(); Assert.assertNotNull(vault); // GET From 34207df0c5e543ca626969bcb9926f3721aff0f3 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 3 Aug 2016 01:26:02 -0700 Subject: [PATCH 05/33] Add update flow to vault --- .../management/keyvault/AccessPolicy.java | 154 ++++++++++++------ .../azure/management/keyvault/Vault.java | 16 +- .../azure/management/keyvault/VaultTests.java | 21 ++- 3 files changed, 138 insertions(+), 53 deletions(-) diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java index db46dc0a5071..c1467c18b130 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java @@ -10,6 +10,7 @@ import com.microsoft.azure.management.graphrbac.User; import com.microsoft.azure.management.resources.fluentcore.arm.models.ChildResource; import com.microsoft.azure.management.resources.fluentcore.model.Attachable; +import com.microsoft.azure.management.resources.fluentcore.model.Settable; import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; import java.util.List; @@ -74,55 +75,50 @@ interface WithIdentity { * The access policy definition stage allowing permissions to be added. * @param the return type of the final {@link WithAttach#attach()} */ - interface WithPermissions { - WithAttach allowKeyDecrypting(); - WithAttach allowKeyEncrypting(); - WithAttach allowKeyUnwrapping(); - WithAttach allowKeyWrapping(); - WithAttach allowKeyVerifying(); - WithAttach allowKeySigning(); - WithAttach allowKeyGetting(); - WithAttach allowKeyListing(); - WithAttach allowKeyUpdating(); - WithAttach allowKeyCreating(); - WithAttach allowKeyImporting(); - WithAttach allowKeyDeleting(); - WithAttach allowKeyBackingUp(); - WithAttach allowKeyRestoring(); - WithAttach allowKeyAllPermissions(); - WithAttach allowKeyPermission(String permission); - WithAttach allowKeyPermissions(List permissions); - WithAttach disallowKeyDecrypting(); - WithAttach disallowKeyEncrypting(); - WithAttach disallowKeyUnwrapping(); - WithAttach disallowKeyWrapping(); - WithAttach disallowKeyVerifying(); - WithAttach disallowKeySigning(); - WithAttach disallowKeyGetting(); - WithAttach disallowKeyListing(); - WithAttach disallowKeyUpdating(); - WithAttach disallowKeyCreating(); - WithAttach disallowKeyImporting(); - WithAttach disallowKeyDeleting(); - WithAttach disallowKeyBackingUp(); - WithAttach disallowKeyRestoring(); - WithAttach disallowKeyAllPermissions(); - WithAttach disallowKeyPermission(String permission); - WithAttach disallowKeyPermissions(List permissions); - WithAttach allowSecretGetting(); - WithAttach allowSecretListing(); - WithAttach allowSecretSetting(); - WithAttach allowSecretDeleting(); - WithAttach allowSecretAllPermissions(); - WithAttach allowSecretPermission(String permission); - WithAttach allowSecretPermissions(List permissions); - WithAttach disallowSecretGetting(); - WithAttach disallowSecretListing(); - WithAttach disallowSecretSetting(); - WithAttach disallowSecretDeleting(); - WithAttach disallowSecretAllPermissions(); - WithAttach disallowSecretPermission(String permission); - WithAttach disallowSecretPermissions(List permissions); + interface WithPermissions extends WithPermissionsBase> { + } + + /** The final stage of the access policy definition. + *

+ * At this stage, more permissions can be added or application ID can be specified, + * or the access policy definition can be attached to the parent key vault definition + * using {@link WithAttach#attach()}. + * @param the return type of {@link WithAttach#attach()} + */ + interface WithAttach extends + Attachable.InDefinition, + WithPermissions { + } + } + + interface UpdateDefinition extends + UpdateDefinitionStages.Blank, + UpdateDefinitionStages.WithAttach { + } + + /** + * Grouping of access policy definition stages applicable as part of a key vault creation. + */ + interface UpdateDefinitionStages { + /** + * The first stage of an access policy definition. + * + * @param the return type of the final {@link WithAttach#attach()} + */ + interface Blank extends WithIdentity { + } + + interface WithIdentity { + WithAttach forObjectId(UUID objectId); + WithAttach forUser(User user); + WithAttach forServicePrincipal(ServicePrincipal servicePrincipal); + } + + /** + * The access policy definition stage allowing permissions to be added. + * @param the return type of the final {@link WithAttach#attach()} + */ + interface WithPermissions extends WithPermissionsBase> { } /** The final stage of the access policy definition. @@ -142,12 +138,70 @@ interface WithAttach extends * Grouping of all the key vault update stages. */ interface UpdateStages { + /** + * The access policy definition stage allowing permissions to be added. + */ + interface WithPermissions extends WithPermissionsBase { + } } /** * The template for a key vault update operation, containing all the settings that can be modified. */ - interface Update { + interface Update extends + UpdateStages.WithPermissions, + Settable{ + } + + interface WithPermissionsBase { + T allowKeyDecrypting(); + T allowKeyEncrypting(); + T allowKeyUnwrapping(); + T allowKeyWrapping(); + T allowKeyVerifying(); + T allowKeySigning(); + T allowKeyGetting(); + T allowKeyListing(); + T allowKeyUpdating(); + T allowKeyCreating(); + T allowKeyImporting(); + T allowKeyDeleting(); + T allowKeyBackingUp(); + T allowKeyRestoring(); + T allowKeyAllPermissions(); + T allowKeyPermission(String permission); + T allowKeyPermissions(List permissions); + T disallowKeyDecrypting(); + T disallowKeyEncrypting(); + T disallowKeyUnwrapping(); + T disallowKeyWrapping(); + T disallowKeyVerifying(); + T disallowKeySigning(); + T disallowKeyGetting(); + T disallowKeyListing(); + T disallowKeyUpdating(); + T disallowKeyCreating(); + T disallowKeyImporting(); + T disallowKeyDeleting(); + T disallowKeyBackingUp(); + T disallowKeyRestoring(); + T disallowKeyAllPermissions(); + T disallowKeyPermission(String permission); + T disallowKeyPermissions(List permissions); + T allowSecretGetting(); + T allowSecretListing(); + T allowSecretSetting(); + T allowSecretDeleting(); + T allowSecretAllPermissions(); + T allowSecretPermission(String permission); + T allowSecretPermissions(List permissions); + T disallowSecretGetting(); + T disallowSecretListing(); + T disallowSecretSetting(); + T disallowSecretDeleting(); + T disallowSecretAllPermissions(); + T disallowSecretPermission(String permission); + T disallowSecretPermissions(List permissions); } } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java index 46b32579bed6..27285255b8c3 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java @@ -145,13 +145,27 @@ interface WithCreate extends * Grouping of all the key vault update stages. */ interface UpdateStages { + interface WithAccessPolicy { + Update withoutAccessPolicy(String objectId); + Update withAccessPolicy(AccessPolicy accessPolicy); + AccessPolicy.UpdateDefinitionStages.Blank defineAccessPolicy(); + AccessPolicy.Update updateAccessPolicy(String objectId); + } + + interface WithConfigurations { + Update enabledForDeployment(boolean enabled); + Update enabledForDiskEncryption(boolean enabled); + Update enabledForTemplateDeployment(boolean enabled); + } } /** * The template for a key vault update operation, containing all the settings that can be modified. */ interface Update extends - Appliable { + Appliable, + UpdateStages.WithAccessPolicy, + UpdateStages.WithConfigurations { } } diff --git a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java index 3782ec8f2647..22430ae84495 100644 --- a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java +++ b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java @@ -14,7 +14,7 @@ import org.junit.BeforeClass; import org.junit.Test; -import java.util.UUID; +import java.util.List; public class VaultTests extends KeyVaultManagementTestBase { private static final String RG_NAME = "javacsmrg901"; @@ -38,7 +38,6 @@ public void canCRUDVault() throws Exception { Vault vault = keyVaultManager.vaults().define(VAULT_NAME) .withRegion(Region.US_WEST) .withNewResourceGroup(RG_NAME) - .withTenantId(UUID.fromString(credentials.getDomain())) .defineAccessPolicy() .forServicePrincipal(sp) .allowKeyGetting() @@ -49,5 +48,23 @@ public void canCRUDVault() throws Exception { .create(); Assert.assertNotNull(vault); // GET + vault = keyVaultManager.vaults().getByGroup(RG_NAME, VAULT_NAME); + Assert.assertNotNull(vault); + // LIST + List vaults = keyVaultManager.vaults().listByGroup(RG_NAME); + for (Vault v : vaults) { + if (VAULT_NAME.equals(v.name())) { + vault = v; + break; + } + } + Assert.assertNotNull(vault); + // UPDATE + vault.update() + .updateAccessPolicy(sp.objectId()) + .allowKeyAllPermissions() + .disallowSecretAllPermissions() + .parent() + .apply(); } } From 3a3b5d5c3048f6eaf24df63c8f6d20757cbbb808 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 3 Aug 2016 10:49:22 -0700 Subject: [PATCH 06/33] Add authorize flow --- .../implementation/GraphRbacManager.java | 2 +- .../management/keyvault/AccessPolicy.java | 14 ++++++++++++ .../azure/management/keyvault/Vault.java | 2 ++ .../azure/management/keyvault/VaultTests.java | 22 ++++++++++++++++++- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManager.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManager.java index 3c0b086690d4..c6585a9e3c63 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManager.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManager.java @@ -92,7 +92,7 @@ private GraphRbacManager(RestClient restClient, String tenantId) { /** * @return the storage account management API entry point */ - public Users storageAccounts() { + public Users users() { if (users == null) { users = new UsersImpl(graphRbacManagementClient.users(), this); } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java index c1467c18b130..f7d2dab4e554 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java @@ -6,6 +6,7 @@ package com.microsoft.azure.management.keyvault; +import com.microsoft.azure.CloudException; import com.microsoft.azure.management.graphrbac.ServicePrincipal; import com.microsoft.azure.management.graphrbac.User; import com.microsoft.azure.management.resources.fluentcore.arm.models.ChildResource; @@ -13,6 +14,7 @@ import com.microsoft.azure.management.resources.fluentcore.model.Settable; import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; +import java.io.IOException; import java.util.List; import java.util.UUID; @@ -153,6 +155,18 @@ interface Update extends Settable{ } + interface AppAuthorizationStages { + /** + * The access policy definition stage allowing permissions to be added. + */ + interface WithPermissions extends WithPermissionsBase { + } + } + + interface Authorize extends AppAuthorizationStages.WithPermissions { + void authorize() throws CloudException, IOException; + } + interface WithPermissionsBase { T allowKeyDecrypting(); T allowKeyEncrypting(); diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java index 27285255b8c3..a761c132dbd0 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java @@ -66,6 +66,8 @@ public interface Vault extends */ Boolean enabledForTemplateDeployment(); + AccessPolicy.AppAuthorizationStages.WithPermissions defineAppAuthorization(String applicationId); + /************************************************************** * Fluent interfaces to provision a Vault **************************************************************/ diff --git a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java index 22430ae84495..0c20738fffbc 100644 --- a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java +++ b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java @@ -7,6 +7,7 @@ package com.microsoft.azure.management.keyvault; import com.microsoft.azure.management.graphrbac.ServicePrincipal; +import com.microsoft.azure.management.graphrbac.User; import com.microsoft.azure.management.resources.ResourceGroup; import com.microsoft.azure.management.resources.fluentcore.arm.Region; import org.junit.AfterClass; @@ -35,6 +36,7 @@ public static void cleanup() throws Exception { public void canCRUDVault() throws Exception { // CREATE ServicePrincipal sp = graphRbacManager.servicePrincipals().getByName(credentials.getClientId()); + User user = graphRbacManager.users().getByName("azuresdk@outlook.com"); Vault vault = keyVaultManager.vaults().define(VAULT_NAME) .withRegion(Region.US_WEST) .withNewResourceGroup(RG_NAME) @@ -61,10 +63,28 @@ public void canCRUDVault() throws Exception { Assert.assertNotNull(vault); // UPDATE vault.update() - .updateAccessPolicy(sp.objectId()) + .updateAccessPolicy(vault.accessPolicies().get(0).objectId().toString()) .allowKeyAllPermissions() .disallowSecretAllPermissions() .parent() .apply(); + vault.update() + .defineAccessPolicy() + .forUser(user) + .allowKeyAllPermissions() + .allowSecretGetting() + .allowSecretListing() + .attach() + .apply(); + vault.update() + .withoutAccessPolicy(sp.objectId()) + .apply(); + // AUTHORIZE + vault.defineAppAuthorization("app-id") + .allowKeyListing() + .allowKeyGetting() + .allowSecretListing() + .allowSecretGetting() + .authorize(); } } From 262a7ee1f01bc1f150df5f429e7eeab75c6094bc Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 3 Aug 2016 10:59:43 -0700 Subject: [PATCH 07/33] Rename getters for Users & ServicePrincipals --- .../graphrbac/ServicePrincipals.java | 34 +++++++++++++++++-- .../azure/management/graphrbac/Users.java | 24 +++++++++++-- .../implementation/ServicePrincipalsImpl.java | 2 +- .../graphrbac/implementation/UsersImpl.java | 2 +- .../azure/management/keyvault/VaultTests.java | 6 ++-- 5 files changed, 58 insertions(+), 10 deletions(-) diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java index 3084db1c6e79..0f38e19fa9d6 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java @@ -6,17 +6,47 @@ package com.microsoft.azure.management.graphrbac; -import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByName; +import com.microsoft.azure.CloudException; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; +import java.io.IOException; + /** * Entry point to tenant management API. */ public interface ServicePrincipals extends SupportsCreating, SupportsListing, - SupportsGettingByName, SupportsDeleting { + /** + * Gets the information about a service principal. + * + * @param objectId the unique object id + * @return an immutable representation of the resource + * @throws CloudException exceptions thrown from the cloud + * @throws IOException exceptions thrown from serialization/deserialization + */ + ServicePrincipal getByObjectId(String objectId) throws CloudException, IOException; + + /** + * Gets the information about a service principal. + * + * @param appId the application id (or the client id) + * @return an immutable representation of the resource + * @throws CloudException exceptions thrown from the cloud + * @throws IOException exceptions thrown from serialization/deserialization + */ + ServicePrincipal getByAppId(String appId) throws CloudException, IOException; + + /** + * Gets the information about a service principal. + * + * @param spn the service principal name + * @return an immutable representation of the resource + * @throws CloudException exceptions thrown from the cloud + * @throws IOException exceptions thrown from serialization/deserialization + */ + ServicePrincipal getByServicePrincipalName(String spn) throws CloudException, IOException; } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java index 832ffb2bcdbf..3b3de21766a5 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java @@ -6,17 +6,37 @@ package com.microsoft.azure.management.graphrbac; -import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByName; +import com.microsoft.azure.CloudException; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; +import java.io.IOException; + /** * Entry point to tenant management API. */ public interface Users extends SupportsCreating, SupportsListing, - SupportsGettingByName, SupportsDeleting { + /** + * Gets the information about a user. + * + * @param objectId the unique object id + * @return an immutable representation of the resource + * @throws CloudException exceptions thrown from the cloud + * @throws IOException exceptions thrown from serialization/deserialization + */ + User getByObjectId(String objectId) throws CloudException, IOException; + + /** + * Gets the information about a user. + * + * @param upn the user principal name + * @return an immutable representation of the resource + * @throws CloudException exceptions thrown from the cloud + * @throws IOException exceptions thrown from serialization/deserialization + */ + User getByUserPrincipalName(String upn) throws CloudException, IOException; } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java index 5304ba661fc4..f7dd5eb67171 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java @@ -59,7 +59,7 @@ protected ServicePrincipalImpl wrapModel(ServicePrincipalInner servicePrincipalI } @Override - public ServicePrincipalImpl getByName(String objectId) throws CloudException, IOException { + public ServicePrincipalImpl getByObjectId(String objectId) throws CloudException, IOException { return new ServicePrincipalImpl(innerCollection.get(objectId).getBody(), innerCollection); } } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java index 782959a65bee..7263192dcd89 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java @@ -59,7 +59,7 @@ protected UserImpl wrapModel(UserInner userInner) { } @Override - public UserImpl getByName(String upnOrId) throws CloudException, IOException { + public UserImpl getByObjectId(String upnOrId) throws CloudException, IOException { return new UserImpl(innerCollection.get(upnOrId).getBody(), innerCollection); } } diff --git a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java index 0c20738fffbc..2a01c8d881ef 100644 --- a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java +++ b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java @@ -8,7 +8,6 @@ import com.microsoft.azure.management.graphrbac.ServicePrincipal; import com.microsoft.azure.management.graphrbac.User; -import com.microsoft.azure.management.resources.ResourceGroup; import com.microsoft.azure.management.resources.fluentcore.arm.Region; import org.junit.AfterClass; import org.junit.Assert; @@ -20,7 +19,6 @@ public class VaultTests extends KeyVaultManagementTestBase { private static final String RG_NAME = "javacsmrg901"; private static final String VAULT_NAME = "java-keyvault-901"; - private static ResourceGroup resourceGroup; @BeforeClass public static void setup() throws Exception { @@ -35,8 +33,8 @@ public static void cleanup() throws Exception { @Test public void canCRUDVault() throws Exception { // CREATE - ServicePrincipal sp = graphRbacManager.servicePrincipals().getByName(credentials.getClientId()); - User user = graphRbacManager.users().getByName("azuresdk@outlook.com"); + ServicePrincipal sp = graphRbacManager.servicePrincipals().getByServicePrincipalName("app-123"); + User user = graphRbacManager.users().getByUserPrincipalName("azuresdk@outlook.com"); Vault vault = keyVaultManager.vaults().define(VAULT_NAME) .withRegion(Region.US_WEST) .withNewResourceGroup(RG_NAME) From fd4ce079a84c662d8a11e23a933fb4d7a33baa4e Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 3 Aug 2016 17:59:29 -0700 Subject: [PATCH 08/33] Add group & add graph endpoints to AzureEnvironment --- .../azure/management/graphrbac/Group.java | 96 +++++++++++++++++++ .../azure/management/graphrbac/Groups.java | 43 +++++++++ .../implementation/ServicePrincipalsImpl.java | 10 ++ .../graphrbac/implementation/UsersImpl.java | 13 ++- .../GraphRbacManagementTestBase.java | 20 +++- .../management/graphrbac/GroupsTests.java | 35 +++++++ .../management/graphrbac/UsersTests.java | 41 ++++++++ .../ApplicationTokenCredentials.java | 4 +- .../credentials/UserTokenCredentials.java | 2 +- .../com/microsoft/azure/AzureEnvironment.java | 66 ++++++++----- 10 files changed, 293 insertions(+), 37 deletions(-) create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Group.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Groups.java create mode 100644 azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GroupsTests.java create mode 100644 azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/UsersTests.java diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Group.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Group.java new file mode 100644 index 000000000000..a463a3253d05 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Group.java @@ -0,0 +1,96 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.graphrbac; + +import com.microsoft.azure.management.graphrbac.implementation.ADGroupInner; +import com.microsoft.azure.management.resources.fluentcore.model.Creatable; +import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; + +/** + * An immutable client-side representation of an Azure tenant. + */ +public interface Group extends + Wrapper { + /** + * @return object Id. + */ + String objectId(); + + /** + * @return object type. + */ + String objectType(); + + /** + * @return group display name. + */ + String displayName(); + + /** + * @return security enabled field. + */ + Boolean securityEnabled(); + + /** + * @return mail field. + */ + String mail(); + + /************************************************************** + * Fluent interfaces to provision a StorageAccount + **************************************************************/ + + /** + * Container interface for all the definitions that need to be implemented. + */ + interface Definition extends + DefinitionStages.Blank, + DefinitionStages.WithDisplayName, + DefinitionStages.WithMailNickname, + DefinitionStages.WithCreate { + } + + /** + * Grouping of all the storage account definition stages. + */ + interface DefinitionStages { + /** + * The first stage of the storage account definition. + */ + interface Blank extends WithDisplayName { + } + + interface WithDisplayName { + WithMailNickname withDisplayName(String displayName); + } + + interface WithMailNickname { + WithCreate withMailNickname(String mailNickname); + } + + /** + * A storage account definition with sufficient inputs to create a new + * storage account in the cloud, but exposing additional optional inputs to + * specify. + */ + interface WithCreate extends + Creatable { + } + } + + /** + * Grouping of all the storage account update stages. + */ + interface UpdateStages { + } + + /** + * The template for a storage account update operation, containing all the settings that can be modified. + */ + interface Update { + } +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Groups.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Groups.java new file mode 100644 index 000000000000..8046c554d4ca --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Groups.java @@ -0,0 +1,43 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.graphrbac; + +import com.microsoft.azure.CloudException; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +import java.io.IOException; +import java.util.List; + +/** + * Entry point to tenant management API. + */ +public interface Groups extends + SupportsCreating, + SupportsListing, + SupportsDeleting { + /** + * Gets the information about a user. + * + * @param objectId the unique object id + * @return an immutable representation of the resource + * @throws CloudException exceptions thrown from the cloud + * @throws IOException exceptions thrown from serialization/deserialization + */ + Group getByObjectId(String objectId) throws CloudException, IOException; + + /** + * Gets the information about a user. + * + * @param displayNamePrefix the partial prefix of the display name to search + * @return an immutable representation of the resource + * @throws CloudException exceptions thrown from the cloud + * @throws IOException exceptions thrown from serialization/deserialization + */ + List searchByDisplayName(String displayNamePrefix) throws CloudException, IOException; +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java index f7dd5eb67171..01554b23ed91 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java @@ -62,4 +62,14 @@ protected ServicePrincipalImpl wrapModel(ServicePrincipalInner servicePrincipalI public ServicePrincipalImpl getByObjectId(String objectId) throws CloudException, IOException { return new ServicePrincipalImpl(innerCollection.get(objectId).getBody(), innerCollection); } + + @Override + public ServicePrincipal getByAppId(String appId) throws CloudException, IOException { + return null; + } + + @Override + public ServicePrincipal getByServicePrincipalName(String spn) throws CloudException, IOException { + return null; + } } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java index 7263192dcd89..95344f3aca06 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java @@ -44,8 +44,8 @@ public void delete(String id) throws Exception { } @Override - public UserImpl define(String userPrincipalName) { - return wrapModel(userPrincipalName); + public UserImpl define(String name) { + return wrapModel(name); } @Override @@ -59,7 +59,12 @@ protected UserImpl wrapModel(UserInner userInner) { } @Override - public UserImpl getByObjectId(String upnOrId) throws CloudException, IOException { - return new UserImpl(innerCollection.get(upnOrId).getBody(), innerCollection); + public UserImpl getByObjectId(String objectId) throws CloudException, IOException { + return new UserImpl(innerCollection.get(objectId).getBody(), innerCollection); + } + + @Override + public UserImpl getByUserPrincipalName(String upn) throws CloudException, IOException { + return new UserImpl(innerCollection.get(upn).getBody(), innerCollection); } } diff --git a/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java b/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java index b3fb18e2acf4..dcf676ac7830 100644 --- a/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java +++ b/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java @@ -6,7 +6,8 @@ package com.microsoft.azure.management.graphrbac; -import com.microsoft.azure.credentials.ApplicationTokenCredentials; +import com.microsoft.azure.AzureEnvironment; +import com.microsoft.azure.credentials.UserTokenCredentials; import com.microsoft.azure.management.graphrbac.implementation.GraphRbacManager; import okhttp3.logging.HttpLoggingInterceptor; @@ -17,12 +18,21 @@ public abstract class GraphRbacManagementTestBase { protected static GraphRbacManager graphRbacManager; protected static void createClients() { - ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( - System.getenv("client-id"), +// ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( +// System.getenv("client-id"), +// System.getenv("domain"), +// System.getenv("secret"), +// "https://graph.windows.net", +// null); + UserTokenCredentials credentials = new UserTokenCredentials( + "1950a258-227b-4e31-a9cf-717495945fc2", System.getenv("domain"), - System.getenv("secret"), + System.getenv("username"), + System.getenv("password"), "https://graph.windows.net", - null); + "https://graph.windows.net", + AzureEnvironment.AZURE + ); graphRbacManager = GraphRbacManager .configure() diff --git a/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GroupsTests.java b/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GroupsTests.java new file mode 100644 index 000000000000..37d0f0df6792 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GroupsTests.java @@ -0,0 +1,35 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.graphrbac; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.List; + +public class GroupsTests extends GraphRbacManagementTestBase { + private static final String RG_NAME = "javacsmrg350"; + private static final String APP_NAME = "app-javacsm350"; + + @BeforeClass + public static void setup() throws Exception { + createClients(); + } + + @AfterClass + public static void cleanup() throws Exception { + } + + @Test + public void getServicePrincipal() throws Exception { + List servicePrincipals = graphRbacManager.servicePrincipals().list(); + Assert.assertNotNull(servicePrincipals); + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/UsersTests.java b/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/UsersTests.java new file mode 100644 index 000000000000..19eb9a0eb3f0 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/UsersTests.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.graphrbac; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.List; + +public class UsersTests extends GraphRbacManagementTestBase { + private static final String RG_NAME = "javacsmrg350"; + private static final String APP_NAME = "app-javacsm350"; + + @BeforeClass + public static void setup() throws Exception { + createClients(); + } + + @AfterClass + public static void cleanup() throws Exception { + } + + @Test + public void canCRUDUser() throws Exception { + //LIST + List userList = graphRbacManager.users().list(); + Assert.assertNotNull(userList); + User user = graphRbacManager.users().define("jeffrolfnlu@hotmail.com") + .withDisplayName("Test User 309") + .withPassword("Pa$$w0rd") + .withMailNickname("") + .create(); + } + +} diff --git a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java index abe3a65c9bdd..cc34d1cea766 100644 --- a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java +++ b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java @@ -58,7 +58,7 @@ public ApplicationTokenCredentials(String clientId, String domain, String secret } else { this.environment = environment; } - this.resourceEndpoint = this.environment.getTokenAudience(); + this.resourceEndpoint = this.environment.getManagementEndpoint(); } /** @@ -155,7 +155,7 @@ public static ApplicationTokenCredentials fromFile(File credentialsFile) throws Properties authSettings = new Properties(); authSettings.put(CredentialSettings.AUTH_URL.toString(), AzureEnvironment.AZURE.getAuthenticationEndpoint()); authSettings.put(CredentialSettings.BASE_URL.toString(), AzureEnvironment.AZURE.getBaseUrl()); - authSettings.put(CredentialSettings.MANAGEMENT_URI.toString(), AzureEnvironment.AZURE.getTokenAudience()); + authSettings.put(CredentialSettings.MANAGEMENT_URI.toString(), AzureEnvironment.AZURE.getManagementEndpoint()); // Load the credentials from the file FileInputStream credentialsFileStream = new FileInputStream(credentialsFile); diff --git a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java index c37479771a9b..b703d50ca117 100644 --- a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java +++ b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java @@ -61,7 +61,7 @@ public UserTokenCredentials(String clientId, String domain, String username, Str } else { this.environment = environment; } - this.resourceEndpoint = this.environment.getTokenAudience(); + this.resourceEndpoint = this.environment.getManagementEndpoint(); } /** diff --git a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java index 897e29b622c0..df8a724e7954 100644 --- a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java +++ b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java @@ -14,17 +14,22 @@ public final class AzureEnvironment { /** * Base URL for calls to Azure management API. */ - private final String baseURL; + private final String resourceManagerEndpoint; /** - * ActiveDirectory Endpoint for the Azure Environment. + * ActiveDirectory Endpoint for the authentications. */ private String authenticationEndpoint; /** - * Token audience for an endpoint. + * Base URL for calls to service management and authentications to Active Directory. */ - private String tokenAudience; + private String managementEndpoint; + + /** + * Base URL for calls to graph API. + */ + private String graphEndpoint; /** * Determines whether the authentication endpoint should @@ -36,20 +41,20 @@ public final class AzureEnvironment { * Initializes an instance of AzureEnvironment class. * * @param authenticationEndpoint ActiveDirectory Endpoint for the Azure Environment. - * @param tokenAudience token audience for an endpoint. - * @param validateAuthority whether the authentication endpoint should - * be validated with Azure AD. - * @param baseUrl the base URL for the current environment. + * @param managementEndpoint token audience for an endpoint. + * @param resourceManagerEndpoint the base URL for the current environment. + * @param graphEndpoint the base URL for graph API. */ public AzureEnvironment( String authenticationEndpoint, - String tokenAudience, - boolean validateAuthority, - String baseUrl) { + String managementEndpoint, + String resourceManagerEndpoint, + String graphEndpoint) { this.authenticationEndpoint = authenticationEndpoint; - this.tokenAudience = tokenAudience; - this.validateAuthority = validateAuthority; - this.baseURL = baseUrl; + this.managementEndpoint = managementEndpoint; + this.resourceManagerEndpoint = resourceManagerEndpoint; + this.graphEndpoint = graphEndpoint; + this.validateAuthority = true; } /** @@ -58,8 +63,8 @@ public AzureEnvironment( public static final AzureEnvironment AZURE = new AzureEnvironment( "https://login.microsoftonline.com/", "https://management.core.windows.net/", - true, - "https://management.azure.com/"); + "https://management.azure.com/", + "https://graph.windows.net/"); /** * Provides the settings for authentication with Azure China. @@ -67,8 +72,8 @@ public AzureEnvironment( public static final AzureEnvironment AZURE_CHINA = new AzureEnvironment( "https://login.chinacloudapi.cn/", "https://management.core.chinacloudapi.cn/", - true, - "https://management.chinacloudapi.cn/"); + "https://management.chinacloudapi.cn/", + "https://graph.chinacloudapi.cn/"); /** * Provides the settings for authentication with Azure US Government. @@ -76,8 +81,8 @@ public AzureEnvironment( public static final AzureEnvironment AZURE_US_GOVERNMENT = new AzureEnvironment( "https://login.microsoftonline.com/", "https://management.core.usgovcloudapi.net/", - true, - "https://management.usgovcloudapi.net/"); + "https://management.usgovcloudapi.net/", + "https://graph.windows.net/"); /** * Provides the settings for authentication with Azure Germany. @@ -85,8 +90,8 @@ public AzureEnvironment( public static final AzureEnvironment AZURE_GERMANY = new AzureEnvironment( "https://login.microsoftonline.de/", "https://management.core.cloudapi.de/", - true, - "https://management.microsoftazure.de/"); + "https://management.microsoftazure.de/", + "https://graph.cloudapi.de/"); /** * Gets the base URL of the management service. @@ -94,7 +99,7 @@ public AzureEnvironment( * @return the Base URL for the management service. */ public String getBaseUrl() { - return this.baseURL; + return this.resourceManagerEndpoint; } /** @@ -122,8 +127,8 @@ public String getAuthenticationEndpoint() { * * @return the token audience for an endpoint. */ - public String getTokenAudience() { - return tokenAudience; + public String getManagementEndpoint() { + return managementEndpoint; } /** @@ -136,4 +141,15 @@ public String getTokenAudience() { public boolean isValidateAuthority() { return validateAuthority; } + + /** + * Sets whether the authentication endpoint should + * be validated with Azure AD. + * + * @param validateAuthority true if the authentication endpoint should + * be validated with Azure AD, false otherwise. + */ + public void setValidateAuthority(boolean validateAuthority) { + this.validateAuthority = validateAuthority; + } } From 1d9c0c339ddb625c8c18b60f5f1f76db20d3729c Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 3 Aug 2016 18:04:16 -0700 Subject: [PATCH 09/33] Address some review feedback --- .../management/keyvault/AccessPolicy.java | 16 ++-------- .../azure/management/keyvault/Vault.java | 30 ++++++++----------- .../keyvault/implementation/VaultImpl.java | 12 ++++---- 3 files changed, 21 insertions(+), 37 deletions(-) diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java index f7d2dab4e554..f2ee55ee9a8e 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java @@ -6,7 +6,7 @@ package com.microsoft.azure.management.keyvault; -import com.microsoft.azure.CloudException; +import com.microsoft.azure.management.graphrbac.Group; import com.microsoft.azure.management.graphrbac.ServicePrincipal; import com.microsoft.azure.management.graphrbac.User; import com.microsoft.azure.management.resources.fluentcore.arm.models.ChildResource; @@ -14,7 +14,6 @@ import com.microsoft.azure.management.resources.fluentcore.model.Settable; import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; -import java.io.IOException; import java.util.List; import java.util.UUID; @@ -70,6 +69,7 @@ interface Blank extends WithIdentity { interface WithIdentity { WithAttach forObjectId(UUID objectId); WithAttach forUser(User user); + WithAttach forGroup(Group user); WithAttach forServicePrincipal(ServicePrincipal servicePrincipal); } @@ -155,18 +155,6 @@ interface Update extends Settable{ } - interface AppAuthorizationStages { - /** - * The access policy definition stage allowing permissions to be added. - */ - interface WithPermissions extends WithPermissionsBase { - } - } - - interface Authorize extends AppAuthorizationStages.WithPermissions { - void authorize() throws CloudException, IOException; - } - interface WithPermissionsBase { T allowKeyDecrypting(); T allowKeyEncrypting(); diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java index a761c132dbd0..6d391b5284c9 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java @@ -66,8 +66,6 @@ public interface Vault extends */ Boolean enabledForTemplateDeployment(); - AccessPolicy.AppAuthorizationStages.WithPermissions defineAppAuthorization(String applicationId); - /************************************************************** * Fluent interfaces to provision a Vault **************************************************************/ @@ -78,7 +76,6 @@ public interface Vault extends interface Definition extends DefinitionStages.Blank, DefinitionStages.WithGroup, - DefinitionStages.WithTenantIdOrAccessPolicy, DefinitionStages.WithCreate { } @@ -95,14 +92,7 @@ interface Blank extends DefinitionWithRegion { /** * A key vault definition allowing resource group to be set. */ - interface WithGroup extends GroupableResource.DefinitionStages.WithGroup { - } - - interface WithTenantIdOrAccessPolicy extends WithTenantId, WithAccessPolicy { - } - - interface WithTenantId { - WithAccessPolicy withTenantId(UUID tenantId); + interface WithGroup extends GroupableResource.DefinitionStages.WithGroup { } /** @@ -125,9 +115,12 @@ interface WithAccessPolicy { } interface WithConfigurations { - WithCreate enabledForDeployment(boolean enabled); - WithCreate enabledForDiskEncryption(boolean enabled); - WithCreate enabledForTemplateDeployment(boolean enabled); + WithCreate enableDeployment(); + WithCreate enableDiskEncryption(); + WithCreate enableTemplateDeployment(); + WithCreate disableDeployment(); + WithCreate disableDiskEncryption(); + WithCreate disableTemplateDeployment(); } /** @@ -155,9 +148,12 @@ interface WithAccessPolicy { } interface WithConfigurations { - Update enabledForDeployment(boolean enabled); - Update enabledForDiskEncryption(boolean enabled); - Update enabledForTemplateDeployment(boolean enabled); + Update enableDeployment(); + Update enableDiskEncryption(); + Update enableTemplateDeployment(); + Update disableDeployment(); + Update disableDiskEncryption(); + Update disableTemplateDeployment(); } } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java index e957e2ec6ce5..22671d760fd5 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java @@ -125,20 +125,20 @@ public AccessPolicyImpl defineAccessPolicy() { } @Override - public VaultImpl enabledForDeployment(boolean enabled) { - inner().properties().withEnabledForDeployment(enabled); + public VaultImpl enableDeployment() { + inner().properties().withEnabledForDeployment(true); return this; } @Override - public VaultImpl enabledForDiskEncryption(boolean enabled) { - inner().properties().withEnabledForDiskEncryption(enabled); + public VaultImpl enableDiskEncryption() { + inner().properties().withEnabledForDiskEncryption(true); return this; } @Override - public VaultImpl enabledForTemplateDeployment(boolean enabled) { - inner().properties().withEnabledForTemplateDeployment(enabled); + public VaultImpl enableTemplateDeployment() { + inner().properties().withEnabledForTemplateDeployment(true); return this; } From 622029cd44fd611deea739d79f029d70d343c560 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 3 Aug 2016 18:35:50 -0700 Subject: [PATCH 10/33] Basic impl for vault --- .../management/keyvault/AccessPolicy.java | 87 ++--- .../azure/management/keyvault/Vault.java | 3 +- .../implementation/AccessPolicyImpl.java | 324 ++---------------- .../keyvault/implementation/VaultImpl.java | 84 ++++- .../azure/management/keyvault/VaultTests.java | 9 - .../azure/management/redis/SkuFamily.java | 22 +- 6 files changed, 139 insertions(+), 390 deletions(-) diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java index f2ee55ee9a8e..e62eb48261a6 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java @@ -69,7 +69,7 @@ interface Blank extends WithIdentity { interface WithIdentity { WithAttach forObjectId(UUID objectId); WithAttach forUser(User user); - WithAttach forGroup(Group user); + WithAttach forGroup(Group group); WithAttach forServicePrincipal(ServicePrincipal servicePrincipal); } @@ -77,7 +77,14 @@ interface WithIdentity { * The access policy definition stage allowing permissions to be added. * @param the return type of the final {@link WithAttach#attach()} */ - interface WithPermissions extends WithPermissionsBase> { + interface WithPermissions { + WithAttach allowKeyAllPermissions(); + WithAttach allowKeyPermissions(KeyPermissions... permissions); + WithAttach allowKeyPermissions(List permissions); + WithAttach allowSecretAllPermissions(); + WithAttach allowSecretPermissions(SecretPermissions... permissions); + WithAttach allowSecretPermissions(List permissions); + } /** The final stage of the access policy definition. @@ -88,7 +95,7 @@ interface WithPermissions extends WithPermissionsBase the return type of {@link WithAttach#attach()} */ interface WithAttach extends - Attachable.InDefinition, + Attachable.InUpdate, WithPermissions { } } @@ -120,7 +127,13 @@ interface WithIdentity { * The access policy definition stage allowing permissions to be added. * @param the return type of the final {@link WithAttach#attach()} */ - interface WithPermissions extends WithPermissionsBase> { + interface WithPermissions { + WithAttach allowKeyAllPermissions(); + WithAttach allowKeyPermissions(KeyPermissions... permissions); + WithAttach allowKeyPermissions(List permissions); + WithAttach allowSecretAllPermissions(); + WithAttach allowSecretPermissions(SecretPermissions... permissions); + WithAttach allowSecretPermissions(List permissions); } /** The final stage of the access policy definition. @@ -143,7 +156,20 @@ interface UpdateStages { /** * The access policy definition stage allowing permissions to be added. */ - interface WithPermissions extends WithPermissionsBase { + interface WithPermissions { + Update allowKeyAllPermissions(); + Update allowKeyPermissions(KeyPermissions... permissions); + Update allowKeyPermissions(List permissions); + Update disallowKeyAllPermissions(); + Update disallowKeyPermissions(KeyPermissions... permissions); + Update disallowKeyPermissions(List permissions); + Update allowSecretAllPermissions(); + Update allowSecretPermissions(SecretPermissions... permissions); + Update allowSecretPermissions(List permissions); + Update disallowSecretAllPermissions(); + Update disallowSecretPermissions(SecretPermissions... permissions); + Update disallowSecretPermissions(List permissions); + } } @@ -154,56 +180,5 @@ interface Update extends UpdateStages.WithPermissions, Settable{ } - - interface WithPermissionsBase { - T allowKeyDecrypting(); - T allowKeyEncrypting(); - T allowKeyUnwrapping(); - T allowKeyWrapping(); - T allowKeyVerifying(); - T allowKeySigning(); - T allowKeyGetting(); - T allowKeyListing(); - T allowKeyUpdating(); - T allowKeyCreating(); - T allowKeyImporting(); - T allowKeyDeleting(); - T allowKeyBackingUp(); - T allowKeyRestoring(); - T allowKeyAllPermissions(); - T allowKeyPermission(String permission); - T allowKeyPermissions(List permissions); - T disallowKeyDecrypting(); - T disallowKeyEncrypting(); - T disallowKeyUnwrapping(); - T disallowKeyWrapping(); - T disallowKeyVerifying(); - T disallowKeySigning(); - T disallowKeyGetting(); - T disallowKeyListing(); - T disallowKeyUpdating(); - T disallowKeyCreating(); - T disallowKeyImporting(); - T disallowKeyDeleting(); - T disallowKeyBackingUp(); - T disallowKeyRestoring(); - T disallowKeyAllPermissions(); - T disallowKeyPermission(String permission); - T disallowKeyPermissions(List permissions); - T allowSecretGetting(); - T allowSecretListing(); - T allowSecretSetting(); - T allowSecretDeleting(); - T allowSecretAllPermissions(); - T allowSecretPermission(String permission); - T allowSecretPermissions(List permissions); - T disallowSecretGetting(); - T disallowSecretListing(); - T disallowSecretSetting(); - T disallowSecretDeleting(); - T disallowSecretAllPermissions(); - T disallowSecretPermission(String permission); - T disallowSecretPermissions(List permissions); - } } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java index 6d391b5284c9..0bbb56b4fffa 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java @@ -46,7 +46,7 @@ public interface Vault extends * identities in the array must use the same tenant ID as the key vault's * tenant ID. */ - List accessPolicies(); + List accessPolicies(); /** * @return Property to specify whether Azure Virtual Machines are permitted to @@ -76,6 +76,7 @@ public interface Vault extends interface Definition extends DefinitionStages.Blank, DefinitionStages.WithGroup, + DefinitionStages.WithAccessPolicy, DefinitionStages.WithCreate { } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java index 03db44b39218..f481ad570d39 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java @@ -6,15 +6,19 @@ package com.microsoft.azure.management.keyvault.implementation; +import com.microsoft.azure.management.graphrbac.Group; import com.microsoft.azure.management.graphrbac.ServicePrincipal; import com.microsoft.azure.management.graphrbac.User; import com.microsoft.azure.management.keyvault.AccessPolicy; import com.microsoft.azure.management.keyvault.AccessPolicyEntry; +import com.microsoft.azure.management.keyvault.KeyPermissions; import com.microsoft.azure.management.keyvault.Permissions; +import com.microsoft.azure.management.keyvault.SecretPermissions; import com.microsoft.azure.management.keyvault.Vault; import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.ChildResourceImpl; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.UUID; @@ -27,30 +31,9 @@ class AccessPolicyImpl VaultImpl> implements AccessPolicy, - AccessPolicy.Definition { - private enum ALLOWED_KEY_PERMISSIONS { - DECRYPT("Decrypt"), ENCRYPT("Encrypt"), UNWRAPKEY("UnwrapKey"), WRAPKEY("WrapKey"), VERIFY("Verify"), SIGN("Sign"), GET("Get"), LIST("List"), UPDATE("Update"), CREATE("Create"), IMPORT("Import"), DELETE("Delete"), BACKUP("Backup"), RESTORE("Restore"), ALL("All"); - private String value; - ALLOWED_KEY_PERMISSIONS(String value) { - this.value = value; - } - @Override - public String toString() { - return value; - } - } - - private enum ALLOWED_SECRET_PERMISSIONS { - GET("Get"), LIST("List"), SET("Set"), DELETE("Delete"), ALL("All"); - private String value; - ALLOWED_SECRET_PERMISSIONS(String value) { - this.value = value; - } - @Override - public String toString() { - return value; - } - } + AccessPolicy.Definition, + AccessPolicy.UpdateDefinition, + AccessPolicy.Update { AccessPolicyImpl(AccessPolicyEntry innerObject, VaultImpl parent) { super(null, innerObject, parent); @@ -86,7 +69,7 @@ private void initializeKeyPermissions() { inner().withPermissions(new Permissions()); } if (inner().permissions().keys() == null) { - inner().permissions().withKeys(new ArrayList()); + inner().permissions().withKeys(new ArrayList()); } } @@ -95,33 +78,33 @@ private void initializeSecretPermissions() { inner().withPermissions(new Permissions()); } if (inner().permissions().secrets() == null) { - inner().permissions().withSecrets(new ArrayList()); + inner().permissions().withSecrets(new ArrayList()); } } @Override - public AccessPolicyImpl allowKeyPermission(String permission) { + public AccessPolicyImpl allowKeyPermissions(KeyPermissions... permissions) { initializeKeyPermissions(); - inner().permissions().keys().add(permission); + inner().permissions().keys().addAll(Arrays.asList(permissions)); return this; } @Override - public AccessPolicyImpl allowKeyPermissions(List permissions) { + public AccessPolicyImpl allowKeyPermissions(List permissions) { initializeKeyPermissions(); inner().permissions().keys().addAll(permissions); return this; } @Override - public AccessPolicyImpl allowSecretPermission(String permission) { + public AccessPolicyImpl allowSecretPermissions(SecretPermissions... permissions) { initializeSecretPermissions(); - inner().permissions().secrets().add(permission); + inner().permissions().secrets().addAll(Arrays.asList(permissions)); return this; } @Override - public AccessPolicyImpl allowSecretPermissions(List permissions) { + public AccessPolicyImpl allowSecretPermissions(List permissions) { initializeSecretPermissions(); inner().permissions().secrets().addAll(permissions); return this; @@ -146,213 +129,21 @@ public AccessPolicyImpl forUser(User user) { } @Override - public AccessPolicyImpl forServicePrincipal(ServicePrincipal servicePrincipal) { - inner().withObjectId(UUID.fromString(servicePrincipal.objectId())); - return this; - } - - @Override - public AccessPolicyImpl allowKeyDecrypting() { - initializeKeyPermissions(); - inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.DECRYPT.toString()); - return this; - } - - @Override - public AccessPolicyImpl allowKeyEncrypting() { - initializeKeyPermissions(); - inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.ENCRYPT.toString()); - return this; - } - - @Override - public AccessPolicyImpl allowKeyUnwrapping() { - initializeKeyPermissions(); - inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.UNWRAPKEY.toString()); - return this; - } - - @Override - public AccessPolicyImpl allowKeyWrapping() { - initializeKeyPermissions(); - inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.WRAPKEY.toString()); - return this; - } - - @Override - public AccessPolicyImpl allowKeyVerifying() { - initializeKeyPermissions(); - inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.VERIFY.toString()); - return this; - } - - @Override - public AccessPolicyImpl allowKeySigning() { - initializeKeyPermissions(); - inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.SIGN.toString()); - return this; - } - - @Override - public AccessPolicyImpl allowKeyGetting() { - initializeKeyPermissions(); - inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.GET.toString()); - return this; - } - - @Override - public AccessPolicyImpl allowKeyListing() { - initializeKeyPermissions(); - inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.LIST.toString()); - return this; - } - - @Override - public AccessPolicyImpl allowKeyUpdating() { - initializeKeyPermissions(); - inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.UPDATE.toString()); - return this; - } - - @Override - public AccessPolicyImpl allowKeyCreating() { - initializeKeyPermissions(); - inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.CREATE.toString()); - return this; - } - - @Override - public AccessPolicyImpl allowKeyImporting() { - initializeKeyPermissions(); - inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.IMPORT.toString()); - return this; - } - - @Override - public AccessPolicyImpl allowKeyDeleting() { - initializeKeyPermissions(); - inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.DELETE.toString()); - return this; - } - - @Override - public AccessPolicyImpl allowKeyBackingUp() { - initializeKeyPermissions(); - inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.BACKUP.toString()); + public AccessPolicyImpl forGroup(Group group) { + inner().withObjectId(UUID.fromString(group.objectId())); return this; } @Override - public AccessPolicyImpl allowKeyRestoring() { - initializeKeyPermissions(); - inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.RESTORE.toString()); + public AccessPolicyImpl forServicePrincipal(ServicePrincipal servicePrincipal) { + inner().withObjectId(UUID.fromString(servicePrincipal.objectId())); return this; } @Override public AccessPolicyImpl allowKeyAllPermissions() { initializeKeyPermissions(); - for(ALLOWED_KEY_PERMISSIONS permission : ALLOWED_KEY_PERMISSIONS.values()) { - inner().permissions().keys().add(permission.toString()); - } - return this; - } - - @Override - public AccessPolicyImpl disallowKeyDecrypting() { - initializeKeyPermissions(); - inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.DECRYPT.toString()); - return this; - } - - @Override - public AccessPolicyImpl disallowKeyEncrypting() { - initializeKeyPermissions(); - inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.ENCRYPT.toString()); - return this; - } - - @Override - public AccessPolicyImpl disallowKeyUnwrapping() { - initializeKeyPermissions(); - inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.UNWRAPKEY.toString()); - return this; - } - - @Override - public AccessPolicyImpl disallowKeyWrapping() { - initializeKeyPermissions(); - inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.WRAPKEY.toString()); - return this; - } - - @Override - public AccessPolicyImpl disallowKeyVerifying() { - initializeKeyPermissions(); - inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.VERIFY.toString()); - return this; - } - - @Override - public AccessPolicyImpl disallowKeySigning() { - initializeKeyPermissions(); - inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.SIGN.toString()); - return this; - } - - @Override - public AccessPolicyImpl disallowKeyGetting() { - initializeKeyPermissions(); - inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.GET.toString()); - return this; - } - - @Override - public AccessPolicyImpl disallowKeyListing() { - initializeKeyPermissions(); - inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.LIST.toString()); - return this; - } - - @Override - public AccessPolicyImpl disallowKeyUpdating() { - initializeKeyPermissions(); - inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.UPDATE.toString()); - return this; - } - - @Override - public AccessPolicyImpl disallowKeyCreating() { - initializeKeyPermissions(); - inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.CREATE.toString()); - return this; - } - - @Override - public AccessPolicyImpl disallowKeyImporting() { - initializeKeyPermissions(); - inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.IMPORT.toString()); - return this; - } - - @Override - public AccessPolicyImpl disallowKeyDeleting() { - initializeKeyPermissions(); - inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.DELETE.toString()); - return this; - } - - @Override - public AccessPolicyImpl disallowKeyBackingUp() { - initializeKeyPermissions(); - inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.BACKUP.toString()); - return this; - } - - @Override - public AccessPolicyImpl disallowKeyRestoring() { - initializeKeyPermissions(); - inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.RESTORE.toString()); + // TODO: Add all return this; } @@ -364,98 +155,43 @@ public AccessPolicyImpl disallowKeyAllPermissions() { } @Override - public AccessPolicyImpl disallowKeyPermission(String permission) { - initializeKeyPermissions(); - inner().permissions().keys().remove(permission); - return this; - } - - @Override - public AccessPolicyImpl disallowKeyPermissions(List permissions) { - initializeKeyPermissions(); - inner().permissions().keys().removeAll(permissions); - return this; - } - - @Override - public AccessPolicyImpl allowSecretGetting() { - initializeSecretPermissions(); - inner().permissions().keys().add(ALLOWED_SECRET_PERMISSIONS.GET.toString()); - return this; - } - - @Override - public AccessPolicyImpl allowSecretListing() { - initializeSecretPermissions(); - inner().permissions().keys().add(ALLOWED_SECRET_PERMISSIONS.LIST.toString()); - return this; - } - - @Override - public AccessPolicyImpl allowSecretSetting() { + public AccessPolicyImpl disallowKeyPermissions(KeyPermissions... permissions) { initializeSecretPermissions(); - inner().permissions().keys().add(ALLOWED_SECRET_PERMISSIONS.SET.toString()); + inner().permissions().keys().removeAll(Arrays.asList(permissions)); return this; } @Override - public AccessPolicyImpl allowSecretDeleting() { + public AccessPolicyImpl disallowKeyPermissions(List permissions) { initializeSecretPermissions(); - inner().permissions().keys().add(ALLOWED_SECRET_PERMISSIONS.DELETE.toString()); + inner().permissions().keys().removeAll(permissions); return this; } @Override public AccessPolicyImpl allowSecretAllPermissions() { + // TODO: add all return null; } - @Override - public AccessPolicyImpl disallowSecretGetting() { - initializeSecretPermissions(); - inner().permissions().keys().remove(ALLOWED_SECRET_PERMISSIONS.GET.toString()); - return this; - } - - @Override - public AccessPolicyImpl disallowSecretListing() { - initializeSecretPermissions(); - inner().permissions().keys().remove(ALLOWED_SECRET_PERMISSIONS.LIST.toString()); - return this; - } - - @Override - public AccessPolicyImpl disallowSecretSetting() { - initializeSecretPermissions(); - inner().permissions().keys().remove(ALLOWED_SECRET_PERMISSIONS.SET.toString()); - return this; - } - - @Override - public AccessPolicyImpl disallowSecretDeleting() { - initializeSecretPermissions(); - inner().permissions().keys().remove(ALLOWED_SECRET_PERMISSIONS.DELETE.toString()); - return this; - } - @Override public AccessPolicyImpl disallowSecretAllPermissions() { initializeSecretPermissions(); - inner().permissions().keys().clear(); + inner().permissions().secrets().clear(); return this; } @Override - public AccessPolicyImpl disallowSecretPermission(String permission) { + public AccessPolicyImpl disallowSecretPermissions(SecretPermissions... permissions) { initializeSecretPermissions(); - inner().permissions().keys().remove(permission); + inner().permissions().secrets().removeAll(Arrays.asList(permissions)); return this; } @Override - public AccessPolicyImpl disallowSecretPermissions(List permissions) { + public AccessPolicyImpl disallowSecretPermissions(List permissions) { initializeSecretPermissions(); - inner().permissions().keys().removeAll(permissions); + inner().permissions().secrets().removeAll(permissions); return this; } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java index 22671d760fd5..d0e8da09b386 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java @@ -17,9 +17,11 @@ import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceResponse; import java.util.ArrayList; import java.util.List; +import java.util.NoSuchElementException; import java.util.UUID; /** @@ -67,11 +69,18 @@ public Sku sku() { } @Override - public List accessPolicies() { + public List accessPolicies() { if (inner().properties() == null) { return null; } - return inner().properties().accessPolicies(); + if (inner().properties().accessPolicies() == null) { + return null; + } + List accessPolicies = new ArrayList<>(); + for (AccessPolicyEntry entry : inner().properties().accessPolicies()) { + accessPolicies.add(new AccessPolicyImpl(entry, this)); + } + return accessPolicies; } @Override @@ -107,6 +116,11 @@ public VaultImpl withEmptyAccessPolicy() { return this; } + @Override + public Update withoutAccessPolicy(String objectId) { + return null; + } + @Override public VaultImpl withAccessPolicy(AccessPolicy accessPolicy) { if (inner().properties() == null) { @@ -124,6 +138,22 @@ public AccessPolicyImpl defineAccessPolicy() { return new AccessPolicyImpl(new AccessPolicyEntry(), this); } + @Override + public AccessPolicyImpl updateAccessPolicy(String objectId) { + if (inner().properties() == null) { + return null; + } + if (inner().properties().accessPolicies() == null) { + return null; + } + for (AccessPolicyEntry entry : inner().properties().accessPolicies()) { + if (entry.objectId().toString().equals(objectId)) { + return new AccessPolicyImpl(entry, this); + } + } + throw new NoSuchElementException(String.format("Identity %s not found in the access policies.", objectId)); + } + @Override public VaultImpl enableDeployment() { inner().properties().withEnabledForDeployment(true); @@ -143,36 +173,61 @@ public VaultImpl enableTemplateDeployment() { } @Override - public VaultImpl withSku(SkuName skuName) { - if (inner().properties() == null) { - inner().withProperties(new VaultProperties()); - } - inner().properties().withSku(new Sku().withName(skuName).withFamily(SkuFamily.A)); + public VaultImpl disableDeployment() { + inner().properties().withEnabledForDeployment(false); + return this; + } + + @Override + public VaultImpl disableDiskEncryption() { + inner().properties().withEnabledForDiskEncryption(false); return this; } @Override - public VaultImpl withTenantId(UUID tenantId) { + public VaultImpl disableTemplateDeployment() { + inner().properties().withEnabledForTemplateDeployment(false); + return this; + } + + @Override + public VaultImpl withSku(SkuName skuName) { if (inner().properties() == null) { inner().withProperties(new VaultProperties()); } - inner().properties().withTenantId(tenantId); + inner().properties().withSku(new Sku().withName(skuName).withFamily(SkuFamily.A)); return this; } @Override public VaultImpl apply() throws Exception { - return createResource(); + return create(); } @Override public ServiceCall applyAsync(ServiceCallback callback) { - return null; + return createAsync(callback); } @Override - public ServiceCall createResourceAsync(ServiceCallback serviceCallback) { - return null; + public ServiceCall createResourceAsync(final ServiceCallback serviceCallback) { + VaultCreateOrUpdateParametersInner parameters = new VaultCreateOrUpdateParametersInner(); + parameters.withLocation(regionName()); + parameters.withProperties(inner().properties()); + parameters.withTags(inner().getTags()); + final VaultImpl self = this; + return client.createOrUpdateAsync(resourceGroupName(), name(), parameters, new ServiceCallback() { + @Override + public void failure(Throwable t) { + serviceCallback.failure(t); + } + + @Override + public void success(ServiceResponse result) { + setInner(result.getBody()); + serviceCallback.success(new ServiceResponse(self, result.getResponse())); + } + }); } @Override @@ -187,6 +242,7 @@ public VaultImpl createResource() throws Exception { @Override public VaultImpl refresh() throws Exception { - return null; + setInner(client.get(resourceGroupName(), name()).getBody()); + return this; } } diff --git a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java index 2a01c8d881ef..d7c6f5ee6d15 100644 --- a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java +++ b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java @@ -70,19 +70,10 @@ public void canCRUDVault() throws Exception { .defineAccessPolicy() .forUser(user) .allowKeyAllPermissions() - .allowSecretGetting() - .allowSecretListing() .attach() .apply(); vault.update() .withoutAccessPolicy(sp.objectId()) .apply(); - // AUTHORIZE - vault.defineAppAuthorization("app-id") - .allowKeyListing() - .allowKeyGetting() - .allowSecretListing() - .allowSecretGetting() - .authorize(); } } diff --git a/azure-mgmt-redis/src/main/java/com/microsoft/azure/management/redis/SkuFamily.java b/azure-mgmt-redis/src/main/java/com/microsoft/azure/management/redis/SkuFamily.java index 4027ed51be40..5d1c4cf82083 100644 --- a/azure-mgmt-redis/src/main/java/com/microsoft/azure/management/redis/SkuFamily.java +++ b/azure-mgmt-redis/src/main/java/com/microsoft/azure/management/redis/SkuFamily.java @@ -8,12 +8,11 @@ package com.microsoft.azure.management.redis; -import com.fasterxml.jackson.annotation.JsonValue; - /** * Defines values for SkuFamily. */ public final class SkuFamily { +<<<<<<< 1d9c0c339ddb625c8c18b60f5f1f76db20d3729c:azure-mgmt-redis/src/main/java/com/microsoft/azure/management/redis/SkuFamily.java /** Static value C for SkuFamily. */ public static final SkuFamily C = new SkuFamily("C"); @@ -40,20 +39,11 @@ public String toString() { public int hashCode() { return value.hashCode(); } +======= + /** Static value A for SkuFamily. */ + public static final String A = "A"; +>>>>>>> Basic impl for vault:azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SkuFamily.java - @Override - public boolean equals(Object obj) { - if (!(obj instanceof SkuFamily)) { - return false; - } - if (obj == this) { - return true; - } - SkuFamily rhs = (SkuFamily) obj; - if (value == null) { - return rhs.value == null; - } else { - return value.equals(rhs.value); - } + private SkuFamily() { } } From e9aca426972ece888d34f20053ebf678b32d7a01 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Mon, 8 Aug 2016 11:41:25 -0700 Subject: [PATCH 11/33] default tenant id --- .../GraphRbacManagementTestBase.java | 0 .../management/graphrbac/GroupsTests.java | 0 .../graphrbac/ServicePrincipalsTests.java | 0 .../management/graphrbac/UsersTests.java | 0 .../implementation/KeyVaultManager.java | 39 +++++++++++++------ .../keyvault/implementation/VaultsImpl.java | 21 +++++++--- .../keyvault/KeyVaultManagementTestBase.java | 0 .../azure/management/keyvault/VaultTests.java | 3 -- 8 files changed, 44 insertions(+), 19 deletions(-) rename azure-mgmt-graph-rbac/src/main/test/{ => java}/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java (100%) rename azure-mgmt-graph-rbac/src/main/test/{ => java}/com/microsoft/azure/management/graphrbac/GroupsTests.java (100%) rename azure-mgmt-graph-rbac/src/main/test/{ => java}/com/microsoft/azure/management/graphrbac/ServicePrincipalsTests.java (100%) rename azure-mgmt-graph-rbac/src/main/test/{ => java}/com/microsoft/azure/management/graphrbac/UsersTests.java (100%) rename azure-mgmt-keyvault/src/main/test/{ => java}/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java (100%) rename azure-mgmt-keyvault/src/main/test/{ => java}/com/microsoft/azure/management/keyvault/VaultTests.java (95%) diff --git a/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java b/azure-mgmt-graph-rbac/src/main/test/java/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java similarity index 100% rename from azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java rename to azure-mgmt-graph-rbac/src/main/test/java/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java diff --git a/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GroupsTests.java b/azure-mgmt-graph-rbac/src/main/test/java/com/microsoft/azure/management/graphrbac/GroupsTests.java similarity index 100% rename from azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GroupsTests.java rename to azure-mgmt-graph-rbac/src/main/test/java/com/microsoft/azure/management/graphrbac/GroupsTests.java diff --git a/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/ServicePrincipalsTests.java b/azure-mgmt-graph-rbac/src/main/test/java/com/microsoft/azure/management/graphrbac/ServicePrincipalsTests.java similarity index 100% rename from azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/ServicePrincipalsTests.java rename to azure-mgmt-graph-rbac/src/main/test/java/com/microsoft/azure/management/graphrbac/ServicePrincipalsTests.java diff --git a/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/UsersTests.java b/azure-mgmt-graph-rbac/src/main/test/java/com/microsoft/azure/management/graphrbac/UsersTests.java similarity index 100% rename from azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/UsersTests.java rename to azure-mgmt-graph-rbac/src/main/test/java/com/microsoft/azure/management/graphrbac/UsersTests.java diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java index 59a7bf6f9077..d482876a88e3 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java @@ -7,7 +7,9 @@ package com.microsoft.azure.management.keyvault.implementation; import com.microsoft.azure.AzureEnvironment; +import com.microsoft.azure.RequestIdHeaderInterceptor; import com.microsoft.azure.RestClient; +import com.microsoft.azure.management.graphrbac.implementation.GraphRbacManager; import com.microsoft.azure.management.keyvault.Vaults; import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; @@ -18,8 +20,12 @@ * Entry point to Azure storage resource management. */ public final class KeyVaultManager extends Manager { + // Service managers + private GraphRbacManager graphRbacManager; // Collections private Vaults vaults; + // Variables + private final String tenantId; /** * Get a Configurable instance that can be used to create StorageManager with optional configuration. @@ -34,24 +40,26 @@ public static Configurable configure() { * Creates an instance of StorageManager that exposes storage resource management API entry points. * * @param credentials the credentials to use + * @param tenantId the tenant UUID * @param subscriptionId the subscription UUID * @return the StorageManager */ - public static KeyVaultManager authenticate(ServiceClientCredentials credentials, String subscriptionId) { + public static KeyVaultManager authenticate(ServiceClientCredentials credentials, String tenantId, String subscriptionId) { return new KeyVaultManager(AzureEnvironment.AZURE.newRestClientBuilder() .withCredentials(credentials) - .build(), subscriptionId); + .build(), tenantId, subscriptionId); } /** * Creates an instance of StorageManager that exposes storage resource management API entry points. * - * @param restClient the RestClient to be used for API calls. + * @param restClient the RestClient to be used for API calls + * @param tenantId the tenant UUID * @param subscriptionId the subscription UUID * @return the StorageManager */ - public static KeyVaultManager authenticate(RestClient restClient, String subscriptionId) { - return new KeyVaultManager(restClient, subscriptionId); + public static KeyVaultManager authenticate(RestClient restClient, String tenantId, String subscriptionId) { + return new KeyVaultManager(restClient, tenantId, subscriptionId); } /** @@ -62,27 +70,34 @@ public interface Configurable extends AzureConfigurable { * Creates an instance of StorageManager that exposes storage management API entry points. * * @param credentials the credentials to use + * @param tenantId the tenant UUID * @param subscriptionId the subscription UUID * @return the interface exposing storage management API entry points that work across subscriptions */ - KeyVaultManager authenticate(ServiceClientCredentials credentials, String subscriptionId); + KeyVaultManager authenticate(ServiceClientCredentials credentials, String tenantId, String subscriptionId); } /** * The implementation for Configurable interface. */ private static final class ConfigurableImpl extends AzureConfigurableImpl implements Configurable { - public KeyVaultManager authenticate(ServiceClientCredentials credentials, String subscriptionId) { - return KeyVaultManager.authenticate(buildRestClient(credentials), subscriptionId); + public KeyVaultManager authenticate(ServiceClientCredentials credentials, String tenantId, String subscriptionId) { + return KeyVaultManager.authenticate(buildRestClient(credentials), tenantId, subscriptionId); } } - private KeyVaultManager(RestClient restClient, String subscriptionId) { + private KeyVaultManager(RestClient restClient, String tenantId, String subscriptionId) { super( restClient, subscriptionId, new KeyVaultManagementClientImpl(restClient).withSubscriptionId(subscriptionId)); - } + graphRbacManager = GraphRbacManager.authenticate(new RestClient.Builder() + .withBaseUrl("https://graph.windows.net") + .withInterceptor(new RequestIdHeaderInterceptor()) + .withCredentials(restClient.credentials()) + .build(), tenantId); + this.tenantId = tenantId; + } /** * @return the storage account management API entry point @@ -91,7 +106,9 @@ public Vaults vaults() { if (vaults == null) { vaults = new VaultsImpl( super.innerManagementClient.vaults(), - this); + this, + graphRbacManager, + tenantId); } return vaults; } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java index f19965465424..c2fb25ad737c 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java @@ -8,13 +8,16 @@ import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.graphrbac.implementation.GraphRbacManager; import com.microsoft.azure.management.keyvault.SkuName; import com.microsoft.azure.management.keyvault.Vault; +import com.microsoft.azure.management.keyvault.VaultProperties; import com.microsoft.azure.management.keyvault.Vaults; import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; import java.io.IOException; +import java.util.UUID; /** * The implementation of StorageAccounts and its parent interfaces. @@ -27,11 +30,17 @@ class VaultsImpl VaultsInner, KeyVaultManager> implements Vaults { + private final GraphRbacManager graphRbacManager; + private final String tenantId; VaultsImpl( final VaultsInner client, - final KeyVaultManager keyVaultManager) { + final KeyVaultManager keyVaultManager, + final GraphRbacManager graphRbacManager, + final String tenantId) { super(client, keyVaultManager); + this.graphRbacManager = graphRbacManager; + this.tenantId = tenantId; } @Override @@ -68,18 +77,20 @@ public VaultImpl define(String name) { @Override protected VaultImpl wrapModel(String name) { + VaultInner inner = new VaultInner().withProperties(new VaultProperties()); + inner.properties().withTenantId(UUID.fromString(tenantId)); return new VaultImpl( name, - new VaultInner(), + inner, this.innerCollection, super.myManager); } @Override - protected VaultImpl wrapModel(VaultInner storageAccountInner) { + protected VaultImpl wrapModel(VaultInner vaultInner) { return new VaultImpl( - storageAccountInner.name(), - storageAccountInner, + vaultInner.name(), + vaultInner, this.innerCollection, super.myManager); } diff --git a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java b/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java similarity index 100% rename from azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java rename to azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java diff --git a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java b/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/VaultTests.java similarity index 95% rename from azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java rename to azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/VaultTests.java index d7c6f5ee6d15..22185e80d0c3 100644 --- a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java +++ b/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/VaultTests.java @@ -40,9 +40,6 @@ public void canCRUDVault() throws Exception { .withNewResourceGroup(RG_NAME) .defineAccessPolicy() .forServicePrincipal(sp) - .allowKeyGetting() - .allowKeyListing() - .allowKeyCreating() .allowSecretAllPermissions() .attach() .create(); From 4b86b42e356d2b9f2f39b56f9ba49d6729c50759 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Mon, 8 Aug 2016 11:52:31 -0700 Subject: [PATCH 12/33] Regen graph and a bunch of refactors --- .../implementation/AvailabilitySetsImpl.java | 2 +- .../VirtualMachineImagesImpl.java | 18 +- .../VirtualMachineImagesInSkuImpl.java | 3 +- .../VirtualMachineSkusImpl.java | 4 +- .../graphrbac/ServicePrincipals.java | 13 +- .../azure/management/graphrbac/Users.java | 9 +- .../implementation/ApplicationsInner.java | 664 +++++++++++++++++ .../graphrbac/implementation/GroupsInner.java | 522 ++++++++++++++ .../implementation/ObjectsInner.java | 37 + .../implementation/ServicePrincipalImpl.java | 5 + .../implementation/ServicePrincipalsImpl.java | 10 +- .../ServicePrincipalsInner.java | 677 ++++++++++++++++++ .../graphrbac/implementation/UserImpl.java | 5 + .../graphrbac/implementation/UsersImpl.java | 9 +- .../graphrbac/implementation/UsersInner.java | 354 +++++++++ .../implementation/AccessPolicyImpl.java | 2 +- .../keyvault/implementation/VaultsImpl.java | 3 +- .../keyvault/KeyVaultManagementTestBase.java | 2 +- .../implementation/NetworkInterfacesImpl.java | 2 +- .../network/implementation/NetworksImpl.java | 4 +- .../collection/SupportsListing.java | 3 +- .../DeploymentOperationsImpl.java | 1 + .../implementation/DeploymentsImpl.java | 12 +- .../implementation/FeaturesImpl.java | 3 +- .../FeaturesInResourceProviderImpl.java | 3 +- .../implementation/ResourceGroupsImpl.java | 2 +- .../implementation/SubscriptionsImpl.java | 3 +- .../resources/implementation/TenantsImpl.java | 4 +- .../implementation/StorageAccountsImpl.java | 2 +- .../storage/implementation/UsagesImpl.java | 1 + .../main/java/com/microsoft/azure/Azure.java | 5 +- .../java/com/microsoft/azure/AzureTests.java | 34 +- .../ApplicationTokenCredentials.java | 4 +- 33 files changed, 2361 insertions(+), 61 deletions(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetsImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetsImpl.java index 180f5f663df7..3dc3ba7d7027 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetsImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetsImpl.java @@ -36,7 +36,7 @@ class AvailabilitySetsImpl } @Override - public PagedList list() throws CloudException, IOException { + public PagedList list() throws RestException, IOException { return new GroupPagedList(this.myManager.resourceManager().resourceGroups().list()) { @Override public List listNextGroup(String resourceGroupName) throws RestException, IOException { diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImagesImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImagesImpl.java index 48ee88179860..715b064acb6f 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImagesImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImagesImpl.java @@ -35,7 +35,11 @@ public PagedList listByRegion(String regionName) throws Clo new ChildListFlattener<>(publishers, new ChildListFlattener.ChildListLoader() { @Override public PagedList loadList(VirtualMachinePublisher publisher) throws CloudException, IOException { - return publisher.offers().list(); + try { + return publisher.offers().list(); + } catch (com.microsoft.rest.RestException e) { + e.printStackTrace(); + } } }).flatten(); @@ -43,7 +47,11 @@ public PagedList loadList(VirtualMachinePublisher publisher new ChildListFlattener<>(offers, new ChildListFlattener.ChildListLoader() { @Override public PagedList loadList(VirtualMachineOffer offer) throws CloudException, IOException { - return offer.skus().list(); + try { + return offer.skus().list(); + } catch (com.microsoft.rest.RestException e) { + e.printStackTrace(); + } } }).flatten(); @@ -51,7 +59,11 @@ public PagedList loadList(VirtualMachineOffer offer) throws C new ChildListFlattener<>(skus, new ChildListFlattener.ChildListLoader() { @Override public PagedList loadList(VirtualMachineSku sku) throws CloudException, IOException { - return sku.images().list(); + try { + return sku.images().list(); + } catch (com.microsoft.rest.RestException e) { + e.printStackTrace(); + } } }).flatten(); diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImagesInSkuImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImagesInSkuImpl.java index 0883fb32b253..28d2ecfbb5e8 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImagesInSkuImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImagesInSkuImpl.java @@ -1,6 +1,5 @@ package com.microsoft.azure.management.compute.implementation; -import com.microsoft.azure.CloudException; import com.microsoft.azure.Page; import com.microsoft.azure.PagedList; import com.microsoft.azure.management.compute.VirtualMachineImage; @@ -25,7 +24,7 @@ class VirtualMachineImagesInSkuImpl implements VirtualMachineImagesInSku { this.innerCollection = innerCollection; } - public PagedList list() throws CloudException, IOException { + public PagedList list() throws RestException, IOException { final List images = new ArrayList<>(); for (VirtualMachineImageResourceInner inner : innerCollection.list( diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineSkusImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineSkusImpl.java index b672af42fb56..ec8e4e05310f 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineSkusImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineSkusImpl.java @@ -5,12 +5,12 @@ */ package com.microsoft.azure.management.compute.implementation; -import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; import com.microsoft.azure.management.compute.VirtualMachineOffer; import com.microsoft.azure.management.compute.VirtualMachineSkus; import com.microsoft.azure.management.compute.VirtualMachineSku; import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl; +import com.microsoft.rest.RestException; import java.io.IOException; @@ -30,7 +30,7 @@ class VirtualMachineSkusImpl } @Override - public PagedList list() throws CloudException, IOException { + public PagedList list() throws RestException, IOException { return wrapList(innerCollection.listSkus( offer.region().toString(), offer.publisher().name(), diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java index 0f38e19fa9d6..15714e3836e8 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java @@ -6,7 +6,6 @@ package com.microsoft.azure.management.graphrbac; -import com.microsoft.azure.CloudException; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; @@ -25,28 +24,28 @@ public interface ServicePrincipals extends * * @param objectId the unique object id * @return an immutable representation of the resource - * @throws CloudException exceptions thrown from the cloud + * @throws GraphErrorException exceptions thrown from the graph API * @throws IOException exceptions thrown from serialization/deserialization */ - ServicePrincipal getByObjectId(String objectId) throws CloudException, IOException; + ServicePrincipal getByObjectId(String objectId) throws GraphErrorException, IOException; /** * Gets the information about a service principal. * * @param appId the application id (or the client id) * @return an immutable representation of the resource - * @throws CloudException exceptions thrown from the cloud + * @throws GraphErrorException exceptions thrown from the graph API * @throws IOException exceptions thrown from serialization/deserialization */ - ServicePrincipal getByAppId(String appId) throws CloudException, IOException; + ServicePrincipal getByAppId(String appId) throws GraphErrorException, IOException; /** * Gets the information about a service principal. * * @param spn the service principal name * @return an immutable representation of the resource - * @throws CloudException exceptions thrown from the cloud + * @throws GraphErrorException exceptions thrown from the graph API * @throws IOException exceptions thrown from serialization/deserialization */ - ServicePrincipal getByServicePrincipalName(String spn) throws CloudException, IOException; + ServicePrincipal getByServicePrincipalName(String spn) throws GraphErrorException, IOException; } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java index 3b3de21766a5..e2432276fef9 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java @@ -6,7 +6,6 @@ package com.microsoft.azure.management.graphrbac; -import com.microsoft.azure.CloudException; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; @@ -25,18 +24,18 @@ public interface Users extends * * @param objectId the unique object id * @return an immutable representation of the resource - * @throws CloudException exceptions thrown from the cloud + * @throws GraphErrorException exceptions thrown from the graph API * @throws IOException exceptions thrown from serialization/deserialization */ - User getByObjectId(String objectId) throws CloudException, IOException; + User getByObjectId(String objectId) throws GraphErrorException, IOException; /** * Gets the information about a user. * * @param upn the user principal name * @return an immutable representation of the resource - * @throws CloudException exceptions thrown from the cloud + * @throws GraphErrorException exceptions thrown from the graph API * @throws IOException exceptions thrown from serialization/deserialization */ - User getByUserPrincipalName(String upn) throws CloudException, IOException; + User getByUserPrincipalName(String upn) throws GraphErrorException, IOException; } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationsInner.java index d77097b6d262..873c03b5635a 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationsInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationsInner.java @@ -96,6 +96,22 @@ interface ApplicationsService { @PATCH("{tenantID}/applications/{applicationObjectId}/passwordCredentials") Observable> updatePasswordCredentials(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body PasswordCredentialsUpdateParameters parameters, @Header("User-Agent") String userAgent); + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/applications/{applicationObjectId}/keyCredentials") + Call listKeyCredentials(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @PATCH("{tenantID}/applications/{applicationObjectId}/keyCredentials") + Call updateKeyCredentials(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body KeyCredentialsUpdateParameters parameters, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/applications/{applicationObjectId}/passwordCredentials") + Call listPasswordCredentials(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @PATCH("{tenantID}/applications/{applicationObjectId}/passwordCredentials") + Call updatePasswordCredentials(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body PasswordCredentialsUpdateParameters parameters, @Header("User-Agent") String userAgent); + } /** @@ -107,8 +123,24 @@ interface ApplicationsService { * @throws IllegalArgumentException exception thrown from invalid parameters * @return the ApplicationInner object if successful. */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public ApplicationInner create(ApplicationCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { return createWithServiceResponseAsync(parameters).toBlocking().single().getBody(); +======= + public ServiceResponse create(ApplicationCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(parameters); + Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return createDelegate(call.execute()); +>>>>>>> Regen graph and a bunch of refactors } /** @@ -116,6 +148,7 @@ public ApplicationInner create(ApplicationCreateParametersInner parameters) thro * * @param parameters Parameters to create an application. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall createAsync(ApplicationCreateParametersInner parameters, final ServiceCallback serviceCallback) { @@ -144,6 +177,11 @@ public ApplicationInner call(ServiceResponse response) { * @return the observable to the ApplicationInner object */ public Observable> createWithServiceResponseAsync(ApplicationCreateParametersInner parameters) { +======= + * @return the {@link Call} object + */ + public ServiceCall createAsync(ApplicationCreateParametersInner parameters, final ServiceCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -154,6 +192,7 @@ public Observable> createWithServiceResponseAs throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(parameters); +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -164,6 +203,24 @@ public Observable> call(Response } catch (Throwable t) { return Observable.error(t); } +======= + Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = createDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -216,7 +273,11 @@ public List call(ServiceResponse> respo * * @return the observable to the List<ApplicationInner> object */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public Observable>> listWithServiceResponseAsync() { +======= + public ServiceResponse> list() throws GraphErrorException, IOException, IllegalArgumentException { +>>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -257,6 +318,7 @@ public List list(String filter) throws GraphErrorException, IO * * @param filter The filters to apply on the operation * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listAsync(String filter, final ServiceCallback> serviceCallback) { @@ -274,6 +336,32 @@ public Observable> listAsync(String filter) { @Override public List call(ServiceResponse> response) { return response.getBody(); +======= + * @return the {@link Call} object + */ + public ServiceCall> listAsync(final ServiceCallback> serviceCallback) { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + final String filter = null; + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall> serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listDelegate(response); + serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); + } +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -282,9 +370,18 @@ public List call(ServiceResponse> respo * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. * * @param filter The filters to apply on the operation +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the observable to the List<ApplicationInner> object */ public Observable>> listWithServiceResponseAsync(String filter) { +======= + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<ApplicationInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> list(String filter) throws GraphErrorException, IOException, IllegalArgumentException { +>>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -330,6 +427,7 @@ public void delete(String applicationObjectId) throws GraphErrorException, IOExc * * @param applicationObjectId Application object id * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall deleteAsync(String applicationObjectId, final ServiceCallback serviceCallback) { @@ -361,12 +459,18 @@ public Observable> deleteWithServiceResponseAsync(String a if (applicationObjectId == null) { throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } +======= + * @return the {@link Call} object + */ + public ServiceCall> listAsync(String filter, final ServiceCallback> serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.delete(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -377,6 +481,21 @@ public Observable> call(Response response) { } catch (Throwable t) { return Observable.error(t); } +======= + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall> serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listDelegate(response); + serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -427,6 +546,7 @@ public ApplicationInner call(ServiceResponse response) { }); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 /** * Get an application by object Id. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. * @@ -460,6 +580,11 @@ public Observable> call(Response private ServiceResponse getDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(200, new TypeToken() { }.getType()) +======= + private ServiceResponse> listDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) +>>>>>>> Regen graph and a bunch of refactors .registerError(GraphErrorException.class) .build(response); } @@ -468,7 +593,10 @@ private ServiceResponse getDelegate(Response res * Update existing application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. * * @param applicationObjectId Application object id +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @param parameters Parameters to update an existing application. +======= +>>>>>>> Regen graph and a bunch of refactors * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters @@ -496,6 +624,7 @@ public ServiceCall patchAsync(String applicationObjectId, ApplicationUpdat * @param parameters Parameters to update an existing application. * @return the {@link ServiceResponse} object if successful. */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public Observable patchAsync(String applicationObjectId, ApplicationUpdateParametersInner parameters) { return patchWithServiceResponseAsync(applicationObjectId, parameters).map(new Func1, Void>() { @Override @@ -513,6 +642,9 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> patchWithServiceResponseAsync(String applicationObjectId, ApplicationUpdateParametersInner parameters) { +======= + public ServiceResponse delete(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { +>>>>>>> Regen graph and a bunch of refactors if (applicationObjectId == null) { throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } @@ -565,6 +697,7 @@ public List listKeyCredentials(String applicationObjectId) t * * @param applicationObjectId Application object id * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listKeyCredentialsAsync(String applicationObjectId, final ServiceCallback> serviceCallback) { @@ -593,6 +726,11 @@ public List call(ServiceResponse> r * @return the observable to the List<KeyCredentialInner> object */ public Observable>> listKeyCredentialsWithServiceResponseAsync(String applicationObjectId) { +======= + * @return the {@link Call} object + */ + public ServiceCall deleteAsync(String applicationObjectId, final ServiceCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (applicationObjectId == null) { throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } @@ -602,6 +740,7 @@ public Observable>> listKeyCredentialsW if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.listKeyCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -613,13 +752,37 @@ public Observable>> call(Response call = service.delete(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 private ServiceResponse> listKeyCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) +======= + private ServiceResponse deleteDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) +>>>>>>> Regen graph and a bunch of refactors .registerError(GraphErrorException.class) .build(response); } @@ -632,6 +795,7 @@ private ServiceResponse> listKeyCredentialsDelegate * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public void updateKeyCredentials(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { updateKeyCredentialsWithServiceResponseAsync(applicationObjectId).toBlocking().single().getBody(); } @@ -669,6 +833,9 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> updateKeyCredentialsWithServiceResponseAsync(String applicationObjectId) { +======= + public ServiceResponse get(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { +>>>>>>> Regen graph and a bunch of refactors if (applicationObjectId == null) { throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } @@ -714,6 +881,7 @@ public void updateKeyCredentials(String applicationObjectId, List updateKeyCredentialsAsync(String applicationObjectId, List value, final ServiceCallback serviceCallback) { @@ -744,6 +912,11 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> updateKeyCredentialsWithServiceResponseAsync(String applicationObjectId, List value) { +======= + * @return the {@link Call} object + */ + public ServiceCall getAsync(String applicationObjectId, final ServiceCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (applicationObjectId == null) { throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } @@ -753,6 +926,7 @@ public Observable> updateKeyCredentialsWithServiceResponse if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 Validator.validate(value); KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); parameters.withValue(value); @@ -766,6 +940,24 @@ public Observable> call(Response response) { } catch (Throwable t) { return Observable.error(t); } +======= + Call call = service.get(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -816,6 +1008,7 @@ public List call(ServiceResponse>> call(Response< private ServiceResponse> listPasswordCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) +======= + private ServiceResponse getDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(200, new TypeToken() { }.getType()) +>>>>>>> Regen graph and a bunch of refactors .registerError(GraphErrorException.class) .build(response); } @@ -858,6 +1056,10 @@ private ServiceResponse> listPasswordCredentia * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. * * @param applicationObjectId Application object id +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 +======= + * @param parameters Parameters to update an existing application. +>>>>>>> Regen graph and a bunch of refactors * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters @@ -883,6 +1085,7 @@ public ServiceCall updatePasswordCredentialsAsync(String applicationObject * @param applicationObjectId Application object id * @return the {@link ServiceResponse} object if successful. */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public Observable updatePasswordCredentialsAsync(String applicationObjectId) { return updatePasswordCredentialsWithServiceResponseAsync(applicationObjectId).map(new Func1, Void>() { @Override @@ -899,6 +1102,9 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> updatePasswordCredentialsWithServiceResponseAsync(String applicationObjectId) { +======= + public ServiceResponse patch(String applicationObjectId, ApplicationUpdateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { +>>>>>>> Regen graph and a bunch of refactors if (applicationObjectId == null) { throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } @@ -944,6 +1150,7 @@ public void updatePasswordCredentials(String applicationObjectId, List updatePasswordCredentialsAsync(String applicationObjectId, List value, final ServiceCallback serviceCallback) { @@ -974,15 +1181,27 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> updatePasswordCredentialsWithServiceResponseAsync(String applicationObjectId, List value) { +======= + * @return the {@link Call} object + */ + public ServiceCall patchAsync(String applicationObjectId, ApplicationUpdateParametersInner parameters, final ServiceCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (applicationObjectId == null) { throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 +======= + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); +>>>>>>> Regen graph and a bunch of refactors } if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 Validator.validate(value); PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); parameters.withValue(value); @@ -996,6 +1215,451 @@ public Observable> call(Response response) { } catch (Throwable t) { return Observable.error(t); } +======= + Validator.validate(parameters); + Call call = service.patch(applicationObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = patchDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse patchDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); + } + + /** + * Get keyCredentials associated with the application by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<KeyCredentialInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> listKeyCredentials(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.listKeyCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listKeyCredentialsDelegate(call.execute()); + List result = response.getBody().getItems(); + return new ServiceResponse<>(result, response.getResponse()); + } + + /** + * Get keyCredentials associated with the application by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link Call} object + */ + public ServiceCall> listKeyCredentialsAsync(String applicationObjectId, final ServiceCallback> serviceCallback) { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.listKeyCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall> serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listKeyCredentialsDelegate(response); + serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse> listKeyCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); + } + + /** + * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse updateKeyCredentials(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + final List value = null; + KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); + parameters.withValue(null); + Call call = service.updateKeyCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + return updateKeyCredentialsDelegate(call.execute()); + } + + /** + * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link Call} object + */ + public ServiceCall updateKeyCredentialsAsync(String applicationObjectId, final ServiceCallback serviceCallback) { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + final List value = null; + KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); + parameters.withValue(null); + Call call = service.updateKeyCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = updateKeyCredentialsDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); + } + } + }); + return serviceCall; + } + + /** + * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @param value KeyCredential list. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse updateKeyCredentials(String applicationObjectId, List value) throws GraphErrorException, IOException, IllegalArgumentException { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(value); + KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); + parameters.withValue(value); + Call call = service.updateKeyCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + return updateKeyCredentialsDelegate(call.execute()); + } + + /** + * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @param value KeyCredential list. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link Call} object + */ + public ServiceCall updateKeyCredentialsAsync(String applicationObjectId, List value, final ServiceCallback serviceCallback) { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(value); + KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); + parameters.withValue(value); + Call call = service.updateKeyCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = updateKeyCredentialsDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse updateKeyCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); + } + + /** + * Gets passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<PasswordCredentialInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> listPasswordCredentials(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.listPasswordCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listPasswordCredentialsDelegate(call.execute()); + List result = response.getBody().getItems(); + return new ServiceResponse<>(result, response.getResponse()); + } + + /** + * Gets passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link Call} object + */ + public ServiceCall> listPasswordCredentialsAsync(String applicationObjectId, final ServiceCallback> serviceCallback) { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.listPasswordCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall> serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listPasswordCredentialsDelegate(response); + serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse> listPasswordCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); + } + + /** + * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse updatePasswordCredentials(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + final List value = null; + PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); + parameters.withValue(null); + Call call = service.updatePasswordCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + return updatePasswordCredentialsDelegate(call.execute()); + } + + /** + * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link Call} object + */ + public ServiceCall updatePasswordCredentialsAsync(String applicationObjectId, final ServiceCallback serviceCallback) { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + final List value = null; + PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); + parameters.withValue(null); + Call call = service.updatePasswordCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = updatePasswordCredentialsDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); + } + } + }); + return serviceCall; + } + + /** + * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @param value PasswordCredential list. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse updatePasswordCredentials(String applicationObjectId, List value) throws GraphErrorException, IOException, IllegalArgumentException { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(value); + PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); + parameters.withValue(value); + Call call = service.updatePasswordCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + return updatePasswordCredentialsDelegate(call.execute()); + } + + /** + * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @param value PasswordCredential list. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link Call} object + */ + public ServiceCall updatePasswordCredentialsAsync(String applicationObjectId, List value, final ServiceCallback serviceCallback) { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(value); + PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); + parameters.withValue(value); + Call call = service.updatePasswordCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = updatePasswordCredentialsDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java index 909a198bd288..0614c3c2f655 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java @@ -119,8 +119,24 @@ interface GroupsService { * @throws IllegalArgumentException exception thrown from invalid parameters * @return the CheckGroupMembershipResultInner object if successful. */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public CheckGroupMembershipResultInner isMemberOf(CheckGroupMembershipParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { return isMemberOfWithServiceResponseAsync(parameters).toBlocking().single().getBody(); +======= + public ServiceResponse isMemberOf(CheckGroupMembershipParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(parameters); + Call call = service.isMemberOf(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return isMemberOfDelegate(call.execute()); +>>>>>>> Regen graph and a bunch of refactors } /** @@ -128,6 +144,7 @@ public CheckGroupMembershipResultInner isMemberOf(CheckGroupMembershipParameters * * @param parameters Check group membership parameters. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall isMemberOfAsync(CheckGroupMembershipParametersInner parameters, final ServiceCallback serviceCallback) { @@ -156,6 +173,11 @@ public CheckGroupMembershipResultInner call(ServiceResponse> isMemberOfWithServiceResponseAsync(CheckGroupMembershipParametersInner parameters) { +======= + * @return the {@link Call} object + */ + public ServiceCall isMemberOfAsync(CheckGroupMembershipParametersInner parameters, final ServiceCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -166,6 +188,7 @@ public Observable> isMemberOfWi throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(parameters); +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.isMemberOf(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -176,6 +199,24 @@ public Observable> call(Respons } catch (Throwable t) { return Observable.error(t); } +======= + Call call = service.isMemberOf(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = isMemberOfDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -196,8 +237,26 @@ private ServiceResponse isMemberOfDelegate(Resp * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public void removeMember(String groupObjectId, String memberObjectId) throws GraphErrorException, IOException, IllegalArgumentException { removeMemberWithServiceResponseAsync(groupObjectId, memberObjectId).toBlocking().single().getBody(); +======= + public ServiceResponse removeMember(String groupObjectId, String memberObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + if (groupObjectId == null) { + throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); + } + if (memberObjectId == null) { + throw new IllegalArgumentException("Parameter memberObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.removeMember(groupObjectId, memberObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return removeMemberDelegate(call.execute()); +>>>>>>> Regen graph and a bunch of refactors } /** @@ -206,6 +265,7 @@ public void removeMember(String groupObjectId, String memberObjectId) throws Gra * @param groupObjectId Group object id * @param memberObjectId Member Object id * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall removeMemberAsync(String groupObjectId, String memberObjectId, final ServiceCallback serviceCallback) { @@ -236,6 +296,11 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> removeMemberWithServiceResponseAsync(String groupObjectId, String memberObjectId) { +======= + * @return the {@link Call} object + */ + public ServiceCall removeMemberAsync(String groupObjectId, String memberObjectId, final ServiceCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (groupObjectId == null) { throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); } @@ -248,6 +313,7 @@ public Observable> removeMemberWithServiceResponseAsync(St if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.removeMember(groupObjectId, memberObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -258,6 +324,24 @@ public Observable> call(Response response) { } catch (Throwable t) { return Observable.error(t); } +======= + Call call = service.removeMember(groupObjectId, memberObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = removeMemberDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -278,8 +362,28 @@ private ServiceResponse removeMemberDelegate(Response respon * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public void addMember(String groupObjectId, String url) throws GraphErrorException, IOException, IllegalArgumentException { addMemberWithServiceResponseAsync(groupObjectId, url).toBlocking().single().getBody(); +======= + public ServiceResponse addMember(String groupObjectId, String url) throws GraphErrorException, IOException, IllegalArgumentException { + if (groupObjectId == null) { + throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (url == null) { + throw new IllegalArgumentException("Parameter url is required and cannot be null."); + } + GroupAddMemberParameters parameters = new GroupAddMemberParameters(); + parameters.withUrl(url); + Call call = service.addMember(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + return addMemberDelegate(call.execute()); +>>>>>>> Regen graph and a bunch of refactors } /** @@ -288,6 +392,7 @@ public void addMember(String groupObjectId, String url) throws GraphErrorExcepti * @param groupObjectId Group object id * @param url Member Object Url as "https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd", where "0b1f9851-1bf0-433f-aec3-cb9272f093dc" is the tenantId and "f260bbc4-c254-447b-94cf-293b5ec434dd" is the objectId of the member (user, application, servicePrincipal, group) to be added. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall addMemberAsync(String groupObjectId, String url, final ServiceCallback serviceCallback) { @@ -318,6 +423,11 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> addMemberWithServiceResponseAsync(String groupObjectId, String url) { +======= + * @return the {@link Call} object + */ + public ServiceCall addMemberAsync(String groupObjectId, String url, final ServiceCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (groupObjectId == null) { throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); } @@ -332,6 +442,7 @@ public Observable> addMemberWithServiceResponseAsync(Strin } GroupAddMemberParameters parameters = new GroupAddMemberParameters(); parameters.withUrl(url); +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.addMember(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -342,6 +453,24 @@ public Observable> call(Response response) { } catch (Throwable t) { return Observable.error(t); } +======= + Call call = service.addMember(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = addMemberDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -361,8 +490,23 @@ private ServiceResponse addMemberDelegate(Response response) * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public void delete(String groupObjectId) throws GraphErrorException, IOException, IllegalArgumentException { deleteWithServiceResponseAsync(groupObjectId).toBlocking().single().getBody(); +======= + public ServiceResponse delete(String groupObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + if (groupObjectId == null) { + throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.delete(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return deleteDelegate(call.execute()); +>>>>>>> Regen graph and a bunch of refactors } /** @@ -370,6 +514,7 @@ public void delete(String groupObjectId) throws GraphErrorException, IOException * * @param groupObjectId Object id * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall deleteAsync(String groupObjectId, final ServiceCallback serviceCallback) { @@ -398,6 +543,11 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> deleteWithServiceResponseAsync(String groupObjectId) { +======= + * @return the {@link Call} object + */ + public ServiceCall deleteAsync(String groupObjectId, final ServiceCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (groupObjectId == null) { throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); } @@ -407,6 +557,7 @@ public Observable> deleteWithServiceResponseAsync(String g if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.delete(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -417,6 +568,24 @@ public Observable> call(Response response) { } catch (Throwable t) { return Observable.error(t); } +======= + Call call = service.delete(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -437,8 +606,24 @@ private ServiceResponse deleteDelegate(Response response) th * @throws IllegalArgumentException exception thrown from invalid parameters * @return the ADGroupInner object if successful. */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public ADGroupInner create(GroupCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { return createWithServiceResponseAsync(parameters).toBlocking().single().getBody(); +======= + public ServiceResponse create(GroupCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(parameters); + Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return createDelegate(call.execute()); +>>>>>>> Regen graph and a bunch of refactors } /** @@ -446,6 +631,7 @@ public ADGroupInner create(GroupCreateParametersInner parameters) throws GraphEr * * @param parameters Parameters to create a group * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall createAsync(GroupCreateParametersInner parameters, final ServiceCallback serviceCallback) { @@ -474,6 +660,11 @@ public ADGroupInner call(ServiceResponse response) { * @return the observable to the ADGroupInner object */ public Observable> createWithServiceResponseAsync(GroupCreateParametersInner parameters) { +======= + * @return the {@link Call} object + */ + public ServiceCall createAsync(GroupCreateParametersInner parameters, final ServiceCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -484,6 +675,7 @@ public Observable> createWithServiceResponseAsync( throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(parameters); +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -494,6 +686,24 @@ public Observable> call(Response res } catch (Throwable t) { return Observable.error(t); } +======= + Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = createDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -513,12 +723,29 @@ private ServiceResponse createDelegate(Response resp * @throws IllegalArgumentException exception thrown from invalid parameters * @return the PagedList<ADGroupInner> object if successful. */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public PagedList list() throws GraphErrorException, IOException, IllegalArgumentException { ServiceResponse> response = listSinglePageAsync().toBlocking().single(); return new PagedList(response.getBody()) { @Override public Page nextPage(String nextLink) throws RestException, IOException { return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); +======= + public ServiceResponse> list() throws GraphErrorException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + final String filter = null; + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listDelegate(call.execute()); + PagedList result = new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextLink) throws GraphErrorException, IOException { + return listNext(nextLink).getBody(); +>>>>>>> Regen graph and a bunch of refactors } }; } @@ -527,6 +754,7 @@ public Page nextPage(String nextLink) throws RestException, IOExce * Gets list of groups for the current tenant. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listAsync(final ListOperationCallback serviceCallback) { @@ -581,6 +809,11 @@ public Observable>> call(ServiceResponse>> listSinglePageAsync() { +======= + * @return the {@link Call} object + */ + public ServiceCall> listAsync(final ListOperationCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -588,6 +821,7 @@ public Observable>> listSinglePageAsync() { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } final String filter = null; +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -598,6 +832,30 @@ public Observable>> call(Response call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall> serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listDelegate(response); + if (serviceCallback != null) { + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } + serviceCall.success(new ServiceResponse<>(result.getBody().getItems(), response)); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -611,12 +869,28 @@ public Observable>> call(Response list(final String filter) throws GraphErrorException, IOException, IllegalArgumentException { ServiceResponse> response = listSinglePageAsync(filter).toBlocking().single(); return new PagedList(response.getBody()) { @Override public Page nextPage(String nextLink) throws RestException, IOException { return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); +======= + public ServiceResponse> list(final String filter) throws GraphErrorException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listDelegate(call.execute()); + PagedList result = new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextLink) throws GraphErrorException, IOException { + return listNext(nextLink).getBody(); +>>>>>>> Regen graph and a bunch of refactors } }; } @@ -626,6 +900,7 @@ public Page nextPage(String nextLink) throws RestException, IOExce * * @param filter The filter to apply on the operation. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listAsync(final String filter, final ListOperationCallback serviceCallback) { @@ -683,12 +958,18 @@ public Observable>> call(ServiceResponse>> listSinglePageAsync(final String filter) { +======= + * @return the {@link Call} object + */ + public ServiceCall> listAsync(final String filter, final ListOperationCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -699,6 +980,30 @@ public Observable>> call(Response call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall> serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listDelegate(response); + if (serviceCallback != null) { + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } + serviceCall.success(new ServiceResponse<>(result.getBody().getItems(), response)); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -719,12 +1024,31 @@ private ServiceResponse> listDelegate(Response getGroupMembers(final String objectId) throws GraphErrorException, IOException, IllegalArgumentException { ServiceResponse> response = getGroupMembersSinglePageAsync(objectId).toBlocking().single(); return new PagedList(response.getBody()) { @Override public Page nextPage(String nextLink) throws RestException, IOException { return getGroupMembersNextSinglePageAsync(nextLink).toBlocking().single().getBody(); +======= + public ServiceResponse> getGroupMembers(final String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.getGroupMembers(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = getGroupMembersDelegate(call.execute()); + PagedList result = new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextLink) throws GraphErrorException, IOException { + return getGroupMembersNext(nextLink).getBody(); +>>>>>>> Regen graph and a bunch of refactors } }; } @@ -734,6 +1058,7 @@ public Page nextPage(String nextLink) throws RestException, IOEx * * @param objectId Group object Id who's members should be retrieved. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> getGroupMembersAsync(final String objectId, final ListOperationCallback serviceCallback) { @@ -791,6 +1116,11 @@ public Observable>> call(ServiceResponse>> getGroupMembersSinglePageAsync(final String objectId) { +======= + * @return the {@link Call} object + */ + public ServiceCall> getGroupMembersAsync(final String objectId, final ListOperationCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -800,6 +1130,7 @@ public Observable>> getGroupMembersSinglePa if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.getGroupMembers(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -810,6 +1141,30 @@ public Observable>> call(Response call = service.getGroupMembers(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall> serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = getGroupMembersDelegate(response); + if (serviceCallback != null) { + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + getGroupMembersNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } + serviceCall.success(new ServiceResponse<>(result.getBody().getItems(), response)); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -830,8 +1185,23 @@ private ServiceResponse> getGroupMembersDelegate(Respo * @throws IllegalArgumentException exception thrown from invalid parameters * @return the ADGroupInner object if successful. */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public ADGroupInner get(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { return getWithServiceResponseAsync(objectId).toBlocking().single().getBody(); +======= + public ServiceResponse get(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return getDelegate(call.execute()); +>>>>>>> Regen graph and a bunch of refactors } /** @@ -839,6 +1209,7 @@ public ADGroupInner get(String objectId) throws GraphErrorException, IOException * * @param objectId User objectId to get group information. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall getAsync(String objectId, final ServiceCallback serviceCallback) { @@ -867,6 +1238,11 @@ public ADGroupInner call(ServiceResponse response) { * @return the observable to the ADGroupInner object */ public Observable> getWithServiceResponseAsync(String objectId) { +======= + * @return the {@link Call} object + */ + public ServiceCall getAsync(String objectId, final ServiceCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -876,6 +1252,7 @@ public Observable> getWithServiceResponseAsync(Str if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -886,6 +1263,24 @@ public Observable> call(Response res } catch (Throwable t) { return Observable.error(t); } +======= + Call call = service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -907,8 +1302,27 @@ private ServiceResponse getDelegate(Response respons * @throws IllegalArgumentException exception thrown from invalid parameters * @return the List<String> object if successful. */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public List getMemberGroups(String objectId, boolean securityEnabledOnly) throws GraphErrorException, IOException, IllegalArgumentException { return getMemberGroupsWithServiceResponseAsync(objectId, securityEnabledOnly).toBlocking().single().getBody(); +======= + public ServiceResponse> getMemberGroups(String objectId, boolean securityEnabledOnly) throws GraphErrorException, IOException, IllegalArgumentException { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + GroupGetMemberGroupsParameters parameters = new GroupGetMemberGroupsParameters(); + parameters.withSecurityEnabledOnly(securityEnabledOnly); + Call call = service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + ServiceResponse> response = getMemberGroupsDelegate(call.execute()); + List result = response.getBody().getItems(); + return new ServiceResponse<>(result, response.getResponse()); +>>>>>>> Regen graph and a bunch of refactors } /** @@ -917,6 +1331,7 @@ public List getMemberGroups(String objectId, boolean securityEnabledOnly * @param objectId Group filtering parameters. * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> getMemberGroupsAsync(String objectId, boolean securityEnabledOnly, final ServiceCallback> serviceCallback) { @@ -947,6 +1362,11 @@ public List call(ServiceResponse> response) { * @return the observable to the List<String> object */ public Observable>> getMemberGroupsWithServiceResponseAsync(String objectId, boolean securityEnabledOnly) { +======= + * @return the {@link Call} object + */ + public ServiceCall> getMemberGroupsAsync(String objectId, boolean securityEnabledOnly, final ServiceCallback> serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -958,6 +1378,7 @@ public Observable>> getMemberGroupsWithServiceRespo } GroupGetMemberGroupsParameters parameters = new GroupGetMemberGroupsParameters(); parameters.withSecurityEnabledOnly(securityEnabledOnly); +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -969,6 +1390,21 @@ public Observable>> call(Response res } catch (Throwable t) { return Observable.error(t); } +======= + Call call = service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + final ServiceCall> serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = getMemberGroupsDelegate(response); + serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -989,6 +1425,7 @@ private ServiceResponse> getMemberGroupsDelegate(Response listNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { ServiceResponse> response = listNextSinglePageAsync(nextLink).toBlocking().single(); return new PagedList(response.getBody()) { @@ -997,6 +1434,20 @@ public Page nextPage(String nextLink) throws RestException, IOExce return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); } }; +======= + public ServiceResponse> listNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { + if (nextLink == null) { + throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return listNextDelegate(call.execute()); +>>>>>>> Regen graph and a bunch of refactors } /** @@ -1005,6 +1456,7 @@ public Page nextPage(String nextLink) throws RestException, IOExce * @param nextLink Next link for list operation. * @param serviceCall the ServiceCall object tracking the Retrofit calls * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { @@ -1062,6 +1514,11 @@ public Observable>> call(ServiceResponse>> listNextSinglePageAsync(final String nextLink) { +======= + * @return the {@link Call} object + */ + public ServiceCall> listNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (nextLink == null) { throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); } @@ -1071,6 +1528,7 @@ public Observable>> listNextSinglePageAsync(f if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -1081,6 +1539,27 @@ public Observable>> call(Response call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + serviceCall.newCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listNextDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -1101,6 +1580,7 @@ private ServiceResponse> listNextDelegate(Response getGroupMembersNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { ServiceResponse> response = getGroupMembersNextSinglePageAsync(nextLink).toBlocking().single(); return new PagedList(response.getBody()) { @@ -1109,6 +1589,20 @@ public Page nextPage(String nextLink) throws RestException, IOEx return getGroupMembersNextSinglePageAsync(nextLink).toBlocking().single().getBody(); } }; +======= + public ServiceResponse> getGroupMembersNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { + if (nextLink == null) { + throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.getGroupMembersNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return getGroupMembersNextDelegate(call.execute()); +>>>>>>> Regen graph and a bunch of refactors } /** @@ -1117,6 +1611,7 @@ public Page nextPage(String nextLink) throws RestException, IOEx * @param nextLink Next link for list operation. * @param serviceCall the ServiceCall object tracking the Retrofit calls * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> getGroupMembersNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { @@ -1174,6 +1669,11 @@ public Observable>> call(ServiceResponse>> getGroupMembersNextSinglePageAsync(final String nextLink) { +======= + * @return the {@link Call} object + */ + public ServiceCall> getGroupMembersNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (nextLink == null) { throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); } @@ -1183,6 +1683,7 @@ public Observable>> getGroupMembersNextSing if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.getGroupMembersNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -1193,6 +1694,27 @@ public Observable>> call(Response call = service.getGroupMembersNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + serviceCall.newCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = getGroupMembersNextDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + getGroupMembersNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ObjectsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ObjectsInner.java index 98ae94a7696e..de17efb2f365 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ObjectsInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ObjectsInner.java @@ -66,14 +66,27 @@ interface ObjectsService { * @throws IllegalArgumentException exception thrown from invalid parameters * @return the AADObjectInner object if successful. */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public AADObjectInner getCurrentUser() throws GraphErrorException, IOException, IllegalArgumentException { return getCurrentUserWithServiceResponseAsync().toBlocking().single().getBody(); +======= + public ServiceResponse getCurrentUser() throws GraphErrorException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.getCurrentUser(this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return getCurrentUserDelegate(call.execute()); +>>>>>>> Regen graph and a bunch of refactors } /** * Gets the details for current logged in user. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall getCurrentUserAsync(final ServiceCallback serviceCallback) { @@ -100,12 +113,18 @@ public AADObjectInner call(ServiceResponse response) { * @return the observable to the AADObjectInner object */ public Observable> getCurrentUserWithServiceResponseAsync() { +======= + * @return the {@link Call} object + */ + public ServiceCall getCurrentUserAsync(final ServiceCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.getCurrentUser(this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -116,6 +135,24 @@ public Observable> call(Response r } catch (Throwable t) { return Observable.error(t); } +======= + Call call = service.getCurrentUser(this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = getCurrentUserDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalImpl.java index 93a040a896f5..4445fe4b711d 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalImpl.java @@ -69,6 +69,11 @@ public ServicePrincipalImpl withAccountEnabled(boolean enabled) { return this; } + @Override + public String name() { + return inner().appId(); + } + @Override public ServicePrincipalImpl create() throws Exception { this.setInner(client.create(createParameters).getBody()); diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java index 01554b23ed91..ec0c86cfdad9 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java @@ -6,8 +6,8 @@ package com.microsoft.azure.management.graphrbac.implementation; -import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.graphrbac.GraphErrorException; import com.microsoft.azure.management.graphrbac.ServicePrincipal; import com.microsoft.azure.management.graphrbac.ServicePrincipals; import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.CreatableWrappersImpl; @@ -34,7 +34,7 @@ class ServicePrincipalsImpl } @Override - public PagedList list() throws CloudException, IOException { + public PagedList list() throws GraphErrorException, IOException { return wrapList(this.innerCollection.list().getBody()); } @@ -59,17 +59,17 @@ protected ServicePrincipalImpl wrapModel(ServicePrincipalInner servicePrincipalI } @Override - public ServicePrincipalImpl getByObjectId(String objectId) throws CloudException, IOException { + public ServicePrincipalImpl getByObjectId(String objectId) throws GraphErrorException, IOException { return new ServicePrincipalImpl(innerCollection.get(objectId).getBody(), innerCollection); } @Override - public ServicePrincipal getByAppId(String appId) throws CloudException, IOException { + public ServicePrincipal getByAppId(String appId) throws GraphErrorException, IOException { return null; } @Override - public ServicePrincipal getByServicePrincipalName(String spn) throws CloudException, IOException { + public ServicePrincipal getByServicePrincipalName(String spn) throws GraphErrorException, IOException { return null; } } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java index 963ea8bfe284..9a5d1bd6737e 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java @@ -97,6 +97,22 @@ interface ServicePrincipalsService { @PATCH("{tenantID}/servicePrincipals/{objectId}/passwordCredentials") Observable> updatePasswordCredentials(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body PasswordCredentialsUpdateParameters parameters, @Header("User-Agent") String userAgent); + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/servicePrincipals/{objectId}/keyCredentials") + Call listKeyCredentials(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @PATCH("{tenantID}/servicePrincipals/{objectId}/keyCredentials") + Call updateKeyCredentials(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body KeyCredentialsUpdateParameters parameters, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/servicePrincipals/{objectId}/passwordCredentials") + Call listPasswordCredentials(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @PATCH("{tenantID}/servicePrincipals/{objectId}/passwordCredentials") + Call updatePasswordCredentials(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body PasswordCredentialsUpdateParameters parameters, @Header("User-Agent") String userAgent); + @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/{nextLink}") Observable> listNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @@ -112,8 +128,24 @@ interface ServicePrincipalsService { * @throws IllegalArgumentException exception thrown from invalid parameters * @return the ServicePrincipalInner object if successful. */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public ServicePrincipalInner create(ServicePrincipalCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { return createWithServiceResponseAsync(parameters).toBlocking().single().getBody(); +======= + public ServiceResponse create(ServicePrincipalCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(parameters); + Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return createDelegate(call.execute()); +>>>>>>> Regen graph and a bunch of refactors } /** @@ -121,6 +153,7 @@ public ServicePrincipalInner create(ServicePrincipalCreateParametersInner parame * * @param parameters Parameters to create a service principal. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall createAsync(ServicePrincipalCreateParametersInner parameters, final ServiceCallback serviceCallback) { @@ -149,6 +182,11 @@ public ServicePrincipalInner call(ServiceResponse respons * @return the observable to the ServicePrincipalInner object */ public Observable> createWithServiceResponseAsync(ServicePrincipalCreateParametersInner parameters) { +======= + * @return the {@link Call} object + */ + public ServiceCall createAsync(ServicePrincipalCreateParametersInner parameters, final ServiceCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -159,6 +197,7 @@ public Observable> createWithServiceRespo throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(parameters); +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -169,6 +208,24 @@ public Observable> call(Response call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = createDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -188,12 +245,29 @@ private ServiceResponse createDelegate(Response list() throws GraphErrorException, IOException, IllegalArgumentException { ServiceResponse> response = listSinglePageAsync().toBlocking().single(); return new PagedList(response.getBody()) { @Override public Page nextPage(String nextLink) throws RestException, IOException { return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); +======= + public ServiceResponse> list() throws GraphErrorException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + final String filter = null; + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listDelegate(call.execute()); + PagedList result = new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextLink) throws GraphErrorException, IOException { + return listNext(nextLink).getBody(); +>>>>>>> Regen graph and a bunch of refactors } }; } @@ -202,6 +276,7 @@ public Page nextPage(String nextLink) throws RestExceptio * Gets list of service principals from the current tenant. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listAsync(final ListOperationCallback serviceCallback) { @@ -256,6 +331,11 @@ public Observable>> call(ServiceResp * @return the PagedList<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. */ public Observable>> listSinglePageAsync() { +======= + * @return the {@link Call} object + */ + public ServiceCall> listAsync(final ListOperationCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -263,6 +343,7 @@ public Observable>> listSinglePageAs throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } final String filter = null; +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -273,6 +354,30 @@ public Observable>> call(Response call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall> serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listDelegate(response); + if (serviceCallback != null) { + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } + serviceCall.success(new ServiceResponse<>(result.getBody().getItems(), response)); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -286,12 +391,28 @@ public Observable>> call(Response list(final String filter) throws GraphErrorException, IOException, IllegalArgumentException { ServiceResponse> response = listSinglePageAsync(filter).toBlocking().single(); return new PagedList(response.getBody()) { @Override public Page nextPage(String nextLink) throws RestException, IOException { return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); +======= + public ServiceResponse> list(final String filter) throws GraphErrorException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listDelegate(call.execute()); + PagedList result = new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextLink) throws GraphErrorException, IOException { + return listNext(nextLink).getBody(); +>>>>>>> Regen graph and a bunch of refactors } }; } @@ -301,6 +422,7 @@ public Page nextPage(String nextLink) throws RestExceptio * * @param filter The filter to apply on the operation. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listAsync(final String filter, final ListOperationCallback serviceCallback) { @@ -358,12 +480,18 @@ public Observable>> call(ServiceResp * @return the PagedList<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. */ public Observable>> listSinglePageAsync(final String filter) { +======= + * @return the {@link Call} object + */ + public ServiceCall> listAsync(final String filter, final ListOperationCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -374,6 +502,30 @@ public Observable>> call(Response call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall> serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listDelegate(response); + if (serviceCallback != null) { + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } + serviceCall.success(new ServiceResponse<>(result.getBody().getItems(), response)); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -429,7 +581,11 @@ public Void call(ServiceResponse response) { * @param objectId Object id to delete service principal information. * @return the {@link ServiceResponse} object if successful. */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public Observable> deleteWithServiceResponseAsync(String objectId) { +======= + public ServiceResponse delete(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { +>>>>>>> Regen graph and a bunch of refactors if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -478,6 +634,7 @@ public ServicePrincipalInner get(String objectId) throws GraphErrorException, IO * * @param objectId Object id to get service principal information. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall getAsync(String objectId, final ServiceCallback serviceCallback) { @@ -506,6 +663,11 @@ public ServicePrincipalInner call(ServiceResponse respons * @return the observable to the ServicePrincipalInner object */ public Observable> getWithServiceResponseAsync(String objectId) { +======= + * @return the {@link Call} object + */ + public ServiceCall deleteAsync(String objectId, final ServiceCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -515,6 +677,7 @@ public Observable> getWithServiceResponse if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -525,6 +688,24 @@ public Observable> call(Response call = service.delete(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -575,6 +756,7 @@ public List call(ServiceResponse> r }); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 /** * Get keyCredentials associated with the service principal by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. * @@ -609,6 +791,11 @@ public Observable>> call(Response> listKeyCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) +======= + private ServiceResponse deleteDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) +>>>>>>> Regen graph and a bunch of refactors .registerError(GraphErrorException.class) .build(response); } @@ -621,6 +808,7 @@ private ServiceResponse> listKeyCredentialsDelegate * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public void updateKeyCredentials(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { updateKeyCredentialsWithServiceResponseAsync(objectId).toBlocking().single().getBody(); } @@ -658,6 +846,9 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> updateKeyCredentialsWithServiceResponseAsync(String objectId) { +======= + public ServiceResponse get(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { +>>>>>>> Regen graph and a bunch of refactors if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -703,6 +894,7 @@ public void updateKeyCredentials(String objectId, List value * @param objectId Object id to get service principal information. * @param value KeyCredential list. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall updateKeyCredentialsAsync(String objectId, List value, final ServiceCallback serviceCallback) { @@ -733,6 +925,11 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> updateKeyCredentialsWithServiceResponseAsync(String objectId, List value) { +======= + * @return the {@link Call} object + */ + public ServiceCall getAsync(String objectId, final ServiceCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -742,6 +939,7 @@ public Observable> updateKeyCredentialsWithServiceResponse if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 Validator.validate(value); KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); parameters.withValue(value); @@ -755,6 +953,24 @@ public Observable> call(Response response) { } catch (Throwable t) { return Observable.error(t); } +======= + Call call = service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -805,13 +1021,268 @@ public List call(ServiceResponse getDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); + } + + /** + * Get keyCredentials associated with the service principal by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<KeyCredentialInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> listKeyCredentials(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.listKeyCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listKeyCredentialsDelegate(call.execute()); + List result = response.getBody().getItems(); + return new ServiceResponse<>(result, response.getResponse()); + } + + /** + * Get keyCredentials associated with the service principal by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link Call} object + */ + public ServiceCall> listKeyCredentialsAsync(String objectId, final ServiceCallback> serviceCallback) { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.listKeyCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall> serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listKeyCredentialsDelegate(response); + serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse> listKeyCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); + } + + /** + * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse updateKeyCredentials(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + final List value = null; + KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); + parameters.withValue(null); + Call call = service.updateKeyCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + return updateKeyCredentialsDelegate(call.execute()); + } + + /** + * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link Call} object + */ + public ServiceCall updateKeyCredentialsAsync(String objectId, final ServiceCallback serviceCallback) { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + final List value = null; + KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); + parameters.withValue(null); + Call call = service.updateKeyCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = updateKeyCredentialsDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); + } + } + }); + return serviceCall; + } + + /** + * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @param value KeyCredential list. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse updateKeyCredentials(String objectId, List value) throws GraphErrorException, IOException, IllegalArgumentException { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(value); + KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); + parameters.withValue(value); + Call call = service.updateKeyCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + return updateKeyCredentialsDelegate(call.execute()); + } + + /** + * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @param value KeyCredential list. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link Call} object + */ + public ServiceCall updateKeyCredentialsAsync(String objectId, List value, final ServiceCallback serviceCallback) { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(value); + KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); + parameters.withValue(value); + Call call = service.updateKeyCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = updateKeyCredentialsDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse updateKeyCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); + } + + /** + * Gets passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<PasswordCredentialInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> listPasswordCredentials(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.listPasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listPasswordCredentialsDelegate(call.execute()); + List result = response.getBody().getItems(); + return new ServiceResponse<>(result, response.getResponse()); + } + +>>>>>>> Regen graph and a bunch of refactors /** * Gets passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. * * @param objectId Object id to get service principal information. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the observable to the List<PasswordCredentialInner> object */ public Observable>> listPasswordCredentialsWithServiceResponseAsync(String objectId) { +======= + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link Call} object + */ + public ServiceCall> listPasswordCredentialsAsync(String objectId, final ServiceCallback> serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -821,6 +1292,7 @@ public Observable>> listPasswordCr if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.listPasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -834,12 +1306,33 @@ public Observable>> call(Response< } } }); +======= + Call call = service.listPasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall> serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listPasswordCredentialsDelegate(response); + serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); + } + } + }); + return serviceCall; +>>>>>>> Regen graph and a bunch of refactors } private ServiceResponse> listPasswordCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) .registerError(GraphErrorException.class) +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 +======= .build(response); } @@ -850,7 +1343,158 @@ private ServiceResponse> listPasswordCredentia * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. */ + public ServiceResponse updatePasswordCredentials(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + final List value = null; + PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); + parameters.withValue(null); + Call call = service.updatePasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + return updatePasswordCredentialsDelegate(call.execute()); + } + + /** + * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link Call} object + */ + public ServiceCall updatePasswordCredentialsAsync(String objectId, final ServiceCallback serviceCallback) { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + final List value = null; + PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); + parameters.withValue(null); + Call call = service.updatePasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = updatePasswordCredentialsDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); + } + } + }); + return serviceCall; + } + + /** + * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @param value PasswordCredential list. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse updatePasswordCredentials(String objectId, List value) throws GraphErrorException, IOException, IllegalArgumentException { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(value); + PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); + parameters.withValue(value); + Call call = service.updatePasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + return updatePasswordCredentialsDelegate(call.execute()); + } + + /** + * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @param value PasswordCredential list. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link Call} object + */ + public ServiceCall updatePasswordCredentialsAsync(String objectId, List value, final ServiceCallback serviceCallback) { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(value); + PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); + parameters.withValue(value); + Call call = service.updatePasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = updatePasswordCredentialsDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse updatePasswordCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) +>>>>>>> Regen graph and a bunch of refactors + .build(response); + } + + /** + * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 + * @param objectId Object id to get service principal information. +======= + * @param nextLink Next link for list operation. +>>>>>>> Regen graph and a bunch of refactors + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public void updatePasswordCredentials(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { updatePasswordCredentialsWithServiceResponseAsync(objectId).toBlocking().single().getBody(); } @@ -890,6 +1534,11 @@ public Void call(ServiceResponse response) { public Observable> updatePasswordCredentialsWithServiceResponseAsync(String objectId) { if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); +======= + public ServiceResponse> listNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { + if (nextLink == null) { + throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); +>>>>>>> Regen graph and a bunch of refactors } if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); @@ -1021,6 +1670,7 @@ public Page nextPage(String nextLink) throws RestExceptio * @param nextLink Next link for list operation. * @param serviceCall the ServiceCall object tracking the Retrofit calls * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { @@ -1078,6 +1728,11 @@ public Observable>> call(ServiceResp * @return the PagedList<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. */ public Observable>> listNextSinglePageAsync(final String nextLink) { +======= + * @return the {@link Call} object + */ + public ServiceCall> listNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (nextLink == null) { throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); } @@ -1087,6 +1742,7 @@ public Observable>> listNextSinglePa if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -1097,6 +1753,27 @@ public Observable>> call(Response call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + serviceCall.newCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listNextDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java index fb48278c65ff..bcec0e6bb798 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java @@ -72,6 +72,11 @@ public String mailNickname() { return inner().mailNickname(); } + @Override + public String name() { + return userPrincipalName(); + } + @Override public UserImpl create() throws Exception { setInner(client.create(createParameters).getBody()); diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java index 95344f3aca06..3bbdb8db31da 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java @@ -6,11 +6,12 @@ package com.microsoft.azure.management.graphrbac.implementation; -import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.graphrbac.GraphErrorException; import com.microsoft.azure.management.graphrbac.User; import com.microsoft.azure.management.graphrbac.Users; import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.CreatableWrappersImpl; +import com.microsoft.rest.RestException; import java.io.IOException; @@ -34,7 +35,7 @@ class UsersImpl } @Override - public PagedList list() throws CloudException, IOException { + public PagedList list() throws RestException, IOException { return wrapList(this.innerCollection.list().getBody()); } @@ -59,12 +60,12 @@ protected UserImpl wrapModel(UserInner userInner) { } @Override - public UserImpl getByObjectId(String objectId) throws CloudException, IOException { + public UserImpl getByObjectId(String objectId) throws GraphErrorException, IOException { return new UserImpl(innerCollection.get(objectId).getBody(), innerCollection); } @Override - public UserImpl getByUserPrincipalName(String upn) throws CloudException, IOException { + public UserImpl getByUserPrincipalName(String upn) throws GraphErrorException, IOException { return new UserImpl(innerCollection.get(upn).getBody(), innerCollection); } } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java index 91499376d8cd..a5fbd748859d 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java @@ -17,7 +17,10 @@ import com.microsoft.azure.management.graphrbac.UserGetMemberGroupsParameters; import com.microsoft.azure.Page; import com.microsoft.azure.PagedList; +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 import com.microsoft.rest.RestException; +======= +>>>>>>> Regen graph and a bunch of refactors import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; @@ -25,6 +28,10 @@ import java.io.IOException; import java.util.List; import okhttp3.ResponseBody; +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 +======= +import retrofit2.Call; +>>>>>>> Regen graph and a bunch of refactors import retrofit2.http.Body; import retrofit2.http.GET; import retrofit2.http.Header; @@ -35,8 +42,11 @@ import retrofit2.http.POST; import retrofit2.http.Query; import retrofit2.Response; +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 import rx.functions.Func1; import rx.Observable; +======= +>>>>>>> Regen graph and a bunch of refactors /** * An instance of this class provides access to all the operations defined @@ -103,8 +113,24 @@ interface UsersService { * @throws IllegalArgumentException exception thrown from invalid parameters * @return the UserInner object if successful. */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public UserInner create(UserCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { return createWithServiceResponseAsync(parameters).toBlocking().single().getBody(); +======= + public ServiceResponse create(UserCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(parameters); + Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return createDelegate(call.execute()); +>>>>>>> Regen graph and a bunch of refactors } /** @@ -112,6 +138,7 @@ public UserInner create(UserCreateParametersInner parameters) throws GraphErrorE * * @param parameters Parameters to create a user. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall createAsync(UserCreateParametersInner parameters, final ServiceCallback serviceCallback) { @@ -140,6 +167,11 @@ public UserInner call(ServiceResponse response) { * @return the observable to the UserInner object */ public Observable> createWithServiceResponseAsync(UserCreateParametersInner parameters) { +======= + * @return the {@link Call} object + */ + public ServiceCall createAsync(UserCreateParametersInner parameters, final ServiceCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -150,6 +182,7 @@ public Observable> createWithServiceResponseAsync(Use throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(parameters); +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -160,6 +193,24 @@ public Observable> call(Response respon } catch (Throwable t) { return Observable.error(t); } +======= + Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = createDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -179,12 +230,29 @@ private ServiceResponse createDelegate(Response respons * @throws IllegalArgumentException exception thrown from invalid parameters * @return the PagedList<UserInner> object if successful. */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public PagedList list() throws GraphErrorException, IOException, IllegalArgumentException { ServiceResponse> response = listSinglePageAsync().toBlocking().single(); return new PagedList(response.getBody()) { @Override public Page nextPage(String nextLink) throws RestException, IOException { return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); +======= + public ServiceResponse> list() throws GraphErrorException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + final String filter = null; + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listDelegate(call.execute()); + PagedList result = new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextLink) throws GraphErrorException, IOException { + return listNext(nextLink).getBody(); +>>>>>>> Regen graph and a bunch of refactors } }; } @@ -193,6 +261,7 @@ public Page nextPage(String nextLink) throws RestException, IOExcepti * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listAsync(final ListOperationCallback serviceCallback) { @@ -247,6 +316,11 @@ public Observable>> call(ServiceResponse>> listSinglePageAsync() { +======= + * @return the {@link Call} object + */ + public ServiceCall> listAsync(final ListOperationCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -254,6 +328,7 @@ public Observable>> listSinglePageAsync() { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } final String filter = null; +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -264,6 +339,30 @@ public Observable>> call(Response } catch (Throwable t) { return Observable.error(t); } +======= + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall> serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listDelegate(response); + if (serviceCallback != null) { + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } + serviceCall.success(new ServiceResponse<>(result.getBody().getItems(), response)); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -277,12 +376,28 @@ public Observable>> call(Response * @throws IllegalArgumentException exception thrown from invalid parameters * @return the PagedList<UserInner> object if successful. */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public PagedList list(final String filter) throws GraphErrorException, IOException, IllegalArgumentException { ServiceResponse> response = listSinglePageAsync(filter).toBlocking().single(); return new PagedList(response.getBody()) { @Override public Page nextPage(String nextLink) throws RestException, IOException { return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); +======= + public ServiceResponse> list(final String filter) throws GraphErrorException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listDelegate(call.execute()); + PagedList result = new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextLink) throws GraphErrorException, IOException { + return listNext(nextLink).getBody(); +>>>>>>> Regen graph and a bunch of refactors } }; } @@ -292,6 +407,7 @@ public Page nextPage(String nextLink) throws RestException, IOExcepti * * @param filter The filter to apply on the operation. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listAsync(final String filter, final ListOperationCallback serviceCallback) { @@ -349,12 +465,18 @@ public Observable>> call(ServiceResponse>> listSinglePageAsync(final String filter) { +======= + * @return the {@link Call} object + */ + public ServiceCall> listAsync(final String filter, final ListOperationCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -365,6 +487,30 @@ public Observable>> call(Response } catch (Throwable t) { return Observable.error(t); } +======= + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall> serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listDelegate(response); + if (serviceCallback != null) { + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } + serviceCall.success(new ServiceResponse<>(result.getBody().getItems(), response)); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -385,8 +531,23 @@ private ServiceResponse> listDelegate(Response get(String upnOrObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + if (upnOrObjectId == null) { + throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.get(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return getDelegate(call.execute()); +>>>>>>> Regen graph and a bunch of refactors } /** @@ -394,6 +555,7 @@ public UserInner get(String upnOrObjectId) throws GraphErrorException, IOExcepti * * @param upnOrObjectId User object Id or user principal name to get user information. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall getAsync(String upnOrObjectId, final ServiceCallback serviceCallback) { @@ -422,6 +584,11 @@ public UserInner call(ServiceResponse response) { * @return the observable to the UserInner object */ public Observable> getWithServiceResponseAsync(String upnOrObjectId) { +======= + * @return the {@link Call} object + */ + public ServiceCall getAsync(String upnOrObjectId, final ServiceCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (upnOrObjectId == null) { throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); } @@ -431,6 +598,7 @@ public Observable> getWithServiceResponseAsync(String if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.get(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -441,6 +609,24 @@ public Observable> call(Response respon } catch (Throwable t) { return Observable.error(t); } +======= + Call call = service.get(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -461,8 +647,27 @@ private ServiceResponse getDelegate(Response response) * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public void update(String upnOrObjectId, UserUpdateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { updateWithServiceResponseAsync(upnOrObjectId, parameters).toBlocking().single().getBody(); +======= + public ServiceResponse update(String upnOrObjectId, UserUpdateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { + if (upnOrObjectId == null) { + throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(parameters); + Call call = service.update(upnOrObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return updateDelegate(call.execute()); +>>>>>>> Regen graph and a bunch of refactors } /** @@ -471,6 +676,7 @@ public void update(String upnOrObjectId, UserUpdateParametersInner parameters) t * @param upnOrObjectId User object Id or user principal name to get user information. * @param parameters Parameters to update an exisitng user. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall updateAsync(String upnOrObjectId, UserUpdateParametersInner parameters, final ServiceCallback serviceCallback) { @@ -501,6 +707,11 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> updateWithServiceResponseAsync(String upnOrObjectId, UserUpdateParametersInner parameters) { +======= + * @return the {@link Call} object + */ + public ServiceCall updateAsync(String upnOrObjectId, UserUpdateParametersInner parameters, final ServiceCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (upnOrObjectId == null) { throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); } @@ -514,6 +725,7 @@ public Observable> updateWithServiceResponseAsync(String u throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(parameters); +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.update(upnOrObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -524,6 +736,24 @@ public Observable> call(Response response) { } catch (Throwable t) { return Observable.error(t); } +======= + Call call = service.update(upnOrObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = updateDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -543,8 +773,23 @@ private ServiceResponse updateDelegate(Response response) th * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public void delete(String upnOrObjectId) throws GraphErrorException, IOException, IllegalArgumentException { deleteWithServiceResponseAsync(upnOrObjectId).toBlocking().single().getBody(); +======= + public ServiceResponse delete(String upnOrObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + if (upnOrObjectId == null) { + throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.delete(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return deleteDelegate(call.execute()); +>>>>>>> Regen graph and a bunch of refactors } /** @@ -552,6 +797,7 @@ public void delete(String upnOrObjectId) throws GraphErrorException, IOException * * @param upnOrObjectId user object id or user principal name (upn) * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall deleteAsync(String upnOrObjectId, final ServiceCallback serviceCallback) { @@ -580,6 +826,11 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> deleteWithServiceResponseAsync(String upnOrObjectId) { +======= + * @return the {@link Call} object + */ + public ServiceCall deleteAsync(String upnOrObjectId, final ServiceCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (upnOrObjectId == null) { throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); } @@ -589,6 +840,7 @@ public Observable> deleteWithServiceResponseAsync(String u if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.delete(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -599,6 +851,24 @@ public Observable> call(Response response) { } catch (Throwable t) { return Observable.error(t); } +======= + Call call = service.delete(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + if (serviceCallback != null) { + serviceCallback.success(clientResponse); + } + serviceCall.success(clientResponse); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -620,8 +890,27 @@ private ServiceResponse deleteDelegate(Response response) th * @throws IllegalArgumentException exception thrown from invalid parameters * @return the List<String> object if successful. */ +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public List getMemberGroups(String objectId, boolean securityEnabledOnly) throws GraphErrorException, IOException, IllegalArgumentException { return getMemberGroupsWithServiceResponseAsync(objectId, securityEnabledOnly).toBlocking().single().getBody(); +======= + public ServiceResponse> getMemberGroups(String objectId, boolean securityEnabledOnly) throws GraphErrorException, IOException, IllegalArgumentException { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + UserGetMemberGroupsParameters parameters = new UserGetMemberGroupsParameters(); + parameters.withSecurityEnabledOnly(securityEnabledOnly); + Call call = service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + ServiceResponse> response = getMemberGroupsDelegate(call.execute()); + List result = response.getBody().getItems(); + return new ServiceResponse<>(result, response.getResponse()); +>>>>>>> Regen graph and a bunch of refactors } /** @@ -630,6 +919,7 @@ public List getMemberGroups(String objectId, boolean securityEnabledOnly * @param objectId User filtering parameters. * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> getMemberGroupsAsync(String objectId, boolean securityEnabledOnly, final ServiceCallback> serviceCallback) { @@ -660,6 +950,11 @@ public List call(ServiceResponse> response) { * @return the observable to the List<String> object */ public Observable>> getMemberGroupsWithServiceResponseAsync(String objectId, boolean securityEnabledOnly) { +======= + * @return the {@link Call} object + */ + public ServiceCall> getMemberGroupsAsync(String objectId, boolean securityEnabledOnly, final ServiceCallback> serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -671,6 +966,7 @@ public Observable>> getMemberGroupsWithServiceRespo } UserGetMemberGroupsParameters parameters = new UserGetMemberGroupsParameters(); parameters.withSecurityEnabledOnly(securityEnabledOnly); +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -682,6 +978,21 @@ public Observable>> call(Response res } catch (Throwable t) { return Observable.error(t); } +======= + Call call = service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + final ServiceCall> serviceCall = new ServiceCall<>(call); + call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = getMemberGroupsDelegate(response); + serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } @@ -702,6 +1013,7 @@ private ServiceResponse> getMemberGroupsDelegate(Response listNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { ServiceResponse> response = listNextSinglePageAsync(nextLink).toBlocking().single(); return new PagedList(response.getBody()) { @@ -710,6 +1022,20 @@ public Page nextPage(String nextLink) throws RestException, IOExcepti return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); } }; +======= + public ServiceResponse> listNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { + if (nextLink == null) { + throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return listNextDelegate(call.execute()); +>>>>>>> Regen graph and a bunch of refactors } /** @@ -718,6 +1044,7 @@ public Page nextPage(String nextLink) throws RestException, IOExcepti * @param nextLink Next link for list operation. * @param serviceCall the ServiceCall object tracking the Retrofit calls * @param serviceCallback the async ServiceCallback to handle successful and failed responses. +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { @@ -775,6 +1102,11 @@ public Observable>> call(ServiceResponse>> listNextSinglePageAsync(final String nextLink) { +======= + * @return the {@link Call} object + */ + public ServiceCall> listNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { +>>>>>>> Regen graph and a bunch of refactors if (nextLink == null) { throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); } @@ -784,6 +1116,7 @@ public Observable>> listNextSinglePageAsync(fina if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } +<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -794,6 +1127,27 @@ public Observable>> call(Response } catch (Throwable t) { return Observable.error(t); } +======= + Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + serviceCall.newCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listNextDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (GraphErrorException | IOException exception) { + if (serviceCallback != null) { + serviceCallback.failure(exception); + } + serviceCall.failure(exception); +>>>>>>> Regen graph and a bunch of refactors } }); } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java index f481ad570d39..b364a3f08e99 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java @@ -36,7 +36,7 @@ class AccessPolicyImpl AccessPolicy.Update { AccessPolicyImpl(AccessPolicyEntry innerObject, VaultImpl parent) { - super(null, innerObject, parent); + super(innerObject, parent); } @Override diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java index c2fb25ad737c..ebda765beb04 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java @@ -15,6 +15,7 @@ import com.microsoft.azure.management.keyvault.Vaults; import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; +import com.microsoft.rest.RestException; import java.io.IOException; import java.util.UUID; @@ -44,7 +45,7 @@ class VaultsImpl } @Override - public PagedList list() throws CloudException, IOException { + public PagedList list() throws RestException, IOException { return wrapList(this.innerCollection.list().getBody()); } diff --git a/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java b/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java index 3e9f9bb9ac14..0cfbfd701213 100644 --- a/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java +++ b/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java @@ -50,6 +50,6 @@ protected static void createClients() { .authenticate(graphCredentials, System.getenv("domain")); keyVaultManager = KeyVaultManager - .authenticate(restClient, System.getenv("subscription-id")); + .authenticate(restClient, System.getenv("subscription-id"), graphCredentials.getDomain()); } } diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfacesImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfacesImpl.java index 45ff125bd78c..4778bba77079 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfacesImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfacesImpl.java @@ -3,8 +3,8 @@ import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; import com.microsoft.azure.management.network.NetworkInterface; -import com.microsoft.azure.management.network.NetworkInterfaces; import com.microsoft.azure.management.network.NetworkInterfaceDnsSettings; +import com.microsoft.azure.management.network.NetworkInterfaces; import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworksImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworksImpl.java index b3cc00ca4908..6e9038a5eb90 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworksImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworksImpl.java @@ -7,10 +7,10 @@ import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; -import com.microsoft.azure.management.network.Network; -import com.microsoft.azure.management.network.Networks; import com.microsoft.azure.management.network.AddressSpace; import com.microsoft.azure.management.network.DhcpOptions; +import com.microsoft.azure.management.network.Network; +import com.microsoft.azure.management.network.Networks; import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsListing.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsListing.java index f89bf32a552d..b0bcc8251ab3 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsListing.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsListing.java @@ -8,6 +8,7 @@ import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; +import com.microsoft.rest.RestException; import java.io.IOException; @@ -26,5 +27,5 @@ public interface SupportsListing { * @throws CloudException exceptions thrown from the cloud. * @throws IOException exceptions thrown from serialization/deserialization. */ - PagedList list() throws CloudException, IOException; + PagedList list() throws RestException, IOException; } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationsImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationsImpl.java index 73f3185ceaec..0dba4a4aa4c6 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationsImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationsImpl.java @@ -12,6 +12,7 @@ import com.microsoft.azure.management.resources.DeploymentOperation; import com.microsoft.azure.management.resources.DeploymentOperations; import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl; + import java.io.IOException; /** diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentsImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentsImpl.java index 4214b34988e8..ed2ca9d51b2b 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentsImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentsImpl.java @@ -45,7 +45,7 @@ public Deployment typeConvert(DeploymentExtendedInner deploymentInner) { } @Override - public PagedList list() throws CloudException, IOException { + public PagedList list() throws RestException, IOException { return new GroupPagedList(this.resourceManager.resourceGroups().list()) { @Override public List listNextGroup(String resourceGroupName) throws RestException, IOException { @@ -62,13 +62,9 @@ public PagedList listByGroup(String groupName) throws CloudException @Override public Deployment getByName(String name) throws IOException, CloudException { for (ResourceGroup group : this.resourceManager.resourceGroups().list()) { - try { - DeploymentExtendedInner inner = client.get(group.name(), name); - if (inner != null) { - return createFluentModel(inner); - } - } catch (CloudException ex) { - // Do nothing + DeploymentExtendedInner inner = client.get(group.name(), name); + if (inner != null) { + return createFluentModel(inner); } } return null; diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeaturesImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeaturesImpl.java index 40be00ce6c41..34ade7e2cfcb 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeaturesImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeaturesImpl.java @@ -8,9 +8,10 @@ import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.resources.Feature; import com.microsoft.azure.management.resources.Features; import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl; -import com.microsoft.azure.management.resources.Feature; + import java.io.IOException; /** diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeaturesInResourceProviderImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeaturesInResourceProviderImpl.java index 325cd951c4ab..c1be1b5bbdf0 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeaturesInResourceProviderImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeaturesInResourceProviderImpl.java @@ -11,6 +11,7 @@ import com.microsoft.azure.management.resources.Feature; import com.microsoft.azure.management.resources.Features; import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; +import com.microsoft.rest.RestException; import java.io.IOException; @@ -28,7 +29,7 @@ final class FeaturesInResourceProviderImpl } @Override - public PagedList list() throws CloudException, IOException { + public PagedList list() throws RestException, IOException { PagedListConverter converter = new PagedListConverter() { @Override public Feature typeConvert(FeatureResultInner tenantInner) { diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceGroupsImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceGroupsImpl.java index c2d3edb1564c..f609c088d309 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceGroupsImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceGroupsImpl.java @@ -8,9 +8,9 @@ import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.resources.ResourceGroup; import com.microsoft.azure.management.resources.ResourceGroups; import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.CreatableResourcesImpl; -import com.microsoft.azure.management.resources.ResourceGroup; import java.io.IOException; diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/SubscriptionsImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/SubscriptionsImpl.java index 9e06529b67a0..948704d62b41 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/SubscriptionsImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/SubscriptionsImpl.java @@ -11,6 +11,7 @@ import com.microsoft.azure.management.resources.Subscription; import com.microsoft.azure.management.resources.Subscriptions; import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; +import com.microsoft.rest.RestException; import java.io.IOException; @@ -26,7 +27,7 @@ final class SubscriptionsImpl } @Override - public PagedList list() throws CloudException, IOException { + public PagedList list() throws RestException, IOException { PagedListConverter converter = new PagedListConverter() { @Override public Subscription typeConvert(SubscriptionInner subscriptionInner) { diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/TenantsImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/TenantsImpl.java index 92fc559b1f7a..4d760e5b6f0c 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/TenantsImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/TenantsImpl.java @@ -6,11 +6,11 @@ package com.microsoft.azure.management.resources.implementation; -import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; import com.microsoft.azure.management.resources.Tenant; import com.microsoft.azure.management.resources.Tenants; import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; +import com.microsoft.rest.RestException; import java.io.IOException; @@ -26,7 +26,7 @@ final class TenantsImpl } @Override - public PagedList list() throws CloudException, IOException { + public PagedList list() throws RestException, IOException { PagedListConverter converter = new PagedListConverter() { @Override public Tenant typeConvert(TenantIdDescriptionInner tenantInner) { diff --git a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountsImpl.java b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountsImpl.java index dcaa33b5a81d..42394d94ea0b 100644 --- a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountsImpl.java +++ b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountsImpl.java @@ -11,9 +11,9 @@ import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; import com.microsoft.azure.management.storage.CheckNameAvailabilityResult; +import com.microsoft.azure.management.storage.SkuName; import com.microsoft.azure.management.storage.StorageAccount; import com.microsoft.azure.management.storage.StorageAccounts; -import com.microsoft.azure.management.storage.SkuName; import java.io.IOException; diff --git a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/UsagesImpl.java b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/UsagesImpl.java index 7497a4ea5ed4..55ccef9406e6 100644 --- a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/UsagesImpl.java +++ b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/UsagesImpl.java @@ -5,6 +5,7 @@ import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl; import com.microsoft.azure.management.storage.StorageUsage; import com.microsoft.azure.management.storage.Usages; + import java.io.IOException; /** diff --git a/azure/src/main/java/com/microsoft/azure/Azure.java b/azure/src/main/java/com/microsoft/azure/Azure.java index 6fa39a6061ac..fbe8ca394a90 100644 --- a/azure/src/main/java/com/microsoft/azure/Azure.java +++ b/azure/src/main/java/com/microsoft/azure/Azure.java @@ -225,7 +225,10 @@ public Azure withDefaultSubscription() throws CloudException, IOException { if (this.defaultSubscription != null) { return withSubscription(this.defaultSubscription); } else { - PagedList subs = this.subscriptions().list(); + try {PagedList subs = this.subscriptions().list(); + } catch (com.microsoft.rest.RestException e) { + e.printStackTrace(); + } if (!subs.isEmpty()) { return withSubscription(subs.get(0).subscriptionId()); } else { diff --git a/azure/src/test/java/com/microsoft/azure/AzureTests.java b/azure/src/test/java/com/microsoft/azure/AzureTests.java index 44ea55003011..0f4cc24a21fa 100644 --- a/azure/src/test/java/com/microsoft/azure/AzureTests.java +++ b/azure/src/test/java/com/microsoft/azure/AzureTests.java @@ -41,16 +41,28 @@ public static void main(String[] args) throws IOException, CloudException { final File credFile = new File("my.azureauth"); Azure azure = Azure.authenticate(credFile).withDefaultSubscription(); - System.out.println(String.valueOf(azure.resourceGroups().list().size())); + try { + System.out.println(String.valueOf(azure.resourceGroups().list().size())); + } catch (com.microsoft.rest.RestException e) { + e.printStackTrace(); + } Azure.configure().withLogLevel(Level.BASIC).authenticate(credFile); System.out.println("Selected subscription: " + azure.subscriptionId()); - System.out.println(String.valueOf(azure.resourceGroups().list().size())); + try { + System.out.println(String.valueOf(azure.resourceGroups().list().size())); + } catch (com.microsoft.rest.RestException e) { + e.printStackTrace(); + } final File authFileNoSubscription = new File("nosub.azureauth"); azure = Azure.authenticate(authFileNoSubscription).withDefaultSubscription(); System.out.println("Selected subscription: " + azure.subscriptionId()); - System.out.println(String.valueOf(azure.resourceGroups().list().size())); + try { + System.out.println(String.valueOf(azure.resourceGroups().list().size())); + } catch (com.microsoft.rest.RestException e) { + e.printStackTrace(); + } } @Before @@ -125,11 +137,19 @@ public void setup() throws Exception { Assert.assertTrue(publishers.size() > 0); for (VirtualMachinePublisher p : publishers) { System.out.println(String.format("Publisher name: %s, region: %s", p.name(), p.region())); - for (VirtualMachineOffer o : p.offers().list()) { - System.out.println(String.format("\tOffer name: %s", o.name())); - for (VirtualMachineSku s : o.skus().list()) { - System.out.println(String.format("\t\tSku name: %s", s.name())); + try { + for (VirtualMachineOffer o : p.offers().list()) { + System.out.println(String.format("\tOffer name: %s", o.name())); + try { + for (VirtualMachineSku s : o.skus().list()) { + System.out.println(String.format("\t\tSku name: %s", s.name())); + } + } catch (com.microsoft.rest.RestException e) { + e.printStackTrace(); + } } + } catch (com.microsoft.rest.RestException e) { + e.printStackTrace(); } } List images = azure.virtualMachineImages().listByRegion(Region.US_WEST); diff --git a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java index cc34d1cea766..94af0f3192cf 100644 --- a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java +++ b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java @@ -177,8 +177,8 @@ public static ApplicationTokenCredentials fromFile(File credentialsFile) throws new AzureEnvironment( authUrl, mgmtUri, - true, - baseUrl) + baseUrl, + "https://graph.windows.net/") // TODO: cred file should contain GRAPH endpoint ).withDefaultSubscriptionId(defaultSubscriptionId); } From 52449ff7f94d12157c41a7512af08ea5461976f1 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 10 Aug 2016 16:18:38 -0700 Subject: [PATCH 13/33] Allow specifying upn and spn --- .../graphrbac/ServicePrincipals.java | 17 ++- .../azure/management/graphrbac/Users.java | 11 ++ .../implementation/ServicePrincipalsImpl.java | 32 +++- .../graphrbac/implementation/UsersImpl.java | 24 +++ .../management/keyvault/AccessPolicy.java | 5 + .../implementation/AccessPolicyImpl.java | 25 +++- .../keyvault/implementation/VaultImpl.java | 137 ++++++++++++------ .../keyvault/implementation/VaultsImpl.java | 6 +- .../keyvault/KeyVaultManagementTestBase.java | 29 ++-- .../azure/management/keyvault/VaultTests.java | 12 +- .../microsoft/azure/ParallelServiceCall.java | 50 +++++++ 11 files changed, 271 insertions(+), 77 deletions(-) create mode 100644 runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/ParallelServiceCall.java diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java index 15714e3836e8..96bc608cf9d7 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java @@ -9,6 +9,8 @@ import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; import java.io.IOException; @@ -25,7 +27,7 @@ public interface ServicePrincipals extends * @param objectId the unique object id * @return an immutable representation of the resource * @throws GraphErrorException exceptions thrown from the graph API - * @throws IOException exceptions thrown from serialization/deserialization + * @throws IOException exceptions thrown from serialization/deserialization */ ServicePrincipal getByObjectId(String objectId) throws GraphErrorException, IOException; @@ -35,7 +37,7 @@ public interface ServicePrincipals extends * @param appId the application id (or the client id) * @return an immutable representation of the resource * @throws GraphErrorException exceptions thrown from the graph API - * @throws IOException exceptions thrown from serialization/deserialization + * @throws IOException exceptions thrown from serialization/deserialization */ ServicePrincipal getByAppId(String appId) throws GraphErrorException, IOException; @@ -45,7 +47,16 @@ public interface ServicePrincipals extends * @param spn the service principal name * @return an immutable representation of the resource * @throws GraphErrorException exceptions thrown from the graph API - * @throws IOException exceptions thrown from serialization/deserialization + * @throws IOException exceptions thrown from serialization/deserialization */ ServicePrincipal getByServicePrincipalName(String spn) throws GraphErrorException, IOException; + + /** + * Gets the information about a service principal. + * + * @param spn the service principal name + * @param callback the call back to handle response + * @return the Future based service call + */ + ServiceCall getByServicePrincipalNameAsync(String spn, final ServiceCallback callback); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java index e2432276fef9..42b09e31b295 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java @@ -9,6 +9,8 @@ import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; import java.io.IOException; @@ -38,4 +40,13 @@ public interface Users extends * @throws IOException exceptions thrown from serialization/deserialization */ User getByUserPrincipalName(String upn) throws GraphErrorException, IOException; + + /** + * Gets the information about a user. + * + * @param upn the user principal name + * @param callback the callback to handle the response + * @return an Future based service call + */ + ServiceCall getByUserPrincipalNameAsync(String upn, ServiceCallback callback); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java index ec0c86cfdad9..bc7f797736eb 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java @@ -11,8 +11,12 @@ import com.microsoft.azure.management.graphrbac.ServicePrincipal; import com.microsoft.azure.management.graphrbac.ServicePrincipals; import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.CreatableWrappersImpl; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceResponse; import java.io.IOException; +import java.util.List; /** * The implementation of StorageAccounts and its parent interfaces. @@ -70,6 +74,32 @@ public ServicePrincipal getByAppId(String appId) throws GraphErrorException, IOE @Override public ServicePrincipal getByServicePrincipalName(String spn) throws GraphErrorException, IOException { - return null; + List spList = innerCollection.list(String.format("servicePrincipalNames/any(c:c eq '%s')", spn)).getBody(); + if (spList == null || spList.isEmpty()) { + return null; + } else { + return new ServicePrincipalImpl(spList.get(0), innerCollection); + } + } + + @Override + public ServiceCall getByServicePrincipalNameAsync(String spn, final ServiceCallback callback) { + final ServiceCall serviceCall = new ServiceCall<>(null); + serviceCall.newCall(innerCollection.getAsync(spn, new ServiceCallback() { + @Override + public void failure(Throwable t) { + callback.failure(t); + serviceCall.failure(t); + } + + @Override + public void success(ServiceResponse result) { + ServicePrincipal user = new ServicePrincipalImpl(result.getBody(), innerCollection); + ServiceResponse clientResponse = new ServiceResponse<>(user, result.getResponse()); + callback.success(clientResponse); + serviceCall.success(clientResponse); + } + }).getCall()); + return serviceCall; } } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java index 3bbdb8db31da..66515f776f3d 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java @@ -12,6 +12,9 @@ import com.microsoft.azure.management.graphrbac.Users; import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.CreatableWrappersImpl; import com.microsoft.rest.RestException; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceResponse; import java.io.IOException; @@ -68,4 +71,25 @@ public UserImpl getByObjectId(String objectId) throws GraphErrorException, IOExc public UserImpl getByUserPrincipalName(String upn) throws GraphErrorException, IOException { return new UserImpl(innerCollection.get(upn).getBody(), innerCollection); } + + @Override + public ServiceCall getByUserPrincipalNameAsync(String upn, final ServiceCallback callback) { + final ServiceCall serviceCall = new ServiceCall<>(null); + serviceCall.newCall(innerCollection.getAsync(upn, new ServiceCallback() { + @Override + public void failure(Throwable t) { + callback.failure(t); + serviceCall.failure(t); + } + + @Override + public void success(ServiceResponse result) { + User user = new UserImpl(result.getBody(), innerCollection); + ServiceResponse clientResponse = new ServiceResponse(user, result.getResponse()); + callback.success(clientResponse); + serviceCall.success(clientResponse); + } + }).getCall()); + return serviceCall; + } } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java index e62eb48261a6..bf26fc88f18d 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java @@ -69,8 +69,10 @@ interface Blank extends WithIdentity { interface WithIdentity { WithAttach forObjectId(UUID objectId); WithAttach forUser(User user); + WithAttach forUser(String userPrincipalName); WithAttach forGroup(Group group); WithAttach forServicePrincipal(ServicePrincipal servicePrincipal); + WithAttach forServicePrincipal(String servicePrincipalName); } /** @@ -120,7 +122,10 @@ interface Blank extends WithIdentity { interface WithIdentity { WithAttach forObjectId(UUID objectId); WithAttach forUser(User user); + WithAttach forUser(String userPrincipalName); + WithAttach forGroup(Group group); WithAttach forServicePrincipal(ServicePrincipal servicePrincipal); + WithAttach forServicePrincipal(String servicePrincipalName); } /** diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java index b364a3f08e99..32928758577e 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java @@ -34,6 +34,8 @@ class AccessPolicyImpl AccessPolicy.Definition, AccessPolicy.UpdateDefinition, AccessPolicy.Update { + String userPrincipalName; + String servicePrincipalName; AccessPolicyImpl(AccessPolicyEntry innerObject, VaultImpl parent) { super(innerObject, parent); @@ -119,34 +121,48 @@ public VaultImpl attach() { @Override public AccessPolicyImpl forObjectId(UUID objectId) { inner().withObjectId(objectId); + inner().withTenantId(parent().tenantId()); return this; } @Override public AccessPolicyImpl forUser(User user) { inner().withObjectId(UUID.fromString(user.objectId())); + inner().withTenantId(parent().tenantId()); + return this; + } + + @Override + public AccessPolicyImpl forUser(String userPrincipalName) { + this.userPrincipalName = userPrincipalName; return this; } @Override public AccessPolicyImpl forGroup(Group group) { inner().withObjectId(UUID.fromString(group.objectId())); + inner().withTenantId(parent().tenantId()); return this; } @Override public AccessPolicyImpl forServicePrincipal(ServicePrincipal servicePrincipal) { inner().withObjectId(UUID.fromString(servicePrincipal.objectId())); + inner().withTenantId(parent().tenantId()); return this; } @Override - public AccessPolicyImpl allowKeyAllPermissions() { - initializeKeyPermissions(); - // TODO: Add all + public AccessPolicyImpl forServicePrincipal(String servicePrincipalName) { + this.servicePrincipalName = servicePrincipalName; return this; } + @Override + public AccessPolicyImpl allowKeyAllPermissions() { + return allowKeyPermissions(KeyPermissions.ALL); + } + @Override public AccessPolicyImpl disallowKeyAllPermissions() { initializeKeyPermissions(); @@ -170,8 +186,7 @@ public AccessPolicyImpl disallowKeyPermissions(List permissions) @Override public AccessPolicyImpl allowSecretAllPermissions() { - // TODO: add all - return null; + return allowSecretPermissions(SecretPermissions.ALL); } @Override diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java index d0e8da09b386..b3c22caef672 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java @@ -6,6 +6,10 @@ package com.microsoft.azure.management.keyvault.implementation; +import com.microsoft.azure.ParallelServiceCall; +import com.microsoft.azure.management.graphrbac.ServicePrincipal; +import com.microsoft.azure.management.graphrbac.User; +import com.microsoft.azure.management.graphrbac.implementation.GraphRbacManager; import com.microsoft.azure.management.keyvault.AccessPolicy; import com.microsoft.azure.management.keyvault.AccessPolicyEntry; import com.microsoft.azure.management.keyvault.Sku; @@ -20,6 +24,7 @@ import com.microsoft.rest.ServiceResponse; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.NoSuchElementException; import java.util.UUID; @@ -38,10 +43,19 @@ class VaultImpl Vault.Definition, Vault.Update { private VaultsInner client; + private GraphRbacManager graphRbacManager; + private List accessPolicies; - protected VaultImpl(String key, VaultInner innerObject, VaultsInner client, KeyVaultManager manager) { + protected VaultImpl(String key, VaultInner innerObject, VaultsInner client, KeyVaultManager manager, GraphRbacManager graphRbacManager) { super(key, innerObject, manager); this.client = client; + this.graphRbacManager = graphRbacManager; + this.accessPolicies = new ArrayList<>(); + if (innerObject != null && innerObject.properties() != null && innerObject.properties().accessPolicies() != null) { + for (AccessPolicyEntry entry : innerObject.properties().accessPolicies()) { + this.accessPolicies.add(new AccessPolicyImpl(entry, this)); + } + } } @Override @@ -70,17 +84,8 @@ public Sku sku() { @Override public List accessPolicies() { - if (inner().properties() == null) { - return null; - } - if (inner().properties().accessPolicies() == null) { - return null; - } - List accessPolicies = new ArrayList<>(); - for (AccessPolicyEntry entry : inner().properties().accessPolicies()) { - accessPolicies.add(new AccessPolicyImpl(entry, this)); - } - return accessPolicies; + AccessPolicy[] array = new AccessPolicy[accessPolicies.size()]; + return Arrays.asList(accessPolicies.toArray(array)); } @Override @@ -109,27 +114,24 @@ public Boolean enabledForTemplateDeployment() { @Override public VaultImpl withEmptyAccessPolicy() { - if (inner().properties() == null) { - inner().withProperties(new VaultProperties()); - } - inner().properties().withAccessPolicies(new ArrayList()); + this.accessPolicies = new ArrayList<>(); return this; } @Override - public Update withoutAccessPolicy(String objectId) { - return null; + public VaultImpl withoutAccessPolicy(String objectId) { + for (AccessPolicyImpl entry : this.accessPolicies) { + if (entry.objectId().toString().equals(objectId)) { + accessPolicies.remove(entry); + break; + } + } + return this; } @Override public VaultImpl withAccessPolicy(AccessPolicy accessPolicy) { - if (inner().properties() == null) { - inner().withProperties(new VaultProperties()); - } - if (inner().properties().accessPolicies() == null) { - inner().properties().withAccessPolicies(new ArrayList()); - } - inner().properties().accessPolicies().add(accessPolicy.inner()); + accessPolicies.add((AccessPolicyImpl) accessPolicy); return this; } @@ -140,15 +142,9 @@ public AccessPolicyImpl defineAccessPolicy() { @Override public AccessPolicyImpl updateAccessPolicy(String objectId) { - if (inner().properties() == null) { - return null; - } - if (inner().properties().accessPolicies() == null) { - return null; - } - for (AccessPolicyEntry entry : inner().properties().accessPolicies()) { + for (AccessPolicyImpl entry : this.accessPolicies) { if (entry.objectId().toString().equals(objectId)) { - return new AccessPolicyImpl(entry, this); + return entry; } } throw new NoSuchElementException(String.format("Identity %s not found in the access policies.", objectId)); @@ -211,27 +207,84 @@ public ServiceCall applyAsync(ServiceCallback callback) { @Override public ServiceCall createResourceAsync(final ServiceCallback serviceCallback) { - VaultCreateOrUpdateParametersInner parameters = new VaultCreateOrUpdateParametersInner(); - parameters.withLocation(regionName()); - parameters.withProperties(inner().properties()); - parameters.withTags(inner().getTags()); + final ServiceCall serviceCall = new ServiceCall(null); final VaultImpl self = this; - return client.createOrUpdateAsync(resourceGroupName(), name(), parameters, new ServiceCallback() { + serviceCall.newCall(populateAccessPolicies(new ServiceCallback() { @Override public void failure(Throwable t) { serviceCallback.failure(t); + serviceCall.failure(t); } @Override - public void success(ServiceResponse result) { - setInner(result.getBody()); - serviceCallback.success(new ServiceResponse(self, result.getResponse())); + public void success(ServiceResponse result) { + VaultCreateOrUpdateParametersInner parameters = new VaultCreateOrUpdateParametersInner(); + parameters.withLocation(regionName()); + parameters.withProperties(inner().properties()); + parameters.withTags(inner().getTags()); + serviceCall.newCall(client.createOrUpdateAsync(resourceGroupName(), name(), parameters, new ServiceCallback() { + @Override + public void failure(Throwable t) { + serviceCallback.failure(t); + serviceCall.failure(t); + } + + @Override + public void success(ServiceResponse result) { + setInner(result.getBody()); + ServiceResponse clientResponse = new ServiceResponse(self, result.getResponse()); + serviceCallback.success(clientResponse); + serviceCall.success(clientResponse); + } + }).getCall()); + } + }).getCall()); + return serviceCall; + } + + private ParallelServiceCall populateAccessPolicies(final ServiceCallback callback) { + final ParallelServiceCall parallelServiceCall = new ParallelServiceCall(); + for (final AccessPolicyImpl accessPolicy : accessPolicies) { + if (accessPolicy.objectId() == null) { + if (accessPolicy.userPrincipalName != null) { + parallelServiceCall.addCall(graphRbacManager.users().getByUserPrincipalNameAsync(accessPolicy.userPrincipalName, new ServiceCallback() { + @Override + public void failure(Throwable t) { + callback.failure(t); + parallelServiceCall.failure(t); + } + + @Override + public void success(ServiceResponse result) { + callback.success(null); + accessPolicy.forUser(result.getBody()); + } + })); + } else if (accessPolicy.servicePrincipalName != null) { + parallelServiceCall.addCall(graphRbacManager.servicePrincipals().getByServicePrincipalNameAsync(accessPolicy.servicePrincipalName, new ServiceCallback() { + @Override + public void failure(Throwable t) { + callback.failure(t); + parallelServiceCall.failure(t); + } + + @Override + public void success(ServiceResponse result) { + callback.success(null); + accessPolicy.forServicePrincipal(result.getBody()); + } + })); + } else { + throw new IllegalArgumentException("Access policy must specify object ID."); + } } - }); + } + return parallelServiceCall; } @Override public VaultImpl createResource() throws Exception { + populateAccessPolicies(null).get(); VaultCreateOrUpdateParametersInner parameters = new VaultCreateOrUpdateParametersInner(); parameters.withLocation(regionName()); parameters.withProperties(inner().properties()); diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java index ebda765beb04..e35af2c9c398 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java @@ -84,7 +84,8 @@ protected VaultImpl wrapModel(String name) { name, inner, this.innerCollection, - super.myManager); + super.myManager, + graphRbacManager); } @Override @@ -93,6 +94,7 @@ protected VaultImpl wrapModel(VaultInner vaultInner) { vaultInner.name(), vaultInner, this.innerCollection, - super.myManager); + super.myManager, + graphRbacManager); } } diff --git a/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java b/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java index 0cfbfd701213..f55da5a334fc 100644 --- a/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java +++ b/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java @@ -8,10 +8,10 @@ import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.RestClient; -import com.microsoft.azure.credentials.ApplicationTokenCredentials; import com.microsoft.azure.management.graphrbac.implementation.GraphRbacManager; import com.microsoft.azure.management.keyvault.implementation.KeyVaultManager; import com.microsoft.azure.management.resources.implementation.ResourceManager; +import com.microsoft.rest.credentials.TokenCredentials; import okhttp3.logging.HttpLoggingInterceptor; /** @@ -21,21 +21,20 @@ public abstract class KeyVaultManagementTestBase { protected static ResourceManager resourceManager; protected static GraphRbacManager graphRbacManager; protected static KeyVaultManager keyVaultManager; - protected static ApplicationTokenCredentials credentials; protected static void createClients() { - credentials = new ApplicationTokenCredentials( - System.getenv("client-id"), - System.getenv("domain"), - System.getenv("secret"), - null); - - ApplicationTokenCredentials graphCredentials = new ApplicationTokenCredentials( - System.getenv("client-id"), - System.getenv("domain"), - System.getenv("secret"), - "https://graph.windows.net/", - null); +// ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( +// System.getenv("client-id"), +// System.getenv("domain"), +// System.getenv("secret"), +// null); + +// ApplicationTokenCredentials graphCredentials = new ApplicationTokenCredentials( +// System.getenv("client-id"), +// System.getenv("domain"), +// System.getenv("secret"), +// "https://graph.windows.net/", +// null); RestClient restClient = AzureEnvironment.AZURE.newRestClientBuilder() .withCredentials(credentials) @@ -50,6 +49,6 @@ protected static void createClients() { .authenticate(graphCredentials, System.getenv("domain")); keyVaultManager = KeyVaultManager - .authenticate(restClient, System.getenv("subscription-id"), graphCredentials.getDomain()); + .authenticate(restClient, System.getenv("domain"), System.getenv("subscription-id")); } } diff --git a/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/VaultTests.java b/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/VaultTests.java index 22185e80d0c3..9b42d82a43f7 100644 --- a/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/VaultTests.java +++ b/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/VaultTests.java @@ -6,8 +6,6 @@ package com.microsoft.azure.management.keyvault; -import com.microsoft.azure.management.graphrbac.ServicePrincipal; -import com.microsoft.azure.management.graphrbac.User; import com.microsoft.azure.management.resources.fluentcore.arm.Region; import org.junit.AfterClass; import org.junit.Assert; @@ -33,13 +31,12 @@ public static void cleanup() throws Exception { @Test public void canCRUDVault() throws Exception { // CREATE - ServicePrincipal sp = graphRbacManager.servicePrincipals().getByServicePrincipalName("app-123"); - User user = graphRbacManager.users().getByUserPrincipalName("azuresdk@outlook.com"); Vault vault = keyVaultManager.vaults().define(VAULT_NAME) .withRegion(Region.US_WEST) .withNewResourceGroup(RG_NAME) .defineAccessPolicy() - .forServicePrincipal(sp) + .forServicePrincipal("http://nativeapp") + .allowKeyPermissions(KeyPermissions.LIST) .allowSecretAllPermissions() .attach() .create(); @@ -65,12 +62,9 @@ public void canCRUDVault() throws Exception { .apply(); vault.update() .defineAccessPolicy() - .forUser(user) + .forServicePrincipal("http://nativeapp") .allowKeyAllPermissions() .attach() .apply(); - vault.update() - .withoutAccessPolicy(sp.objectId()) - .apply(); } } diff --git a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/ParallelServiceCall.java b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/ParallelServiceCall.java new file mode 100644 index 000000000000..316384152031 --- /dev/null +++ b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/ParallelServiceCall.java @@ -0,0 +1,50 @@ +package com.microsoft.azure; + +import com.microsoft.rest.ServiceCall; + +import java.util.concurrent.ConcurrentLinkedQueue; + +/** + * Type represents a set of REST calls running possibly in parallel. + */ +public class ParallelServiceCall extends ServiceCall { + private ConcurrentLinkedQueue> serviceCalls; + + /** + * Creates a ParallelServiceCall. + */ + public ParallelServiceCall() { + super(null); + this.serviceCalls = new ConcurrentLinkedQueue<>(); + } + + /** + * Cancels all the service calls currently executing. + */ + public void cancel() { + for (ServiceCall call : this.serviceCalls) { + call.cancel(); + } + } + + /** + * @return true if the call has been canceled; false otherwise. + */ + public boolean isCancelled() { + for (ServiceCall call : this.serviceCalls) { + if (!call.isCanceled()) { + return false; + } + } + return true; + } + + /** + * Add a call to the list of parallel calls. + * + * @param call the call + */ + public void addCall(ServiceCall call) { + this.serviceCalls.add(call); + } +} From ef9f961b5d62fad1b67a32edb42c64f630c6b43e Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 10 Aug 2016 16:19:08 -0700 Subject: [PATCH 14/33] more checks --- .../keyvault/implementation/VaultImpl.java | 9 +++++++++ .../keyvault/KeyVaultManagementTestBase.java | 2 +- .../azure/management/keyvault/VaultTests.java | 14 +++++++++++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java index b3c22caef672..6e86d2cef4fa 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java @@ -244,8 +244,10 @@ public void success(ServiceResponse result) { private ParallelServiceCall populateAccessPolicies(final ServiceCallback callback) { final ParallelServiceCall parallelServiceCall = new ParallelServiceCall(); + boolean any = false; for (final AccessPolicyImpl accessPolicy : accessPolicies) { if (accessPolicy.objectId() == null) { + any = true; if (accessPolicy.userPrincipalName != null) { parallelServiceCall.addCall(graphRbacManager.users().getByUserPrincipalNameAsync(accessPolicy.userPrincipalName, new ServiceCallback() { @Override @@ -279,6 +281,9 @@ public void success(ServiceResponse result) { } } } + if (!any) { + parallelServiceCall.success(null); + } return parallelServiceCall; } @@ -289,6 +294,10 @@ public VaultImpl createResource() throws Exception { parameters.withLocation(regionName()); parameters.withProperties(inner().properties()); parameters.withTags(inner().getTags()); + parameters.properties().accessPolicies().clear(); + for (AccessPolicy accessPolicy : accessPolicies) { + parameters.properties().accessPolicies().add(accessPolicy.inner()); + } this.setInner(client.createOrUpdate(resourceGroupName(), name(), parameters).getBody()); return this; } diff --git a/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java b/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java index f55da5a334fc..31cfe9eaa0bf 100644 --- a/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java +++ b/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java @@ -49,6 +49,6 @@ protected static void createClients() { .authenticate(graphCredentials, System.getenv("domain")); keyVaultManager = KeyVaultManager - .authenticate(restClient, System.getenv("domain"), System.getenv("subscription-id")); + .authenticate(restClient, System.getenv("domain"), "6b085460-5f21-477e-ba44-1035046e9101"); } } diff --git a/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/VaultTests.java b/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/VaultTests.java index 9b42d82a43f7..9f2c52a1486a 100644 --- a/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/VaultTests.java +++ b/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/VaultTests.java @@ -6,13 +6,11 @@ package com.microsoft.azure.management.keyvault; -import com.microsoft.azure.management.resources.fluentcore.arm.Region; import org.junit.AfterClass; -import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.util.List; +import java.util.UUID; public class VaultTests extends KeyVaultManagementTestBase { private static final String RG_NAME = "javacsmrg901"; @@ -30,6 +28,7 @@ public static void cleanup() throws Exception { @Test public void canCRUDVault() throws Exception { + /* // CREATE Vault vault = keyVaultManager.vaults().define(VAULT_NAME) .withRegion(Region.US_WEST) @@ -66,5 +65,14 @@ public void canCRUDVault() throws Exception { .allowKeyAllPermissions() .attach() .apply(); + */ + keyVaultManager.vaults().getByGroup("RG-AzureSDK-WUS", "KV-AzureSDK") + .update() + .defineAccessPolicy() + .forObjectId(UUID.fromString("794b8347-c398-4fd8-b557-37b60946e830")) + .allowKeyPermissions(KeyPermissions.ALL) + .allowSecretPermissions(SecretPermissions.ALL) + .attach() + .apply(); } } From 1e307c459ebb60d56992641895ee2b616af264bc Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 17 Aug 2016 10:46:00 -0700 Subject: [PATCH 15/33] Move key vault tests to correct location --- .../implementation/ServicePrincipalsImpl.java | 13 +++++--- .../keyvault/implementation/VaultImpl.java | 16 +++++++--- .../keyvault/KeyVaultManagementTestBase.java | 32 ++++++++++--------- .../azure/management/keyvault/VaultTests.java | 16 +++------- 4 files changed, 42 insertions(+), 35 deletions(-) rename azure-mgmt-keyvault/src/{main => }/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java (64%) rename azure-mgmt-keyvault/src/{main => }/test/java/com/microsoft/azure/management/keyvault/VaultTests.java (80%) diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java index bc7f797736eb..e21a57c8e74f 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java @@ -6,6 +6,7 @@ package com.microsoft.azure.management.graphrbac.implementation; +import com.microsoft.azure.ListOperationCallback; import com.microsoft.azure.PagedList; import com.microsoft.azure.management.graphrbac.GraphErrorException; import com.microsoft.azure.management.graphrbac.ServicePrincipal; @@ -83,9 +84,9 @@ public ServicePrincipal getByServicePrincipalName(String spn) throws GraphErrorE } @Override - public ServiceCall getByServicePrincipalNameAsync(String spn, final ServiceCallback callback) { + public ServiceCall getByServicePrincipalNameAsync(final String spn, final ServiceCallback callback) { final ServiceCall serviceCall = new ServiceCall<>(null); - serviceCall.newCall(innerCollection.getAsync(spn, new ServiceCallback() { + serviceCall.newCall(innerCollection.listAsync(String.format("servicePrincipalNames/any(c:c eq '%s')", spn), new ListOperationCallback() { @Override public void failure(Throwable t) { callback.failure(t); @@ -93,8 +94,12 @@ public void failure(Throwable t) { } @Override - public void success(ServiceResponse result) { - ServicePrincipal user = new ServicePrincipalImpl(result.getBody(), innerCollection); + public void success(ServiceResponse> result) { + List servicePrincipals = result.getBody(); + if (servicePrincipals == null || servicePrincipals.isEmpty()) { + failure(new GraphErrorException("Service principal not found for SPN: " + spn)); + } + ServicePrincipal user = new ServicePrincipalImpl(servicePrincipals.get(0), innerCollection); ServiceResponse clientResponse = new ServiceResponse<>(user, result.getResponse()); callback.success(clientResponse); serviceCall.success(clientResponse); diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java index 6e86d2cef4fa..eeb5e51d42f1 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java @@ -252,13 +252,17 @@ private ParallelServiceCall populateAccessPolicies(final ServiceCallback call parallelServiceCall.addCall(graphRbacManager.users().getByUserPrincipalNameAsync(accessPolicy.userPrincipalName, new ServiceCallback() { @Override public void failure(Throwable t) { - callback.failure(t); + if (callback != null) { + callback.failure(t); + } parallelServiceCall.failure(t); } @Override public void success(ServiceResponse result) { - callback.success(null); + if (callback != null) { + callback.success(null); + } accessPolicy.forUser(result.getBody()); } })); @@ -266,13 +270,17 @@ public void success(ServiceResponse result) { parallelServiceCall.addCall(graphRbacManager.servicePrincipals().getByServicePrincipalNameAsync(accessPolicy.servicePrincipalName, new ServiceCallback() { @Override public void failure(Throwable t) { - callback.failure(t); + if (callback != null) { + callback.failure(t); + } parallelServiceCall.failure(t); } @Override public void success(ServiceResponse result) { - callback.success(null); + if (callback != null) { + callback.success(null); + } accessPolicy.forServicePrincipal(result.getBody()); } })); diff --git a/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java b/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java similarity index 64% rename from azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java rename to azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java index 31cfe9eaa0bf..e94591a4f33a 100644 --- a/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java +++ b/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java @@ -8,10 +8,10 @@ import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.RestClient; +import com.microsoft.azure.credentials.ApplicationTokenCredentials; import com.microsoft.azure.management.graphrbac.implementation.GraphRbacManager; import com.microsoft.azure.management.keyvault.implementation.KeyVaultManager; import com.microsoft.azure.management.resources.implementation.ResourceManager; -import com.microsoft.rest.credentials.TokenCredentials; import okhttp3.logging.HttpLoggingInterceptor; /** @@ -23,22 +23,22 @@ public abstract class KeyVaultManagementTestBase { protected static KeyVaultManager keyVaultManager; protected static void createClients() { -// ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( -// System.getenv("client-id"), -// System.getenv("domain"), -// System.getenv("secret"), -// null); - -// ApplicationTokenCredentials graphCredentials = new ApplicationTokenCredentials( -// System.getenv("client-id"), -// System.getenv("domain"), -// System.getenv("secret"), -// "https://graph.windows.net/", -// null); + ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( + System.getenv("client-id"), + System.getenv("domain"), + System.getenv("secret"), + null); + + ApplicationTokenCredentials graphCredentials = new ApplicationTokenCredentials( + System.getenv("client-id"), + System.getenv("domain"), + System.getenv("secret"), + "https://graph.windows.net/", + null); RestClient restClient = AzureEnvironment.AZURE.newRestClientBuilder() .withCredentials(credentials) - .withLogLevel(HttpLoggingInterceptor.Level.BODY) + .withLogLevel(HttpLoggingInterceptor.Level.NONE) .build(); resourceManager = ResourceManager @@ -46,9 +46,11 @@ protected static void createClients() { .withSubscription(System.getenv("subscription-id")); graphRbacManager = GraphRbacManager + .configure() + .withLogLevel(HttpLoggingInterceptor.Level.BASIC) .authenticate(graphCredentials, System.getenv("domain")); keyVaultManager = KeyVaultManager - .authenticate(restClient, System.getenv("domain"), "6b085460-5f21-477e-ba44-1035046e9101"); + .authenticate(restClient, System.getenv("domain"), System.getenv("subscription-id")); } } diff --git a/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/VaultTests.java b/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/VaultTests.java similarity index 80% rename from azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/VaultTests.java rename to azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/VaultTests.java index 9f2c52a1486a..59b43e85beba 100644 --- a/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/VaultTests.java +++ b/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/VaultTests.java @@ -6,11 +6,13 @@ package com.microsoft.azure.management.keyvault; +import com.microsoft.azure.management.resources.fluentcore.arm.Region; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.util.UUID; +import java.util.List; public class VaultTests extends KeyVaultManagementTestBase { private static final String RG_NAME = "javacsmrg901"; @@ -28,13 +30,12 @@ public static void cleanup() throws Exception { @Test public void canCRUDVault() throws Exception { - /* // CREATE Vault vault = keyVaultManager.vaults().define(VAULT_NAME) .withRegion(Region.US_WEST) .withNewResourceGroup(RG_NAME) .defineAccessPolicy() - .forServicePrincipal("http://nativeapp") + .forServicePrincipal("http://graphapp") .allowKeyPermissions(KeyPermissions.LIST) .allowSecretAllPermissions() .attach() @@ -65,14 +66,5 @@ public void canCRUDVault() throws Exception { .allowKeyAllPermissions() .attach() .apply(); - */ - keyVaultManager.vaults().getByGroup("RG-AzureSDK-WUS", "KV-AzureSDK") - .update() - .defineAccessPolicy() - .forObjectId(UUID.fromString("794b8347-c398-4fd8-b557-37b60946e830")) - .allowKeyPermissions(KeyPermissions.ALL) - .allowSecretPermissions(SecretPermissions.ALL) - .attach() - .apply(); } } From cd66a2099c8ffef503d749ac7270f9a3e449f549 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Tue, 30 Aug 2016 16:12:57 -0700 Subject: [PATCH 16/33] Regenerate graph & keyvault client --- .../azure/management/graphrbac/Users.java | 9 + .../implementation/ApplicationsInner.java | 664 ----------------- .../graphrbac/implementation/GroupsInner.java | 522 -------------- .../implementation/ObjectsInner.java | 37 - .../implementation/ServicePrincipalImpl.java | 14 +- .../ServicePrincipalsInner.java | 677 ------------------ .../graphrbac/implementation/UserImpl.java | 30 +- .../graphrbac/implementation/UsersImpl.java | 36 +- .../graphrbac/implementation/UsersInner.java | 354 --------- .../implementation/AccessPolicyImpl.java | 5 - .../resources/fluentcore/model/Creatable.java | 2 +- .../model/implementation/IndexableImpl.java | 2 +- 12 files changed, 58 insertions(+), 2294 deletions(-) diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java index 42b09e31b295..2a50b619ee29 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java @@ -11,6 +11,7 @@ import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; +import rx.Observable; import java.io.IOException; @@ -49,4 +50,12 @@ public interface Users extends * @return an Future based service call */ ServiceCall getByUserPrincipalNameAsync(String upn, ServiceCallback callback); + + /** + * Gets the information about a user. + * + * @param upn the user principal name + * @return an Future based service call + */ + Observable getByUserPrincipalNameAsync(String upn); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationsInner.java index 873c03b5635a..d77097b6d262 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationsInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationsInner.java @@ -96,22 +96,6 @@ interface ApplicationsService { @PATCH("{tenantID}/applications/{applicationObjectId}/passwordCredentials") Observable> updatePasswordCredentials(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body PasswordCredentialsUpdateParameters parameters, @Header("User-Agent") String userAgent); - @Headers("Content-Type: application/json; charset=utf-8") - @GET("{tenantID}/applications/{applicationObjectId}/keyCredentials") - Call listKeyCredentials(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); - - @Headers("Content-Type: application/json; charset=utf-8") - @PATCH("{tenantID}/applications/{applicationObjectId}/keyCredentials") - Call updateKeyCredentials(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body KeyCredentialsUpdateParameters parameters, @Header("User-Agent") String userAgent); - - @Headers("Content-Type: application/json; charset=utf-8") - @GET("{tenantID}/applications/{applicationObjectId}/passwordCredentials") - Call listPasswordCredentials(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); - - @Headers("Content-Type: application/json; charset=utf-8") - @PATCH("{tenantID}/applications/{applicationObjectId}/passwordCredentials") - Call updatePasswordCredentials(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body PasswordCredentialsUpdateParameters parameters, @Header("User-Agent") String userAgent); - } /** @@ -123,24 +107,8 @@ interface ApplicationsService { * @throws IllegalArgumentException exception thrown from invalid parameters * @return the ApplicationInner object if successful. */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public ApplicationInner create(ApplicationCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { return createWithServiceResponseAsync(parameters).toBlocking().single().getBody(); -======= - public ServiceResponse create(ApplicationCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(parameters); - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return createDelegate(call.execute()); ->>>>>>> Regen graph and a bunch of refactors } /** @@ -148,7 +116,6 @@ public ServiceResponse create(ApplicationCreateParametersInner * * @param parameters Parameters to create an application. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall createAsync(ApplicationCreateParametersInner parameters, final ServiceCallback serviceCallback) { @@ -177,11 +144,6 @@ public ApplicationInner call(ServiceResponse response) { * @return the observable to the ApplicationInner object */ public Observable> createWithServiceResponseAsync(ApplicationCreateParametersInner parameters) { -======= - * @return the {@link Call} object - */ - public ServiceCall createAsync(ApplicationCreateParametersInner parameters, final ServiceCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -192,7 +154,6 @@ public ServiceCall createAsync(ApplicationCreateParametersInne throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(parameters); -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -203,24 +164,6 @@ public Observable> call(Response } catch (Throwable t) { return Observable.error(t); } -======= - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = createDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -273,11 +216,7 @@ public List call(ServiceResponse> respo * * @return the observable to the List<ApplicationInner> object */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public Observable>> listWithServiceResponseAsync() { -======= - public ServiceResponse> list() throws GraphErrorException, IOException, IllegalArgumentException { ->>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -318,7 +257,6 @@ public List list(String filter) throws GraphErrorException, IO * * @param filter The filters to apply on the operation * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listAsync(String filter, final ServiceCallback> serviceCallback) { @@ -336,32 +274,6 @@ public Observable> listAsync(String filter) { @Override public List call(ServiceResponse> response) { return response.getBody(); -======= - * @return the {@link Call} object - */ - public ServiceCall> listAsync(final ServiceCallback> serviceCallback) { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - final String filter = null; - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); - } ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -370,18 +282,9 @@ public void onResponse(Call call, Response response) * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. * * @param filter The filters to apply on the operation -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the observable to the List<ApplicationInner> object */ public Observable>> listWithServiceResponseAsync(String filter) { -======= - * @throws GraphErrorException exception thrown from REST call - * @throws IOException exception thrown from serialization/deserialization - * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<ApplicationInner> object wrapped in {@link ServiceResponse} if successful. - */ - public ServiceResponse> list(String filter) throws GraphErrorException, IOException, IllegalArgumentException { ->>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -427,7 +330,6 @@ public void delete(String applicationObjectId) throws GraphErrorException, IOExc * * @param applicationObjectId Application object id * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall deleteAsync(String applicationObjectId, final ServiceCallback serviceCallback) { @@ -459,18 +361,12 @@ public Observable> deleteWithServiceResponseAsync(String a if (applicationObjectId == null) { throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } -======= - * @return the {@link Call} object - */ - public ServiceCall> listAsync(String filter, final ServiceCallback> serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.delete(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -481,21 +377,6 @@ public Observable> call(Response response) { } catch (Throwable t) { return Observable.error(t); } -======= - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -546,7 +427,6 @@ public ApplicationInner call(ServiceResponse response) { }); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 /** * Get an application by object Id. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. * @@ -580,11 +460,6 @@ public Observable> call(Response private ServiceResponse getDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(200, new TypeToken() { }.getType()) -======= - private ServiceResponse> listDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) - .register(200, new TypeToken>() { }.getType()) ->>>>>>> Regen graph and a bunch of refactors .registerError(GraphErrorException.class) .build(response); } @@ -593,10 +468,7 @@ private ServiceResponse> listDelegate(Response>>>>>> Regen graph and a bunch of refactors * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters @@ -624,7 +496,6 @@ public ServiceCall patchAsync(String applicationObjectId, ApplicationUpdat * @param parameters Parameters to update an existing application. * @return the {@link ServiceResponse} object if successful. */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public Observable patchAsync(String applicationObjectId, ApplicationUpdateParametersInner parameters) { return patchWithServiceResponseAsync(applicationObjectId, parameters).map(new Func1, Void>() { @Override @@ -642,9 +513,6 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> patchWithServiceResponseAsync(String applicationObjectId, ApplicationUpdateParametersInner parameters) { -======= - public ServiceResponse delete(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { ->>>>>>> Regen graph and a bunch of refactors if (applicationObjectId == null) { throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } @@ -697,7 +565,6 @@ public List listKeyCredentials(String applicationObjectId) t * * @param applicationObjectId Application object id * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listKeyCredentialsAsync(String applicationObjectId, final ServiceCallback> serviceCallback) { @@ -726,11 +593,6 @@ public List call(ServiceResponse> r * @return the observable to the List<KeyCredentialInner> object */ public Observable>> listKeyCredentialsWithServiceResponseAsync(String applicationObjectId) { -======= - * @return the {@link Call} object - */ - public ServiceCall deleteAsync(String applicationObjectId, final ServiceCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (applicationObjectId == null) { throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } @@ -740,7 +602,6 @@ public ServiceCall deleteAsync(String applicationObjectId, final ServiceCa if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.listKeyCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -752,37 +613,13 @@ public Observable>> call(Response call = service.delete(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = deleteDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 private ServiceResponse> listKeyCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) -======= - private ServiceResponse deleteDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) - .register(204, new TypeToken() { }.getType()) ->>>>>>> Regen graph and a bunch of refactors .registerError(GraphErrorException.class) .build(response); } @@ -795,7 +632,6 @@ private ServiceResponse deleteDelegate(Response response) th * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public void updateKeyCredentials(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { updateKeyCredentialsWithServiceResponseAsync(applicationObjectId).toBlocking().single().getBody(); } @@ -833,9 +669,6 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> updateKeyCredentialsWithServiceResponseAsync(String applicationObjectId) { -======= - public ServiceResponse get(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { ->>>>>>> Regen graph and a bunch of refactors if (applicationObjectId == null) { throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } @@ -881,7 +714,6 @@ public void updateKeyCredentials(String applicationObjectId, List updateKeyCredentialsAsync(String applicationObjectId, List value, final ServiceCallback serviceCallback) { @@ -912,11 +744,6 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> updateKeyCredentialsWithServiceResponseAsync(String applicationObjectId, List value) { -======= - * @return the {@link Call} object - */ - public ServiceCall getAsync(String applicationObjectId, final ServiceCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (applicationObjectId == null) { throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } @@ -926,7 +753,6 @@ public ServiceCall getAsync(String applicationObjectId, final if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 Validator.validate(value); KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); parameters.withValue(value); @@ -940,24 +766,6 @@ public Observable> call(Response response) { } catch (Throwable t) { return Observable.error(t); } -======= - Call call = service.get(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = getDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -1008,7 +816,6 @@ public List call(ServiceResponse>> call(Response< private ServiceResponse> listPasswordCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) -======= - private ServiceResponse getDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) - .register(200, new TypeToken() { }.getType()) ->>>>>>> Regen graph and a bunch of refactors .registerError(GraphErrorException.class) .build(response); } @@ -1056,10 +858,6 @@ private ServiceResponse getDelegate(Response res * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. * * @param applicationObjectId Application object id -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 -======= - * @param parameters Parameters to update an existing application. ->>>>>>> Regen graph and a bunch of refactors * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters @@ -1085,7 +883,6 @@ public ServiceCall updatePasswordCredentialsAsync(String applicationObject * @param applicationObjectId Application object id * @return the {@link ServiceResponse} object if successful. */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public Observable updatePasswordCredentialsAsync(String applicationObjectId) { return updatePasswordCredentialsWithServiceResponseAsync(applicationObjectId).map(new Func1, Void>() { @Override @@ -1102,9 +899,6 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> updatePasswordCredentialsWithServiceResponseAsync(String applicationObjectId) { -======= - public ServiceResponse patch(String applicationObjectId, ApplicationUpdateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { ->>>>>>> Regen graph and a bunch of refactors if (applicationObjectId == null) { throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } @@ -1150,7 +944,6 @@ public void updatePasswordCredentials(String applicationObjectId, List updatePasswordCredentialsAsync(String applicationObjectId, List value, final ServiceCallback serviceCallback) { @@ -1181,27 +974,15 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> updatePasswordCredentialsWithServiceResponseAsync(String applicationObjectId, List value) { -======= - * @return the {@link Call} object - */ - public ServiceCall patchAsync(String applicationObjectId, ApplicationUpdateParametersInner parameters, final ServiceCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (applicationObjectId == null) { throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 -======= - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); ->>>>>>> Regen graph and a bunch of refactors } if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 Validator.validate(value); PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); parameters.withValue(value); @@ -1215,451 +996,6 @@ public Observable> call(Response response) { } catch (Throwable t) { return Observable.error(t); } -======= - Validator.validate(parameters); - Call call = service.patch(applicationObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = patchDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); - } - } - }); - return serviceCall; - } - - private ServiceResponse patchDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) - .register(204, new TypeToken() { }.getType()) - .registerError(GraphErrorException.class) - .build(response); - } - - /** - * Get keyCredentials associated with the application by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. - * - * @param applicationObjectId Application object id - * @throws GraphErrorException exception thrown from REST call - * @throws IOException exception thrown from serialization/deserialization - * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<KeyCredentialInner> object wrapped in {@link ServiceResponse} if successful. - */ - public ServiceResponse> listKeyCredentials(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { - if (applicationObjectId == null) { - throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.listKeyCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listKeyCredentialsDelegate(call.execute()); - List result = response.getBody().getItems(); - return new ServiceResponse<>(result, response.getResponse()); - } - - /** - * Get keyCredentials associated with the application by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. - * - * @param applicationObjectId Application object id - * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object - */ - public ServiceCall> listKeyCredentialsAsync(String applicationObjectId, final ServiceCallback> serviceCallback) { - if (applicationObjectId == null) { - throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.listKeyCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listKeyCredentialsDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); - } - } - }); - return serviceCall; - } - - private ServiceResponse> listKeyCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) - .register(200, new TypeToken>() { }.getType()) - .registerError(GraphErrorException.class) - .build(response); - } - - /** - * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. - * - * @param applicationObjectId Application object id - * @throws GraphErrorException exception thrown from REST call - * @throws IOException exception thrown from serialization/deserialization - * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the {@link ServiceResponse} object if successful. - */ - public ServiceResponse updateKeyCredentials(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { - if (applicationObjectId == null) { - throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - final List value = null; - KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); - parameters.withValue(null); - Call call = service.updateKeyCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - return updateKeyCredentialsDelegate(call.execute()); - } - - /** - * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. - * - * @param applicationObjectId Application object id - * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object - */ - public ServiceCall updateKeyCredentialsAsync(String applicationObjectId, final ServiceCallback serviceCallback) { - if (applicationObjectId == null) { - throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - final List value = null; - KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); - parameters.withValue(null); - Call call = service.updateKeyCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = updateKeyCredentialsDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); - } - } - }); - return serviceCall; - } - - /** - * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. - * - * @param applicationObjectId Application object id - * @param value KeyCredential list. - * @throws GraphErrorException exception thrown from REST call - * @throws IOException exception thrown from serialization/deserialization - * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the {@link ServiceResponse} object if successful. - */ - public ServiceResponse updateKeyCredentials(String applicationObjectId, List value) throws GraphErrorException, IOException, IllegalArgumentException { - if (applicationObjectId == null) { - throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(value); - KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); - parameters.withValue(value); - Call call = service.updateKeyCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - return updateKeyCredentialsDelegate(call.execute()); - } - - /** - * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. - * - * @param applicationObjectId Application object id - * @param value KeyCredential list. - * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object - */ - public ServiceCall updateKeyCredentialsAsync(String applicationObjectId, List value, final ServiceCallback serviceCallback) { - if (applicationObjectId == null) { - throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(value); - KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); - parameters.withValue(value); - Call call = service.updateKeyCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = updateKeyCredentialsDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); - } - } - }); - return serviceCall; - } - - private ServiceResponse updateKeyCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) - .register(204, new TypeToken() { }.getType()) - .registerError(GraphErrorException.class) - .build(response); - } - - /** - * Gets passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. - * - * @param applicationObjectId Application object id - * @throws GraphErrorException exception thrown from REST call - * @throws IOException exception thrown from serialization/deserialization - * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<PasswordCredentialInner> object wrapped in {@link ServiceResponse} if successful. - */ - public ServiceResponse> listPasswordCredentials(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { - if (applicationObjectId == null) { - throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.listPasswordCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listPasswordCredentialsDelegate(call.execute()); - List result = response.getBody().getItems(); - return new ServiceResponse<>(result, response.getResponse()); - } - - /** - * Gets passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. - * - * @param applicationObjectId Application object id - * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object - */ - public ServiceCall> listPasswordCredentialsAsync(String applicationObjectId, final ServiceCallback> serviceCallback) { - if (applicationObjectId == null) { - throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.listPasswordCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listPasswordCredentialsDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); - } - } - }); - return serviceCall; - } - - private ServiceResponse> listPasswordCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) - .register(200, new TypeToken>() { }.getType()) - .registerError(GraphErrorException.class) - .build(response); - } - - /** - * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. - * - * @param applicationObjectId Application object id - * @throws GraphErrorException exception thrown from REST call - * @throws IOException exception thrown from serialization/deserialization - * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the {@link ServiceResponse} object if successful. - */ - public ServiceResponse updatePasswordCredentials(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { - if (applicationObjectId == null) { - throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - final List value = null; - PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); - parameters.withValue(null); - Call call = service.updatePasswordCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - return updatePasswordCredentialsDelegate(call.execute()); - } - - /** - * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. - * - * @param applicationObjectId Application object id - * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object - */ - public ServiceCall updatePasswordCredentialsAsync(String applicationObjectId, final ServiceCallback serviceCallback) { - if (applicationObjectId == null) { - throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - final List value = null; - PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); - parameters.withValue(null); - Call call = service.updatePasswordCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = updatePasswordCredentialsDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); - } - } - }); - return serviceCall; - } - - /** - * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. - * - * @param applicationObjectId Application object id - * @param value PasswordCredential list. - * @throws GraphErrorException exception thrown from REST call - * @throws IOException exception thrown from serialization/deserialization - * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the {@link ServiceResponse} object if successful. - */ - public ServiceResponse updatePasswordCredentials(String applicationObjectId, List value) throws GraphErrorException, IOException, IllegalArgumentException { - if (applicationObjectId == null) { - throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(value); - PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); - parameters.withValue(value); - Call call = service.updatePasswordCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - return updatePasswordCredentialsDelegate(call.execute()); - } - - /** - * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. - * - * @param applicationObjectId Application object id - * @param value PasswordCredential list. - * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object - */ - public ServiceCall updatePasswordCredentialsAsync(String applicationObjectId, List value, final ServiceCallback serviceCallback) { - if (applicationObjectId == null) { - throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(value); - PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); - parameters.withValue(value); - Call call = service.updatePasswordCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = updatePasswordCredentialsDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java index 0614c3c2f655..909a198bd288 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java @@ -119,24 +119,8 @@ interface GroupsService { * @throws IllegalArgumentException exception thrown from invalid parameters * @return the CheckGroupMembershipResultInner object if successful. */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public CheckGroupMembershipResultInner isMemberOf(CheckGroupMembershipParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { return isMemberOfWithServiceResponseAsync(parameters).toBlocking().single().getBody(); -======= - public ServiceResponse isMemberOf(CheckGroupMembershipParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(parameters); - Call call = service.isMemberOf(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return isMemberOfDelegate(call.execute()); ->>>>>>> Regen graph and a bunch of refactors } /** @@ -144,7 +128,6 @@ public ServiceResponse isMemberOf(CheckGroupMem * * @param parameters Check group membership parameters. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall isMemberOfAsync(CheckGroupMembershipParametersInner parameters, final ServiceCallback serviceCallback) { @@ -173,11 +156,6 @@ public CheckGroupMembershipResultInner call(ServiceResponse> isMemberOfWithServiceResponseAsync(CheckGroupMembershipParametersInner parameters) { -======= - * @return the {@link Call} object - */ - public ServiceCall isMemberOfAsync(CheckGroupMembershipParametersInner parameters, final ServiceCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -188,7 +166,6 @@ public ServiceCall isMemberOfAsync(CheckGroupMe throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(parameters); -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.isMemberOf(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -199,24 +176,6 @@ public Observable> call(Respons } catch (Throwable t) { return Observable.error(t); } -======= - Call call = service.isMemberOf(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = isMemberOfDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -237,26 +196,8 @@ private ServiceResponse isMemberOfDelegate(Resp * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public void removeMember(String groupObjectId, String memberObjectId) throws GraphErrorException, IOException, IllegalArgumentException { removeMemberWithServiceResponseAsync(groupObjectId, memberObjectId).toBlocking().single().getBody(); -======= - public ServiceResponse removeMember(String groupObjectId, String memberObjectId) throws GraphErrorException, IOException, IllegalArgumentException { - if (groupObjectId == null) { - throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); - } - if (memberObjectId == null) { - throw new IllegalArgumentException("Parameter memberObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.removeMember(groupObjectId, memberObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return removeMemberDelegate(call.execute()); ->>>>>>> Regen graph and a bunch of refactors } /** @@ -265,7 +206,6 @@ public ServiceResponse removeMember(String groupObjectId, String memberObj * @param groupObjectId Group object id * @param memberObjectId Member Object id * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall removeMemberAsync(String groupObjectId, String memberObjectId, final ServiceCallback serviceCallback) { @@ -296,11 +236,6 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> removeMemberWithServiceResponseAsync(String groupObjectId, String memberObjectId) { -======= - * @return the {@link Call} object - */ - public ServiceCall removeMemberAsync(String groupObjectId, String memberObjectId, final ServiceCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (groupObjectId == null) { throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); } @@ -313,7 +248,6 @@ public ServiceCall removeMemberAsync(String groupObjectId, String memberOb if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.removeMember(groupObjectId, memberObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -324,24 +258,6 @@ public Observable> call(Response response) { } catch (Throwable t) { return Observable.error(t); } -======= - Call call = service.removeMember(groupObjectId, memberObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = removeMemberDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -362,28 +278,8 @@ private ServiceResponse removeMemberDelegate(Response respon * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public void addMember(String groupObjectId, String url) throws GraphErrorException, IOException, IllegalArgumentException { addMemberWithServiceResponseAsync(groupObjectId, url).toBlocking().single().getBody(); -======= - public ServiceResponse addMember(String groupObjectId, String url) throws GraphErrorException, IOException, IllegalArgumentException { - if (groupObjectId == null) { - throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - if (url == null) { - throw new IllegalArgumentException("Parameter url is required and cannot be null."); - } - GroupAddMemberParameters parameters = new GroupAddMemberParameters(); - parameters.withUrl(url); - Call call = service.addMember(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - return addMemberDelegate(call.execute()); ->>>>>>> Regen graph and a bunch of refactors } /** @@ -392,7 +288,6 @@ public ServiceResponse addMember(String groupObjectId, String url) throws * @param groupObjectId Group object id * @param url Member Object Url as "https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd", where "0b1f9851-1bf0-433f-aec3-cb9272f093dc" is the tenantId and "f260bbc4-c254-447b-94cf-293b5ec434dd" is the objectId of the member (user, application, servicePrincipal, group) to be added. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall addMemberAsync(String groupObjectId, String url, final ServiceCallback serviceCallback) { @@ -423,11 +318,6 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> addMemberWithServiceResponseAsync(String groupObjectId, String url) { -======= - * @return the {@link Call} object - */ - public ServiceCall addMemberAsync(String groupObjectId, String url, final ServiceCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (groupObjectId == null) { throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); } @@ -442,7 +332,6 @@ public ServiceCall addMemberAsync(String groupObjectId, String url, final } GroupAddMemberParameters parameters = new GroupAddMemberParameters(); parameters.withUrl(url); -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.addMember(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -453,24 +342,6 @@ public Observable> call(Response response) { } catch (Throwable t) { return Observable.error(t); } -======= - Call call = service.addMember(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = addMemberDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -490,23 +361,8 @@ private ServiceResponse addMemberDelegate(Response response) * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public void delete(String groupObjectId) throws GraphErrorException, IOException, IllegalArgumentException { deleteWithServiceResponseAsync(groupObjectId).toBlocking().single().getBody(); -======= - public ServiceResponse delete(String groupObjectId) throws GraphErrorException, IOException, IllegalArgumentException { - if (groupObjectId == null) { - throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.delete(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return deleteDelegate(call.execute()); ->>>>>>> Regen graph and a bunch of refactors } /** @@ -514,7 +370,6 @@ public ServiceResponse delete(String groupObjectId) throws GraphErrorExcep * * @param groupObjectId Object id * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall deleteAsync(String groupObjectId, final ServiceCallback serviceCallback) { @@ -543,11 +398,6 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> deleteWithServiceResponseAsync(String groupObjectId) { -======= - * @return the {@link Call} object - */ - public ServiceCall deleteAsync(String groupObjectId, final ServiceCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (groupObjectId == null) { throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); } @@ -557,7 +407,6 @@ public ServiceCall deleteAsync(String groupObjectId, final ServiceCallback if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.delete(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -568,24 +417,6 @@ public Observable> call(Response response) { } catch (Throwable t) { return Observable.error(t); } -======= - Call call = service.delete(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = deleteDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -606,24 +437,8 @@ private ServiceResponse deleteDelegate(Response response) th * @throws IllegalArgumentException exception thrown from invalid parameters * @return the ADGroupInner object if successful. */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public ADGroupInner create(GroupCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { return createWithServiceResponseAsync(parameters).toBlocking().single().getBody(); -======= - public ServiceResponse create(GroupCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(parameters); - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return createDelegate(call.execute()); ->>>>>>> Regen graph and a bunch of refactors } /** @@ -631,7 +446,6 @@ public ServiceResponse create(GroupCreateParametersInner parameter * * @param parameters Parameters to create a group * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall createAsync(GroupCreateParametersInner parameters, final ServiceCallback serviceCallback) { @@ -660,11 +474,6 @@ public ADGroupInner call(ServiceResponse response) { * @return the observable to the ADGroupInner object */ public Observable> createWithServiceResponseAsync(GroupCreateParametersInner parameters) { -======= - * @return the {@link Call} object - */ - public ServiceCall createAsync(GroupCreateParametersInner parameters, final ServiceCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -675,7 +484,6 @@ public ServiceCall createAsync(GroupCreateParametersInner paramete throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(parameters); -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -686,24 +494,6 @@ public Observable> call(Response res } catch (Throwable t) { return Observable.error(t); } -======= - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = createDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -723,29 +513,12 @@ private ServiceResponse createDelegate(Response resp * @throws IllegalArgumentException exception thrown from invalid parameters * @return the PagedList<ADGroupInner> object if successful. */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public PagedList list() throws GraphErrorException, IOException, IllegalArgumentException { ServiceResponse> response = listSinglePageAsync().toBlocking().single(); return new PagedList(response.getBody()) { @Override public Page nextPage(String nextLink) throws RestException, IOException { return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); -======= - public ServiceResponse> list() throws GraphErrorException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - final String filter = null; - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { - @Override - public Page nextPage(String nextLink) throws GraphErrorException, IOException { - return listNext(nextLink).getBody(); ->>>>>>> Regen graph and a bunch of refactors } }; } @@ -754,7 +527,6 @@ public Page nextPage(String nextLink) throws GraphErrorException, * Gets list of groups for the current tenant. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listAsync(final ListOperationCallback serviceCallback) { @@ -809,11 +581,6 @@ public Observable>> call(ServiceResponse>> listSinglePageAsync() { -======= - * @return the {@link Call} object - */ - public ServiceCall> listAsync(final ListOperationCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -821,7 +588,6 @@ public ServiceCall> listAsync(final ListOperationCallback, Observable>>>() { @Override @@ -832,30 +598,6 @@ public Observable>> call(Response call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - if (serviceCallback != null) { - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); - } - } - serviceCall.success(new ServiceResponse<>(result.getBody().getItems(), response)); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -869,28 +611,12 @@ public void onResponse(Call call, Response response) * @throws IllegalArgumentException exception thrown from invalid parameters * @return the PagedList<ADGroupInner> object if successful. */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public PagedList list(final String filter) throws GraphErrorException, IOException, IllegalArgumentException { ServiceResponse> response = listSinglePageAsync(filter).toBlocking().single(); return new PagedList(response.getBody()) { @Override public Page nextPage(String nextLink) throws RestException, IOException { return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); -======= - public ServiceResponse> list(final String filter) throws GraphErrorException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { - @Override - public Page nextPage(String nextLink) throws GraphErrorException, IOException { - return listNext(nextLink).getBody(); ->>>>>>> Regen graph and a bunch of refactors } }; } @@ -900,7 +626,6 @@ public Page nextPage(String nextLink) throws GraphErrorException, * * @param filter The filter to apply on the operation. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listAsync(final String filter, final ListOperationCallback serviceCallback) { @@ -958,18 +683,12 @@ public Observable>> call(ServiceResponse>> listSinglePageAsync(final String filter) { -======= - * @return the {@link Call} object - */ - public ServiceCall> listAsync(final String filter, final ListOperationCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -980,30 +699,6 @@ public Observable>> call(Response call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - if (serviceCallback != null) { - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); - } - } - serviceCall.success(new ServiceResponse<>(result.getBody().getItems(), response)); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -1024,31 +719,12 @@ private ServiceResponse> listDelegate(Response getGroupMembers(final String objectId) throws GraphErrorException, IOException, IllegalArgumentException { ServiceResponse> response = getGroupMembersSinglePageAsync(objectId).toBlocking().single(); return new PagedList(response.getBody()) { @Override public Page nextPage(String nextLink) throws RestException, IOException { return getGroupMembersNextSinglePageAsync(nextLink).toBlocking().single().getBody(); -======= - public ServiceResponse> getGroupMembers(final String objectId) throws GraphErrorException, IOException, IllegalArgumentException { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.getGroupMembers(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = getGroupMembersDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { - @Override - public Page nextPage(String nextLink) throws GraphErrorException, IOException { - return getGroupMembersNext(nextLink).getBody(); ->>>>>>> Regen graph and a bunch of refactors } }; } @@ -1058,7 +734,6 @@ public Page nextPage(String nextLink) throws GraphErrorException * * @param objectId Group object Id who's members should be retrieved. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> getGroupMembersAsync(final String objectId, final ListOperationCallback serviceCallback) { @@ -1116,11 +791,6 @@ public Observable>> call(ServiceResponse>> getGroupMembersSinglePageAsync(final String objectId) { -======= - * @return the {@link Call} object - */ - public ServiceCall> getGroupMembersAsync(final String objectId, final ListOperationCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -1130,7 +800,6 @@ public ServiceCall> getGroupMembersAsync(final String objec if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.getGroupMembers(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -1141,30 +810,6 @@ public Observable>> call(Response call = service.getGroupMembers(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = getGroupMembersDelegate(response); - if (serviceCallback != null) { - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - getGroupMembersNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); - } - } - serviceCall.success(new ServiceResponse<>(result.getBody().getItems(), response)); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -1185,23 +830,8 @@ private ServiceResponse> getGroupMembersDelegate(Respo * @throws IllegalArgumentException exception thrown from invalid parameters * @return the ADGroupInner object if successful. */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public ADGroupInner get(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { return getWithServiceResponseAsync(objectId).toBlocking().single().getBody(); -======= - public ServiceResponse get(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return getDelegate(call.execute()); ->>>>>>> Regen graph and a bunch of refactors } /** @@ -1209,7 +839,6 @@ public ServiceResponse get(String objectId) throws GraphErrorExcep * * @param objectId User objectId to get group information. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall getAsync(String objectId, final ServiceCallback serviceCallback) { @@ -1238,11 +867,6 @@ public ADGroupInner call(ServiceResponse response) { * @return the observable to the ADGroupInner object */ public Observable> getWithServiceResponseAsync(String objectId) { -======= - * @return the {@link Call} object - */ - public ServiceCall getAsync(String objectId, final ServiceCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -1252,7 +876,6 @@ public ServiceCall getAsync(String objectId, final ServiceCallback if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -1263,24 +886,6 @@ public Observable> call(Response res } catch (Throwable t) { return Observable.error(t); } -======= - Call call = service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = getDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -1302,27 +907,8 @@ private ServiceResponse getDelegate(Response respons * @throws IllegalArgumentException exception thrown from invalid parameters * @return the List<String> object if successful. */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public List getMemberGroups(String objectId, boolean securityEnabledOnly) throws GraphErrorException, IOException, IllegalArgumentException { return getMemberGroupsWithServiceResponseAsync(objectId, securityEnabledOnly).toBlocking().single().getBody(); -======= - public ServiceResponse> getMemberGroups(String objectId, boolean securityEnabledOnly) throws GraphErrorException, IOException, IllegalArgumentException { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - GroupGetMemberGroupsParameters parameters = new GroupGetMemberGroupsParameters(); - parameters.withSecurityEnabledOnly(securityEnabledOnly); - Call call = service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - ServiceResponse> response = getMemberGroupsDelegate(call.execute()); - List result = response.getBody().getItems(); - return new ServiceResponse<>(result, response.getResponse()); ->>>>>>> Regen graph and a bunch of refactors } /** @@ -1331,7 +917,6 @@ public ServiceResponse> getMemberGroups(String objectId, boolean se * @param objectId Group filtering parameters. * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> getMemberGroupsAsync(String objectId, boolean securityEnabledOnly, final ServiceCallback> serviceCallback) { @@ -1362,11 +947,6 @@ public List call(ServiceResponse> response) { * @return the observable to the List<String> object */ public Observable>> getMemberGroupsWithServiceResponseAsync(String objectId, boolean securityEnabledOnly) { -======= - * @return the {@link Call} object - */ - public ServiceCall> getMemberGroupsAsync(String objectId, boolean securityEnabledOnly, final ServiceCallback> serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -1378,7 +958,6 @@ public ServiceCall> getMemberGroupsAsync(String objectId, boolean s } GroupGetMemberGroupsParameters parameters = new GroupGetMemberGroupsParameters(); parameters.withSecurityEnabledOnly(securityEnabledOnly); -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -1390,21 +969,6 @@ public Observable>> call(Response res } catch (Throwable t) { return Observable.error(t); } -======= - Call call = service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = getMemberGroupsDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -1425,7 +989,6 @@ private ServiceResponse> getMemberGroupsDelegate(Response listNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { ServiceResponse> response = listNextSinglePageAsync(nextLink).toBlocking().single(); return new PagedList(response.getBody()) { @@ -1434,20 +997,6 @@ public Page nextPage(String nextLink) throws RestException, IOExce return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); } }; -======= - public ServiceResponse> listNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { - if (nextLink == null) { - throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return listNextDelegate(call.execute()); ->>>>>>> Regen graph and a bunch of refactors } /** @@ -1456,7 +1005,6 @@ public ServiceResponse> listNext(final String nextLink) * @param nextLink Next link for list operation. * @param serviceCall the ServiceCall object tracking the Retrofit calls * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { @@ -1514,11 +1062,6 @@ public Observable>> call(ServiceResponse>> listNextSinglePageAsync(final String nextLink) { -======= - * @return the {@link Call} object - */ - public ServiceCall> listNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (nextLink == null) { throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); } @@ -1528,7 +1071,6 @@ public ServiceCall> listNextAsync(final String nextLink, fina if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -1539,27 +1081,6 @@ public Observable>> call(Response call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - serviceCall.newCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listNextDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); - } - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -1580,7 +1101,6 @@ private ServiceResponse> listNextDelegate(Response getGroupMembersNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { ServiceResponse> response = getGroupMembersNextSinglePageAsync(nextLink).toBlocking().single(); return new PagedList(response.getBody()) { @@ -1589,20 +1109,6 @@ public Page nextPage(String nextLink) throws RestException, IOEx return getGroupMembersNextSinglePageAsync(nextLink).toBlocking().single().getBody(); } }; -======= - public ServiceResponse> getGroupMembersNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { - if (nextLink == null) { - throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.getGroupMembersNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return getGroupMembersNextDelegate(call.execute()); ->>>>>>> Regen graph and a bunch of refactors } /** @@ -1611,7 +1117,6 @@ public ServiceResponse> getGroupMembersNext(final Stri * @param nextLink Next link for list operation. * @param serviceCall the ServiceCall object tracking the Retrofit calls * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> getGroupMembersNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { @@ -1669,11 +1174,6 @@ public Observable>> call(ServiceResponse>> getGroupMembersNextSinglePageAsync(final String nextLink) { -======= - * @return the {@link Call} object - */ - public ServiceCall> getGroupMembersNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (nextLink == null) { throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); } @@ -1683,7 +1183,6 @@ public ServiceCall> getGroupMembersNextAsync(final String n if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.getGroupMembersNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -1694,27 +1193,6 @@ public Observable>> call(Response call = service.getGroupMembersNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - serviceCall.newCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = getGroupMembersNextDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - getGroupMembersNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); - } - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ObjectsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ObjectsInner.java index de17efb2f365..98ae94a7696e 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ObjectsInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ObjectsInner.java @@ -66,27 +66,14 @@ interface ObjectsService { * @throws IllegalArgumentException exception thrown from invalid parameters * @return the AADObjectInner object if successful. */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public AADObjectInner getCurrentUser() throws GraphErrorException, IOException, IllegalArgumentException { return getCurrentUserWithServiceResponseAsync().toBlocking().single().getBody(); -======= - public ServiceResponse getCurrentUser() throws GraphErrorException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.getCurrentUser(this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return getCurrentUserDelegate(call.execute()); ->>>>>>> Regen graph and a bunch of refactors } /** * Gets the details for current logged in user. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall getCurrentUserAsync(final ServiceCallback serviceCallback) { @@ -113,18 +100,12 @@ public AADObjectInner call(ServiceResponse response) { * @return the observable to the AADObjectInner object */ public Observable> getCurrentUserWithServiceResponseAsync() { -======= - * @return the {@link Call} object - */ - public ServiceCall getCurrentUserAsync(final ServiceCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.getCurrentUser(this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -135,24 +116,6 @@ public Observable> call(Response r } catch (Throwable t) { return Observable.error(t); } -======= - Call call = service.getCurrentUser(this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = getCurrentUserDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalImpl.java index 4445fe4b711d..d5f9a2eda932 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalImpl.java @@ -7,10 +7,11 @@ package com.microsoft.azure.management.graphrbac.implementation; import com.microsoft.azure.management.graphrbac.ServicePrincipal; -import com.microsoft.azure.management.resources.fluentcore.model.implementation.WrapperImpl; +import com.microsoft.azure.management.resources.fluentcore.model.implementation.IndexableRefreshableWrapperImpl; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; +import rx.Observable; import java.util.List; @@ -18,7 +19,7 @@ * Implementation for StorageAccount and its parent interfaces. */ class ServicePrincipalImpl - extends WrapperImpl + extends IndexableRefreshableWrapperImpl implements ServicePrincipal, ServicePrincipal.Definition, @@ -98,7 +99,12 @@ public void success(ServiceResponse result) { } @Override - public String key() { - return objectId(); + public Observable createAsync() { + return null; + } + + @Override + public ServicePrincipal refresh() throws Exception { + return null; } } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java index 9a5d1bd6737e..963ea8bfe284 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java @@ -97,22 +97,6 @@ interface ServicePrincipalsService { @PATCH("{tenantID}/servicePrincipals/{objectId}/passwordCredentials") Observable> updatePasswordCredentials(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body PasswordCredentialsUpdateParameters parameters, @Header("User-Agent") String userAgent); - @Headers("Content-Type: application/json; charset=utf-8") - @GET("{tenantID}/servicePrincipals/{objectId}/keyCredentials") - Call listKeyCredentials(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); - - @Headers("Content-Type: application/json; charset=utf-8") - @PATCH("{tenantID}/servicePrincipals/{objectId}/keyCredentials") - Call updateKeyCredentials(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body KeyCredentialsUpdateParameters parameters, @Header("User-Agent") String userAgent); - - @Headers("Content-Type: application/json; charset=utf-8") - @GET("{tenantID}/servicePrincipals/{objectId}/passwordCredentials") - Call listPasswordCredentials(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); - - @Headers("Content-Type: application/json; charset=utf-8") - @PATCH("{tenantID}/servicePrincipals/{objectId}/passwordCredentials") - Call updatePasswordCredentials(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body PasswordCredentialsUpdateParameters parameters, @Header("User-Agent") String userAgent); - @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/{nextLink}") Observable> listNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @@ -128,24 +112,8 @@ interface ServicePrincipalsService { * @throws IllegalArgumentException exception thrown from invalid parameters * @return the ServicePrincipalInner object if successful. */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public ServicePrincipalInner create(ServicePrincipalCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { return createWithServiceResponseAsync(parameters).toBlocking().single().getBody(); -======= - public ServiceResponse create(ServicePrincipalCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(parameters); - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return createDelegate(call.execute()); ->>>>>>> Regen graph and a bunch of refactors } /** @@ -153,7 +121,6 @@ public ServiceResponse create(ServicePrincipalCreateParam * * @param parameters Parameters to create a service principal. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall createAsync(ServicePrincipalCreateParametersInner parameters, final ServiceCallback serviceCallback) { @@ -182,11 +149,6 @@ public ServicePrincipalInner call(ServiceResponse respons * @return the observable to the ServicePrincipalInner object */ public Observable> createWithServiceResponseAsync(ServicePrincipalCreateParametersInner parameters) { -======= - * @return the {@link Call} object - */ - public ServiceCall createAsync(ServicePrincipalCreateParametersInner parameters, final ServiceCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -197,7 +159,6 @@ public ServiceCall createAsync(ServicePrincipalCreatePara throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(parameters); -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -208,24 +169,6 @@ public Observable> call(Response call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = createDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -245,29 +188,12 @@ private ServiceResponse createDelegate(Response list() throws GraphErrorException, IOException, IllegalArgumentException { ServiceResponse> response = listSinglePageAsync().toBlocking().single(); return new PagedList(response.getBody()) { @Override public Page nextPage(String nextLink) throws RestException, IOException { return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); -======= - public ServiceResponse> list() throws GraphErrorException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - final String filter = null; - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { - @Override - public Page nextPage(String nextLink) throws GraphErrorException, IOException { - return listNext(nextLink).getBody(); ->>>>>>> Regen graph and a bunch of refactors } }; } @@ -276,7 +202,6 @@ public Page nextPage(String nextLink) throws GraphErrorEx * Gets list of service principals from the current tenant. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listAsync(final ListOperationCallback serviceCallback) { @@ -331,11 +256,6 @@ public Observable>> call(ServiceResp * @return the PagedList<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. */ public Observable>> listSinglePageAsync() { -======= - * @return the {@link Call} object - */ - public ServiceCall> listAsync(final ListOperationCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -343,7 +263,6 @@ public ServiceCall> listAsync(final ListOperationCal throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } final String filter = null; -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -354,30 +273,6 @@ public Observable>> call(Response call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - if (serviceCallback != null) { - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); - } - } - serviceCall.success(new ServiceResponse<>(result.getBody().getItems(), response)); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -391,28 +286,12 @@ public void onResponse(Call call, Response response) * @throws IllegalArgumentException exception thrown from invalid parameters * @return the PagedList<ServicePrincipalInner> object if successful. */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public PagedList list(final String filter) throws GraphErrorException, IOException, IllegalArgumentException { ServiceResponse> response = listSinglePageAsync(filter).toBlocking().single(); return new PagedList(response.getBody()) { @Override public Page nextPage(String nextLink) throws RestException, IOException { return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); -======= - public ServiceResponse> list(final String filter) throws GraphErrorException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { - @Override - public Page nextPage(String nextLink) throws GraphErrorException, IOException { - return listNext(nextLink).getBody(); ->>>>>>> Regen graph and a bunch of refactors } }; } @@ -422,7 +301,6 @@ public Page nextPage(String nextLink) throws GraphErrorEx * * @param filter The filter to apply on the operation. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listAsync(final String filter, final ListOperationCallback serviceCallback) { @@ -480,18 +358,12 @@ public Observable>> call(ServiceResp * @return the PagedList<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. */ public Observable>> listSinglePageAsync(final String filter) { -======= - * @return the {@link Call} object - */ - public ServiceCall> listAsync(final String filter, final ListOperationCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -502,30 +374,6 @@ public Observable>> call(Response call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - if (serviceCallback != null) { - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); - } - } - serviceCall.success(new ServiceResponse<>(result.getBody().getItems(), response)); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -581,11 +429,7 @@ public Void call(ServiceResponse response) { * @param objectId Object id to delete service principal information. * @return the {@link ServiceResponse} object if successful. */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public Observable> deleteWithServiceResponseAsync(String objectId) { -======= - public ServiceResponse delete(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { ->>>>>>> Regen graph and a bunch of refactors if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -634,7 +478,6 @@ public ServicePrincipalInner get(String objectId) throws GraphErrorException, IO * * @param objectId Object id to get service principal information. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall getAsync(String objectId, final ServiceCallback serviceCallback) { @@ -663,11 +506,6 @@ public ServicePrincipalInner call(ServiceResponse respons * @return the observable to the ServicePrincipalInner object */ public Observable> getWithServiceResponseAsync(String objectId) { -======= - * @return the {@link Call} object - */ - public ServiceCall deleteAsync(String objectId, final ServiceCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -677,7 +515,6 @@ public ServiceCall deleteAsync(String objectId, final ServiceCallback, Observable>>() { @Override @@ -688,24 +525,6 @@ public Observable> call(Response call = service.delete(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = deleteDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -756,7 +575,6 @@ public List call(ServiceResponse> r }); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 /** * Get keyCredentials associated with the service principal by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. * @@ -791,11 +609,6 @@ public Observable>> call(Response> listKeyCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) -======= - private ServiceResponse deleteDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) - .register(204, new TypeToken() { }.getType()) ->>>>>>> Regen graph and a bunch of refactors .registerError(GraphErrorException.class) .build(response); } @@ -808,7 +621,6 @@ private ServiceResponse deleteDelegate(Response response) th * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public void updateKeyCredentials(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { updateKeyCredentialsWithServiceResponseAsync(objectId).toBlocking().single().getBody(); } @@ -846,9 +658,6 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> updateKeyCredentialsWithServiceResponseAsync(String objectId) { -======= - public ServiceResponse get(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { ->>>>>>> Regen graph and a bunch of refactors if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -894,7 +703,6 @@ public void updateKeyCredentials(String objectId, List value * @param objectId Object id to get service principal information. * @param value KeyCredential list. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall updateKeyCredentialsAsync(String objectId, List value, final ServiceCallback serviceCallback) { @@ -925,11 +733,6 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> updateKeyCredentialsWithServiceResponseAsync(String objectId, List value) { -======= - * @return the {@link Call} object - */ - public ServiceCall getAsync(String objectId, final ServiceCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -939,7 +742,6 @@ public ServiceCall getAsync(String objectId, final Servic if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 Validator.validate(value); KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); parameters.withValue(value); @@ -953,24 +755,6 @@ public Observable> call(Response response) { } catch (Throwable t) { return Observable.error(t); } -======= - Call call = service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = getDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -1021,268 +805,13 @@ public List call(ServiceResponse getDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) - .register(200, new TypeToken() { }.getType()) - .registerError(GraphErrorException.class) - .build(response); - } - - /** - * Get keyCredentials associated with the service principal by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. - * - * @param objectId Object id to get service principal information. - * @throws GraphErrorException exception thrown from REST call - * @throws IOException exception thrown from serialization/deserialization - * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<KeyCredentialInner> object wrapped in {@link ServiceResponse} if successful. - */ - public ServiceResponse> listKeyCredentials(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.listKeyCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listKeyCredentialsDelegate(call.execute()); - List result = response.getBody().getItems(); - return new ServiceResponse<>(result, response.getResponse()); - } - - /** - * Get keyCredentials associated with the service principal by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. - * - * @param objectId Object id to get service principal information. - * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object - */ - public ServiceCall> listKeyCredentialsAsync(String objectId, final ServiceCallback> serviceCallback) { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.listKeyCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listKeyCredentialsDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); - } - } - }); - return serviceCall; - } - - private ServiceResponse> listKeyCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) - .register(200, new TypeToken>() { }.getType()) - .registerError(GraphErrorException.class) - .build(response); - } - - /** - * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. - * - * @param objectId Object id to get service principal information. - * @throws GraphErrorException exception thrown from REST call - * @throws IOException exception thrown from serialization/deserialization - * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the {@link ServiceResponse} object if successful. - */ - public ServiceResponse updateKeyCredentials(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - final List value = null; - KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); - parameters.withValue(null); - Call call = service.updateKeyCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - return updateKeyCredentialsDelegate(call.execute()); - } - - /** - * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. - * - * @param objectId Object id to get service principal information. - * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object - */ - public ServiceCall updateKeyCredentialsAsync(String objectId, final ServiceCallback serviceCallback) { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - final List value = null; - KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); - parameters.withValue(null); - Call call = service.updateKeyCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = updateKeyCredentialsDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); - } - } - }); - return serviceCall; - } - - /** - * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. - * - * @param objectId Object id to get service principal information. - * @param value KeyCredential list. - * @throws GraphErrorException exception thrown from REST call - * @throws IOException exception thrown from serialization/deserialization - * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the {@link ServiceResponse} object if successful. - */ - public ServiceResponse updateKeyCredentials(String objectId, List value) throws GraphErrorException, IOException, IllegalArgumentException { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(value); - KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); - parameters.withValue(value); - Call call = service.updateKeyCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - return updateKeyCredentialsDelegate(call.execute()); - } - - /** - * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. - * - * @param objectId Object id to get service principal information. - * @param value KeyCredential list. - * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object - */ - public ServiceCall updateKeyCredentialsAsync(String objectId, List value, final ServiceCallback serviceCallback) { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(value); - KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); - parameters.withValue(value); - Call call = service.updateKeyCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = updateKeyCredentialsDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); - } - } - }); - return serviceCall; - } - - private ServiceResponse updateKeyCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) - .register(204, new TypeToken() { }.getType()) - .registerError(GraphErrorException.class) - .build(response); - } - - /** - * Gets passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. - * - * @param objectId Object id to get service principal information. - * @throws GraphErrorException exception thrown from REST call - * @throws IOException exception thrown from serialization/deserialization - * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<PasswordCredentialInner> object wrapped in {@link ServiceResponse} if successful. - */ - public ServiceResponse> listPasswordCredentials(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.listPasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listPasswordCredentialsDelegate(call.execute()); - List result = response.getBody().getItems(); - return new ServiceResponse<>(result, response.getResponse()); - } - ->>>>>>> Regen graph and a bunch of refactors /** * Gets passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. * * @param objectId Object id to get service principal information. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the observable to the List<PasswordCredentialInner> object */ public Observable>> listPasswordCredentialsWithServiceResponseAsync(String objectId) { -======= - * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object - */ - public ServiceCall> listPasswordCredentialsAsync(String objectId, final ServiceCallback> serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -1292,7 +821,6 @@ public ServiceCall> listPasswordCredentialsAsync(S if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.listPasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -1306,33 +834,12 @@ public Observable>> call(Response< } } }); -======= - Call call = service.listPasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listPasswordCredentialsDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); - } - } - }); - return serviceCall; ->>>>>>> Regen graph and a bunch of refactors } private ServiceResponse> listPasswordCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) .registerError(GraphErrorException.class) -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 -======= .build(response); } @@ -1343,158 +850,7 @@ private ServiceResponse> listPasswordCredentia * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the {@link ServiceResponse} object if successful. */ - public ServiceResponse updatePasswordCredentials(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - final List value = null; - PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); - parameters.withValue(null); - Call call = service.updatePasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - return updatePasswordCredentialsDelegate(call.execute()); - } - - /** - * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. - * - * @param objectId Object id to get service principal information. - * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object - */ - public ServiceCall updatePasswordCredentialsAsync(String objectId, final ServiceCallback serviceCallback) { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - final List value = null; - PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); - parameters.withValue(null); - Call call = service.updatePasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = updatePasswordCredentialsDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); - } - } - }); - return serviceCall; - } - - /** - * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. - * - * @param objectId Object id to get service principal information. - * @param value PasswordCredential list. - * @throws GraphErrorException exception thrown from REST call - * @throws IOException exception thrown from serialization/deserialization - * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the {@link ServiceResponse} object if successful. - */ - public ServiceResponse updatePasswordCredentials(String objectId, List value) throws GraphErrorException, IOException, IllegalArgumentException { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(value); - PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); - parameters.withValue(value); - Call call = service.updatePasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - return updatePasswordCredentialsDelegate(call.execute()); - } - - /** - * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. - * - * @param objectId Object id to get service principal information. - * @param value PasswordCredential list. - * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object - */ - public ServiceCall updatePasswordCredentialsAsync(String objectId, List value, final ServiceCallback serviceCallback) { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(value); - PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); - parameters.withValue(value); - Call call = service.updatePasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = updatePasswordCredentialsDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); - } - } - }); - return serviceCall; - } - - private ServiceResponse updatePasswordCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) - .register(204, new TypeToken() { }.getType()) - .registerError(GraphErrorException.class) ->>>>>>> Regen graph and a bunch of refactors - .build(response); - } - - /** - * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. - * -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 - * @param objectId Object id to get service principal information. -======= - * @param nextLink Next link for list operation. ->>>>>>> Regen graph and a bunch of refactors - * @throws GraphErrorException exception thrown from REST call - * @throws IOException exception thrown from serialization/deserialization - * @throws IllegalArgumentException exception thrown from invalid parameters - */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public void updatePasswordCredentials(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { updatePasswordCredentialsWithServiceResponseAsync(objectId).toBlocking().single().getBody(); } @@ -1534,11 +890,6 @@ public Void call(ServiceResponse response) { public Observable> updatePasswordCredentialsWithServiceResponseAsync(String objectId) { if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); -======= - public ServiceResponse> listNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { - if (nextLink == null) { - throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); ->>>>>>> Regen graph and a bunch of refactors } if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); @@ -1670,7 +1021,6 @@ public Page nextPage(String nextLink) throws RestExceptio * @param nextLink Next link for list operation. * @param serviceCall the ServiceCall object tracking the Retrofit calls * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { @@ -1728,11 +1078,6 @@ public Observable>> call(ServiceResp * @return the PagedList<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. */ public Observable>> listNextSinglePageAsync(final String nextLink) { -======= - * @return the {@link Call} object - */ - public ServiceCall> listNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (nextLink == null) { throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); } @@ -1742,7 +1087,6 @@ public ServiceCall> listNextAsync(final String nextL if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -1753,27 +1097,6 @@ public Observable>> call(Response call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - serviceCall.newCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listNextDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); - } - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java index bcec0e6bb798..710996714fa5 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java @@ -12,6 +12,8 @@ import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; +import rx.Observable; +import rx.functions.Func1; /** * Implementation for StorageAccount and its parent interfaces. @@ -84,20 +86,22 @@ public UserImpl create() throws Exception { } @Override - public ServiceCall createAsync(final ServiceCallback callback) { + public ServiceCall createAsync(final ServiceCallback callback) { final UserImpl self = this; - return client.createAsync(createParameters, new ServiceCallback() { - @Override - public void failure(Throwable t) { - callback.failure(t); - } - - @Override - public void success(ServiceResponse result) { - setInner(result.getBody()); - callback.success(new ServiceResponse(self, result.getResponse())); - } - }); + return obser + } + + @Override + public Observable createAsync() { + final UserImpl self = this; + return client.createAsync(createParameters) + .map(new Func1, User>() { + @Override + public User call(ServiceResponse userInnerServiceResponse) { + setInner(userInnerServiceResponse.getBody()); + return self; + } + }); } @Override diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java index 66515f776f3d..f9a4e60de1ec 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java @@ -15,6 +15,8 @@ import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; +import rx.Observable; +import rx.functions.Func1; import java.io.IOException; @@ -74,22 +76,24 @@ public UserImpl getByUserPrincipalName(String upn) throws GraphErrorException, I @Override public ServiceCall getByUserPrincipalNameAsync(String upn, final ServiceCallback callback) { - final ServiceCall serviceCall = new ServiceCall<>(null); - serviceCall.newCall(innerCollection.getAsync(upn, new ServiceCallback() { - @Override - public void failure(Throwable t) { - callback.failure(t); - serviceCall.failure(t); - } + return ServiceCall.create( + getByUserPrincipalNameAsync(upn).map(new Func1>() { + @Override + public ServiceResponse call(User fluentModelT) { + return new ServiceResponse<>(fluentModelT, null); + } + }), callback + ); + } - @Override - public void success(ServiceResponse result) { - User user = new UserImpl(result.getBody(), innerCollection); - ServiceResponse clientResponse = new ServiceResponse(user, result.getResponse()); - callback.success(clientResponse); - serviceCall.success(clientResponse); - } - }).getCall()); - return serviceCall; + @Override + public Observable getByUserPrincipalNameAsync(String upn) { + return innerCollection.getAsync(upn) + .map(new Func1, User>() { + @Override + public User call(ServiceResponse userInnerServiceResponse) { + return new UserImpl(userInnerServiceResponse.getBody(), innerCollection); + } + }); } } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java index a5fbd748859d..91499376d8cd 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java @@ -17,10 +17,7 @@ import com.microsoft.azure.management.graphrbac.UserGetMemberGroupsParameters; import com.microsoft.azure.Page; import com.microsoft.azure.PagedList; -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 import com.microsoft.rest.RestException; -======= ->>>>>>> Regen graph and a bunch of refactors import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; @@ -28,10 +25,6 @@ import java.io.IOException; import java.util.List; import okhttp3.ResponseBody; -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 -======= -import retrofit2.Call; ->>>>>>> Regen graph and a bunch of refactors import retrofit2.http.Body; import retrofit2.http.GET; import retrofit2.http.Header; @@ -42,11 +35,8 @@ import retrofit2.http.POST; import retrofit2.http.Query; import retrofit2.Response; -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 import rx.functions.Func1; import rx.Observable; -======= ->>>>>>> Regen graph and a bunch of refactors /** * An instance of this class provides access to all the operations defined @@ -113,24 +103,8 @@ interface UsersService { * @throws IllegalArgumentException exception thrown from invalid parameters * @return the UserInner object if successful. */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public UserInner create(UserCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { return createWithServiceResponseAsync(parameters).toBlocking().single().getBody(); -======= - public ServiceResponse create(UserCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(parameters); - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return createDelegate(call.execute()); ->>>>>>> Regen graph and a bunch of refactors } /** @@ -138,7 +112,6 @@ public ServiceResponse create(UserCreateParametersInner parameters) t * * @param parameters Parameters to create a user. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall createAsync(UserCreateParametersInner parameters, final ServiceCallback serviceCallback) { @@ -167,11 +140,6 @@ public UserInner call(ServiceResponse response) { * @return the observable to the UserInner object */ public Observable> createWithServiceResponseAsync(UserCreateParametersInner parameters) { -======= - * @return the {@link Call} object - */ - public ServiceCall createAsync(UserCreateParametersInner parameters, final ServiceCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -182,7 +150,6 @@ public ServiceCall createAsync(UserCreateParametersInner parameters, throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(parameters); -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -193,24 +160,6 @@ public Observable> call(Response respon } catch (Throwable t) { return Observable.error(t); } -======= - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = createDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -230,29 +179,12 @@ private ServiceResponse createDelegate(Response respons * @throws IllegalArgumentException exception thrown from invalid parameters * @return the PagedList<UserInner> object if successful. */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public PagedList list() throws GraphErrorException, IOException, IllegalArgumentException { ServiceResponse> response = listSinglePageAsync().toBlocking().single(); return new PagedList(response.getBody()) { @Override public Page nextPage(String nextLink) throws RestException, IOException { return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); -======= - public ServiceResponse> list() throws GraphErrorException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - final String filter = null; - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { - @Override - public Page nextPage(String nextLink) throws GraphErrorException, IOException { - return listNext(nextLink).getBody(); ->>>>>>> Regen graph and a bunch of refactors } }; } @@ -261,7 +193,6 @@ public Page nextPage(String nextLink) throws GraphErrorException, IOE * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listAsync(final ListOperationCallback serviceCallback) { @@ -316,11 +247,6 @@ public Observable>> call(ServiceResponse>> listSinglePageAsync() { -======= - * @return the {@link Call} object - */ - public ServiceCall> listAsync(final ListOperationCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -328,7 +254,6 @@ public ServiceCall> listAsync(final ListOperationCallback, Observable>>>() { @Override @@ -339,30 +264,6 @@ public Observable>> call(Response } catch (Throwable t) { return Observable.error(t); } -======= - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - if (serviceCallback != null) { - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); - } - } - serviceCall.success(new ServiceResponse<>(result.getBody().getItems(), response)); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -376,28 +277,12 @@ public void onResponse(Call call, Response response) * @throws IllegalArgumentException exception thrown from invalid parameters * @return the PagedList<UserInner> object if successful. */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public PagedList list(final String filter) throws GraphErrorException, IOException, IllegalArgumentException { ServiceResponse> response = listSinglePageAsync(filter).toBlocking().single(); return new PagedList(response.getBody()) { @Override public Page nextPage(String nextLink) throws RestException, IOException { return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); -======= - public ServiceResponse> list(final String filter) throws GraphErrorException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { - @Override - public Page nextPage(String nextLink) throws GraphErrorException, IOException { - return listNext(nextLink).getBody(); ->>>>>>> Regen graph and a bunch of refactors } }; } @@ -407,7 +292,6 @@ public Page nextPage(String nextLink) throws GraphErrorException, IOE * * @param filter The filter to apply on the operation. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listAsync(final String filter, final ListOperationCallback serviceCallback) { @@ -465,18 +349,12 @@ public Observable>> call(ServiceResponse>> listSinglePageAsync(final String filter) { -======= - * @return the {@link Call} object - */ - public ServiceCall> listAsync(final String filter, final ListOperationCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -487,30 +365,6 @@ public Observable>> call(Response } catch (Throwable t) { return Observable.error(t); } -======= - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - if (serviceCallback != null) { - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); - } - } - serviceCall.success(new ServiceResponse<>(result.getBody().getItems(), response)); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -531,23 +385,8 @@ private ServiceResponse> listDelegate(Response get(String upnOrObjectId) throws GraphErrorException, IOException, IllegalArgumentException { - if (upnOrObjectId == null) { - throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.get(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return getDelegate(call.execute()); ->>>>>>> Regen graph and a bunch of refactors } /** @@ -555,7 +394,6 @@ public ServiceResponse get(String upnOrObjectId) throws GraphErrorExc * * @param upnOrObjectId User object Id or user principal name to get user information. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall getAsync(String upnOrObjectId, final ServiceCallback serviceCallback) { @@ -584,11 +422,6 @@ public UserInner call(ServiceResponse response) { * @return the observable to the UserInner object */ public Observable> getWithServiceResponseAsync(String upnOrObjectId) { -======= - * @return the {@link Call} object - */ - public ServiceCall getAsync(String upnOrObjectId, final ServiceCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (upnOrObjectId == null) { throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); } @@ -598,7 +431,6 @@ public ServiceCall getAsync(String upnOrObjectId, final ServiceCallba if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.get(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -609,24 +441,6 @@ public Observable> call(Response respon } catch (Throwable t) { return Observable.error(t); } -======= - Call call = service.get(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = getDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -647,27 +461,8 @@ private ServiceResponse getDelegate(Response response) * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public void update(String upnOrObjectId, UserUpdateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { updateWithServiceResponseAsync(upnOrObjectId, parameters).toBlocking().single().getBody(); -======= - public ServiceResponse update(String upnOrObjectId, UserUpdateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { - if (upnOrObjectId == null) { - throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(parameters); - Call call = service.update(upnOrObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return updateDelegate(call.execute()); ->>>>>>> Regen graph and a bunch of refactors } /** @@ -676,7 +471,6 @@ public ServiceResponse update(String upnOrObjectId, UserUpdateParametersIn * @param upnOrObjectId User object Id or user principal name to get user information. * @param parameters Parameters to update an exisitng user. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall updateAsync(String upnOrObjectId, UserUpdateParametersInner parameters, final ServiceCallback serviceCallback) { @@ -707,11 +501,6 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> updateWithServiceResponseAsync(String upnOrObjectId, UserUpdateParametersInner parameters) { -======= - * @return the {@link Call} object - */ - public ServiceCall updateAsync(String upnOrObjectId, UserUpdateParametersInner parameters, final ServiceCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (upnOrObjectId == null) { throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); } @@ -725,7 +514,6 @@ public ServiceCall updateAsync(String upnOrObjectId, UserUpdateParametersI throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(parameters); -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.update(upnOrObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -736,24 +524,6 @@ public Observable> call(Response response) { } catch (Throwable t) { return Observable.error(t); } -======= - Call call = service.update(upnOrObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = updateDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -773,23 +543,8 @@ private ServiceResponse updateDelegate(Response response) th * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public void delete(String upnOrObjectId) throws GraphErrorException, IOException, IllegalArgumentException { deleteWithServiceResponseAsync(upnOrObjectId).toBlocking().single().getBody(); -======= - public ServiceResponse delete(String upnOrObjectId) throws GraphErrorException, IOException, IllegalArgumentException { - if (upnOrObjectId == null) { - throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.delete(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return deleteDelegate(call.execute()); ->>>>>>> Regen graph and a bunch of refactors } /** @@ -797,7 +552,6 @@ public ServiceResponse delete(String upnOrObjectId) throws GraphErrorExcep * * @param upnOrObjectId user object id or user principal name (upn) * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall deleteAsync(String upnOrObjectId, final ServiceCallback serviceCallback) { @@ -826,11 +580,6 @@ public Void call(ServiceResponse response) { * @return the {@link ServiceResponse} object if successful. */ public Observable> deleteWithServiceResponseAsync(String upnOrObjectId) { -======= - * @return the {@link Call} object - */ - public ServiceCall deleteAsync(String upnOrObjectId, final ServiceCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (upnOrObjectId == null) { throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); } @@ -840,7 +589,6 @@ public ServiceCall deleteAsync(String upnOrObjectId, final ServiceCallback if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.delete(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>() { @Override @@ -851,24 +599,6 @@ public Observable> call(Response response) { } catch (Throwable t) { return Observable.error(t); } -======= - Call call = service.delete(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = deleteDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -890,27 +620,8 @@ private ServiceResponse deleteDelegate(Response response) th * @throws IllegalArgumentException exception thrown from invalid parameters * @return the List<String> object if successful. */ -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 public List getMemberGroups(String objectId, boolean securityEnabledOnly) throws GraphErrorException, IOException, IllegalArgumentException { return getMemberGroupsWithServiceResponseAsync(objectId, securityEnabledOnly).toBlocking().single().getBody(); -======= - public ServiceResponse> getMemberGroups(String objectId, boolean securityEnabledOnly) throws GraphErrorException, IOException, IllegalArgumentException { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - UserGetMemberGroupsParameters parameters = new UserGetMemberGroupsParameters(); - parameters.withSecurityEnabledOnly(securityEnabledOnly); - Call call = service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - ServiceResponse> response = getMemberGroupsDelegate(call.execute()); - List result = response.getBody().getItems(); - return new ServiceResponse<>(result, response.getResponse()); ->>>>>>> Regen graph and a bunch of refactors } /** @@ -919,7 +630,6 @@ public ServiceResponse> getMemberGroups(String objectId, boolean se * @param objectId User filtering parameters. * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> getMemberGroupsAsync(String objectId, boolean securityEnabledOnly, final ServiceCallback> serviceCallback) { @@ -950,11 +660,6 @@ public List call(ServiceResponse> response) { * @return the observable to the List<String> object */ public Observable>> getMemberGroupsWithServiceResponseAsync(String objectId, boolean securityEnabledOnly) { -======= - * @return the {@link Call} object - */ - public ServiceCall> getMemberGroupsAsync(String objectId, boolean securityEnabledOnly, final ServiceCallback> serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -966,7 +671,6 @@ public ServiceCall> getMemberGroupsAsync(String objectId, boolean s } UserGetMemberGroupsParameters parameters = new UserGetMemberGroupsParameters(); parameters.withSecurityEnabledOnly(securityEnabledOnly); -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -978,21 +682,6 @@ public Observable>> call(Response res } catch (Throwable t) { return Observable.error(t); } -======= - Call call = service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = getMemberGroupsDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } @@ -1013,7 +702,6 @@ private ServiceResponse> getMemberGroupsDelegate(Response listNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { ServiceResponse> response = listNextSinglePageAsync(nextLink).toBlocking().single(); return new PagedList(response.getBody()) { @@ -1022,20 +710,6 @@ public Page nextPage(String nextLink) throws RestException, IOExcepti return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); } }; -======= - public ServiceResponse> listNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { - if (nextLink == null) { - throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return listNextDelegate(call.execute()); ->>>>>>> Regen graph and a bunch of refactors } /** @@ -1044,7 +718,6 @@ public ServiceResponse> listNext(final String nextLink) thr * @param nextLink Next link for list operation. * @param serviceCall the ServiceCall object tracking the Retrofit calls * @param serviceCallback the async ServiceCallback to handle successful and failed responses. -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 * @return the {@link ServiceCall} object */ public ServiceCall> listNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { @@ -1102,11 +775,6 @@ public Observable>> call(ServiceResponse>> listNextSinglePageAsync(final String nextLink) { -======= - * @return the {@link Call} object - */ - public ServiceCall> listNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { ->>>>>>> Regen graph and a bunch of refactors if (nextLink == null) { throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); } @@ -1116,7 +784,6 @@ public ServiceCall> listNextAsync(final String nextLink, final S if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } -<<<<<<< e9aca426972ece888d34f20053ebf678b32d7a01 return service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1, Observable>>>() { @Override @@ -1127,27 +794,6 @@ public Observable>> call(Response } catch (Throwable t) { return Observable.error(t); } -======= - Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - serviceCall.newCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listNextDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); - } - } catch (GraphErrorException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); ->>>>>>> Regen graph and a bunch of refactors } }); } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java index 32928758577e..88b420e5d991 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java @@ -209,9 +209,4 @@ public AccessPolicyImpl disallowSecretPermissions(List permis inner().permissions().secrets().removeAll(permissions); return this; } - - @Override - public String key() { - return objectId().toString(); - } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/Creatable.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/Creatable.java index 0533b0a2ba2e..a96712672357 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/Creatable.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/Creatable.java @@ -42,7 +42,7 @@ public interface Creatable extends Indexable { * Puts the request into the queue and allow the HTTP client to execute * it when system resources are available. * - * @return a handle to cancel the request + * @return an observable of the request */ Observable createAsync(); } \ No newline at end of file diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/IndexableImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/IndexableImpl.java index 7530de343244..43ca1e3f9c42 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/IndexableImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/IndexableImpl.java @@ -13,7 +13,7 @@ /** * The base implementation for {@link Indexable}. */ -public abstract class IndexableImpl implements Indexable { +abstract class IndexableImpl implements Indexable { protected String key; protected IndexableImpl() { From ad615f23d07edcaf2bd8e088f9c35fc43dd44611 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Tue, 30 Aug 2016 17:25:40 -0700 Subject: [PATCH 17/33] basic get in Graph in observable --- .../graphrbac/ServicePrincipals.java | 10 +++ .../implementation/ServicePrincipalImpl.java | 42 +++---------- .../implementation/ServicePrincipalsImpl.java | 46 +++++++------- .../graphrbac/implementation/UserImpl.java | 62 ++++++------------- 4 files changed, 62 insertions(+), 98 deletions(-) diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java index 96bc608cf9d7..449030c991be 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java @@ -11,6 +11,7 @@ import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; +import rx.Observable; import java.io.IOException; @@ -59,4 +60,13 @@ public interface ServicePrincipals extends * @return the Future based service call */ ServiceCall getByServicePrincipalNameAsync(String spn, final ServiceCallback callback); + + /** + * Gets the information about a service principal. + * + * @param spn the service principal name + * @param callback the call back to handle response + * @return the Future based service call + */ + Observable getByServicePrincipalNameAsync(String spn); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalImpl.java index d5f9a2eda932..7e6393cc57ae 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalImpl.java @@ -7,10 +7,7 @@ package com.microsoft.azure.management.graphrbac.implementation; import com.microsoft.azure.management.graphrbac.ServicePrincipal; -import com.microsoft.azure.management.resources.fluentcore.model.implementation.IndexableRefreshableWrapperImpl; -import com.microsoft.rest.ServiceCall; -import com.microsoft.rest.ServiceCallback; -import com.microsoft.rest.ServiceResponse; +import com.microsoft.azure.management.resources.fluentcore.model.implementation.CreatableUpdatableImpl; import rx.Observable; import java.util.List; @@ -19,7 +16,7 @@ * Implementation for StorageAccount and its parent interfaces. */ class ServicePrincipalImpl - extends IndexableRefreshableWrapperImpl + extends CreatableUpdatableImpl implements ServicePrincipal, ServicePrincipal.Definition, @@ -28,13 +25,13 @@ class ServicePrincipalImpl private ServicePrincipalCreateParametersInner createParameters; ServicePrincipalImpl(String appId, ServicePrincipalsInner client) { - super(new ServicePrincipalInner()); + super(appId, new ServicePrincipalInner()); this.client = client; this.createParameters = new ServicePrincipalCreateParametersInner().withAppId(appId); } ServicePrincipalImpl(ServicePrincipalInner innerObject, ServicePrincipalsInner client) { - super(innerObject); + super(innerObject.appId(), innerObject); this.client = client; this.createParameters = new ServicePrincipalCreateParametersInner(); } @@ -71,40 +68,17 @@ public ServicePrincipalImpl withAccountEnabled(boolean enabled) { } @Override - public String name() { - return inner().appId(); - } - - @Override - public ServicePrincipalImpl create() throws Exception { - this.setInner(client.create(createParameters).getBody()); - return this; - } - - @Override - public ServiceCall createAsync(final ServiceCallback callback) { - final ServicePrincipalImpl self = this; - return client.createAsync(createParameters, new ServiceCallback() { - @Override - public void failure(Throwable t) { - callback.failure(t); - } - - @Override - public void success(ServiceResponse result) { - self.setInner(result.getBody()); - callback.success(new ServiceResponse(self, result.getResponse())); - } - }); + public ServicePrincipal refresh() throws Exception { + return null; } @Override - public Observable createAsync() { + public Observable createResourceAsync() { return null; } @Override - public ServicePrincipal refresh() throws Exception { + public Observable applyAsync() { return null; } } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java index e21a57c8e74f..1b0cdb535499 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java @@ -6,7 +6,7 @@ package com.microsoft.azure.management.graphrbac.implementation; -import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.Page; import com.microsoft.azure.PagedList; import com.microsoft.azure.management.graphrbac.GraphErrorException; import com.microsoft.azure.management.graphrbac.ServicePrincipal; @@ -15,6 +15,8 @@ import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; +import rx.Observable; +import rx.functions.Func1; import java.io.IOException; import java.util.List; @@ -85,26 +87,28 @@ public ServicePrincipal getByServicePrincipalName(String spn) throws GraphErrorE @Override public ServiceCall getByServicePrincipalNameAsync(final String spn, final ServiceCallback callback) { - final ServiceCall serviceCall = new ServiceCall<>(null); - serviceCall.newCall(innerCollection.listAsync(String.format("servicePrincipalNames/any(c:c eq '%s')", spn), new ListOperationCallback() { - @Override - public void failure(Throwable t) { - callback.failure(t); - serviceCall.failure(t); - } + return ServiceCall.create( + getByServicePrincipalNameAsync(spn).map(new Func1>() { + @Override + public ServiceResponse call(ServicePrincipal fluentModelT) { + return new ServiceResponse<>(fluentModelT, null); + } + }), callback + ); + } - @Override - public void success(ServiceResponse> result) { - List servicePrincipals = result.getBody(); - if (servicePrincipals == null || servicePrincipals.isEmpty()) { - failure(new GraphErrorException("Service principal not found for SPN: " + spn)); - } - ServicePrincipal user = new ServicePrincipalImpl(servicePrincipals.get(0), innerCollection); - ServiceResponse clientResponse = new ServiceResponse<>(user, result.getResponse()); - callback.success(clientResponse); - serviceCall.success(clientResponse); - } - }).getCall()); - return serviceCall; + @Override + public Observable getByServicePrincipalNameAsync(final String spn) { + return innerCollection.listAsync(String.format("servicePrincipalNames/any(c:c eq '%s')", spn)) + .map(new Func1>, ServicePrincipal>() { + @Override + public ServicePrincipal call(ServiceResponse> result) { + Page servicePrincipals = result.getBody(); + if (servicePrincipals == null || servicePrincipals.getItems() == null || servicePrincipals.getItems().isEmpty()) { + throw new GraphErrorException("Service principal not found for SPN: " + spn); + } + return new ServicePrincipalImpl(servicePrincipals.getItems().get(0), innerCollection); + } + }); } } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java index 710996714fa5..fb5e98848cc4 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java @@ -8,18 +8,14 @@ import com.microsoft.azure.management.graphrbac.PasswordProfile; import com.microsoft.azure.management.graphrbac.User; -import com.microsoft.azure.management.resources.fluentcore.model.implementation.WrapperImpl; -import com.microsoft.rest.ServiceCall; -import com.microsoft.rest.ServiceCallback; -import com.microsoft.rest.ServiceResponse; +import com.microsoft.azure.management.resources.fluentcore.model.implementation.CreatableUpdatableImpl; import rx.Observable; -import rx.functions.Func1; /** * Implementation for StorageAccount and its parent interfaces. */ class UserImpl - extends WrapperImpl + extends CreatableUpdatableImpl implements User, User.Definition, @@ -28,13 +24,13 @@ class UserImpl private UserCreateParametersInner createParameters; UserImpl(String userPrincipalName, UsersInner client) { - super(new UserInner()); + super(userPrincipalName, new UserInner()); this.client = client; this.createParameters = new UserCreateParametersInner().withUserPrincipalName(userPrincipalName); } UserImpl(UserInner innerObject, UsersInner client) { - super(innerObject); + super(innerObject.userPrincipalName(), innerObject); this.client = client; this.createParameters = new UserCreateParametersInner(); } @@ -74,41 +70,6 @@ public String mailNickname() { return inner().mailNickname(); } - @Override - public String name() { - return userPrincipalName(); - } - - @Override - public UserImpl create() throws Exception { - setInner(client.create(createParameters).getBody()); - return this; - } - - @Override - public ServiceCall createAsync(final ServiceCallback callback) { - final UserImpl self = this; - return obser - } - - @Override - public Observable createAsync() { - final UserImpl self = this; - return client.createAsync(createParameters) - .map(new Func1, User>() { - @Override - public User call(ServiceResponse userInnerServiceResponse) { - setInner(userInnerServiceResponse.getBody()); - return self; - } - }); - } - - @Override - public String key() { - return objectId(); - } - @Override public UserImpl withAccountEnabled(boolean enabled) { createParameters.withAccountEnabled(enabled); @@ -138,4 +99,19 @@ public UserImpl withPassword(String password, boolean forceChangePasswordNextLog createParameters.withPasswordProfile(new PasswordProfile().withPassword(password).withForceChangePasswordNextLogin(forceChangePasswordNextLogin)); return this; } + + @Override + public User refresh() throws Exception { + return null; + } + + @Override + public Observable createResourceAsync() { + return null; + } + + @Override + public Observable applyAsync() { + return null; + } } From 08fac8d873e20df390be74e377df7db528028659 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Fri, 2 Sep 2016 15:27:10 -0700 Subject: [PATCH 18/33] Supports spn & upn config in vault creation --- .../graphrbac/ServicePrincipals.java | 3 +- .../azure/management/keyvault/Vault.java | 3 +- .../keyvault/implementation/VaultImpl.java | 163 ++++++------------ .../keyvault/KeyVaultManagementTestBase.java | 18 +- .../azure/management/keyvault/VaultTests.java | 13 +- .../ApplicationTokenCredentials.java | 80 +++------ .../credentials/UserTokenCredentials.java | 7 +- .../com/microsoft/azure/AzureEnvironment.java | 4 + .../credentials/AzureTokenCredentials.java | 26 +++ .../AzureTokenCredentialsInterceptor.java | 59 +++++++ .../rest/ServiceResponseBuilder.java | 10 +- 11 files changed, 196 insertions(+), 190 deletions(-) create mode 100644 runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/credentials/AzureTokenCredentials.java create mode 100644 runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/credentials/AzureTokenCredentialsInterceptor.java diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java index 449030c991be..1d9c6163ac02 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java @@ -65,8 +65,7 @@ public interface ServicePrincipals extends * Gets the information about a service principal. * * @param spn the service principal name - * @param callback the call back to handle response - * @return the Future based service call + * @return the Observable to the request */ Observable getByServicePrincipalNameAsync(String spn); } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java index 0bbb56b4fffa..f19d9ddbe773 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java @@ -133,7 +133,8 @@ interface WithCreate extends Creatable, GroupableResource.DefinitionWithTags, DefinitionStages.WithSku, - DefinitionStages.WithConfigurations { + DefinitionStages.WithConfigurations, + DefinitionStages.WithAccessPolicy { } } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java index eeb5e51d42f1..fe120371b9a5 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java @@ -6,22 +6,22 @@ package com.microsoft.azure.management.keyvault.implementation; -import com.microsoft.azure.ParallelServiceCall; import com.microsoft.azure.management.graphrbac.ServicePrincipal; import com.microsoft.azure.management.graphrbac.User; import com.microsoft.azure.management.graphrbac.implementation.GraphRbacManager; import com.microsoft.azure.management.keyvault.AccessPolicy; import com.microsoft.azure.management.keyvault.AccessPolicyEntry; import com.microsoft.azure.management.keyvault.Sku; -import com.microsoft.azure.management.keyvault.SkuFamily; import com.microsoft.azure.management.keyvault.SkuName; import com.microsoft.azure.management.keyvault.Vault; import com.microsoft.azure.management.keyvault.VaultProperties; -import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource; import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl; -import com.microsoft.rest.ServiceCall; -import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; +import rx.Observable; +import rx.functions.Action1; +import rx.functions.Func1; +import rx.functions.FuncN; +import rx.schedulers.Schedulers; import java.util.ArrayList; import java.util.Arrays; @@ -46,7 +46,7 @@ class VaultImpl private GraphRbacManager graphRbacManager; private List accessPolicies; - protected VaultImpl(String key, VaultInner innerObject, VaultsInner client, KeyVaultManager manager, GraphRbacManager graphRbacManager) { + VaultImpl(String key, VaultInner innerObject, VaultsInner client, KeyVaultManager manager, GraphRbacManager graphRbacManager) { super(key, innerObject, manager); this.client = client; this.graphRbacManager = graphRbacManager; @@ -191,123 +191,67 @@ public VaultImpl withSku(SkuName skuName) { if (inner().properties() == null) { inner().withProperties(new VaultProperties()); } - inner().properties().withSku(new Sku().withName(skuName).withFamily(SkuFamily.A)); + inner().properties().withSku(new Sku().withName(skuName)); return this; } - @Override - public VaultImpl apply() throws Exception { - return create(); - } - - @Override - public ServiceCall applyAsync(ServiceCallback callback) { - return createAsync(callback); - } - - @Override - public ServiceCall createResourceAsync(final ServiceCallback serviceCallback) { - final ServiceCall serviceCall = new ServiceCall(null); - final VaultImpl self = this; - serviceCall.newCall(populateAccessPolicies(new ServiceCallback() { - @Override - public void failure(Throwable t) { - serviceCallback.failure(t); - serviceCall.failure(t); - } - - @Override - public void success(ServiceResponse result) { - VaultCreateOrUpdateParametersInner parameters = new VaultCreateOrUpdateParametersInner(); - parameters.withLocation(regionName()); - parameters.withProperties(inner().properties()); - parameters.withTags(inner().getTags()); - serviceCall.newCall(client.createOrUpdateAsync(resourceGroupName(), name(), parameters, new ServiceCallback() { - @Override - public void failure(Throwable t) { - serviceCallback.failure(t); - serviceCall.failure(t); - } - - @Override - public void success(ServiceResponse result) { - setInner(result.getBody()); - ServiceResponse clientResponse = new ServiceResponse(self, result.getResponse()); - serviceCallback.success(clientResponse); - serviceCall.success(clientResponse); - } - }).getCall()); - } - }).getCall()); - return serviceCall; - } - - private ParallelServiceCall populateAccessPolicies(final ServiceCallback callback) { - final ParallelServiceCall parallelServiceCall = new ParallelServiceCall(); - boolean any = false; + private Observable> populateAccessPolicies() { + List>observables = new ArrayList<>(); for (final AccessPolicyImpl accessPolicy : accessPolicies) { if (accessPolicy.objectId() == null) { - any = true; if (accessPolicy.userPrincipalName != null) { - parallelServiceCall.addCall(graphRbacManager.users().getByUserPrincipalNameAsync(accessPolicy.userPrincipalName, new ServiceCallback() { - @Override - public void failure(Throwable t) { - if (callback != null) { - callback.failure(t); - } - parallelServiceCall.failure(t); - } - - @Override - public void success(ServiceResponse result) { - if (callback != null) { - callback.success(null); - } - accessPolicy.forUser(result.getBody()); - } - })); + observables.add(graphRbacManager.users().getByUserPrincipalNameAsync(accessPolicy.userPrincipalName) + .subscribeOn(Schedulers.io()) + .doOnNext(new Action1() { + @Override + public void call(User user) { + accessPolicy.forObjectId(UUID.fromString(user.objectId())); + } + })); } else if (accessPolicy.servicePrincipalName != null) { - parallelServiceCall.addCall(graphRbacManager.servicePrincipals().getByServicePrincipalNameAsync(accessPolicy.servicePrincipalName, new ServiceCallback() { - @Override - public void failure(Throwable t) { - if (callback != null) { - callback.failure(t); - } - parallelServiceCall.failure(t); - } - - @Override - public void success(ServiceResponse result) { - if (callback != null) { - callback.success(null); - } - accessPolicy.forServicePrincipal(result.getBody()); - } - })); + observables.add(graphRbacManager.servicePrincipals().getByServicePrincipalNameAsync(accessPolicy.servicePrincipalName) + .subscribeOn(Schedulers.io()) + .doOnNext(new Action1() { + @Override + public void call(ServicePrincipal sp) { + accessPolicy.forObjectId(UUID.fromString(sp.objectId())); + } + })); } else { throw new IllegalArgumentException("Access policy must specify object ID."); } } } - if (!any) { - parallelServiceCall.success(null); + if (observables.isEmpty()) { + return Observable.just(accessPolicies()); + } else { + return Observable.zip(observables, new FuncN>() { + @Override + public List call(Object... args) { + return accessPolicies(); + } + }); } - return parallelServiceCall; } @Override - public VaultImpl createResource() throws Exception { - populateAccessPolicies(null).get(); - VaultCreateOrUpdateParametersInner parameters = new VaultCreateOrUpdateParametersInner(); - parameters.withLocation(regionName()); - parameters.withProperties(inner().properties()); - parameters.withTags(inner().getTags()); - parameters.properties().accessPolicies().clear(); - for (AccessPolicy accessPolicy : accessPolicies) { - parameters.properties().accessPolicies().add(accessPolicy.inner()); - } - this.setInner(client.createOrUpdate(resourceGroupName(), name(), parameters).getBody()); - return this; + public Observable createResourceAsync() { + return populateAccessPolicies() + .flatMap(new Func1>>() { + @Override + public Observable> call(Object o) { + VaultCreateOrUpdateParametersInner parameters = new VaultCreateOrUpdateParametersInner(); + parameters.withLocation(regionName()); + parameters.withProperties(inner().properties()); + parameters.withTags(inner().getTags()); + parameters.properties().withAccessPolicies(new ArrayList()); + for (AccessPolicy accessPolicy : accessPolicies) { + parameters.properties().accessPolicies().add(accessPolicy.inner()); + } + return client.createOrUpdateAsync(resourceGroupName(), name(), parameters); + } + }) + .map(innerToFluentMap(this)); } @Override @@ -315,4 +259,9 @@ public VaultImpl refresh() throws Exception { setInner(client.get(resourceGroupName(), name()).getBody()); return this; } + + @Override + public Observable applyAsync() { + return createAsync(); + } } diff --git a/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java b/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java index e94591a4f33a..a55f9c6e8506 100644 --- a/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java +++ b/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java @@ -9,7 +9,6 @@ import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.RestClient; import com.microsoft.azure.credentials.ApplicationTokenCredentials; -import com.microsoft.azure.management.graphrbac.implementation.GraphRbacManager; import com.microsoft.azure.management.keyvault.implementation.KeyVaultManager; import com.microsoft.azure.management.resources.implementation.ResourceManager; import okhttp3.logging.HttpLoggingInterceptor; @@ -19,7 +18,6 @@ */ public abstract class KeyVaultManagementTestBase { protected static ResourceManager resourceManager; - protected static GraphRbacManager graphRbacManager; protected static KeyVaultManager keyVaultManager; protected static void createClients() { @@ -27,29 +25,17 @@ protected static void createClients() { System.getenv("client-id"), System.getenv("domain"), System.getenv("secret"), - null); - - ApplicationTokenCredentials graphCredentials = new ApplicationTokenCredentials( - System.getenv("client-id"), - System.getenv("domain"), - System.getenv("secret"), - "https://graph.windows.net/", - null); + AzureEnvironment.AZURE); RestClient restClient = AzureEnvironment.AZURE.newRestClientBuilder() .withCredentials(credentials) - .withLogLevel(HttpLoggingInterceptor.Level.NONE) + .withLogLevel(HttpLoggingInterceptor.Level.BODY) .build(); resourceManager = ResourceManager .authenticate(restClient) .withSubscription(System.getenv("subscription-id")); - graphRbacManager = GraphRbacManager - .configure() - .withLogLevel(HttpLoggingInterceptor.Level.BASIC) - .authenticate(graphCredentials, System.getenv("domain")); - keyVaultManager = KeyVaultManager .authenticate(restClient, System.getenv("domain"), System.getenv("subscription-id")); } diff --git a/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/VaultTests.java b/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/VaultTests.java index 59b43e85beba..95fbf309fc10 100644 --- a/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/VaultTests.java +++ b/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/VaultTests.java @@ -15,8 +15,8 @@ import java.util.List; public class VaultTests extends KeyVaultManagementTestBase { - private static final String RG_NAME = "javacsmrg901"; - private static final String VAULT_NAME = "java-keyvault-901"; + private static final String RG_NAME = "javacsmrg905"; + private static final String VAULT_NAME = "java-keyvault-905"; @BeforeClass public static void setup() throws Exception { @@ -25,7 +25,7 @@ public static void setup() throws Exception { @AfterClass public static void cleanup() throws Exception { - resourceManager.resourceGroups().delete(RG_NAME); + //resourceManager.resourceGroups().delete(RG_NAME); } @Test @@ -35,10 +35,15 @@ public void canCRUDVault() throws Exception { .withRegion(Region.US_WEST) .withNewResourceGroup(RG_NAME) .defineAccessPolicy() - .forServicePrincipal("http://graphapp") + .forServicePrincipal("http://nativeapp") .allowKeyPermissions(KeyPermissions.LIST) .allowSecretAllPermissions() .attach() + .defineAccessPolicy() + .forUser("admin2@azuresdkteam.onmicrosoft.com") + .allowKeyAllPermissions() + .allowSecretAllPermissions() + .attach() .create(); Assert.assertNotNull(vault); // GET diff --git a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java index 94af0f3192cf..ef1ee836ba91 100644 --- a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java +++ b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java @@ -12,10 +12,14 @@ import com.microsoft.aad.adal4j.ClientCredential; import com.microsoft.azure.AzureEnvironment; import com.microsoft.rest.credentials.TokenCredentials; +import okhttp3.OkHttpClient; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; import java.util.Properties; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -23,19 +27,16 @@ /** * Token based credentials for use with a REST Service Client. */ -public class ApplicationTokenCredentials extends TokenCredentials { - /** The endpoint of the target resource. */ - private String resourceEndpoint; +public class ApplicationTokenCredentials extends TokenCredentials implements AzureTokenCredentials { + private Map tokens; + /** The Azure environment to authenticate with. */ + private AzureEnvironment environment; /** The active directory application client id. */ private String clientId; /** The tenant or domain the containing the application. */ private String domain; /** The authentication secret for the application. */ private String secret; - /** The Azure environment to authenticate with. */ - private AzureEnvironment environment; - /** The current authentication result. */ - private AuthenticationResult authenticationResult; /** The default subscription to use, if any. */ private String defaultSubscription; @@ -50,38 +51,11 @@ public class ApplicationTokenCredentials extends TokenCredentials { */ public ApplicationTokenCredentials(String clientId, String domain, String secret, AzureEnvironment environment) { super(null, null); // defer token acquisition + this.environment = environment; this.clientId = clientId; this.domain = domain; this.secret = secret; - if (environment == null) { - this.environment = AzureEnvironment.AZURE; - } else { - this.environment = environment; - } - this.resourceEndpoint = this.environment.getManagementEndpoint(); - } - - /** - * Initializes a new instance of the UserTokenCredentials. - * - * @param clientId the active directory application client id. - * @param domain the domain or tenant id containing this application. - * @param secret the authentication secret for the application. - * @param resourceEndpoint the endpoint of the target resource. - * @param environment the Azure environment to authenticate with. - * If null is provided, AzureEnvironment.AZURE will be used. - */ - public ApplicationTokenCredentials(String clientId, String domain, String secret, String resourceEndpoint, AzureEnvironment environment) { - super(null, null); // defer token acquisition - this.clientId = clientId; - this.domain = domain; - this.secret = secret; - this.resourceEndpoint = resourceEndpoint; - if (environment == null) { - this.environment = AzureEnvironment.AZURE; - } else { - this.environment = environment; - } + this.tokens = new HashMap<>(); } /** @@ -209,42 +183,40 @@ public String getSecret() { return secret; } - /** - * Gets the Azure environment to authenticate with. - * - * @return the Azure environment to authenticate with. - */ - public AzureEnvironment getEnvironment() { - return environment; - } - @Override - public String getToken() throws IOException { - if (authenticationResult == null - || authenticationResult.getAccessToken() == null) { - acquireAccessToken(); + public String getToken(String resource) throws IOException { + AuthenticationResult authenticationResult = tokens.get(resource); + if (authenticationResult == null || authenticationResult.getExpiresOnDate().before(new Date())) { + authenticationResult = acquireAccessToken(resource); } return authenticationResult.getAccessToken(); } @Override - public void refreshToken() throws IOException { - acquireAccessToken(); + public AzureEnvironment getEnvironment() { + return this.environment; } - private void acquireAccessToken() throws IOException { + private AuthenticationResult acquireAccessToken(String resource) throws IOException { String authorityUrl = this.getEnvironment().getAuthenticationEndpoint() + this.getDomain(); ExecutorService executor = Executors.newSingleThreadExecutor(); AuthenticationContext context = new AuthenticationContext(authorityUrl, this.getEnvironment().isValidateAuthority(), executor); try { - authenticationResult = context.acquireToken( - this.resourceEndpoint, + AuthenticationResult result = context.acquireToken( + resource, new ClientCredential(this.getClientId(), this.getSecret()), null).get(); + tokens.put(resource, result); + return result; } catch (Exception e) { throw new IOException(e.getMessage(), e); } finally { executor.shutdown(); } } + + @Override + public void applyCredentialsFilter(OkHttpClient.Builder clientBuilder) { + clientBuilder.interceptors().add(new AzureTokenCredentialsInterceptor(this)); + } } diff --git a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java index b703d50ca117..704b0fde2b45 100644 --- a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java +++ b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java @@ -20,7 +20,7 @@ /** * Token based credentials for use with a REST Service Client. */ -public class UserTokenCredentials extends TokenCredentials { +public class UserTokenCredentials extends TokenCredentials implements AzureTokenCredentials { /** The endpoint of the target resource. */ private String resourceEndpoint; /** The Active Directory application client id. */ @@ -136,6 +136,11 @@ public String getClientRedirectUri() { return clientRedirectUri; } + @Override + public String getToken(String resource) throws IOException { + return null; + } + /** * Gets the Azure environment to authenticate with. * diff --git a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java index df8a724e7954..80e42856e417 100644 --- a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java +++ b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java @@ -131,6 +131,10 @@ public String getManagementEndpoint() { return managementEndpoint; } + public String getGraphEndpoint() { + return graphEndpoint; + } + /** * Gets whether the authentication endpoint should * be validated with Azure AD. diff --git a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/credentials/AzureTokenCredentials.java b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/credentials/AzureTokenCredentials.java new file mode 100644 index 000000000000..1f59be80cbb8 --- /dev/null +++ b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/credentials/AzureTokenCredentials.java @@ -0,0 +1,26 @@ +/** + * + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + * + */ + +package com.microsoft.azure.credentials; + +import com.microsoft.azure.AzureEnvironment; +import com.microsoft.rest.credentials.ServiceClientCredentials; + +import java.io.IOException; + +/** + * AzureServiceClientCredentials is the abstraction for credentials used by + * ServiceClients accessing Azure. + */ +public interface AzureTokenCredentials extends ServiceClientCredentials { + String getToken(String resource) throws IOException; + + /** + * @return the environment details the credential has access to. + */ + AzureEnvironment getEnvironment(); +} diff --git a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/credentials/AzureTokenCredentialsInterceptor.java b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/credentials/AzureTokenCredentialsInterceptor.java new file mode 100644 index 000000000000..33f8b7c7a16d --- /dev/null +++ b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/credentials/AzureTokenCredentialsInterceptor.java @@ -0,0 +1,59 @@ +/** + * + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + * + */ + +package com.microsoft.azure.credentials; + +import okhttp3.Interceptor; +import okhttp3.Request; +import okhttp3.Response; + +import java.io.IOException; + +/** + * Token credentials filter for placing a token credential into request headers. + */ +public class AzureTokenCredentialsInterceptor implements Interceptor { + /** + * The credentials instance to apply to the HTTP client pipeline. + */ + private AzureTokenCredentials credentials; + + /** + * Initialize a TokenCredentialsFilter class with a + * TokenCredentials credential. + * + * @param credentials a TokenCredentials instance + */ + public AzureTokenCredentialsInterceptor(AzureTokenCredentials credentials) { + this.credentials = credentials; + } + + @Override + public Response intercept(Chain chain) throws IOException { + String resource = credentials.getEnvironment().getManagementEndpoint(); + // Use graph resource if the host if graph endpoint + if (credentials.getEnvironment().getGraphEndpoint().contains(chain.request().url().host())) { + resource = credentials.getEnvironment().getGraphEndpoint(); + } + Request newRequest = chain.request().newBuilder() + .header("Authorization", "Bearer " + credentials.getToken(resource)) + .build(); + return chain.proceed(newRequest); + } + + private Response sendRequestWithToken(Chain chain) throws IOException { + String resource = credentials.getEnvironment().getManagementEndpoint(); + // Use graph resource if the host if graph endpoint + if (chain.request().url().host().equals(credentials.getEnvironment().getGraphEndpoint())) { + resource = credentials.getEnvironment().getGraphEndpoint(); + } + Request newRequest = chain.request().newBuilder() + .header("Authorization", "Bearer " + credentials.getToken(resource)) + .build(); + return chain.proceed(newRequest); + } +} diff --git a/runtimes/client-runtime/src/main/java/com/microsoft/rest/ServiceResponseBuilder.java b/runtimes/client-runtime/src/main/java/com/microsoft/rest/ServiceResponseBuilder.java index 3ad57cb938f4..34d11a14c17a 100644 --- a/runtimes/client-runtime/src/main/java/com/microsoft/rest/ServiceResponseBuilder.java +++ b/runtimes/client-runtime/src/main/java/com/microsoft/rest/ServiceResponseBuilder.java @@ -9,6 +9,8 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.microsoft.rest.serializer.JacksonMapperAdapter; +import okhttp3.ResponseBody; +import retrofit2.Response; import java.io.IOException; import java.io.InputStream; @@ -18,9 +20,6 @@ import java.util.HashMap; import java.util.Map; -import okhttp3.ResponseBody; -import retrofit2.Response; - /** * The builder for building a {@link ServiceResponse}. * @@ -144,9 +143,10 @@ public ServiceResponse build(Response response) throws E, IOExc return new ServiceResponse<>((T) buildBody(statusCode, responseBody), response); } else { try { - E exception = (E) exceptionType.getConstructor(String.class).newInstance("Invalid status code " + statusCode); + Object errorBody = buildBody(statusCode, responseBody); + E exception = (E) exceptionType.getConstructor(String.class).newInstance(mapperAdapter.serialize(errorBody)); exceptionType.getMethod("setResponse", response.getClass()).invoke(exception, response); - exceptionType.getMethod("setBody", (Class) responseTypes.get(0)).invoke(exception, buildBody(statusCode, responseBody)); + exceptionType.getMethod("setBody", (Class) responseTypes.get(0)).invoke(exception, errorBody); throw exception; } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new IOException("Invalid status code " + statusCode + ", but an instance of " + exceptionType.getCanonicalName() From e0106a54b025a81a80a56f910c792c1f7a012fd4 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Fri, 2 Sep 2016 17:02:33 -0700 Subject: [PATCH 19/33] Enable user login --- .../ApplicationTokenCredentials.java | 1 + .../credentials/UserTokenCredentials.java | 108 ++++++------------ .../UserTokenCredentialsTests.java | 5 +- .../com/microsoft/azure/AzureEnvironment.java | 2 +- 4 files changed, 37 insertions(+), 79 deletions(-) diff --git a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java index ef1ee836ba91..7cfd0aa81372 100644 --- a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java +++ b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java @@ -28,6 +28,7 @@ * Token based credentials for use with a REST Service Client. */ public class ApplicationTokenCredentials extends TokenCredentials implements AzureTokenCredentials { + /** A mapping from resource endpoint to its cached access token. */ private Map tokens; /** The Azure environment to authenticate with. */ private AzureEnvironment environment; diff --git a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java index 704b0fde2b45..179b6d5a2fdc 100644 --- a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java +++ b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java @@ -11,9 +11,12 @@ import com.microsoft.aad.adal4j.AuthenticationResult; import com.microsoft.azure.AzureEnvironment; import com.microsoft.rest.credentials.TokenCredentials; +import okhttp3.OkHttpClient; import java.io.IOException; import java.util.Date; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -21,8 +24,8 @@ * Token based credentials for use with a REST Service Client. */ public class UserTokenCredentials extends TokenCredentials implements AzureTokenCredentials { - /** The endpoint of the target resource. */ - private String resourceEndpoint; + /** A mapping from resource endpoint to its cached access token. */ + private Map tokens; /** The Active Directory application client id. */ private String clientId; /** The domain or tenant id containing this application. */ @@ -31,12 +34,8 @@ public class UserTokenCredentials extends TokenCredentials implements AzureToken private String username; /** The password for the Organization Id account. */ private String password; - /** The Uri where the user will be redirected after authenticating with AD. */ - private String clientRedirectUri; /** The Azure environment to authenticate with. */ private AzureEnvironment environment; - /** The current authentication result. */ - private AuthenticationResult authenticationResult; /** * Initializes a new instance of the UserTokenCredentials. @@ -45,50 +44,17 @@ public class UserTokenCredentials extends TokenCredentials implements AzureToken * @param domain the domain or tenant id containing this application. * @param username the user name for the Organization Id account. * @param password the password for the Organization Id account. - * @param clientRedirectUri the Uri where the user will be redirected after authenticating with AD. * @param environment the Azure environment to authenticate with. * If null is provided, AzureEnvironment.AZURE will be used. */ - public UserTokenCredentials(String clientId, String domain, String username, String password, String clientRedirectUri, AzureEnvironment environment) { + public UserTokenCredentials(String clientId, String domain, String username, String password, AzureEnvironment environment) { super(null, null); // defer token acquisition this.clientId = clientId; this.domain = domain; this.username = username; this.password = password; - this.clientRedirectUri = clientRedirectUri; - if (environment == null) { - this.environment = AzureEnvironment.AZURE; - } else { - this.environment = environment; - } - this.resourceEndpoint = this.environment.getManagementEndpoint(); - } - - /** - * Initializes a new instance of the UserTokenCredentials. - * - * @param clientId the active directory application client id. - * @param domain the domain or tenant id containing this application. - * @param username the user name for the Organization Id account. - * @param password the password for the Organization Id account. - * @param clientRedirectUri the Uri where the user will be redirected after authenticating with AD. - * @param resourceEndpoint the endpoint of the target resource. - * @param environment the Azure environment to authenticate with. - * If null is provided, AzureEnvironment.AZURE will be used. - */ - public UserTokenCredentials(String clientId, String domain, String username, String password, String clientRedirectUri, String resourceEndpoint, AzureEnvironment environment) { - super(null, null); // defer token acquisition - this.clientId = clientId; - this.domain = domain; - this.username = username; - this.password = password; - this.clientRedirectUri = clientRedirectUri; - this.resourceEndpoint = resourceEndpoint; - if (environment == null) { - this.environment = AzureEnvironment.AZURE; - } else { - this.environment = environment; - } + this.environment = environment; + this.tokens = new HashMap<>(); } /** @@ -127,18 +93,13 @@ public String getPassword() { return password; } - /** - * Gets the Uri where the user will be redirected after authenticating with AD. - * - * @return the redirecting Uri. - */ - public String getClientRedirectUri() { - return clientRedirectUri; - } - @Override public String getToken(String resource) throws IOException { - return null; + AuthenticationResult authenticationResult = tokens.get(resource); + if (authenticationResult == null || authenticationResult.getExpiresOnDate().before(new Date())) { + authenticationResult = acquireAccessToken(resource); + } + return authenticationResult.getAccessToken(); } /** @@ -150,50 +111,47 @@ public AzureEnvironment getEnvironment() { return environment; } - @Override - public String getToken() throws IOException { - if (authenticationResult != null - && authenticationResult.getExpiresOnDate().before(new Date())) { - acquireAccessTokenFromRefreshToken(); - } else { - acquireAccessToken(); - } - return authenticationResult.getAccessToken(); - } - - @Override - public void refreshToken() throws IOException { - acquireAccessToken(); - } - - private void acquireAccessToken() throws IOException { + private AuthenticationResult acquireAccessToken(String resource) throws IOException { String authorityUrl = this.getEnvironment().getAuthenticationEndpoint() + this.getDomain(); - AuthenticationContext context = new AuthenticationContext(authorityUrl, this.getEnvironment().isValidateAuthority(), Executors.newSingleThreadExecutor()); + ExecutorService executor = Executors.newSingleThreadExecutor(); + AuthenticationContext context = new AuthenticationContext(authorityUrl, this.getEnvironment().isValidateAuthority(), executor); try { - authenticationResult = context.acquireToken( - this.resourceEndpoint, + AuthenticationResult result = context.acquireToken( + resource, this.getClientId(), this.getUsername(), this.getPassword(), null).get(); + tokens.put(resource, result); + return result; } catch (Exception e) { throw new IOException(e.getMessage(), e); + } finally { + executor.shutdown(); } } - private void acquireAccessTokenFromRefreshToken() throws IOException { + // Refresh tokens are currently not used since we don't know if the refresh token has expired + private AuthenticationResult acquireAccessTokenFromRefreshToken(String resource) throws IOException { String authorityUrl = this.getEnvironment().getAuthenticationEndpoint() + this.getDomain(); ExecutorService executor = Executors.newSingleThreadExecutor(); AuthenticationContext context = new AuthenticationContext(authorityUrl, this.getEnvironment().isValidateAuthority(), executor); try { - authenticationResult = context.acquireTokenByRefreshToken( - authenticationResult.getRefreshToken(), + AuthenticationResult result = context.acquireTokenByRefreshToken( + tokens.get(resource).getRefreshToken(), this.getClientId(), null, null).get(); + tokens.put(resource, result); + return result; } catch (Exception e) { throw new IOException(e.getMessage(), e); } finally { executor.shutdown(); } } + + @Override + public void applyCredentialsFilter(OkHttpClient.Builder clientBuilder) { + clientBuilder.interceptors().add(new AzureTokenCredentialsInterceptor(this)); + } } diff --git a/runtimes/azure-client-authentication/src/test/java/com/microsoft/azure/credentials/UserTokenCredentialsTests.java b/runtimes/azure-client-authentication/src/test/java/com/microsoft/azure/credentials/UserTokenCredentialsTests.java index 7905ba7e7b21..caab41dd8e7c 100644 --- a/runtimes/azure-client-authentication/src/test/java/com/microsoft/azure/credentials/UserTokenCredentialsTests.java +++ b/runtimes/azure-client-authentication/src/test/java/com/microsoft/azure/credentials/UserTokenCredentialsTests.java @@ -21,7 +21,6 @@ public class UserTokenCredentialsTests { "domain", "username", "password", - "redirect", AzureEnvironment.AZURE ); @@ -36,8 +35,8 @@ public void testAcquireToken() throws Exception { public static class MockUserTokenCredentials extends UserTokenCredentials { private AuthenticationResult authenticationResult; - public MockUserTokenCredentials(String clientId, String domain, String username, String password, String clientRedirectUri, AzureEnvironment environment) { - super(clientId, domain, username, password, clientRedirectUri, environment); + public MockUserTokenCredentials(String clientId, String domain, String username, String password, AzureEnvironment environment) { + super(clientId, domain, username, password, environment); } @Override diff --git a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java index 80e42856e417..cce24b097252 100644 --- a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java +++ b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java @@ -54,7 +54,7 @@ public AzureEnvironment( this.managementEndpoint = managementEndpoint; this.resourceManagerEndpoint = resourceManagerEndpoint; this.graphEndpoint = graphEndpoint; - this.validateAuthority = true; + this.validateAuthority = false; } /** From eca2ca550220b5cc047306d78f27013f65cef21c Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 7 Sep 2016 11:55:01 -0700 Subject: [PATCH 20/33] Add asserts to keyvault tests --- .../azure/management/keyvault/VaultTests.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/VaultTests.java b/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/VaultTests.java index 95fbf309fc10..17d39fab5bb5 100644 --- a/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/VaultTests.java +++ b/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/VaultTests.java @@ -49,6 +49,16 @@ public void canCRUDVault() throws Exception { // GET vault = keyVaultManager.vaults().getByGroup(RG_NAME, VAULT_NAME); Assert.assertNotNull(vault); + for (AccessPolicy policy : vault.accessPolicies()) { + if (policy.objectId().toString().equals("8188d1e8-3090-4e3c-aa76-38cf2b5c7b3a")) { + Assert.assertArrayEquals(new KeyPermissions[] { KeyPermissions.LIST }, policy.permissions().keys().toArray()); + Assert.assertArrayEquals(new SecretPermissions[] { SecretPermissions.ALL }, policy.permissions().secrets().toArray()); + } + if (policy.objectId().toString().equals("5963f50c-7c43-405c-af7e-53294de76abd")) { + Assert.assertArrayEquals(new KeyPermissions[] { KeyPermissions.ALL }, policy.permissions().keys().toArray()); + Assert.assertArrayEquals(new SecretPermissions[] { SecretPermissions.ALL }, policy.permissions().secrets().toArray()); + } + } // LIST List vaults = keyVaultManager.vaults().listByGroup(RG_NAME); for (Vault v : vaults) { @@ -65,9 +75,15 @@ public void canCRUDVault() throws Exception { .disallowSecretAllPermissions() .parent() .apply(); + for (AccessPolicy policy : vault.accessPolicies()) { + if (policy.objectId().toString().equals("8188d1e8-3090-4e3c-aa76-38cf2b5c7b3a")) { + Assert.assertArrayEquals(new KeyPermissions[] { KeyPermissions.LIST, KeyPermissions.ALL }, policy.permissions().keys().toArray()); + Assert.assertArrayEquals(new SecretPermissions[] { }, policy.permissions().secrets().toArray()); + } + } vault.update() .defineAccessPolicy() - .forServicePrincipal("http://nativeapp") + .forServicePrincipal("http://clientapp") .allowKeyAllPermissions() .attach() .apply(); From 000da1341323491f62f2251017ffc1fb482b2d05 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 7 Sep 2016 12:03:28 -0700 Subject: [PATCH 21/33] Regenerate keyvault & graph with latest autorest --- .../implementation/ServicePrincipalsImpl.java | 15 +++++++-------- .../graphrbac/implementation/UsersImpl.java | 12 ++++++------ .../keyvault/implementation/VaultImpl.java | 7 +++---- .../keyvault/implementation/VaultsImpl.java | 6 +++--- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java index 1b0cdb535499..98c1ba33ec32 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java @@ -42,7 +42,7 @@ class ServicePrincipalsImpl @Override public PagedList list() throws GraphErrorException, IOException { - return wrapList(this.innerCollection.list().getBody()); + return wrapList(this.innerCollection.list()); } @Override @@ -67,7 +67,7 @@ protected ServicePrincipalImpl wrapModel(ServicePrincipalInner servicePrincipalI @Override public ServicePrincipalImpl getByObjectId(String objectId) throws GraphErrorException, IOException { - return new ServicePrincipalImpl(innerCollection.get(objectId).getBody(), innerCollection); + return new ServicePrincipalImpl(innerCollection.get(objectId), innerCollection); } @Override @@ -77,7 +77,7 @@ public ServicePrincipal getByAppId(String appId) throws GraphErrorException, IOE @Override public ServicePrincipal getByServicePrincipalName(String spn) throws GraphErrorException, IOException { - List spList = innerCollection.list(String.format("servicePrincipalNames/any(c:c eq '%s')", spn)).getBody(); + List spList = innerCollection.list(String.format("servicePrincipalNames/any(c:c eq '%s')", spn)); if (spList == null || spList.isEmpty()) { return null; } else { @@ -100,14 +100,13 @@ public ServiceResponse call(ServicePrincipal fluentModelT) { @Override public Observable getByServicePrincipalNameAsync(final String spn) { return innerCollection.listAsync(String.format("servicePrincipalNames/any(c:c eq '%s')", spn)) - .map(new Func1>, ServicePrincipal>() { + .map(new Func1, ServicePrincipal>() { @Override - public ServicePrincipal call(ServiceResponse> result) { - Page servicePrincipals = result.getBody(); - if (servicePrincipals == null || servicePrincipals.getItems() == null || servicePrincipals.getItems().isEmpty()) { + public ServicePrincipal call(Page result) { + if (result == null || result.getItems() == null || result.getItems().isEmpty()) { throw new GraphErrorException("Service principal not found for SPN: " + spn); } - return new ServicePrincipalImpl(servicePrincipals.getItems().get(0), innerCollection); + return new ServicePrincipalImpl(result.getItems().get(0), innerCollection); } }); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java index f9a4e60de1ec..771c1c9dd8df 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java @@ -41,7 +41,7 @@ class UsersImpl @Override public PagedList list() throws RestException, IOException { - return wrapList(this.innerCollection.list().getBody()); + return wrapList(this.innerCollection.list()); } @Override @@ -66,12 +66,12 @@ protected UserImpl wrapModel(UserInner userInner) { @Override public UserImpl getByObjectId(String objectId) throws GraphErrorException, IOException { - return new UserImpl(innerCollection.get(objectId).getBody(), innerCollection); + return new UserImpl(innerCollection.get(objectId), innerCollection); } @Override public UserImpl getByUserPrincipalName(String upn) throws GraphErrorException, IOException { - return new UserImpl(innerCollection.get(upn).getBody(), innerCollection); + return new UserImpl(innerCollection.get(upn), innerCollection); } @Override @@ -89,10 +89,10 @@ public ServiceResponse call(User fluentModelT) { @Override public Observable getByUserPrincipalNameAsync(String upn) { return innerCollection.getAsync(upn) - .map(new Func1, User>() { + .map(new Func1() { @Override - public User call(ServiceResponse userInnerServiceResponse) { - return new UserImpl(userInnerServiceResponse.getBody(), innerCollection); + public User call(UserInner userInnerServiceResponse) { + return new UserImpl(userInnerServiceResponse, innerCollection); } }); } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java index fe120371b9a5..6885ffe118cb 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java @@ -16,7 +16,6 @@ import com.microsoft.azure.management.keyvault.Vault; import com.microsoft.azure.management.keyvault.VaultProperties; import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl; -import com.microsoft.rest.ServiceResponse; import rx.Observable; import rx.functions.Action1; import rx.functions.Func1; @@ -237,9 +236,9 @@ public List call(Object... args) { @Override public Observable createResourceAsync() { return populateAccessPolicies() - .flatMap(new Func1>>() { + .flatMap(new Func1>() { @Override - public Observable> call(Object o) { + public Observable call(Object o) { VaultCreateOrUpdateParametersInner parameters = new VaultCreateOrUpdateParametersInner(); parameters.withLocation(regionName()); parameters.withProperties(inner().properties()); @@ -256,7 +255,7 @@ public Observable> call(Object o) { @Override public VaultImpl refresh() throws Exception { - setInner(client.get(resourceGroupName(), name()).getBody()); + setInner(client.get(resourceGroupName(), name())); return this; } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java index e35af2c9c398..a0c69f4c1e76 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java @@ -46,17 +46,17 @@ class VaultsImpl @Override public PagedList list() throws RestException, IOException { - return wrapList(this.innerCollection.list().getBody()); + return wrapList(this.innerCollection.list()); } @Override public PagedList listByGroup(String groupName) throws CloudException, IOException { - return wrapList(this.innerCollection.listByResourceGroup(groupName).getBody()); + return wrapList(this.innerCollection.listByResourceGroup(groupName)); } @Override public Vault getByGroup(String groupName, String name) throws CloudException, IOException { - return wrapModel(this.innerCollection.get(groupName, name).getBody()); + return wrapModel(this.innerCollection.get(groupName, name)); } @Override From 665884d884a0ae1446cbbe0744491d965b01a1a5 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 7 Sep 2016 13:59:36 -0700 Subject: [PATCH 22/33] Fix merge errors and key vault test --- .../compute/implementation/VirtualMachineOffersImpl.java | 2 +- .../analytics/DataLakeAnalyticsManagementTestBase.java | 9 ++++----- .../store/uploader/DataLakeUploaderTestBase.java | 1 - .../datalake/store/DataLakeStoreManagementTestBase.java | 1 - .../microsoft/azure/management/keyvault/VaultTests.java | 2 +- 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineOffersImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineOffersImpl.java index 25342bcf2b40..681cc4544f7e 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineOffersImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineOffersImpl.java @@ -35,7 +35,7 @@ protected VirtualMachineOfferImpl wrapModel(VirtualMachineImageResourceInner inn } @Override - public PagedList list() throws CloudException, IllegalArgumentException, IOException { + public PagedList list() throws RestException, IllegalArgumentException, IOException { return wrapList(innerCollection.listOffers(publisher.region().toString(), publisher.name())); } } diff --git a/azure-mgmt-datalake-analytics/src/test/java/com/microsoft/azure/management/datalake/analytics/DataLakeAnalyticsManagementTestBase.java b/azure-mgmt-datalake-analytics/src/test/java/com/microsoft/azure/management/datalake/analytics/DataLakeAnalyticsManagementTestBase.java index a97e0f63e281..3b6246c1b18c 100644 --- a/azure-mgmt-datalake-analytics/src/test/java/com/microsoft/azure/management/datalake/analytics/DataLakeAnalyticsManagementTestBase.java +++ b/azure-mgmt-datalake-analytics/src/test/java/com/microsoft/azure/management/datalake/analytics/DataLakeAnalyticsManagementTestBase.java @@ -49,8 +49,8 @@ public static void createClients() { authEnv = new AzureEnvironment( "https://login.windows-ppe.net/", "https://management.core.windows.net/", - true, - "https://api-dogfood.resources.windows-int.net"); + "https://api-dogfood.resources.windows-int.net", + "https://graph.windows.net"); break; case "test": armUri = "https://api-dogfood.resources.windows-int.net"; @@ -59,8 +59,8 @@ public static void createClients() { authEnv = new AzureEnvironment( "https://login.windows-ppe.net/", "https://management.core.windows.net/", - true, - "https://api-dogfood.resources.windows-int.net"); + "https://api-dogfood.resources.windows-int.net", + "https://graph.windows.net"); break; default: // default to production armUri = "https://management.azure.com"; @@ -74,7 +74,6 @@ public static void createClients() { System.getenv("arm.domain"), System.getenv("arm.username"), System.getenv("arm.password"), - null, authEnv); RestClient restClient = new RestClient.Builder() diff --git a/azure-mgmt-datalake-store-uploader/src/test/java/com/microsoft/azure/management/datalake/store/uploader/DataLakeUploaderTestBase.java b/azure-mgmt-datalake-store-uploader/src/test/java/com/microsoft/azure/management/datalake/store/uploader/DataLakeUploaderTestBase.java index 38447a18f259..24954721e866 100644 --- a/azure-mgmt-datalake-store-uploader/src/test/java/com/microsoft/azure/management/datalake/store/uploader/DataLakeUploaderTestBase.java +++ b/azure-mgmt-datalake-store-uploader/src/test/java/com/microsoft/azure/management/datalake/store/uploader/DataLakeUploaderTestBase.java @@ -28,7 +28,6 @@ public static void createClients() { System.getenv("arm.domain"), System.getenv("arm.username"), System.getenv("arm.password"), - null, AzureEnvironment.AZURE); RestClient restClient = new RestClient.Builder() diff --git a/azure-mgmt-datalake-store/src/test/java/com/microsoft/azure/management/datalake/store/DataLakeStoreManagementTestBase.java b/azure-mgmt-datalake-store/src/test/java/com/microsoft/azure/management/datalake/store/DataLakeStoreManagementTestBase.java index ae8c934c769c..0fca86a3de9b 100644 --- a/azure-mgmt-datalake-store/src/test/java/com/microsoft/azure/management/datalake/store/DataLakeStoreManagementTestBase.java +++ b/azure-mgmt-datalake-store/src/test/java/com/microsoft/azure/management/datalake/store/DataLakeStoreManagementTestBase.java @@ -19,7 +19,6 @@ public static void createClients() { System.getenv("arm.domain"), System.getenv("arm.username"), System.getenv("arm.password"), - null, AzureEnvironment.AZURE); RestClient restClient = new RestClient.Builder() diff --git a/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/VaultTests.java b/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/VaultTests.java index 17d39fab5bb5..c6d09b738574 100644 --- a/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/VaultTests.java +++ b/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/VaultTests.java @@ -83,7 +83,7 @@ public void canCRUDVault() throws Exception { } vault.update() .defineAccessPolicy() - .forServicePrincipal("http://clientapp") + .forServicePrincipal("https://graphapp") .allowKeyAllPermissions() .attach() .apply(); From 25ae56832b3e295a961cf02ca140592ac5882f61 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 7 Sep 2016 15:40:55 -0700 Subject: [PATCH 23/33] Add tenantId requirement on roll-up client --- azure/pom.xml | 5 ++ .../main/java/com/microsoft/azure/Azure.java | 59 ++++++++++++++----- .../java/com/microsoft/azure/AzureTests.java | 5 +- .../ApplicationTokenCredentials.java | 1 + .../credentials/UserTokenCredentials.java | 1 + .../credentials/AzureTokenCredentials.java | 2 + 6 files changed, 56 insertions(+), 17 deletions(-) diff --git a/azure/pom.xml b/azure/pom.xml index 3695262170a5..43a027b79e7c 100644 --- a/azure/pom.xml +++ b/azure/pom.xml @@ -76,6 +76,11 @@ azure-mgmt-compute 1.0.0-SNAPSHOT + + com.microsoft.azure + azure-mgmt-keyvault + 1.0.0-SNAPSHOT + junit junit diff --git a/azure/src/main/java/com/microsoft/azure/Azure.java b/azure/src/main/java/com/microsoft/azure/Azure.java index fbe8ca394a90..b7716fdf394d 100644 --- a/azure/src/main/java/com/microsoft/azure/Azure.java +++ b/azure/src/main/java/com/microsoft/azure/Azure.java @@ -7,10 +7,13 @@ package com.microsoft.azure; import com.microsoft.azure.credentials.ApplicationTokenCredentials; +import com.microsoft.azure.credentials.AzureTokenCredentials; import com.microsoft.azure.management.compute.AvailabilitySets; import com.microsoft.azure.management.compute.VirtualMachineImages; import com.microsoft.azure.management.compute.VirtualMachines; import com.microsoft.azure.management.compute.implementation.ComputeManager; +import com.microsoft.azure.management.keyvault.Vaults; +import com.microsoft.azure.management.keyvault.implementation.KeyVaultManager; import com.microsoft.azure.management.network.LoadBalancers; import com.microsoft.azure.management.network.NetworkInterfaces; import com.microsoft.azure.management.network.NetworkSecurityGroups; @@ -45,6 +48,7 @@ public final class Azure { private final StorageManager storageManager; private final ComputeManager computeManager; private final NetworkManager networkManager; + private final KeyVaultManager keyVaultManager; private final String subscriptionId; /** @@ -53,11 +57,24 @@ public final class Azure { * @param credentials the credentials object * @return the authenticated Azure client */ - public static Authenticated authenticate(ServiceClientCredentials credentials) { + public static Authenticated authenticate(ServiceClientCredentials credentials, String tenantId) { return new AuthenticatedImpl( AzureEnvironment.AZURE.newRestClientBuilder() - .withCredentials(credentials) - .build()); + .withCredentials(credentials) + .build(), tenantId); + } + + /** + * Authenticate to Azure using an Azure credentials object. + * + * @param credentials the credentials object + * @return the authenticated Azure client + */ + public static Authenticated authenticate(AzureTokenCredentials credentials) { + return new AuthenticatedImpl( + AzureEnvironment.AZURE.newRestClientBuilder() + .withCredentials(credentials) + .build(), credentials.getDomain()); } /** @@ -80,7 +97,7 @@ public static Authenticated authenticate(File credentialsFile) throws IOExceptio ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credentialsFile); return new AuthenticatedImpl(AzureEnvironment.AZURE.newRestClientBuilder() .withCredentials(credentials) - .build()).withDefaultSubscription(credentials.defaultSubscriptionId()); + .build(), credentials.getDomain()).withDefaultSubscription(credentials.defaultSubscriptionId()); } /** @@ -88,12 +105,12 @@ public static Authenticated authenticate(File credentialsFile) throws IOExceptio * @param restClient the {@link RestClient} configured with Azure authentication credentials * @return authenticated Azure client */ - public static Authenticated authenticate(RestClient restClient) { - return new AuthenticatedImpl(restClient); + public static Authenticated authenticate(RestClient restClient, String tenantId) { + return new AuthenticatedImpl(restClient, tenantId); } - private static Authenticated authenticate(RestClient restClient, String subscriptionId) throws IOException { - return new AuthenticatedImpl(restClient).withDefaultSubscription(subscriptionId); + private static Authenticated authenticate(RestClient restClient, String tenantId, String subscriptionId) throws IOException { + return new AuthenticatedImpl(restClient, tenantId).withDefaultSubscription(subscriptionId); } /** @@ -113,7 +130,9 @@ public interface Configurable extends AzureConfigurable { * @param credentials The credentials to authenticate API access with * @return the authenticated Azure client */ - Authenticated authenticate(ServiceClientCredentials credentials); + Authenticated authenticate(ServiceClientCredentials credentials, String tenantId); + + Authenticated authenticate(AzureTokenCredentials credentials); /** * Authenticates API access using a properties file containing the required credentials. @@ -131,8 +150,13 @@ public interface Configurable extends AzureConfigurable { */ private static final class ConfigurableImpl extends AzureConfigurableImpl implements Configurable { @Override - public Authenticated authenticate(ServiceClientCredentials credentials) { - return Azure.authenticate(buildRestClient(credentials)); + public Authenticated authenticate(ServiceClientCredentials credentials, String tenantId) { + return Azure.authenticate(buildRestClient(credentials), tenantId); + } + + @Override + public Authenticated authenticate(AzureTokenCredentials credentials) { + return Azure.authenticate(buildRestClient(credentials), credentials.getDomain()); } @Override @@ -194,10 +218,12 @@ private static final class AuthenticatedImpl implements Authenticated { private final RestClient restClient; private final ResourceManager.Authenticated resourceManagerAuthenticated; private String defaultSubscription; + private String tenantId; - private AuthenticatedImpl(RestClient restClient) { + private AuthenticatedImpl(RestClient restClient, String tenantId) { this.resourceManagerAuthenticated = ResourceManager.authenticate(restClient); this.restClient = restClient; + this.tenantId = tenantId; } private AuthenticatedImpl withDefaultSubscription(String subscriptionId) throws IOException { @@ -217,7 +243,7 @@ public Tenants tenants() { @Override public Azure withSubscription(String subscriptionId) { - return new Azure(restClient, subscriptionId); + return new Azure(restClient, subscriptionId, tenantId); } @Override @@ -238,13 +264,14 @@ public Azure withDefaultSubscription() throws CloudException, IOException { } } - private Azure(RestClient restClient, String subscriptionId) { + private Azure(RestClient restClient, String subscriptionId, String tenantId) { ResourceManagementClientImpl resourceManagementClient = new ResourceManagementClientImpl(restClient); resourceManagementClient.withSubscriptionId(subscriptionId); this.resourceManager = ResourceManager.authenticate(restClient).withSubscription(subscriptionId); this.storageManager = StorageManager.authenticate(restClient, subscriptionId); this.computeManager = ComputeManager.authenticate(restClient, subscriptionId); this.networkManager = NetworkManager.authenticate(restClient, subscriptionId); + this.keyVaultManager = KeyVaultManager.authenticate(restClient, tenantId, subscriptionId); this.subscriptionId = subscriptionId; } @@ -359,4 +386,8 @@ public PublicIpAddresses publicIpAddresses() { public NetworkInterfaces networkInterfaces() { return this.networkManager.networkInterfaces(); } + + public Vaults vaults(String tenantId) { + return this.keyVaultManager.vaults(); + } } diff --git a/azure/src/test/java/com/microsoft/azure/AzureTests.java b/azure/src/test/java/com/microsoft/azure/AzureTests.java index 0f4cc24a21fa..546b31cd5f4b 100644 --- a/azure/src/test/java/com/microsoft/azure/AzureTests.java +++ b/azure/src/test/java/com/microsoft/azure/AzureTests.java @@ -6,9 +6,9 @@ package com.microsoft.azure; import com.microsoft.azure.credentials.ApplicationTokenCredentials; +import com.microsoft.azure.management.compute.VirtualMachineImage; import com.microsoft.azure.management.compute.VirtualMachineOffer; import com.microsoft.azure.management.compute.VirtualMachinePublisher; -import com.microsoft.azure.management.compute.VirtualMachineImage; import com.microsoft.azure.management.compute.VirtualMachineSku; import com.microsoft.azure.management.resources.Deployment; import com.microsoft.azure.management.resources.DeploymentMode; @@ -17,7 +17,6 @@ import com.microsoft.azure.management.resources.fluentcore.arm.Region; import com.microsoft.azure.management.storage.SkuName; import com.microsoft.azure.management.storage.StorageAccount; -import com.microsoft.rest.credentials.ServiceClientCredentials; import okhttp3.logging.HttpLoggingInterceptor.Level; import org.junit.Assert; import org.junit.Before; @@ -28,7 +27,7 @@ import java.util.List; public class AzureTests { - private static final ServiceClientCredentials CREDENTIALS = new ApplicationTokenCredentials( + private static final ApplicationTokenCredentials CREDENTIALS = new ApplicationTokenCredentials( System.getenv("client-id"), System.getenv("domain"), System.getenv("secret"), diff --git a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java index 7cfd0aa81372..48b4a061018e 100644 --- a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java +++ b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java @@ -171,6 +171,7 @@ public String getClientId() { * * @return the tenant or domain the containing the application. */ + @Override public String getDomain() { return domain; } diff --git a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java index 179b6d5a2fdc..9da95726b11a 100644 --- a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java +++ b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java @@ -71,6 +71,7 @@ public String getClientId() { * * @return the tenant or domain the containing the application. */ + @Override public String getDomain() { return domain; } diff --git a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/credentials/AzureTokenCredentials.java b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/credentials/AzureTokenCredentials.java index 1f59be80cbb8..52c5e89ab529 100644 --- a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/credentials/AzureTokenCredentials.java +++ b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/credentials/AzureTokenCredentials.java @@ -19,6 +19,8 @@ public interface AzureTokenCredentials extends ServiceClientCredentials { String getToken(String resource) throws IOException; + String getDomain(); + /** * @return the environment details the credential has access to. */ From a6ea6bbd22195c8c7f1baeb006146aa1ae113f81 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Thu, 8 Sep 2016 16:16:37 -0700 Subject: [PATCH 24/33] Add key vault sample --- .../keyvault/samples/ManageKeyVault.java | 170 ++++++++++++++++++ .../azure/management/samples/Utils.java | 24 ++- 2 files changed, 192 insertions(+), 2 deletions(-) create mode 100644 azure-samples/src/main/java/com/microsoft/azure/management/keyvault/samples/ManageKeyVault.java diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/keyvault/samples/ManageKeyVault.java b/azure-samples/src/main/java/com/microsoft/azure/management/keyvault/samples/ManageKeyVault.java new file mode 100644 index 000000000000..ab7265bba2b7 --- /dev/null +++ b/azure-samples/src/main/java/com/microsoft/azure/management/keyvault/samples/ManageKeyVault.java @@ -0,0 +1,170 @@ +/** + * + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + * + */ + +package com.microsoft.azure.management.keyvault.samples; + +import com.microsoft.azure.Azure; +import com.microsoft.azure.credentials.ApplicationTokenCredentials; +import com.microsoft.azure.management.keyvault.KeyPermissions; +import com.microsoft.azure.management.keyvault.SecretPermissions; +import com.microsoft.azure.management.keyvault.Vault; +import com.microsoft.azure.management.resources.fluentcore.arm.Region; +import com.microsoft.azure.management.resources.fluentcore.utils.ResourceNamer; +import com.microsoft.azure.management.samples.Utils; +import okhttp3.logging.HttpLoggingInterceptor; + +import java.io.File; + +/** + * Azure Key Vault sample for managing key vaults - + * - Create a key vault + * - Authorize an application + * - Update a key vault + * - alter configurations + * - change permissions + * - Create another key vault + * - List key vaults + * - Delete a key vault. + */ +public class ManageKeyVault { + + /** + * Main entry point. + * @param args the parameters + */ + public static void main(String[] args) { + final String vaultName1 = ResourceNamer.randomResourceName("vault1", 20); + final String vaultName2 = ResourceNamer.randomResourceName("vault2", 20); + final String rgName = ResourceNamer.randomResourceName("rgNEMV", 24); + + try { + + //============================================================= + // Authenticate + + final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); + + Azure azure = Azure + .configure() + .withLogLevel(HttpLoggingInterceptor.Level.BODY) + .authenticate(credFile) + .withDefaultSubscription(); + + // Print selected subscription + System.out.println("Selected subscription: " + azure.subscriptionId()); + try { + + + //============================================================ + // Create a key vault with empty access policy + + System.out.println("Creating a key vault..."); + + Vault vault1 = azure.vaults() + .define(vaultName1) + .withRegion(Region.US_WEST) + .withNewResourceGroup(rgName) + .withEmptyAccessPolicy() + .create(); + + System.out.println("Created key vault"); + Utils.print(vault1); + + //============================================================ + // Authorize an application + + System.out.println("Authorizing the application associated with the current service principal..."); + + vault1 = vault1.update() + .defineAccessPolicy() + .forServicePrincipal(ApplicationTokenCredentials.fromFile(credFile).getClientId()) + .allowKeyAllPermissions() + .allowSecretPermissions(SecretPermissions.GET) + .allowSecretPermissions(SecretPermissions.LIST) + .attach() + .apply(); + + System.out.println("Updated key vault"); + Utils.print(vault1); + + //============================================================ + // Update a key vault + + System.out.println("Update a key vault to enable deployments and add permissions to the application..."); + + vault1 = vault1.update() + .enableDeployment() + .enableTemplateDeployment() + .updateAccessPolicy(vault1.accessPolicies().get(0).objectId()) + .allowSecretAllPermissions() + .parent() + .apply(); + + System.out.println("Updated key vault"); + // Print the network security group + Utils.print(vault1); + + + //============================================================ + // Create another key vault + + Vault vault2 = azure.vaults() + .define(vaultName2) + .withRegion(Region.US_EAST) + .withExistingResourceGroup(rgName) + .defineAccessPolicy() + .forServicePrincipal(ApplicationTokenCredentials.fromFile(credFile).getClientId()) + .allowKeyPermissions(KeyPermissions.LIST) + .allowKeyPermissions(KeyPermissions.GET) + .allowKeyPermissions(KeyPermissions.DECRYPT) + .allowSecretPermissions(SecretPermissions.GET) + .attach() + .create(); + + System.out.println("Created key vault"); + // Print the network security group + Utils.print(vault2); + + + //============================================================ + // List key vaults + + System.out.println("Listing key vaults..."); + + for (Vault vault : azure.vaults().listByGroup(rgName)) { + Utils.print(vault); + } + + //============================================================ + // Delete key vaults + System.out.println("Deleting the key vaults"); + azure.vaults().delete(vault1.id()); + azure.vaults().delete(vault2.id()); + System.out.println("Deleted the key vaults"); + } catch (Exception e) { + System.err.println(e.getMessage()); + } finally { + try { + System.out.println("Deleting Resource Group: " + rgName); + azure.resourceGroups().delete(rgName); + System.out.println("Deleted Resource Group: " + rgName); + } catch (NullPointerException npe) { + System.out.println("Did not create any resources in Azure. No clean up is necessary"); + } catch (Exception g) { + g.printStackTrace(); + } + } + + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + } + + private ManageKeyVault() { + } +} diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/samples/Utils.java b/azure-samples/src/main/java/com/microsoft/azure/management/samples/Utils.java index b1881647ca9b..ed24e1f9a4ca 100644 --- a/azure-samples/src/main/java/com/microsoft/azure/management/samples/Utils.java +++ b/azure-samples/src/main/java/com/microsoft/azure/management/samples/Utils.java @@ -7,17 +7,20 @@ package com.microsoft.azure.management.samples; +import com.google.common.base.Joiner; import com.microsoft.azure.CloudException; import com.microsoft.azure.management.compute.AvailabilitySet; -import com.microsoft.azure.management.compute.VirtualMachine; import com.microsoft.azure.management.compute.DataDisk; +import com.microsoft.azure.management.compute.VirtualMachine; import com.microsoft.azure.management.compute.VirtualMachineExtension; +import com.microsoft.azure.management.keyvault.AccessPolicy; +import com.microsoft.azure.management.keyvault.Vault; import com.microsoft.azure.management.network.Network; import com.microsoft.azure.management.network.NetworkInterface; import com.microsoft.azure.management.network.NetworkSecurityGroup; import com.microsoft.azure.management.network.NetworkSecurityRule; -import com.microsoft.azure.management.network.Subnet; import com.microsoft.azure.management.network.PublicIpAddress; +import com.microsoft.azure.management.network.Subnet; import com.microsoft.azure.management.storage.StorageAccount; import com.microsoft.azure.management.storage.StorageAccountKey; @@ -271,6 +274,23 @@ public static void print(PublicIpAddress resource) { .toString()); } + public static void print(Vault vault) { + StringBuilder info = new StringBuilder().append("Key Vault: ").append(vault.id()) + .append("Name: ").append(vault.name()) + .append("\n\tResource group: ").append(vault.resourceGroupName()) + .append("\n\tRegion: ").append(vault.region()) + .append("\n\tSku: ").append(vault.sku().name()).append(" - ").append(vault.sku().family()) + .append("\n\tVault URI: ").append(vault.vaultUri()) + .append("\n\tAccess policies: "); + for (AccessPolicy accessPolicy: + vault.accessPolicies()) { + info.append("\n\t\tIdentity:").append(accessPolicy.objectId()) + .append("\n\t\tKey permissions: ").append(Joiner.on(", ").join(accessPolicy.permissions().keys())) + .append("\n\t\tSecret permissions: ").append(Joiner.on(", ").join(accessPolicy.permissions().secrets())); + } + System.out.println(info.toString()); + } + /** * Print storage account. From f03d29fb2bf450a56da21d1a20ace302ddaa4316 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Thu, 8 Sep 2016 16:17:59 -0700 Subject: [PATCH 25/33] more fixes in key vault --- .../management/keyvault/AccessPolicy.java | 6 ++--- .../azure/management/keyvault/Vault.java | 3 +-- .../implementation/AccessPolicyImpl.java | 26 ++++++++++++------- .../keyvault/implementation/VaultImpl.java | 7 +++-- .../keyvault/implementation/VaultsInner.java | 24 +++++++++-------- .../azure/management/keyvault/VaultTests.java | 8 +++--- 6 files changed, 42 insertions(+), 32 deletions(-) diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java index bf26fc88f18d..4a97debdf737 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java @@ -27,18 +27,18 @@ public interface AccessPolicy extends * @return The Azure Active Directory tenant ID that should be used for * authenticating requests to the key vault. */ - UUID tenantId(); + String tenantId(); /** * @return The object ID of a user or service principal in the Azure Active * Directory tenant for the vault. */ - UUID objectId(); + String objectId(); /** * @return Application ID of the client making request on behalf of a principal. */ - UUID applicationId(); + String applicationId(); /** * @return Permissions the identity has for keys and secrets. diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java index f19d9ddbe773..15008400b434 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java @@ -15,7 +15,6 @@ import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; import java.util.List; -import java.util.UUID; /** * An immutable client-side representation of an Azure Key Vault. @@ -34,7 +33,7 @@ public interface Vault extends * @return The Azure Active Directory tenant ID that should be used for * authenticating requests to the key vault. */ - UUID tenantId(); + String tenantId(); /** * @return SKU details. diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java index 88b420e5d991..6f0c8bd066c6 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java @@ -39,21 +39,31 @@ class AccessPolicyImpl AccessPolicyImpl(AccessPolicyEntry innerObject, VaultImpl parent) { super(innerObject, parent); + inner().withTenantId(UUID.fromString(parent.tenantId())); } @Override - public UUID tenantId() { - return inner().tenantId(); + public String tenantId() { + if (inner().tenantId() == null) { + return null; + } + return inner().tenantId().toString(); } @Override - public UUID objectId() { - return inner().objectId(); + public String objectId() { + if (inner().objectId() == null) { + return null; + } + return inner().objectId().toString(); } @Override - public UUID applicationId() { - return inner().applicationId(); + public String applicationId() { + if (inner().applicationId() == null) { + return null; + } + return inner().applicationId().toString(); } @Override @@ -121,14 +131,12 @@ public VaultImpl attach() { @Override public AccessPolicyImpl forObjectId(UUID objectId) { inner().withObjectId(objectId); - inner().withTenantId(parent().tenantId()); return this; } @Override public AccessPolicyImpl forUser(User user) { inner().withObjectId(UUID.fromString(user.objectId())); - inner().withTenantId(parent().tenantId()); return this; } @@ -141,14 +149,12 @@ public AccessPolicyImpl forUser(String userPrincipalName) { @Override public AccessPolicyImpl forGroup(Group group) { inner().withObjectId(UUID.fromString(group.objectId())); - inner().withTenantId(parent().tenantId()); return this; } @Override public AccessPolicyImpl forServicePrincipal(ServicePrincipal servicePrincipal) { inner().withObjectId(UUID.fromString(servicePrincipal.objectId())); - inner().withTenantId(parent().tenantId()); return this; } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java index 6885ffe118cb..bb7fff07f318 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java @@ -66,11 +66,14 @@ public String vaultUri() { } @Override - public UUID tenantId() { + public String tenantId() { if (inner().properties() == null) { return null; } - return inner().properties().tenantId(); + if (inner().properties().tenantId() == null) { + return null; + } + return inner().properties().tenantId().toString(); } @Override diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsInner.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsInner.java index 4f28b7533faf..33bc29b7c489 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsInner.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsInner.java @@ -8,7 +8,6 @@ package com.microsoft.azure.management.keyvault.implementation; -import retrofit2.Retrofit; import com.google.common.reflect.TypeToken; import com.microsoft.azure.AzureServiceCall; import com.microsoft.azure.AzureServiceResponseBuilder; @@ -21,20 +20,23 @@ import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; import com.microsoft.rest.Validator; -import java.io.IOException; -import java.util.List; import okhttp3.ResponseBody; +import retrofit2.Response; +import retrofit2.Retrofit; import retrofit2.http.Body; import retrofit2.http.GET; +import retrofit2.http.HTTP; import retrofit2.http.Header; import retrofit2.http.Headers; -import retrofit2.http.HTTP; -import retrofit2.http.Path; import retrofit2.http.PUT; +import retrofit2.http.Path; import retrofit2.http.Query; -import retrofit2.Response; -import rx.functions.Func1; +import retrofit2.http.Url; import rx.Observable; +import rx.functions.Func1; + +import java.io.IOException; +import java.util.List; /** * An instance of this class provides access to all the operations defined @@ -83,12 +85,12 @@ interface VaultsService { Observable> list(@Path("subscriptionId") String subscriptionId, @Query("$filter") String filter, @Query("$top") Integer top, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") - @GET("{nextLink}") - Observable> listByResourceGroupNext(@Path(value = "nextLink", encoded = true) String nextPageLink, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + @GET + Observable> listByResourceGroupNext(@Url String nextPageLink, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") - @GET("{nextLink}") - Observable> listNext(@Path(value = "nextLink", encoded = true) String nextPageLink, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + @GET + Observable> listNext(@Url String nextPageLink, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); } diff --git a/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/VaultTests.java b/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/VaultTests.java index c6d09b738574..eb647251cae6 100644 --- a/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/VaultTests.java +++ b/azure-mgmt-keyvault/src/test/java/com/microsoft/azure/management/keyvault/VaultTests.java @@ -50,11 +50,11 @@ public void canCRUDVault() throws Exception { vault = keyVaultManager.vaults().getByGroup(RG_NAME, VAULT_NAME); Assert.assertNotNull(vault); for (AccessPolicy policy : vault.accessPolicies()) { - if (policy.objectId().toString().equals("8188d1e8-3090-4e3c-aa76-38cf2b5c7b3a")) { + if (policy.objectId().equals("8188d1e8-3090-4e3c-aa76-38cf2b5c7b3a")) { Assert.assertArrayEquals(new KeyPermissions[] { KeyPermissions.LIST }, policy.permissions().keys().toArray()); Assert.assertArrayEquals(new SecretPermissions[] { SecretPermissions.ALL }, policy.permissions().secrets().toArray()); } - if (policy.objectId().toString().equals("5963f50c-7c43-405c-af7e-53294de76abd")) { + if (policy.objectId().equals("5963f50c-7c43-405c-af7e-53294de76abd")) { Assert.assertArrayEquals(new KeyPermissions[] { KeyPermissions.ALL }, policy.permissions().keys().toArray()); Assert.assertArrayEquals(new SecretPermissions[] { SecretPermissions.ALL }, policy.permissions().secrets().toArray()); } @@ -70,13 +70,13 @@ public void canCRUDVault() throws Exception { Assert.assertNotNull(vault); // UPDATE vault.update() - .updateAccessPolicy(vault.accessPolicies().get(0).objectId().toString()) + .updateAccessPolicy(vault.accessPolicies().get(0).objectId()) .allowKeyAllPermissions() .disallowSecretAllPermissions() .parent() .apply(); for (AccessPolicy policy : vault.accessPolicies()) { - if (policy.objectId().toString().equals("8188d1e8-3090-4e3c-aa76-38cf2b5c7b3a")) { + if (policy.objectId().equals("8188d1e8-3090-4e3c-aa76-38cf2b5c7b3a")) { Assert.assertArrayEquals(new KeyPermissions[] { KeyPermissions.LIST, KeyPermissions.ALL }, policy.permissions().keys().toArray()); Assert.assertArrayEquals(new SecretPermissions[] { }, policy.permissions().secrets().toArray()); } From ce5012afaaa9d8fe68b236d1351cc9087a460600 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Thu, 8 Sep 2016 16:18:10 -0700 Subject: [PATCH 26/33] Add key vault to roll-up client --- azure/src/main/java/com/microsoft/azure/Azure.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure/src/main/java/com/microsoft/azure/Azure.java b/azure/src/main/java/com/microsoft/azure/Azure.java index b7716fdf394d..5499e0fe086f 100644 --- a/azure/src/main/java/com/microsoft/azure/Azure.java +++ b/azure/src/main/java/com/microsoft/azure/Azure.java @@ -162,7 +162,7 @@ public Authenticated authenticate(AzureTokenCredentials credentials) { @Override public Authenticated authenticate(File credentialsFile) throws IOException { ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credentialsFile); - return Azure.authenticate(buildRestClient(credentials), credentials.defaultSubscriptionId()); + return Azure.authenticate(buildRestClient(credentials), credentials.getDomain(), credentials.defaultSubscriptionId()); } } @@ -387,7 +387,7 @@ public NetworkInterfaces networkInterfaces() { return this.networkManager.networkInterfaces(); } - public Vaults vaults(String tenantId) { + public Vaults vaults() { return this.keyVaultManager.vaults(); } } From 2d12e8529ff9c65732621ba3b21ba7edde6b8b9a Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Thu, 8 Sep 2016 16:18:26 -0700 Subject: [PATCH 27/33] Allow empty pages in paged list --- .../java/com/microsoft/azure/PagedList.java | 55 +++++++++---------- .../com/microsoft/azure/PagedListTests.java | 14 +++-- 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java index 8db10337d989..7cae0efe0c28 100644 --- a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java +++ b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java @@ -17,8 +17,6 @@ import java.util.ListIterator; import java.util.NoSuchElementException; -import javax.xml.bind.DataBindingException; - /** * Defines a list response from a paging operation. The pages are * lazy initialized when an instance of this class is iterated. @@ -28,10 +26,10 @@ public abstract class PagedList implements List { /** The actual items in the list. */ private List items; - /** Stores the link to get the next page of items. */ - private String nextPageLink; /** Stores the latest page fetched. */ private Page currentPage; + /** Cached page right after the current one. */ + private Page cachedPage; /** * Creates an instance of Pagedlist. @@ -48,11 +46,26 @@ public PagedList() { public PagedList(Page page) { this(); List retrievedItems = page.getItems(); - if (retrievedItems != null && retrievedItems.size() != 0) { + if (retrievedItems != null) { items.addAll(retrievedItems); } - nextPageLink = page.getNextPageLink(); currentPage = page; + cachePage(page.getNextPageLink()); + } + + private void cachePage(String nextPageLink) { + try { + while (nextPageLink != null) { + cachedPage = nextPage(nextPageLink); + nextPageLink = cachedPage.getNextPageLink(); + if (hasNextPage()) { + // a legit, non-empty page has been fetched, otherwise keep fetching + break; + } + } + } catch (IOException ex) { + throw new RuntimeException(ex); + } } /** @@ -71,7 +84,7 @@ public PagedList(Page page) { * @return true if there are more pages to load. False otherwise. */ public boolean hasNextPage() { - return this.nextPageLink != null; + return this.cachedPage != null && this.cachedPage.getItems() != null && !this.cachedPage.getItems().isEmpty(); } /** @@ -79,14 +92,10 @@ public boolean hasNextPage() { * The exceptions are wrapped into Java Runtime exceptions. */ public void loadNextPage() { - try { - Page nextPage = nextPage(this.nextPageLink); - this.nextPageLink = nextPage.getNextPageLink(); - this.items.addAll(nextPage.getItems()); - this.currentPage = nextPage; - } catch (IOException e) { - throw new DataBindingException(e.getMessage(), e); - } + this.currentPage = cachedPage; + cachedPage = null; + this.items.addAll(currentPage.getItems()); + cachePage(currentPage.getNextPageLink()); } /** @@ -107,15 +116,6 @@ public Page currentPage() { return currentPage; } - /** - * Gets the next page's link. - * - * @return the next page link. - */ - public String nextPageLink() { - return nextPageLink; - } - /** * The implementation of {@link ListIterator} for PagedList. */ @@ -141,17 +141,14 @@ public boolean hasNext() { public E next() { if (!itemsListItr.hasNext()) { if (!hasNextPage()) { - throw new NoSuchElementException(); + throw new NoSuchElementException(); } else { int size = items.size(); loadNextPage(); itemsListItr = items.listIterator(size); } } - if (itemsListItr.hasNext()) { - return itemsListItr.next(); - } - return null; + return itemsListItr.next(); } @Override diff --git a/runtimes/azure-client-runtime/src/test/java/com/microsoft/azure/PagedListTests.java b/runtimes/azure-client-runtime/src/test/java/com/microsoft/azure/PagedListTests.java index b82c8d062878..04567aa1c673 100644 --- a/runtimes/azure-client-runtime/src/test/java/com/microsoft/azure/PagedListTests.java +++ b/runtimes/azure-client-runtime/src/test/java/com/microsoft/azure/PagedListTests.java @@ -21,11 +21,11 @@ public class PagedListTests { @Before public void setupList() { - list = new PagedList(new TestPage(0, 20)) { + list = new PagedList(new TestPage(0, 21)) { @Override public Page nextPage(String nextPageLink) throws CloudException, IOException { int pageNum = Integer.parseInt(nextPageLink); - return new TestPage(pageNum, 20); + return new TestPage(pageNum, 21); } }; } @@ -119,9 +119,13 @@ public String getNextPageLink() { @Override public List getItems() { - List items = new ArrayList<>(); - items.add(page); - return items; + if (page + 1 != max) { + List items = new ArrayList<>(); + items.add(page); + return items; + } else { + return new ArrayList<>(); + } } } } From 907d8c09d78991df0ce91d29d71eeb804e9be20c Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Thu, 8 Sep 2016 18:09:54 -0700 Subject: [PATCH 28/33] Adapt group paged list to new paged list --- .../models/implementation/GroupPagedList.java | 41 +++++++++---------- .../resources/GroupPagedListTests.java | 6 +-- .../java/com/microsoft/azure/PagedList.java | 14 +++++++ 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/GroupPagedList.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/GroupPagedList.java index bc8e19433776..2ad8436c5039 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/GroupPagedList.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/GroupPagedList.java @@ -13,9 +13,9 @@ import com.microsoft.rest.RestException; import java.io.IOException; -import java.util.LinkedList; +import java.util.ArrayList; +import java.util.Iterator; import java.util.List; -import java.util.Queue; /** * Defines a list of resources paginated across resource groups. @@ -23,9 +23,7 @@ * @param the item type */ public abstract class GroupPagedList extends PagedList { - private PagedList resourceGroupList; - private Page currentPage; - private Queue queue; + private Iterator resourceGroupItr; /** * Creates an instance from a list of resource groups. @@ -33,27 +31,28 @@ public abstract class GroupPagedList extends PagedList { * @param resourceGroupList the list of resource groups */ public GroupPagedList(PagedList resourceGroupList) { - this.resourceGroupList = resourceGroupList; - this.currentPage = resourceGroupList.currentPage(); - this.queue = new LinkedList<>(currentPage.getItems()); - } - - @Override - public boolean hasNextPage() { - return !queue.isEmpty() || this.currentPage.getNextPageLink() != null; + this.resourceGroupItr = resourceGroupList.iterator(); + try { + setCurrentPage(nextPage("dummy")); + } catch (IOException e) { + throw new RuntimeException(e); + } } @Override public Page nextPage(String s) throws RestException, IOException { - if (queue.isEmpty()) { - this.currentPage = resourceGroupList.nextPage(this.currentPage.getNextPageLink()); - queue.addAll(this.currentPage.getItems()); + if (resourceGroupItr.hasNext()) { + ResourceGroup resourceGroup = resourceGroupItr.next(); + PageImpl page = new PageImpl<>(); + page.setItems(listNextGroup(resourceGroup.name())); + page.setNextPageLink(s); + return page; + } else { + // return an empty page without next link so that iteration will terminate + PageImpl page = new PageImpl<>(); + page.setItems(new ArrayList()); + return page; } - - ResourceGroup resourceGroup = queue.poll(); - PageImpl page = new PageImpl<>(); - page.setItems(listNextGroup(resourceGroup.name())); - return page; } /** diff --git a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/GroupPagedListTests.java b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/GroupPagedListTests.java index a501edd19a71..31e258ae08a1 100644 --- a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/GroupPagedListTests.java +++ b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/GroupPagedListTests.java @@ -57,24 +57,24 @@ public void isResourceLoadedLazily() { pages.get(3).setNextPageLink(null); List expected = Arrays.asList( + "1", "RG1Vm1", "RG1Vm2", "RG2Vm1", "RG2Vm2", "RG3Vm1", "RG3Vm2", "RG4Vm1", "RG4Vm2", "RG5Vm1", "RG5Vm2", - "1", + "2", "RG6Vm1", "RG6Vm2", "RG7AVm1", "RG7Vm2", "RG8AVm1", "RG8Vm2", "RG9AVm1", "RG9Vm2", "RG10AVm1", "RG10Vm2", - "2", + "3", "RG11Vm1", "RG11Vm2", "RG12Vm1", "RG12Vm2", "RG13Vm1", "RG13Vm2", "RG14Vm1", "RG14Vm2", "RG15Vm1", "RG15Vm2", - "3", "RG16Vm1", "RG16Vm2", "RG17Vm1", "RG17Vm2", "RG18Vm1", "RG18Vm2", diff --git a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java index 7cae0efe0c28..46c02402ed53 100644 --- a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java +++ b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java @@ -116,6 +116,20 @@ public Page currentPage() { return currentPage; } + /** + * Sets the current page. + * + * @param currentPage the current page. + */ + protected void setCurrentPage(Page currentPage) { + this.currentPage = currentPage; + List retrievedItems = currentPage.getItems(); + if (retrievedItems != null) { + items.addAll(retrievedItems); + } + cachePage(currentPage.getNextPageLink()); + } + /** * The implementation of {@link ListIterator} for PagedList. */ From 7e660165e3245f4b45955bc80b55f033a058acdf Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Fri, 9 Sep 2016 15:06:32 -0700 Subject: [PATCH 29/33] Child list flattener doesn't need to worry about cousins --- .../implementation/ChildListFlattener.java | 41 +++---------------- .../java/com/microsoft/azure/AzureTests.java | 2 +- 2 files changed, 6 insertions(+), 37 deletions(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ChildListFlattener.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ChildListFlattener.java index ea965b14feeb..b095483da840 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ChildListFlattener.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ChildListFlattener.java @@ -17,10 +17,9 @@ * @param the type of child paged list item */ final class ChildListFlattener { - protected final String switchToCousin = "switchToCousin"; - protected Iterator parentItr; - protected PagedList currentChildList; - protected PagedList cousinList; + private final String switchToCousin = "switchToCousin"; + private Iterator parentItr; + private PagedList currentChildList; private final ChildListLoader childListLoader; /** @@ -67,52 +66,22 @@ public PagedList flatten() throws CloudException, IOException { if (this.currentChildList == null) { return emptyPagedList(); } - // setCousin sets the next child paged list (i.e. the current child list's immediate cousin). - // we need to know in advance whether there is going to be a next child paged list (cousin). - // This is because the 'next link' of the current child paged list's last page will be null. - // when the PagedList sees next link as null it assumes there is no more pages hence it won't - // call nextPage and iteration stops, if cousin presents then 'childListPage' method replace - // this null with a marker indicating there is more pages. - setCousin(); return new PagedList(childListPage(currentChildList.currentPage())) { @Override public Page nextPage(String nextPageLink) throws RestException, IOException { if (nextPageLink.equalsIgnoreCase(switchToCousin)) { // Reached end of current child paged list, make next child list(cousin) as current // paged list and return it's first page. - currentChildList = cousinList; - setCousin(); + currentChildList = nextChildList(); return childListPage(currentChildList.currentPage()); } else { currentChildList.loadNextPage(); - if (currentChildList.currentPage().getNextPageLink() == null) { - // This is the last page of the current child paged list set it's cousin - // so that next call to nextPage can start using it. - setCousin(); - } return childListPage(currentChildList.currentPage()); } } }; } - /** - * @return true if the current child paged list has a cousin - */ - private boolean hasCousin() { - return this.cousinList != null; - } - - /** - * Locate and sets the cousin list (the next child paged list). - * - * @throws CloudException exceptions thrown from the cloud - * @throws IOException exceptions thrown from serialization/deserialization - */ - private void setCousin() throws CloudException, IOException { - cousinList = nextChildList(); - } - /** * Returns the next child paged list containing at least one item. *

@@ -152,7 +121,7 @@ public String getNextPageLink() { return page.getNextPageLink(); } - if (hasCousin()) { + if (parentItr.hasNext()) { // The current child paged list has no more pages so switch to it's cousin list return switchToCousin; } diff --git a/azure/src/test/java/com/microsoft/azure/AzureTests.java b/azure/src/test/java/com/microsoft/azure/AzureTests.java index 546b31cd5f4b..03fa1e8b36d2 100644 --- a/azure/src/test/java/com/microsoft/azure/AzureTests.java +++ b/azure/src/test/java/com/microsoft/azure/AzureTests.java @@ -68,7 +68,7 @@ public static void main(String[] args) throws IOException, CloudException { public void setup() throws Exception { // Authenticate based on credentials instance Azure.Authenticated azureAuthed = Azure.configure() - .withLogLevel(Level.BODY) + .withLogLevel(Level.NONE) .withUserAgent("AzureTests") .authenticate(CREDENTIALS); From 53ad799400b732032600b414976dd2970882d8ae Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Fri, 9 Sep 2016 18:23:22 -0700 Subject: [PATCH 30/33] Add javadocs and address checkstyle --- .../management/compute/AvailabilitySet.java | 1 + .../azure/management/graphrbac/Group.java | 34 ++- .../azure/management/graphrbac/Groups.java | 6 +- .../graphrbac/ServicePrincipal.java | 24 +- .../graphrbac/ServicePrincipals.java | 2 +- .../azure/management/graphrbac/User.java | 60 +++- .../azure/management/graphrbac/Users.java | 2 +- .../implementation/GraphRbacManager.java | 3 + .../implementation/ServicePrincipalImpl.java | 2 +- .../implementation/ServicePrincipalsImpl.java | 2 +- .../graphrbac/implementation/UserImpl.java | 2 +- .../graphrbac/implementation/UsersImpl.java | 2 +- .../management/keyvault/AccessPolicy.java | 267 +++++++++++++++++- .../azure/management/keyvault/Vault.java | 126 +++++++++ .../azure/management/keyvault/Vaults.java | 2 +- .../implementation/AccessPolicyImpl.java | 14 +- .../keyvault/implementation/VaultImpl.java | 14 +- .../keyvault/implementation/VaultsImpl.java | 2 +- .../implementation/LoadBalancerImpl.java | 2 +- .../collection/SupportsListing.java | 3 +- .../keyvault/samples/ManageKeyVault.java | 2 +- .../keyvault/samples/package-info.java | 8 + .../azure/management/samples/Utils.java | 7 +- .../main/java/com/microsoft/azure/Azure.java | 12 + .../com/microsoft/azure/AzureEnvironment.java | 11 +- .../credentials/AzureTokenCredentials.java | 16 +- .../azure/credentials/package-info.java | 6 + 27 files changed, 565 insertions(+), 67 deletions(-) create mode 100644 azure-samples/src/main/java/com/microsoft/azure/management/keyvault/samples/package-info.java create mode 100644 runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/credentials/package-info.java diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySet.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySet.java index 462cce394cd7..96505f5c5d1b 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySet.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySet.java @@ -13,6 +13,7 @@ import com.microsoft.azure.management.resources.fluentcore.model.Refreshable; import com.microsoft.azure.management.resources.fluentcore.model.Updatable; import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; + import java.util.List; /** diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Group.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Group.java index a463a3253d05..37824e7e4859 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Group.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Group.java @@ -11,7 +11,7 @@ import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; /** - * An immutable client-side representation of an Azure tenant. + * An immutable client-side representation of an Azure AD group. */ public interface Group extends Wrapper { @@ -41,7 +41,7 @@ public interface Group extends String mail(); /************************************************************** - * Fluent interfaces to provision a StorageAccount + * Fluent interfaces to provision a Group **************************************************************/ /** @@ -55,26 +55,44 @@ interface Definition extends } /** - * Grouping of all the storage account definition stages. + * Grouping of all the group definition stages. */ interface DefinitionStages { /** - * The first stage of the storage account definition. + * The first stage of the group definition. */ interface Blank extends WithDisplayName { } + /** + * The stage of group definition allowing display name to be specified. + */ interface WithDisplayName { + /** + * Specifies the display name of the group. + * + * @param displayName the human readable display name + * @return the next stage of group definition + */ WithMailNickname withDisplayName(String displayName); } + /** + * The stage of group definition allowing mail nickname to be specified. + */ interface WithMailNickname { + /** + * Specifies the mail nickname of the group. + * + * @param mailNickname the mail nickname for the group + * @return the next stage of group definition + */ WithCreate withMailNickname(String mailNickname); } /** - * A storage account definition with sufficient inputs to create a new - * storage account in the cloud, but exposing additional optional inputs to + * An AD group definition with sufficient inputs to create a new + * group in the cloud, but exposing additional optional inputs to * specify. */ interface WithCreate extends @@ -83,13 +101,13 @@ interface WithCreate extends } /** - * Grouping of all the storage account update stages. + * Grouping of all the group update stages. */ interface UpdateStages { } /** - * The template for a storage account update operation, containing all the settings that can be modified. + * The template for a group update operation, containing all the settings that can be modified. */ interface Update { } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Groups.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Groups.java index 8046c554d4ca..c15ccb826e52 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Groups.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Groups.java @@ -15,14 +15,14 @@ import java.util.List; /** - * Entry point to tenant management API. + * Entry point to AD group management API. */ public interface Groups extends SupportsCreating, SupportsListing, SupportsDeleting { /** - * Gets the information about a user. + * Gets the information about a group. * * @param objectId the unique object id * @return an immutable representation of the resource @@ -32,7 +32,7 @@ public interface Groups extends Group getByObjectId(String objectId) throws CloudException, IOException; /** - * Gets the information about a user. + * Gets the information about a group. * * @param displayNamePrefix the partial prefix of the display name to search * @return an immutable representation of the resource diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipal.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipal.java index 08fb88f510a8..5d0a609ee0a0 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipal.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipal.java @@ -13,11 +13,10 @@ import java.util.List; /** - * An immutable client-side representation of an Azure tenant. + * An immutable client-side representation of an Azure AD service principal. */ public interface ServicePrincipal extends Wrapper { - /** * @return object Id. */ @@ -56,22 +55,31 @@ interface Definition extends } /** - * Grouping of all the storage account definition stages. + * Grouping of all the service principal definition stages. */ interface DefinitionStages { /** - * The first stage of the storage account definition. + * The first stage of the service principal definition. */ interface Blank extends WithCreate { } + /** + * The stage of service principal definition allowing specifying if the service principal account is enabled. + */ interface WithAccountEnabled { + /** + * Specifies whether the service principal account is enabled upon creation. + * + * @param enabled if set to true, the service principal account is enabled. + * @return the next stage in service principal definition + */ WithCreate withAccountEnabled(boolean enabled); } /** - * A storage account definition with sufficient inputs to create a new - * storage account in the cloud, but exposing additional optional inputs to + * A service principal definition with sufficient inputs to create a new + * service principal in the cloud, but exposing additional optional inputs to * specify. */ interface WithCreate extends @@ -81,13 +89,13 @@ interface WithCreate extends } /** - * Grouping of all the storage account update stages. + * Grouping of all the service principal update stages. */ interface UpdateStages { } /** - * The template for a storage account update operation, containing all the settings that can be modified. + * The template for a service principal update operation, containing all the settings that can be modified. */ interface Update { } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java index 1d9c6163ac02..f9c2a80eecd3 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java @@ -16,7 +16,7 @@ import java.io.IOException; /** - * Entry point to tenant management API. + * Entry point to service principal management API. */ public interface ServicePrincipals extends SupportsCreating, diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/User.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/User.java index e277dec590c8..45c0b50bf3f8 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/User.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/User.java @@ -11,7 +11,7 @@ import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; /** - * An immutable client-side representation of an Azure tenant. + * An immutable client-side representation of an Azure AD user. */ public interface User extends Wrapper { @@ -52,7 +52,7 @@ public interface User extends String mailNickname(); /************************************************************** - * Fluent interfaces to provision a StorageAccount + * Fluent interfaces to provision a User **************************************************************/ /** @@ -67,35 +67,79 @@ interface Definition extends } /** - * Grouping of all the storage account definition stages. + * Grouping of all the user definition stages. */ interface DefinitionStages { /** - * The first stage of the storage account definition. + * The first stage of the user definition. */ interface Blank extends WithDisplayName { } + /** + * The stage of a user definition allowing display name to be set. + */ interface WithDisplayName { + /** + * Specifies the display name of the user. + * + * @param displayName the human-readable display name + * @return the next stage of a user definition + */ WithPassword withDisplayName(String displayName); } + /** + * The stage of a user definition allowing password to be set. + */ interface WithPassword { + /** + * Specifies the password for the user. + * + * @param password the password + * @return the next stage for a user definition + */ WithMailNickname withPassword(String password); + + /** + * Specifies the temporary password for the user. + * + * @param password the temporary password + * @param forceChangePasswordNextLogin if set to true, the user will have to change the password next time + * @return the next stage for a user definition + */ WithMailNickname withPassword(String password, boolean forceChangePasswordNextLogin); } + /** + * The stage of a user definition allowing mail nickname to be specified. + */ interface WithMailNickname { + /** + * Specifies the mail nickname for the user. + * + * @param mailNickname the mail nickname + * @return the next stage for a user definition + */ WithCreate withMailNickname(String mailNickname); } + /** + * The stage of a user definition allowing specifying if the account is enabled. + */ interface WithAccountEnabled { + /** + * Specifies if the user account is enabled upon creation. + * + * @param enabled if set to true, the user account is enabled + * @return the next stage for a user definition + */ WithCreate withAccountEnabled(boolean enabled); } /** - * A storage account definition with sufficient inputs to create a new - * storage account in the cloud, but exposing additional optional inputs to + * An AD user definition with sufficient inputs to create a new + * user in the cloud, but exposing additional optional inputs to * specify. */ interface WithCreate extends @@ -105,13 +149,13 @@ interface WithCreate extends } /** - * Grouping of all the storage account update stages. + * Grouping of all the user update stages. */ interface UpdateStages { } /** - * The template for a storage account update operation, containing all the settings that can be modified. + * The template for a user update operation, containing all the settings that can be modified. */ interface Update { } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java index 2a50b619ee29..bce73bb9aaed 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java @@ -16,7 +16,7 @@ import java.io.IOException; /** - * Entry point to tenant management API. + * Entry point to AD user management API. */ public interface Users extends SupportsCreating, diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManager.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManager.java index c6585a9e3c63..570cf9456c41 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManager.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManager.java @@ -28,6 +28,7 @@ public final class GraphRbacManager { * Creates an instance of GraphRbacManager that exposes resource management API entry points. * * @param credentials the credentials to use + * @param tenantId the tenantId in Active Directory * @return the GraphRbacManager instance */ public static GraphRbacManager authenticate(ServiceClientCredentials credentials, String tenantId) { @@ -42,6 +43,7 @@ public static GraphRbacManager authenticate(ServiceClientCredentials credentials * Creates an instance of GraphRbacManager that exposes resource management API entry points. * * @param restClient the RestClient to be used for API calls + * @param tenantId the tenantId in Active Directory * @return the interface exposing resource management API entry points that work across subscriptions */ public static GraphRbacManager authenticate(RestClient restClient, String tenantId) { @@ -65,6 +67,7 @@ public interface Configurable extends AzureConfigurable { * Creates an instance of GraphRbacManager that exposes resource management API entry points. * * @param credentials the credentials to use + * @param tenantId the tenantId in Active Directory * @return the interface exposing resource management API entry points that work across subscriptions */ GraphRbacManager authenticate(ServiceClientCredentials credentials, String tenantId); diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalImpl.java index 7e6393cc57ae..c3d44c2b99f7 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalImpl.java @@ -13,7 +13,7 @@ import java.util.List; /** - * Implementation for StorageAccount and its parent interfaces. + * Implementation for ServicePrincipal and its parent interfaces. */ class ServicePrincipalImpl extends CreatableUpdatableImpl diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java index 98c1ba33ec32..1268109be659 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java @@ -22,7 +22,7 @@ import java.util.List; /** - * The implementation of StorageAccounts and its parent interfaces. + * The implementation of ServicePrincipals and its parent interfaces. */ class ServicePrincipalsImpl extends CreatableWrappersImpl< diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java index fb5e98848cc4..1180a58cac48 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java @@ -12,7 +12,7 @@ import rx.Observable; /** - * Implementation for StorageAccount and its parent interfaces. + * Implementation for User and its parent interfaces. */ class UserImpl extends CreatableUpdatableImpl diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java index 771c1c9dd8df..6f4504497f9f 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java @@ -21,7 +21,7 @@ import java.io.IOException; /** - * The implementation of StorageAccounts and its parent interfaces. + * The implementation of Users and its parent interfaces. */ class UsersImpl extends CreatableWrappersImpl< diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java index 4a97debdf737..6e7b3fa10f4a 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java @@ -49,6 +49,10 @@ public interface AccessPolicy extends * Fluent interfaces to attach an access policy **************************************************************/ + /** + * The entirety of an access policy definition. + * @param the return type of the final {@link Attachable#attach()} + */ interface Definition extends DefinitionStages.Blank, DefinitionStages.WithAttach { @@ -66,12 +70,57 @@ interface DefinitionStages { interface Blank extends WithIdentity { } + /** + * The access policy definition stage allowing the Active Directory identity to be specified. + * @param the return type of the final {@link WithAttach#attach()} + */ interface WithIdentity { + /** + * Specifies the object ID of the Active Directory identity this access policy is for. + * + * @param objectId the object ID of the AD identity + * @return the next stage of access policy definition + */ WithAttach forObjectId(UUID objectId); + + /** + * Specifies the Active Directory user this access policy is for. + * + * @param user the AD user object + * @return the next stage of access policy definition + */ WithAttach forUser(User user); + + /** + * Specifies the Active Directory user this access policy is for. + * + * @param userPrincipalName the user principal name of the AD user + * @return the next stage of access policy definition + */ WithAttach forUser(String userPrincipalName); + + /** + * Specifies the Active Directory group this access policy is for. + * + * @param group the AD group object + * @return the next stage of access policy definition + */ WithAttach forGroup(Group group); + + /** + * Specifies the Active Directory service principal this access policy is for. + * + * @param servicePrincipal the AD service principal object + * @return the next stage of access policy definition + */ WithAttach forServicePrincipal(ServicePrincipal servicePrincipal); + + /** + * Specifies the Active Directory service principal this access policy is for. + * + * @param servicePrincipalName the service principal name of the AD user + * @return the next stage of access policy definition + */ WithAttach forServicePrincipal(String servicePrincipalName); } @@ -80,13 +129,51 @@ interface WithIdentity { * @param the return type of the final {@link WithAttach#attach()} */ interface WithPermissions { + /** + * Allow all permissions for the AD identity to access keys. + * + * @return the next stage of access policy definition + */ WithAttach allowKeyAllPermissions(); + + /** + * Allow a list of permissions for the AD identity to access keys. + * + * @param permissions the list of permissions allowed + * @return the next stage of access policy definition + */ WithAttach allowKeyPermissions(KeyPermissions... permissions); + + /** + * Allow a list of permissions for the AD identity to access keys. + * + * @param permissions the list of permissions allowed + * @return the next stage of access policy definition + */ WithAttach allowKeyPermissions(List permissions); + + /** + * Allow all permissions for the AD identity to access secrets. + * + * @return the next stage of access policy definition + */ WithAttach allowSecretAllPermissions(); + + /** + * Allow a list of permissions for the AD identity to access secrets. + * + * @param permissions the list of permissions allowed + * @return the next stage of access policy definition + */ WithAttach allowSecretPermissions(SecretPermissions... permissions); - WithAttach allowSecretPermissions(List permissions); + /** + * Allow a list of permissions for the AD identity to access secrets. + * + * @param permissions the list of permissions allowed + * @return the next stage of access policy definition + */ + WithAttach allowSecretPermissions(List permissions); } /** The final stage of the access policy definition. @@ -102,13 +189,17 @@ interface WithAttach extends } } + /** + * The entirety of an access policy definition as part of a key vault update. + * @param the return type of the final {@link UpdateDefinitionStages.WithAttach#attach()} + */ interface UpdateDefinition extends UpdateDefinitionStages.Blank, UpdateDefinitionStages.WithAttach { } /** - * Grouping of access policy definition stages applicable as part of a key vault creation. + * Grouping of access policy definition stages applicable as part of a key vault update. */ interface UpdateDefinitionStages { /** @@ -119,12 +210,57 @@ interface UpdateDefinitionStages { interface Blank extends WithIdentity { } + /** + * The access policy definition stage allowing the Active Directory identity to be specified. + * @param the return type of the final {@link WithAttach#attach()} + */ interface WithIdentity { + /** + * Specifies the object ID of the Active Directory identity this access policy is for. + * + * @param objectId the object ID of the AD identity + * @return the next stage of access policy definition + */ WithAttach forObjectId(UUID objectId); + + /** + * Specifies the Active Directory user this access policy is for. + * + * @param user the AD user object + * @return the next stage of access policy definition + */ WithAttach forUser(User user); + + /** + * Specifies the Active Directory user this access policy is for. + * + * @param userPrincipalName the user principal name of the AD user + * @return the next stage of access policy definition + */ WithAttach forUser(String userPrincipalName); + + /** + * Specifies the Active Directory group this access policy is for. + * + * @param group the AD group object + * @return the next stage of access policy definition + */ WithAttach forGroup(Group group); + + /** + * Specifies the Active Directory service principal this access policy is for. + * + * @param servicePrincipal the AD service principal object + * @return the next stage of access policy definition + */ WithAttach forServicePrincipal(ServicePrincipal servicePrincipal); + + /** + * Specifies the Active Directory service principal this access policy is for. + * + * @param servicePrincipalName the service principal name of the AD user + * @return the next stage of access policy definition + */ WithAttach forServicePrincipal(String servicePrincipalName); } @@ -133,18 +269,57 @@ interface WithIdentity { * @param the return type of the final {@link WithAttach#attach()} */ interface WithPermissions { + /** + * Allow all permissions for the AD identity to access keys. + * + * @return the next stage of access policy definition + */ WithAttach allowKeyAllPermissions(); + + /** + * Allow a list of permissions for the AD identity to access keys. + * + * @param permissions the list of permissions allowed + * @return the next stage of access policy definition + */ WithAttach allowKeyPermissions(KeyPermissions... permissions); + + /** + * Allow a list of permissions for the AD identity to access keys. + * + * @param permissions the list of permissions allowed + * @return the next stage of access policy definition + */ WithAttach allowKeyPermissions(List permissions); + + /** + * Allow all permissions for the AD identity to access secrets. + * + * @return the next stage of access policy definition + */ WithAttach allowSecretAllPermissions(); + + /** + * Allow a list of permissions for the AD identity to access secrets. + * + * @param permissions the list of permissions allowed + * @return the next stage of access policy definition + */ WithAttach allowSecretPermissions(SecretPermissions... permissions); + + /** + * Allow a list of permissions for the AD identity to access secrets. + * + * @param permissions the list of permissions allowed + * @return the next stage of access policy definition + */ WithAttach allowSecretPermissions(List permissions); } /** The final stage of the access policy definition. *

* At this stage, more permissions can be added or application ID can be specified, - * or the access policy definition can be attached to the parent key vault definition + * or the access policy definition can be attached to the parent key vault update * using {@link WithAttach#attach()}. * @param the return type of {@link WithAttach#attach()} */ @@ -159,31 +334,109 @@ interface WithAttach extends */ interface UpdateStages { /** - * The access policy definition stage allowing permissions to be added. + * The access policy update stage allowing permissions to be added or removed. */ interface WithPermissions { + /** + * Allow all permissions for the AD identity to access keys. + * + * @return the next stage of access policy update + */ Update allowKeyAllPermissions(); + + /** + * Allow a list of permissions for the AD identity to access keys. + * + * @param permissions the list of permissions allowed + * @return the next stage of access policy update + */ Update allowKeyPermissions(KeyPermissions... permissions); + + /** + * Allow a list of permissions for the AD identity to access keys. + * + * @param permissions the list of permissions allowed + * @return the next stage of access policy update + */ Update allowKeyPermissions(List permissions); + + /** + * Revoke all permissions for the AD identity to access keys. + * + * @return the next stage of access policy update + */ Update disallowKeyAllPermissions(); + + /** + * Revoke a list of permissions for the AD identity to access keys. + * + * @param permissions the list of permissions to revoke + * @return the next stage of access policy update + */ Update disallowKeyPermissions(KeyPermissions... permissions); + + /** + * Revoke a list of permissions for the AD identity to access keys. + * + * @param permissions the list of permissions to revoke + * @return the next stage of access policy update + */ Update disallowKeyPermissions(List permissions); + + /** + * Allow all permissions for the AD identity to access secrets. + * + * @return the next stage of access policy definition + */ Update allowSecretAllPermissions(); + + /** + * Allow a list of permissions for the AD identity to access secrets. + * + * @param permissions the list of permissions allowed + * @return the next stage of access policy definition + */ Update allowSecretPermissions(SecretPermissions... permissions); + + /** + * Allow a list of permissions for the AD identity to access secrets. + * + * @param permissions the list of permissions allowed + * @return the next stage of access policy definition + */ Update allowSecretPermissions(List permissions); + + /** + * Revoke all permissions for the AD identity to access secrets. + * + * @return the next stage of access policy update + */ Update disallowSecretAllPermissions(); + + /** + * Revoke a list of permissions for the AD identity to access secrets. + * + * @param permissions the list of permissions to revoke + * @return the next stage of access policy update + */ Update disallowSecretPermissions(SecretPermissions... permissions); - Update disallowSecretPermissions(List permissions); + /** + * Revoke a list of permissions for the AD identity to access secrets. + * + * @param permissions the list of permissions to revoke + * @return the next stage of access policy update + */ + Update disallowSecretPermissions(List permissions); } } /** - * The template for a key vault update operation, containing all the settings that can be modified. + * The entirety of an access policy update as part of a key vault update. */ interface Update extends UpdateStages.WithPermissions, - Settable{ + Settable { } } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java index 15008400b434..064fa02342fb 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java @@ -108,18 +108,77 @@ interface WithSku { WithCreate withSku(SkuName skuName); } + /** + * A key vault definition allowing access policies to be attached. + */ interface WithAccessPolicy { + /** + * Attach no access policy. + * + * @return the next stage of key vault definition + */ WithCreate withEmptyAccessPolicy(); + + /** + * Attach an existing access policy. + * + * @param accessPolicy the existing access policy + * @return the next stage of key vault definition + */ WithCreate withAccessPolicy(AccessPolicy accessPolicy); + + /** + * Begins the definition of a new access policy to be added to this key vault. + * + * @return the first stage of the access policy definition + */ AccessPolicy.DefinitionStages.Blank defineAccessPolicy(); } + /** + * A key vault definition allowing various configurations to be set. + */ interface WithConfigurations { + /** + * Enable Azure Virtual Machines to retrieve certificates stored as secrets from the key vault. + * + * @return the next stage of key vault definition + */ WithCreate enableDeployment(); + + /** + * Enable Azure Disk Encryption to retrieve secrets from the vault and unwrap keys. + * + * @return the next stage of key vault definition + */ WithCreate enableDiskEncryption(); + + /** + * Enable Azure Resource Manager to retrieve secrets from the key vault. + * + * @return the next stage of key vault definition + */ WithCreate enableTemplateDeployment(); + + /** + * Disable Azure Virtual Machines to retrieve certificates stored as secrets from the key vault. + * + * @return the next stage of key vault definition + */ WithCreate disableDeployment(); + + /** + * Disable Azure Disk Encryption to retrieve secrets from the vault and unwrap keys. + * + * @return the next stage of key vault definition + */ WithCreate disableDiskEncryption(); + + /** + * Disable Azure Resource Manager to retrieve secrets from the key vault. + * + * @return the next stage of key vault definition + */ WithCreate disableTemplateDeployment(); } @@ -141,19 +200,86 @@ interface WithCreate extends * Grouping of all the key vault update stages. */ interface UpdateStages { + /** + * A key vault update allowing access policies to be modified, attached, or removed. + */ interface WithAccessPolicy { + /** + * Remove an access policy from the access policy list. + * + * @param objectId the object ID of the Active Directory identity the access policy is for + * @return the key vault update stage + */ Update withoutAccessPolicy(String objectId); + + /** + * Attach an existing access policy. + * + * @param accessPolicy the existing access policy + * @return the key vault update stage + */ Update withAccessPolicy(AccessPolicy accessPolicy); + + /** + * Begins the definition of a new access policy to be added to this key vault. + * + * @return the first stage of the access policy definition + */ AccessPolicy.UpdateDefinitionStages.Blank defineAccessPolicy(); + + /** + * Begins the update of an existing access policy attached to this key vault. + * + * @param objectId the object ID of the Active Directory identity the access policy is for + * @return the update stage of the access policy definition + */ AccessPolicy.Update updateAccessPolicy(String objectId); } + /** + * A key vault update allowing various configurations to be set. + */ interface WithConfigurations { + /** + * Enable Azure Virtual Machines to retrieve certificates stored as secrets from the key vault. + * + * @return the key vault update stage + */ Update enableDeployment(); + + /** + * Enable Azure Disk Encryption to retrieve secrets from the vault and unwrap keys. + * + * @return the key vault update stage + */ Update enableDiskEncryption(); + + /** + * Enable Azure Resource Manager to retrieve secrets from the key vault. + * + * @return the key vault update stage + */ Update enableTemplateDeployment(); + + /** + * Disable Azure Virtual Machines to retrieve certificates stored as secrets from the key vault. + * + * @return the key vault update stage + */ Update disableDeployment(); + + /** + * Disable Azure Disk Encryption to retrieve secrets from the vault and unwrap keys. + * + * @return the next stage of key vault definition + */ Update disableDiskEncryption(); + + /** + * Disable Azure Resource Manager to retrieve secrets from the key vault. + * + * @return the key vault update stage + */ Update disableTemplateDeployment(); } } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vaults.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vaults.java index 6c47f5ed4d75..adb45ae99086 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vaults.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vaults.java @@ -15,7 +15,7 @@ import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; /** - * Entry point for storage accounts management API. + * Entry point for key vaults management API. */ public interface Vaults extends SupportsListing, diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java index 6f0c8bd066c6..a7aec7d59ced 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java @@ -23,7 +23,7 @@ import java.util.UUID; /** - * Implementation for StorageAccount and its parent interfaces. + * Implementation for AccessPolicy and its parent interfaces. */ class AccessPolicyImpl extends ChildResourceImpl< @@ -34,14 +34,22 @@ class AccessPolicyImpl AccessPolicy.Definition, AccessPolicy.UpdateDefinition, AccessPolicy.Update { - String userPrincipalName; - String servicePrincipalName; + private String userPrincipalName; + private String servicePrincipalName; AccessPolicyImpl(AccessPolicyEntry innerObject, VaultImpl parent) { super(innerObject, parent); inner().withTenantId(UUID.fromString(parent.tenantId())); } + String userPrincipalName() { + return userPrincipalName; + } + + String servicePrincipalName() { + return servicePrincipalName; + } + @Override public String tenantId() { if (inner().tenantId() == null) { diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java index bb7fff07f318..dae28691009e 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java @@ -29,7 +29,7 @@ import java.util.UUID; /** - * Implementation for StorageAccount and its parent interfaces. + * Implementation for Vault and its parent interfaces. */ class VaultImpl extends GroupableResourceImpl< @@ -123,7 +123,7 @@ public VaultImpl withEmptyAccessPolicy() { @Override public VaultImpl withoutAccessPolicy(String objectId) { for (AccessPolicyImpl entry : this.accessPolicies) { - if (entry.objectId().toString().equals(objectId)) { + if (entry.objectId().equals(objectId)) { accessPolicies.remove(entry); break; } @@ -145,7 +145,7 @@ public AccessPolicyImpl defineAccessPolicy() { @Override public AccessPolicyImpl updateAccessPolicy(String objectId) { for (AccessPolicyImpl entry : this.accessPolicies) { - if (entry.objectId().toString().equals(objectId)) { + if (entry.objectId().equals(objectId)) { return entry; } } @@ -201,8 +201,8 @@ private Observable> populateAccessPolicies() { List>observables = new ArrayList<>(); for (final AccessPolicyImpl accessPolicy : accessPolicies) { if (accessPolicy.objectId() == null) { - if (accessPolicy.userPrincipalName != null) { - observables.add(graphRbacManager.users().getByUserPrincipalNameAsync(accessPolicy.userPrincipalName) + if (accessPolicy.userPrincipalName() != null) { + observables.add(graphRbacManager.users().getByUserPrincipalNameAsync(accessPolicy.userPrincipalName()) .subscribeOn(Schedulers.io()) .doOnNext(new Action1() { @Override @@ -210,8 +210,8 @@ public void call(User user) { accessPolicy.forObjectId(UUID.fromString(user.objectId())); } })); - } else if (accessPolicy.servicePrincipalName != null) { - observables.add(graphRbacManager.servicePrincipals().getByServicePrincipalNameAsync(accessPolicy.servicePrincipalName) + } else if (accessPolicy.servicePrincipalName() != null) { + observables.add(graphRbacManager.servicePrincipals().getByServicePrincipalNameAsync(accessPolicy.servicePrincipalName()) .subscribeOn(Schedulers.io()) .doOnNext(new Action1() { @Override diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java index a0c69f4c1e76..be66f6aa2336 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java @@ -21,7 +21,7 @@ import java.util.UUID; /** - * The implementation of StorageAccounts and its parent interfaces. + * The implementation of Vaults and its parent interfaces. */ class VaultsImpl extends GroupableResourcesImpl< diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/LoadBalancerImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/LoadBalancerImpl.java index 108c9d94a7a2..e47cce47525f 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/LoadBalancerImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/LoadBalancerImpl.java @@ -20,9 +20,9 @@ import com.microsoft.azure.management.network.ProbeProtocol; import com.microsoft.azure.management.network.PublicIpAddress; import com.microsoft.azure.management.network.PublicIpAddress.DefinitionStages.WithGroup; -import com.microsoft.azure.management.network.model.HasNetworkInterfaces; import com.microsoft.azure.management.network.TcpProbe; import com.microsoft.azure.management.network.TransportProtocol; +import com.microsoft.azure.management.network.model.HasNetworkInterfaces; import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableParentResourceImpl; import com.microsoft.azure.management.resources.fluentcore.model.Creatable; diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsListing.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsListing.java index b0bcc8251ab3..bb9156b0bd92 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsListing.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsListing.java @@ -6,7 +6,6 @@ package com.microsoft.azure.management.resources.fluentcore.collection; -import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; import com.microsoft.rest.RestException; @@ -24,7 +23,7 @@ public interface SupportsListing { * Lists all the resources of the specified type in the currently selected subscription. * * @return list of resources - * @throws CloudException exceptions thrown from the cloud. + * @throws RestException exceptions thrown from the cloud. * @throws IOException exceptions thrown from serialization/deserialization. */ PagedList list() throws RestException, IOException; diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/keyvault/samples/ManageKeyVault.java b/azure-samples/src/main/java/com/microsoft/azure/management/keyvault/samples/ManageKeyVault.java index ab7265bba2b7..c0080f010da1 100644 --- a/azure-samples/src/main/java/com/microsoft/azure/management/keyvault/samples/ManageKeyVault.java +++ b/azure-samples/src/main/java/com/microsoft/azure/management/keyvault/samples/ManageKeyVault.java @@ -30,7 +30,7 @@ * - List key vaults * - Delete a key vault. */ -public class ManageKeyVault { +public final class ManageKeyVault { /** * Main entry point. diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/keyvault/samples/package-info.java b/azure-samples/src/main/java/com/microsoft/azure/management/keyvault/samples/package-info.java new file mode 100644 index 000000000000..21b27292f58a --- /dev/null +++ b/azure-samples/src/main/java/com/microsoft/azure/management/keyvault/samples/package-info.java @@ -0,0 +1,8 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. + +/** + * This package contains the classes for key vault samples. + */ +package com.microsoft.azure.management.keyvault.samples; diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/samples/Utils.java b/azure-samples/src/main/java/com/microsoft/azure/management/samples/Utils.java index ed24e1f9a4ca..191bfd0611ff 100644 --- a/azure-samples/src/main/java/com/microsoft/azure/management/samples/Utils.java +++ b/azure-samples/src/main/java/com/microsoft/azure/management/samples/Utils.java @@ -274,6 +274,10 @@ public static void print(PublicIpAddress resource) { .toString()); } + /** + * Print a key vault. + * @param vault the key vault resource + */ public static void print(Vault vault) { StringBuilder info = new StringBuilder().append("Key Vault: ").append(vault.id()) .append("Name: ").append(vault.name()) @@ -282,8 +286,7 @@ public static void print(Vault vault) { .append("\n\tSku: ").append(vault.sku().name()).append(" - ").append(vault.sku().family()) .append("\n\tVault URI: ").append(vault.vaultUri()) .append("\n\tAccess policies: "); - for (AccessPolicy accessPolicy: - vault.accessPolicies()) { + for (AccessPolicy accessPolicy: vault.accessPolicies()) { info.append("\n\t\tIdentity:").append(accessPolicy.objectId()) .append("\n\t\tKey permissions: ").append(Joiner.on(", ").join(accessPolicy.permissions().keys())) .append("\n\t\tSecret permissions: ").append(Joiner.on(", ").join(accessPolicy.permissions().secrets())); diff --git a/azure/src/main/java/com/microsoft/azure/Azure.java b/azure/src/main/java/com/microsoft/azure/Azure.java index 5499e0fe086f..7a3580e1dad2 100644 --- a/azure/src/main/java/com/microsoft/azure/Azure.java +++ b/azure/src/main/java/com/microsoft/azure/Azure.java @@ -55,6 +55,7 @@ public final class Azure { * Authenticate to Azure using a credentials object. * * @param credentials the credentials object + * @param tenantId the tenantId in Active Directory * @return the authenticated Azure client */ public static Authenticated authenticate(ServiceClientCredentials credentials, String tenantId) { @@ -103,6 +104,7 @@ public static Authenticated authenticate(File credentialsFile) throws IOExceptio /** * Authenticates API access using a {@link RestClient} instance. * @param restClient the {@link RestClient} configured with Azure authentication credentials + * @param tenantId the tenantId in Active Directory * @return authenticated Azure client */ public static Authenticated authenticate(RestClient restClient, String tenantId) { @@ -128,10 +130,17 @@ public interface Configurable extends AzureConfigurable { * Authenticates API access based on the provided credentials. * * @param credentials The credentials to authenticate API access with + * @param tenantId the tenantId in Active Directory * @return the authenticated Azure client */ Authenticated authenticate(ServiceClientCredentials credentials, String tenantId); + /** + * Authenticates API access based on the provided credentials. + * + * @param credentials The credentials to authenticate API access with + * @return the authenticated Azure client + */ Authenticated authenticate(AzureTokenCredentials credentials); /** @@ -387,6 +396,9 @@ public NetworkInterfaces networkInterfaces() { return this.networkManager.networkInterfaces(); } + /** + * @return entry point to managing key vaults + */ public Vaults vaults() { return this.keyVaultManager.vaults(); } diff --git a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java index cce24b097252..421bc2869d0f 100644 --- a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java +++ b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java @@ -103,8 +103,6 @@ public String getBaseUrl() { } /** - * Gets a builder for {@link RestClient}. - * * @return a builder for the rest client. */ public RestClient.Builder.Buildable newRestClientBuilder() { @@ -114,8 +112,6 @@ public RestClient.Builder.Buildable newRestClientBuilder() { } /** - * Gets the ActiveDirectory Endpoint for the Azure Environment. - * * @return the ActiveDirectory Endpoint for the Azure Environment. */ public String getAuthenticationEndpoint() { @@ -123,14 +119,15 @@ public String getAuthenticationEndpoint() { } /** - * Gets the token audience for an endpoint. - * - * @return the token audience for an endpoint. + * @return the Azure Resource Manager endpoint for the environment. */ public String getManagementEndpoint() { return managementEndpoint; } + /** + * @return the Graph API endpoint. + */ public String getGraphEndpoint() { return graphEndpoint; } diff --git a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/credentials/AzureTokenCredentials.java b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/credentials/AzureTokenCredentials.java index 52c5e89ab529..d91962e79855 100644 --- a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/credentials/AzureTokenCredentials.java +++ b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/credentials/AzureTokenCredentials.java @@ -13,12 +13,24 @@ import java.io.IOException; /** - * AzureServiceClientCredentials is the abstraction for credentials used by - * ServiceClients accessing Azure. + * AzureTokenCredentials represents a credentials object with access to Azure + * Resource management. */ public interface AzureTokenCredentials extends ServiceClientCredentials { + /** + * Override this method to provide the mechanism to get a token. + * + * @param resource the resource the access token is for + * @return the token to access the resource + * @throws IOException exceptions from IO + */ String getToken(String resource) throws IOException; + /** + * Override this method to provide the domain or tenant ID the token is valid in. + * + * @return the domain or tenant ID string + */ String getDomain(); /** diff --git a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/credentials/package-info.java b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/credentials/package-info.java new file mode 100644 index 000000000000..22ff7d1a5d6e --- /dev/null +++ b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/credentials/package-info.java @@ -0,0 +1,6 @@ +/** + * The package contains the credentials classes required for AutoRest generated + * Azure clients to compile and function. To learn more about AutoRest generator, + * see https://github.com/azure/autorest. + */ +package com.microsoft.azure.credentials; \ No newline at end of file From 93be0f4fffdec5683c4a06a5dcc0866ace12432d Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Mon, 12 Sep 2016 18:58:15 -0700 Subject: [PATCH 31/33] Fix merge errors --- .../VirtualMachineImagesImpl.java | 23 +++------ .../VirtualMachineOffersImpl.java | 2 +- .../azure/management/redis/SkuFamily.java | 24 ++++++--- .../main/java/com/microsoft/azure/Azure.java | 7 +-- .../microsoft/azure/ParallelServiceCall.java | 50 ------------------- 5 files changed, 26 insertions(+), 80 deletions(-) delete mode 100644 runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/ParallelServiceCall.java diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImagesImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImagesImpl.java index 715b064acb6f..e23dcf587991 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImagesImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImagesImpl.java @@ -2,13 +2,14 @@ import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.compute.VirtualMachineImage; +import com.microsoft.azure.management.compute.VirtualMachineImages; import com.microsoft.azure.management.compute.VirtualMachineOffer; import com.microsoft.azure.management.compute.VirtualMachinePublisher; import com.microsoft.azure.management.compute.VirtualMachinePublishers; -import com.microsoft.azure.management.compute.VirtualMachineImage; -import com.microsoft.azure.management.compute.VirtualMachineImages; import com.microsoft.azure.management.compute.VirtualMachineSku; import com.microsoft.azure.management.resources.fluentcore.arm.Region; + import java.io.IOException; /** @@ -35,11 +36,7 @@ public PagedList listByRegion(String regionName) throws Clo new ChildListFlattener<>(publishers, new ChildListFlattener.ChildListLoader() { @Override public PagedList loadList(VirtualMachinePublisher publisher) throws CloudException, IOException { - try { - return publisher.offers().list(); - } catch (com.microsoft.rest.RestException e) { - e.printStackTrace(); - } + return publisher.offers().list(); } }).flatten(); @@ -47,11 +44,7 @@ public PagedList loadList(VirtualMachinePublisher publisher new ChildListFlattener<>(offers, new ChildListFlattener.ChildListLoader() { @Override public PagedList loadList(VirtualMachineOffer offer) throws CloudException, IOException { - try { - return offer.skus().list(); - } catch (com.microsoft.rest.RestException e) { - e.printStackTrace(); - } + return offer.skus().list(); } }).flatten(); @@ -59,11 +52,7 @@ public PagedList loadList(VirtualMachineOffer offer) throws C new ChildListFlattener<>(skus, new ChildListFlattener.ChildListLoader() { @Override public PagedList loadList(VirtualMachineSku sku) throws CloudException, IOException { - try { - return sku.images().list(); - } catch (com.microsoft.rest.RestException e) { - e.printStackTrace(); - } + return sku.images().list(); } }).flatten(); diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineOffersImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineOffersImpl.java index 681cc4544f7e..25342bcf2b40 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineOffersImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineOffersImpl.java @@ -35,7 +35,7 @@ protected VirtualMachineOfferImpl wrapModel(VirtualMachineImageResourceInner inn } @Override - public PagedList list() throws RestException, IllegalArgumentException, IOException { + public PagedList list() throws CloudException, IllegalArgumentException, IOException { return wrapList(innerCollection.listOffers(publisher.region().toString(), publisher.name())); } } diff --git a/azure-mgmt-redis/src/main/java/com/microsoft/azure/management/redis/SkuFamily.java b/azure-mgmt-redis/src/main/java/com/microsoft/azure/management/redis/SkuFamily.java index 5d1c4cf82083..0c37984ddee5 100644 --- a/azure-mgmt-redis/src/main/java/com/microsoft/azure/management/redis/SkuFamily.java +++ b/azure-mgmt-redis/src/main/java/com/microsoft/azure/management/redis/SkuFamily.java @@ -8,11 +8,12 @@ package com.microsoft.azure.management.redis; +import com.fasterxml.jackson.annotation.JsonValue; + /** * Defines values for SkuFamily. */ public final class SkuFamily { -<<<<<<< 1d9c0c339ddb625c8c18b60f5f1f76db20d3729c:azure-mgmt-redis/src/main/java/com/microsoft/azure/management/redis/SkuFamily.java /** Static value C for SkuFamily. */ public static final SkuFamily C = new SkuFamily("C"); @@ -39,11 +40,20 @@ public String toString() { public int hashCode() { return value.hashCode(); } -======= - /** Static value A for SkuFamily. */ - public static final String A = "A"; ->>>>>>> Basic impl for vault:azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SkuFamily.java - private SkuFamily() { + @Override + public boolean equals(Object obj) { + if (!(obj instanceof SkuFamily)) { + return false; + } + if (obj == this) { + return true; + } + SkuFamily rhs = (SkuFamily) obj; + if (value == null) { + return rhs.value == null; + } else { + return value.equals(rhs.value); + } } -} +} \ No newline at end of file diff --git a/azure/src/main/java/com/microsoft/azure/Azure.java b/azure/src/main/java/com/microsoft/azure/Azure.java index 7a3580e1dad2..b926f4da8fd8 100644 --- a/azure/src/main/java/com/microsoft/azure/Azure.java +++ b/azure/src/main/java/com/microsoft/azure/Azure.java @@ -30,8 +30,8 @@ import com.microsoft.azure.management.resources.Tenants; import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; -import com.microsoft.azure.management.resources.implementation.ResourceManager; import com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl; +import com.microsoft.azure.management.resources.implementation.ResourceManager; import com.microsoft.azure.management.storage.StorageAccounts; import com.microsoft.azure.management.storage.Usages; import com.microsoft.azure.management.storage.implementation.StorageManager; @@ -260,10 +260,7 @@ public Azure withDefaultSubscription() throws CloudException, IOException { if (this.defaultSubscription != null) { return withSubscription(this.defaultSubscription); } else { - try {PagedList subs = this.subscriptions().list(); - } catch (com.microsoft.rest.RestException e) { - e.printStackTrace(); - } + PagedList subs = this.subscriptions().list(); if (!subs.isEmpty()) { return withSubscription(subs.get(0).subscriptionId()); } else { diff --git a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/ParallelServiceCall.java b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/ParallelServiceCall.java deleted file mode 100644 index 316384152031..000000000000 --- a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/ParallelServiceCall.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.microsoft.azure; - -import com.microsoft.rest.ServiceCall; - -import java.util.concurrent.ConcurrentLinkedQueue; - -/** - * Type represents a set of REST calls running possibly in parallel. - */ -public class ParallelServiceCall extends ServiceCall { - private ConcurrentLinkedQueue> serviceCalls; - - /** - * Creates a ParallelServiceCall. - */ - public ParallelServiceCall() { - super(null); - this.serviceCalls = new ConcurrentLinkedQueue<>(); - } - - /** - * Cancels all the service calls currently executing. - */ - public void cancel() { - for (ServiceCall call : this.serviceCalls) { - call.cancel(); - } - } - - /** - * @return true if the call has been canceled; false otherwise. - */ - public boolean isCancelled() { - for (ServiceCall call : this.serviceCalls) { - if (!call.isCanceled()) { - return false; - } - } - return true; - } - - /** - * Add a call to the list of parallel calls. - * - * @param call the call - */ - public void addCall(ServiceCall call) { - this.serviceCalls.add(call); - } -} From dd319273a1d901cca7fa4b569b6eb2eb0eaf9244 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Tue, 13 Sep 2016 10:09:58 -0700 Subject: [PATCH 32/33] Address cr feedback in key vault --- .../azure/management/keyvault/Vault.java | 42 +++++++++---------- .../keyvault/implementation/VaultImpl.java | 30 ++++++------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java index 064fa02342fb..eafee197a260 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java @@ -25,12 +25,12 @@ public interface Vault extends Updatable, Wrapper { /** - * @return The URI of the vault for performing operations on keys and secrets. + * @return the URI of the vault for performing operations on keys and secrets. */ String vaultUri(); /** - * @return The Azure Active Directory tenant ID that should be used for + * @return the Azure Active Directory tenant ID that should be used for * authenticating requests to the key vault. */ String tenantId(); @@ -41,29 +41,29 @@ public interface Vault extends Sku sku(); /** - * @return An array of 0 to 16 identities that have access to the key vault. All + * @return an array of 0 to 16 identities that have access to the key vault. All * identities in the array must use the same tenant ID as the key vault's * tenant ID. */ List accessPolicies(); /** - * @return Property to specify whether Azure Virtual Machines are permitted to + * @return whether Azure Virtual Machines are permitted to * retrieve certificates stored as secrets from the key vault. */ - Boolean enabledForDeployment(); + boolean enabledForDeployment(); /** - * @return Property to specify whether Azure Disk Encryption is permitted to + * @return whether Azure Disk Encryption is permitted to * retrieve secrets from the vault and unwrap keys. */ - Boolean enabledForDiskEncryption(); + boolean enabledForDiskEncryption(); /** - * @return Property to specify whether Azure Resource Manager is permitted to + * @return whether Azure Resource Manager is permitted to * retrieve secrets from the key vault. */ - Boolean enabledForTemplateDeployment(); + boolean enabledForTemplateDeployment(); /************************************************************** * Fluent interfaces to provision a Vault @@ -144,42 +144,42 @@ interface WithConfigurations { * * @return the next stage of key vault definition */ - WithCreate enableDeployment(); + WithCreate withDeploymentEnabled(); /** * Enable Azure Disk Encryption to retrieve secrets from the vault and unwrap keys. * * @return the next stage of key vault definition */ - WithCreate enableDiskEncryption(); + WithCreate withDiskEncryptionEnabled(); /** * Enable Azure Resource Manager to retrieve secrets from the key vault. * * @return the next stage of key vault definition */ - WithCreate enableTemplateDeployment(); + WithCreate withTemplateDeploymentEnabled(); /** * Disable Azure Virtual Machines to retrieve certificates stored as secrets from the key vault. * * @return the next stage of key vault definition */ - WithCreate disableDeployment(); + WithCreate withDeploymentDisabled(); /** * Disable Azure Disk Encryption to retrieve secrets from the vault and unwrap keys. * * @return the next stage of key vault definition */ - WithCreate disableDiskEncryption(); + WithCreate withDiskEncryptionDisabled(); /** * Disable Azure Resource Manager to retrieve secrets from the key vault. * * @return the next stage of key vault definition */ - WithCreate disableTemplateDeployment(); + WithCreate withTemplateDeploymentDisabled(); } /** @@ -245,42 +245,42 @@ interface WithConfigurations { * * @return the key vault update stage */ - Update enableDeployment(); + Update withDeploymentEnabled(); /** * Enable Azure Disk Encryption to retrieve secrets from the vault and unwrap keys. * * @return the key vault update stage */ - Update enableDiskEncryption(); + Update withDiskEncryptionEnabled(); /** * Enable Azure Resource Manager to retrieve secrets from the key vault. * * @return the key vault update stage */ - Update enableTemplateDeployment(); + Update withTemplateDeploymentEnabled(); /** * Disable Azure Virtual Machines to retrieve certificates stored as secrets from the key vault. * * @return the key vault update stage */ - Update disableDeployment(); + Update withDeploymentDisabled(); /** * Disable Azure Disk Encryption to retrieve secrets from the vault and unwrap keys. * * @return the next stage of key vault definition */ - Update disableDiskEncryption(); + Update withDiskEncryptionDisabled(); /** * Disable Azure Resource Manager to retrieve secrets from the key vault. * * @return the key vault update stage */ - Update disableTemplateDeployment(); + Update withTemplateDeploymentDisabled(); } } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java index dae28691009e..bfb4d8b76283 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java @@ -91,25 +91,25 @@ public List accessPolicies() { } @Override - public Boolean enabledForDeployment() { - if (inner().properties() == null) { - return null; + public boolean enabledForDeployment() { + if (inner().properties() == null || inner().properties().enabledForDeployment() == null) { + return false; } return inner().properties().enabledForDeployment(); } @Override - public Boolean enabledForDiskEncryption() { - if (inner().properties() == null) { - return null; + public boolean enabledForDiskEncryption() { + if (inner().properties() == null || inner().properties().enabledForDiskEncryption() == null) { + return false; } return inner().properties().enabledForDiskEncryption(); } @Override - public Boolean enabledForTemplateDeployment() { - if (inner().properties() == null) { - return null; + public boolean enabledForTemplateDeployment() { + if (inner().properties() == null || inner().properties().enabledForTemplateDeployment()) { + return false; } return inner().properties().enabledForTemplateDeployment(); } @@ -153,37 +153,37 @@ public AccessPolicyImpl updateAccessPolicy(String objectId) { } @Override - public VaultImpl enableDeployment() { + public VaultImpl withDeploymentEnabled() { inner().properties().withEnabledForDeployment(true); return this; } @Override - public VaultImpl enableDiskEncryption() { + public VaultImpl withDiskEncryptionEnabled() { inner().properties().withEnabledForDiskEncryption(true); return this; } @Override - public VaultImpl enableTemplateDeployment() { + public VaultImpl withTemplateDeploymentEnabled() { inner().properties().withEnabledForTemplateDeployment(true); return this; } @Override - public VaultImpl disableDeployment() { + public VaultImpl withDeploymentDisabled() { inner().properties().withEnabledForDeployment(false); return this; } @Override - public VaultImpl disableDiskEncryption() { + public VaultImpl withDiskEncryptionDisabled() { inner().properties().withEnabledForDiskEncryption(false); return this; } @Override - public VaultImpl disableTemplateDeployment() { + public VaultImpl withTemplateDeploymentDisabled() { inner().properties().withEnabledForTemplateDeployment(false); return this; } From dd0e9859c624ef9e51363c76918766d9b2e203fd Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Tue, 13 Sep 2016 11:33:29 -0700 Subject: [PATCH 33/33] Rename Group to ActiveDirectoryGroup --- .../graphrbac/{Group.java => ActiveDirectoryGroup.java} | 4 ++-- .../com/microsoft/azure/management/graphrbac/Groups.java | 8 ++++---- .../microsoft/azure/management/keyvault/AccessPolicy.java | 6 +++--- .../keyvault/implementation/AccessPolicyImpl.java | 4 ++-- .../azure/management/keyvault/samples/ManageKeyVault.java | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) rename azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/{Group.java => ActiveDirectoryGroup.java} (96%) diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Group.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ActiveDirectoryGroup.java similarity index 96% rename from azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Group.java rename to azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ActiveDirectoryGroup.java index 37824e7e4859..c7ec7af4cd3f 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Group.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ActiveDirectoryGroup.java @@ -13,7 +13,7 @@ /** * An immutable client-side representation of an Azure AD group. */ -public interface Group extends +public interface ActiveDirectoryGroup extends Wrapper { /** * @return object Id. @@ -96,7 +96,7 @@ interface WithMailNickname { * specify. */ interface WithCreate extends - Creatable { + Creatable { } } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Groups.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Groups.java index c15ccb826e52..c8844b3e9d0b 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Groups.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Groups.java @@ -18,8 +18,8 @@ * Entry point to AD group management API. */ public interface Groups extends - SupportsCreating, - SupportsListing, + SupportsCreating, + SupportsListing, SupportsDeleting { /** * Gets the information about a group. @@ -29,7 +29,7 @@ public interface Groups extends * @throws CloudException exceptions thrown from the cloud * @throws IOException exceptions thrown from serialization/deserialization */ - Group getByObjectId(String objectId) throws CloudException, IOException; + ActiveDirectoryGroup getByObjectId(String objectId) throws CloudException, IOException; /** * Gets the information about a group. @@ -39,5 +39,5 @@ public interface Groups extends * @throws CloudException exceptions thrown from the cloud * @throws IOException exceptions thrown from serialization/deserialization */ - List searchByDisplayName(String displayNamePrefix) throws CloudException, IOException; + List searchByDisplayName(String displayNamePrefix) throws CloudException, IOException; } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java index 6e7b3fa10f4a..7e09d5331f9f 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java @@ -6,7 +6,7 @@ package com.microsoft.azure.management.keyvault; -import com.microsoft.azure.management.graphrbac.Group; +import com.microsoft.azure.management.graphrbac.ActiveDirectoryGroup; import com.microsoft.azure.management.graphrbac.ServicePrincipal; import com.microsoft.azure.management.graphrbac.User; import com.microsoft.azure.management.resources.fluentcore.arm.models.ChildResource; @@ -105,7 +105,7 @@ interface WithIdentity { * @param group the AD group object * @return the next stage of access policy definition */ - WithAttach forGroup(Group group); + WithAttach forGroup(ActiveDirectoryGroup group); /** * Specifies the Active Directory service principal this access policy is for. @@ -245,7 +245,7 @@ interface WithIdentity { * @param group the AD group object * @return the next stage of access policy definition */ - WithAttach forGroup(Group group); + WithAttach forGroup(ActiveDirectoryGroup group); /** * Specifies the Active Directory service principal this access policy is for. diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java index a7aec7d59ced..62a6397fe7f9 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java @@ -6,7 +6,7 @@ package com.microsoft.azure.management.keyvault.implementation; -import com.microsoft.azure.management.graphrbac.Group; +import com.microsoft.azure.management.graphrbac.ActiveDirectoryGroup; import com.microsoft.azure.management.graphrbac.ServicePrincipal; import com.microsoft.azure.management.graphrbac.User; import com.microsoft.azure.management.keyvault.AccessPolicy; @@ -155,7 +155,7 @@ public AccessPolicyImpl forUser(String userPrincipalName) { } @Override - public AccessPolicyImpl forGroup(Group group) { + public AccessPolicyImpl forGroup(ActiveDirectoryGroup group) { inner().withObjectId(UUID.fromString(group.objectId())); return this; } diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/keyvault/samples/ManageKeyVault.java b/azure-samples/src/main/java/com/microsoft/azure/management/keyvault/samples/ManageKeyVault.java index c0080f010da1..39a2722b3ef3 100644 --- a/azure-samples/src/main/java/com/microsoft/azure/management/keyvault/samples/ManageKeyVault.java +++ b/azure-samples/src/main/java/com/microsoft/azure/management/keyvault/samples/ManageKeyVault.java @@ -97,8 +97,8 @@ public static void main(String[] args) { System.out.println("Update a key vault to enable deployments and add permissions to the application..."); vault1 = vault1.update() - .enableDeployment() - .enableTemplateDeployment() + .withDeploymentEnabled() + .withTemplateDeploymentEnabled() .updateAccessPolicy(vault1.accessPolicies().get(0).objectId()) .allowSecretAllPermissions() .parent()