diff --git a/sdk/azurestack/azure-resourcemanager-azurestack/CHANGELOG.md b/sdk/azurestack/azure-resourcemanager-azurestack/CHANGELOG.md index 241b9efc07830..dfaedcf2f4785 100644 --- a/sdk/azurestack/azure-resourcemanager-azurestack/CHANGELOG.md +++ b/sdk/azurestack/azure-resourcemanager-azurestack/CHANGELOG.md @@ -1,7 +1,8 @@ # Release History -## 1.0.0-beta.2 (Unreleased) +## 1.0.0-beta.1 (2021-06-28) +- Azure Resource Manager AzureStack client library for Java. This package contains Microsoft Azure SDK for AzureStack Management SDK. Azure Stack. Package tag package-preview-2020-06. For documentation on how to use this package, please see [Azure Management Libraries for Java](https://aka.ms/azsdk/java/mgmt). ## 1.0.0-beta.1 (2021-04-12) diff --git a/sdk/azurestack/azure-resourcemanager-azurestack/README.md b/sdk/azurestack/azure-resourcemanager-azurestack/README.md index 81f5985377957..c7388038caea0 100644 --- a/sdk/azurestack/azure-resourcemanager-azurestack/README.md +++ b/sdk/azurestack/azure-resourcemanager-azurestack/README.md @@ -32,7 +32,7 @@ Various documentation is available to help you get started com.azure.resourcemanager azure-resourcemanager-azurestack - 1.0.0-beta.1 + 1.0.0-beta.2 ``` [//]: # ({x-version-update-end}) @@ -74,13 +74,15 @@ See [API design][design] for general introduction on design and key concepts on ## Examples + + ## Troubleshooting ## Next steps ## Contributing -For details on contributing to this repository, see the [contributing guide](https://github.com/Azure/azure-sdk-for-java/blob/main/CONTRIBUTING.md). +For details on contributing to this repository, see the [contributing guide](https://github.com/Azure/azure-sdk-for-java/blob/master/CONTRIBUTING.md). 1. Fork it 1. Create your feature branch (`git checkout -b my-new-feature`) @@ -93,7 +95,7 @@ For details on contributing to this repository, see the [contributing guide](htt [docs]: https://azure.github.io/azure-sdk-for-java/ [jdk]: https://docs.microsoft.com/java/azure/jdk/ [azure_subscription]: https://azure.microsoft.com/free/ -[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/identity/azure-identity -[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/core/azure-core-http-netty -[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/resourcemanager/docs/AUTH.md -[design]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/resourcemanager/docs/DESIGN.md +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/azurestack/azure-resourcemanager-azurestack/pom.xml b/sdk/azurestack/azure-resourcemanager-azurestack/pom.xml index c2422e06c4210..745a7f83c4277 100644 --- a/sdk/azurestack/azure-resourcemanager-azurestack/pom.xml +++ b/sdk/azurestack/azure-resourcemanager-azurestack/pom.xml @@ -1,67 +1,86 @@ - 4.0.0 - - com.azure - azure-client-sdk-parent - 1.7.0 - ../../parents/azure-client-sdk-parent - + 4.0.0 + + com.azure + azure-client-sdk-parent + 1.7.0 + ../../parents/azure-client-sdk-parent + - com.azure.resourcemanager - azure-resourcemanager-azurestack - 1.0.0-beta.2 - jar + com.azure.resourcemanager + azure-resourcemanager-azurestack + 1.0.0-beta.2 + jar - Microsoft Azure SDK for AzureStack Management - This package contains Microsoft Azure SDK for AzureStack Management SDK. For documentation on how to use this package, please see https://aka.ms/azsdk/java/mgmt. Azure Stack. Package tag package-preview-2020-06. - https://github.com/Azure/azure-sdk-for-java + Microsoft Azure SDK for AzureStack Management + This package contains Microsoft Azure SDK for AzureStack Management SDK. For documentation on how to use this package, please see https://aka.ms/azsdk/java/mgmt. Azure Stack. Package tag package-preview-2020-06. + https://github.com/Azure/azure-sdk-for-java - - - The MIT License (MIT) - http://opensource.org/licenses/MIT - repo - - + + + The MIT License (MIT) + http://opensource.org/licenses/MIT + repo + + - - https://github.com/Azure/azure-sdk-for-java - scm:git:git@github.com:Azure/azure-sdk-for-java.git - scm:git:git@github.com:Azure/azure-sdk-for-java.git - HEAD - - - - microsoft - Microsoft - - - - UTF-8 - - - - - com.azure - azure-core - 1.17.0 - - - com.azure - azure-core-management - 1.3.0 - - - - - - org.jacoco - jacoco-maven-plugin - 0.8.5 - - true - - - - + + https://github.com/Azure/azure-sdk-for-java + scm:git:git@github.com:Azure/azure-sdk-for-java.git + scm:git:git@github.com:Azure/azure-sdk-for-java.git + HEAD + + + + microsoft + Microsoft + + + + UTF-8 + + + + + com.azure + azure-core + 1.17.0 + + + com.azure + azure-core-management + 1.3.0 + + + + + + org.jacoco + jacoco-maven-plugin + 0.8.5 + + true + + + + org.revapi + revapi-maven-plugin + 0.11.2 + + + + + java.method.addedToInterface + + + true + .* + com\.azure\.resourcemanager(\.[^.]+)+\.fluent(\.[^.]+)* + + + + + + + diff --git a/sdk/azurestack/azure-resourcemanager-azurestack/src/main/java/com/azure/resourcemanager/azurestack/AzureStackManager.java b/sdk/azurestack/azure-resourcemanager-azurestack/src/main/java/com/azure/resourcemanager/azurestack/AzureStackManager.java index 8b7b19d4825a6..0d372bb0d4728 100644 --- a/sdk/azurestack/azure-resourcemanager-azurestack/src/main/java/com/azure/resourcemanager/azurestack/AzureStackManager.java +++ b/sdk/azurestack/azure-resourcemanager-azurestack/src/main/java/com/azure/resourcemanager/azurestack/AzureStackManager.java @@ -9,7 +9,6 @@ import com.azure.core.http.HttpPipeline; import com.azure.core.http.HttpPipelineBuilder; import com.azure.core.http.policy.AddDatePolicy; -import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.http.policy.HttpLoggingPolicy; import com.azure.core.http.policy.HttpPipelinePolicy; @@ -17,6 +16,7 @@ import com.azure.core.http.policy.RequestIdPolicy; import com.azure.core.http.policy.RetryPolicy; import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.management.http.policy.ArmChallengeAuthenticationPolicy; import com.azure.core.management.profile.AzureProfile; import com.azure.core.util.Configuration; import com.azure.core.util.logging.ClientLogger; @@ -97,6 +97,7 @@ public static final class Configurable { private HttpClient httpClient; private HttpLogOptions httpLogOptions; private final List policies = new ArrayList<>(); + private final List scopes = new ArrayList<>(); private RetryPolicy retryPolicy; private Duration defaultPollInterval; @@ -136,6 +137,17 @@ public Configurable withPolicy(HttpPipelinePolicy policy) { return this; } + /** + * Adds the scope to permission sets. + * + * @param scope the scope. + * @return the configurable object itself. + */ + public Configurable withScope(String scope) { + this.scopes.add(Objects.requireNonNull(scope, "'scope' cannot be null.")); + return this; + } + /** * Sets the retry policy to the HTTP pipeline. * @@ -192,6 +204,9 @@ public AzureStackManager authenticate(TokenCredential credential, AzureProfile p userAgentBuilder.append(" (auto-generated)"); } + if (scopes.isEmpty()) { + scopes.add(profile.getEnvironment().getManagementEndpoint() + "/.default"); + } if (retryPolicy == null) { retryPolicy = new RetryPolicy("Retry-After", ChronoUnit.SECONDS); } @@ -201,10 +216,7 @@ public AzureStackManager authenticate(TokenCredential credential, AzureProfile p HttpPolicyProviders.addBeforeRetryPolicies(policies); policies.add(retryPolicy); policies.add(new AddDatePolicy()); - policies - .add( - new BearerTokenAuthenticationPolicy( - credential, profile.getEnvironment().getManagementEndpoint() + "/.default")); + policies.add(new ArmChallengeAuthenticationPolicy(credential, scopes.toArray(new String[0]))); policies.addAll(this.policies); HttpPolicyProviders.addAfterRetryPolicies(policies); policies.add(new HttpLoggingPolicy(httpLogOptions)); diff --git a/sdk/azurestack/azure-resourcemanager-azurestack/src/main/java/com/azure/resourcemanager/azurestack/fluent/RegistrationsClient.java b/sdk/azurestack/azure-resourcemanager-azurestack/src/main/java/com/azure/resourcemanager/azurestack/fluent/RegistrationsClient.java index 062a41d3d102d..7f444d711da37 100644 --- a/sdk/azurestack/azure-resourcemanager-azurestack/src/main/java/com/azure/resourcemanager/azurestack/fluent/RegistrationsClient.java +++ b/sdk/azurestack/azure-resourcemanager-azurestack/src/main/java/com/azure/resourcemanager/azurestack/fluent/RegistrationsClient.java @@ -40,6 +40,28 @@ public interface RegistrationsClient { @ServiceMethod(returns = ReturnType.COLLECTION) PagedIterable listByResourceGroup(String resourceGroup, Context context); + /** + * Returns a list of all registrations under current subscription. + * + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return pageable list of registrations. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable list(); + + /** + * Returns a list of all registrations under current subscription. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return pageable list of registrations. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable list(Context context); + /** * Returns the properties of an Azure Stack registration. * diff --git a/sdk/azurestack/azure-resourcemanager-azurestack/src/main/java/com/azure/resourcemanager/azurestack/implementation/RegistrationsClientImpl.java b/sdk/azurestack/azure-resourcemanager-azurestack/src/main/java/com/azure/resourcemanager/azurestack/implementation/RegistrationsClientImpl.java index e73366114a722..14ead4f666193 100644 --- a/sdk/azurestack/azure-resourcemanager-azurestack/src/main/java/com/azure/resourcemanager/azurestack/implementation/RegistrationsClientImpl.java +++ b/sdk/azurestack/azure-resourcemanager-azurestack/src/main/java/com/azure/resourcemanager/azurestack/implementation/RegistrationsClientImpl.java @@ -80,6 +80,17 @@ Mono> listByResourceGroup( @HeaderParam("Accept") String accept, Context context); + @Headers({"Content-Type: application/json"}) + @Get("/subscriptions/{subscriptionId}/providers/Microsoft.AzureStack/registrations") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> list( + @HostParam("$host") String endpoint, + @PathParam("subscriptionId") String subscriptionId, + @QueryParam("api-version") String apiVersion, + @HeaderParam("Accept") String accept, + Context context); + @Headers({"Content-Type: application/json"}) @Get( "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.AzureStack" @@ -180,6 +191,16 @@ Mono> listNext( @HostParam("$host") String endpoint, @HeaderParam("Accept") String accept, Context context); + + @Headers({"Content-Type: application/json"}) + @Get("{nextLink}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> listBySubscriptionNext( + @PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("$host") String endpoint, + @HeaderParam("Accept") String accept, + Context context); } /** @@ -342,6 +363,147 @@ public PagedIterable listByResourceGroup(String resourceGroup return new PagedIterable<>(listByResourceGroupAsync(resourceGroup, context)); } + /** + * Returns a list of all registrations under current subscription. + * + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return pageable list of registrations. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listSinglePageAsync() { + if (this.client.getEndpoint() == null) { + return Mono + .error( + new IllegalArgumentException( + "Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono + .error( + new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil + .withContext( + context -> + service + .list( + this.client.getEndpoint(), + this.client.getSubscriptionId(), + this.client.getApiVersion(), + accept, + context)) + .>map( + res -> + new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().value(), + res.getValue().nextLink(), + null)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Returns a list of all registrations under current subscription. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return pageable list of registrations. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listSinglePageAsync(Context context) { + if (this.client.getEndpoint() == null) { + return Mono + .error( + new IllegalArgumentException( + "Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono + .error( + new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service + .list( + this.client.getEndpoint(), + this.client.getSubscriptionId(), + this.client.getApiVersion(), + accept, + context) + .map( + res -> + new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().value(), + res.getValue().nextLink(), + null)); + } + + /** + * Returns a list of all registrations under current subscription. + * + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return pageable list of registrations. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + private PagedFlux listAsync() { + return new PagedFlux<>( + () -> listSinglePageAsync(), nextLink -> listBySubscriptionNextSinglePageAsync(nextLink)); + } + + /** + * Returns a list of all registrations under current subscription. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return pageable list of registrations. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + private PagedFlux listAsync(Context context) { + return new PagedFlux<>( + () -> listSinglePageAsync(context), nextLink -> listBySubscriptionNextSinglePageAsync(nextLink, context)); + } + + /** + * Returns a list of all registrations under current subscription. + * + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return pageable list of registrations. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable list() { + return new PagedIterable<>(listAsync()); + } + + /** + * Returns a list of all registrations under current subscription. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return pageable list of registrations. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable list(Context context) { + return new PagedIterable<>(listAsync(context)); + } + /** * Returns the properties of an Azure Stack registration. * @@ -1322,4 +1484,77 @@ private Mono> listNextSinglePageAsync(String ne res.getValue().nextLink(), null)); } + + /** + * Get the next page of items. + * + * @param nextLink The nextLink parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return pageable list of registrations. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listBySubscriptionNextSinglePageAsync(String nextLink) { + if (nextLink == null) { + return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); + } + if (this.client.getEndpoint() == null) { + return Mono + .error( + new IllegalArgumentException( + "Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil + .withContext( + context -> service.listBySubscriptionNext(nextLink, this.client.getEndpoint(), accept, context)) + .>map( + res -> + new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().value(), + res.getValue().nextLink(), + null)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Get the next page of items. + * + * @param nextLink The nextLink parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return pageable list of registrations. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listBySubscriptionNextSinglePageAsync( + String nextLink, Context context) { + if (nextLink == null) { + return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); + } + if (this.client.getEndpoint() == null) { + return Mono + .error( + new IllegalArgumentException( + "Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service + .listBySubscriptionNext(nextLink, this.client.getEndpoint(), accept, context) + .map( + res -> + new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().value(), + res.getValue().nextLink(), + null)); + } } diff --git a/sdk/azurestack/azure-resourcemanager-azurestack/src/main/java/com/azure/resourcemanager/azurestack/implementation/RegistrationsImpl.java b/sdk/azurestack/azure-resourcemanager-azurestack/src/main/java/com/azure/resourcemanager/azurestack/implementation/RegistrationsImpl.java index 8876a6eea40f5..f4ba8c21ebb8e 100644 --- a/sdk/azurestack/azure-resourcemanager-azurestack/src/main/java/com/azure/resourcemanager/azurestack/implementation/RegistrationsImpl.java +++ b/sdk/azurestack/azure-resourcemanager-azurestack/src/main/java/com/azure/resourcemanager/azurestack/implementation/RegistrationsImpl.java @@ -40,6 +40,16 @@ public PagedIterable listByResourceGroup(String resourceGroup, Con return Utils.mapPage(inner, inner1 -> new RegistrationImpl(inner1, this.manager())); } + public PagedIterable list() { + PagedIterable inner = this.serviceClient().list(); + return Utils.mapPage(inner, inner1 -> new RegistrationImpl(inner1, this.manager())); + } + + public PagedIterable list(Context context) { + PagedIterable inner = this.serviceClient().list(context); + return Utils.mapPage(inner, inner1 -> new RegistrationImpl(inner1, this.manager())); + } + public Registration getByResourceGroup(String resourceGroup, String registrationName) { RegistrationInner inner = this.serviceClient().getByResourceGroup(resourceGroup, registrationName); if (inner != null) { diff --git a/sdk/azurestack/azure-resourcemanager-azurestack/src/main/java/com/azure/resourcemanager/azurestack/models/Registrations.java b/sdk/azurestack/azure-resourcemanager-azurestack/src/main/java/com/azure/resourcemanager/azurestack/models/Registrations.java index 0f4b81ae0c207..48637cf5c03be 100644 --- a/sdk/azurestack/azure-resourcemanager-azurestack/src/main/java/com/azure/resourcemanager/azurestack/models/Registrations.java +++ b/sdk/azurestack/azure-resourcemanager-azurestack/src/main/java/com/azure/resourcemanager/azurestack/models/Registrations.java @@ -33,6 +33,26 @@ public interface Registrations { */ PagedIterable listByResourceGroup(String resourceGroup, Context context); + /** + * Returns a list of all registrations under current subscription. + * + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return pageable list of registrations. + */ + PagedIterable list(); + + /** + * Returns a list of all registrations under current subscription. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return pageable list of registrations. + */ + PagedIterable list(Context context); + /** * Returns the properties of an Azure Stack registration. *