From f30e66fcb3e6363602e6052a4008d99764e09cf0 Mon Sep 17 00:00:00 2001 From: m-nash Date: Wed, 26 May 2021 15:16:59 -0700 Subject: [PATCH 1/3] Add lambda wrapper in armclient for getting container objects in other RPs --- .../Azure.ResourceManager.Core/src/ArmClient.cs | 13 +++++++++++++ .../src/SubscriptionOperations.cs | 11 +++++++---- .../compute/Extensions/SubscriptionExtensions.cs | 8 ++++---- .../network/Extensions/SubscriptionExtensions.cs | 16 ++++++++-------- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs index 07433568676d4..ea47c0f752f8f 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.ComponentModel; using System.Globalization; using System.Linq; using Azure.Core; @@ -160,5 +161,17 @@ public GenericResourceOperations GetGenericResourcesOperations(TenantResourceIde { return new GenericResourceOperations(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline), id); } + + /// + /// Creates a container using the lambda expression passed in + /// + /// The type of container to construct. + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public T GetContainer(Func func) + { + return func(ClientOptions, Credential, BaseUri, Pipeline); + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/SubscriptionOperations.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/SubscriptionOperations.cs index 80223c57ca0bc..230a9e45091ec 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/SubscriptionOperations.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/SubscriptionOperations.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.ComponentModel; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -53,9 +54,10 @@ internal SubscriptionOperations(OperationsBase operations, TenantResourceIdentif /// /// /// - public virtual T ListResources(Func func) + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual T ListResources(Func func) { - return func(BaseUri, Credential, ClientOptions); + return func(BaseUri, Credential, ClientOptions, Pipeline); } /// @@ -64,9 +66,10 @@ public virtual T ListResources(Func /// /// - public virtual AsyncPageable ListResourcesAsync(Func> func) + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual AsyncPageable ListResourcesAsync(Func> func) { - return func(BaseUri, Credential, ClientOptions); + return func(BaseUri, Credential, ClientOptions, Pipeline); } /// diff --git a/sdk/resourcemanager/Proto.Client/compute/Extensions/SubscriptionExtensions.cs b/sdk/resourcemanager/Proto.Client/compute/Extensions/SubscriptionExtensions.cs index bb085bd408daa..39dec49389b8f 100644 --- a/sdk/resourcemanager/Proto.Client/compute/Extensions/SubscriptionExtensions.cs +++ b/sdk/resourcemanager/Proto.Client/compute/Extensions/SubscriptionExtensions.cs @@ -32,7 +32,7 @@ private static ComputeManagementClient GetComputeClient(Uri baseUri, string subs public static Pageable ListVirtualMachines(this SubscriptionOperations subscription) { return subscription.ListResources( - (baseUri, credential, options) => + (baseUri, credential, options, pipeline) => { ComputeManagementClient computeClient = GetComputeClient(baseUri, subscription.Id.SubscriptionId, credential, options); var vmOperations = computeClient.VirtualMachines; @@ -52,7 +52,7 @@ public static Pageable ListVirtualMachines(this SubscriptionOper public static AsyncPageable ListVirtualMachinesAsync(this SubscriptionOperations subscription) { return subscription.ListResourcesAsync( - (baseUri, credential, options) => + (baseUri, credential, options, pipeline) => { ComputeManagementClient computeClient = GetComputeClient(baseUri, subscription.Id.SubscriptionId, credential, options); var vmOperations = computeClient.VirtualMachines; @@ -104,7 +104,7 @@ public static AsyncPageable ListVirtualMachinesByNameAsync(this public static Pageable ListAvailabilitySets(this SubscriptionOperations subscription) { return subscription.ListResources( - (baseUri, credential, options) => + (baseUri, credential, options, pipeline) => { ComputeManagementClient computeClient = GetComputeClient(baseUri, subscription.Id.SubscriptionId, credential, options); var availabilitySetOperations = computeClient.AvailabilitySets; @@ -124,7 +124,7 @@ public static Pageable ListAvailabilitySets(this SubscriptionOp public static AsyncPageable ListAvailabilitySetsAsync(this SubscriptionOperations subscription) { return subscription.ListResourcesAsync( - (baseUri, credential, options) => + (baseUri, credential, options, pipeline) => { ComputeManagementClient computeClient = GetComputeClient(baseUri, subscription.Id.SubscriptionId, credential, options); var availabilitySetOperations = computeClient.AvailabilitySets; diff --git a/sdk/resourcemanager/Proto.Client/network/Extensions/SubscriptionExtensions.cs b/sdk/resourcemanager/Proto.Client/network/Extensions/SubscriptionExtensions.cs index ef06733a28dd9..2e9d22ef69269 100644 --- a/sdk/resourcemanager/Proto.Client/network/Extensions/SubscriptionExtensions.cs +++ b/sdk/resourcemanager/Proto.Client/network/Extensions/SubscriptionExtensions.cs @@ -33,7 +33,7 @@ private static NetworkManagementClient GetNetworkClient(Uri baseUri, string subs public static Pageable ListVnets(this SubscriptionOperations subscription) { return subscription.ListResources( - (baseUri, credential, options) => + (baseUri, credential, options, pipeline) => { NetworkManagementClient networkClient = GetNetworkClient(baseUri, subscription.Id.SubscriptionId, credential, options); var vmOperations = networkClient.VirtualNetworks; @@ -53,7 +53,7 @@ public static Pageable ListVnets(this SubscriptionOperations sub public static AsyncPageable ListVnetsAsync(this SubscriptionOperations subscription) { return subscription.ListResourcesAsync( - (baseUri, credential, options) => + (baseUri, credential, options, pipeline) => { NetworkManagementClient networkClient = GetNetworkClient(baseUri, subscription.Id.SubscriptionId, credential, options); var vmOperations = networkClient.VirtualNetworks; @@ -77,7 +77,7 @@ public static AsyncPageable ListVnetsAsync(this SubscriptionOper public static Pageable ListPublicIps(this SubscriptionOperations subscription) { return subscription.ListResources( - (baseUri, credential, options) => + (baseUri, credential, options, pipeline) => { NetworkManagementClient networkClient = GetNetworkClient(baseUri, subscription.Id.SubscriptionId, credential, options); var publicIPAddressesOperations = networkClient.PublicIPAddresses; @@ -97,7 +97,7 @@ public static Pageable ListPublicIps(this SubscriptionOperation public static AsyncPageable ListPublicIpsAsync(this SubscriptionOperations subscription) { return subscription.ListResourcesAsync( - (baseUri, credential, options) => + (baseUri, credential, options, pipeline) => { NetworkManagementClient networkClient = GetNetworkClient(baseUri, subscription.Id.SubscriptionId, credential, options); var publicIPAddressesOperations = networkClient.PublicIPAddresses; @@ -121,7 +121,7 @@ public static AsyncPageable ListPublicIpsAsync(this Subscriptio public static Pageable ListNics(this SubscriptionOperations subscription) { return subscription.ListResources( - (baseUri, credential, options) => + (baseUri, credential, options, pipeline) => { NetworkManagementClient networkClient = GetNetworkClient(baseUri, subscription.Id.SubscriptionId, credential, options); var networkInterfacesOperations = networkClient.NetworkInterfaces; @@ -141,7 +141,7 @@ public static Pageable ListNics(this SubscriptionOperations su public static AsyncPageable ListNicsAsync(this SubscriptionOperations subscription) { return subscription.ListResourcesAsync( - (baseUri, credential, options) => + (baseUri, credential, options, pipeline) => { NetworkManagementClient networkClient = GetNetworkClient(baseUri, subscription.Id.SubscriptionId, credential, options); var networkInterfacesOperations = networkClient.NetworkInterfaces; @@ -165,7 +165,7 @@ public static AsyncPageable ListNicsAsync(this SubscriptionOpe public static Pageable ListNsgs(this SubscriptionOperations subscription) { return subscription.ListResources( - (baseUri, credential, options) => + (baseUri, credential, options, pipeline) => { NetworkManagementClient networkClient = GetNetworkClient(baseUri, subscription.Id.SubscriptionId, credential, options); var networkSecurityGroupsOperations = networkClient.NetworkSecurityGroups; @@ -185,7 +185,7 @@ public static Pageable ListNsgs(this SubscriptionOperation public static AsyncPageable ListNsgsAsync(this SubscriptionOperations subscription) { return subscription.ListResourcesAsync( - (baseUri, credential, options) => + (baseUri, credential, options, pipeline) => { NetworkManagementClient networkClient = GetNetworkClient(baseUri, subscription.Id.SubscriptionId, credential, options); var networkSecurityGroupsOperations = networkClient.NetworkSecurityGroups; From b7d9552f3b7461e6394c999dd4f665599acd7e13 Mon Sep 17 00:00:00 2001 From: m-nash Date: Wed, 26 May 2021 15:18:01 -0700 Subject: [PATCH 2/3] update xml comments --- .../Azure.ResourceManager.Core/src/ArmClient.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs index ea47c0f752f8f..7aea736aa91bc 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs @@ -163,11 +163,11 @@ public GenericResourceOperations GetGenericResourcesOperations(TenantResourceIde } /// - /// Creates a container using the lambda expression passed in + /// Creates a container using the lambda expression passed in. /// /// The type of container to construct. - /// - /// + /// The lambda expression to execute. + /// The container type requested. [EditorBrowsable(EditorBrowsableState.Never)] public T GetContainer(Func func) { From 94053e9ffd70017ae18db14f3b06e6cfa5b9ca51 Mon Sep 17 00:00:00 2001 From: m-nash Date: Wed, 26 May 2021 17:51:08 -0700 Subject: [PATCH 3/3] update to add externally accesible constructor that doesn't have an operation base like armclient as the parent --- .../src/ContainerBase.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ContainerBase.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ContainerBase.cs index 89760db2c4110..74f5ad739b675 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ContainerBase.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ContainerBase.cs @@ -1,6 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; +using Azure.Core; +using Azure.Core.Pipeline; + namespace Azure.ResourceManager.Core { /// @@ -34,6 +38,18 @@ internal ContainerBase(ClientContext clientContext, ResourceIdentifier id) { } + /// + /// Initializes a new instance of the class. + /// + /// The options to use. + /// The credential to use. + /// The base uri to use. + /// The http pipeline policy to use. + protected ContainerBase(ArmClientOptions options, TokenCredential credential, Uri baseUri, HttpPipeline pipeline) + : this(new ClientContext(options, credential, baseUri, pipeline)) + { + } + /// /// Initializes a new instance of the class. ///