From 09b2b1368d3790f4827386ec7c0a33387f2ffba2 Mon Sep 17 00:00:00 2001 From: m-nash <64171366+m-nash@users.noreply.github.com> Date: Wed, 26 May 2021 16:17:10 -0700 Subject: [PATCH] =?UTF-8?q?Add=20lambda=20wrapper=20in=20armclient=20for?= =?UTF-8?q?=20getting=20container=20objects=20in=20othe=E2=80=A6=20(#21390?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add lambda wrapper in armclient for getting container objects in other RPs * update xml comments --- .../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..7aea736aa91bc 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. + /// The lambda expression to execute. + /// The container type requested. + [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;