Skip to content

Commit

Permalink
Add lambda wrapper in armclient for getting container objects in othe… (
Browse files Browse the repository at this point in the history
#21390)

* Add lambda wrapper in armclient for getting container objects in other RPs

* update xml comments
  • Loading branch information
m-nash authored May 26, 2021
1 parent fc2841f commit 09b2b13
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
13 changes: 13 additions & 0 deletions sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using Azure.Core;
Expand Down Expand Up @@ -160,5 +161,17 @@ public GenericResourceOperations GetGenericResourcesOperations(TenantResourceIde
{
return new GenericResourceOperations(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline), id);
}

/// <summary>
/// Creates a container using the lambda expression passed in.
/// </summary>
/// <typeparam name="T"> The type of container to construct. </typeparam>
/// <param name="func"> The lambda expression to execute. </param>
/// <returns> The container type requested. </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public T GetContainer<T>(Func<ArmClientOptions, TokenCredential, Uri, HttpPipeline, T> func)
{
return func(ClientOptions, Credential, BaseUri, Pipeline);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -53,9 +54,10 @@ internal SubscriptionOperations(OperationsBase operations, TenantResourceIdentif
/// <typeparam name="T"></typeparam>
/// <param name="func"></param>
/// <returns></returns>
public virtual T ListResources<T>(Func<Uri, TokenCredential, ArmClientOptions, T> func)
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual T ListResources<T>(Func<Uri, TokenCredential, ArmClientOptions, HttpPipeline, T> func)
{
return func(BaseUri, Credential, ClientOptions);
return func(BaseUri, Credential, ClientOptions, Pipeline);
}

/// <summary>
Expand All @@ -64,9 +66,10 @@ public virtual T ListResources<T>(Func<Uri, TokenCredential, ArmClientOptions, T
/// <typeparam name="T"></typeparam>
/// <param name="func"></param>
/// <returns></returns>
public virtual AsyncPageable<T> ListResourcesAsync<T>(Func<Uri, TokenCredential, ArmClientOptions, AsyncPageable<T>> func)
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual AsyncPageable<T> ListResourcesAsync<T>(Func<Uri, TokenCredential, ArmClientOptions, HttpPipeline, AsyncPageable<T>> func)
{
return func(BaseUri, Credential, ClientOptions);
return func(BaseUri, Credential, ClientOptions, Pipeline);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private static ComputeManagementClient GetComputeClient(Uri baseUri, string subs
public static Pageable<VirtualMachine> 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;
Expand All @@ -52,7 +52,7 @@ public static Pageable<VirtualMachine> ListVirtualMachines(this SubscriptionOper
public static AsyncPageable<VirtualMachine> 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;
Expand Down Expand Up @@ -104,7 +104,7 @@ public static AsyncPageable<GenericResource> ListVirtualMachinesByNameAsync(this
public static Pageable<AvailabilitySet> 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;
Expand All @@ -124,7 +124,7 @@ public static Pageable<AvailabilitySet> ListAvailabilitySets(this SubscriptionOp
public static AsyncPageable<AvailabilitySet> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private static NetworkManagementClient GetNetworkClient(Uri baseUri, string subs
public static Pageable<VirtualNetwork> 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;
Expand All @@ -53,7 +53,7 @@ public static Pageable<VirtualNetwork> ListVnets(this SubscriptionOperations sub
public static AsyncPageable<VirtualNetwork> 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;
Expand All @@ -77,7 +77,7 @@ public static AsyncPageable<VirtualNetwork> ListVnetsAsync(this SubscriptionOper
public static Pageable<PublicIpAddress> 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;
Expand All @@ -97,7 +97,7 @@ public static Pageable<PublicIpAddress> ListPublicIps(this SubscriptionOperation
public static AsyncPageable<PublicIpAddress> 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;
Expand All @@ -121,7 +121,7 @@ public static AsyncPageable<PublicIpAddress> ListPublicIpsAsync(this Subscriptio
public static Pageable<NetworkInterface> 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;
Expand All @@ -141,7 +141,7 @@ public static Pageable<NetworkInterface> ListNics(this SubscriptionOperations su
public static AsyncPageable<NetworkInterface> 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;
Expand All @@ -165,7 +165,7 @@ public static AsyncPageable<NetworkInterface> ListNicsAsync(this SubscriptionOpe
public static Pageable<NetworkSecurityGroup> 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;
Expand All @@ -185,7 +185,7 @@ public static Pageable<NetworkSecurityGroup> ListNsgs(this SubscriptionOperation
public static AsyncPageable<NetworkSecurityGroup> 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;
Expand Down

0 comments on commit 09b2b13

Please sign in to comment.