Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move feature operations to azure.resourcemanager.core #22570

Merged
merged 3 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Core.Pipeline;

Expand All @@ -20,12 +22,7 @@ public class ArmClient
/// The base URI of the service.
/// </summary>
internal const string DefaultUri = "https://management.azure.com";

private TenantOperations _tenant;
/// <summary>
/// Get the tenant operations <see cref="TenantOperations"/> class.
/// </summary>
public TenantOperations Tenant => _tenant ??= new TenantOperations(ClientOptions, Credential, BaseUri, Pipeline);

/// <summary>
/// Initializes a new instance of the <see cref="ArmClient"/> class for mocking.
Expand Down Expand Up @@ -99,6 +96,7 @@ public ArmClient(
DefaultSubscription = string.IsNullOrWhiteSpace(defaultSubscriptionId)
? GetDefaultSubscription()
: GetSubscriptions().TryGet(defaultSubscriptionId);
_tenant = new TenantOperations(ClientOptions, Credential, BaseUri, Pipeline);
ClientOptions.ApiVersions.SetProviderClient(this);
}

Expand Down Expand Up @@ -219,5 +217,31 @@ public virtual RestApiContainer GetRestApis(string nameSpace)
{
return new RestApiContainer(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline), nameSpace);
}
}

/// <summary> Gets all resource providers for a subscription. </summary>
/// <param name="top"> The number of results to return. If null is passed returns all deployments. </param>
/// <param name="expand"> The properties to include in the results. For example, use &amp;$expand=metadata in the query string to retrieve resource provider metadata. To include property aliases in response, use $expand=resourceTypes/aliases. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Pageable<ProviderInfo> ListProviders(int? top = null, string expand = null, CancellationToken cancellationToken = default) => _tenant.ListProviders(top, expand, cancellationToken);

/// <summary> Gets all resource providers for a subscription. </summary>
/// <param name="top"> The number of results to return. If null is passed returns all deployments. </param>
/// <param name="expand"> The properties to include in the results. For example, use &amp;$expand=metadata in the query string to retrieve resource provider metadata. To include property aliases in response, use $expand=resourceTypes/aliases. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual AsyncPageable<ProviderInfo> ListProvidersAsync(int? top = null, string expand = null, CancellationToken cancellationToken = default) => _tenant.ListProvidersAsync(top, expand, cancellationToken);

/// <summary> Gets the specified resource provider at the tenant level. </summary>
/// <param name="resourceProviderNamespace"> The namespace of the resource provider. </param>
/// <param name="expand"> The $expand query parameter. For example, to include property aliases in response, use $expand=resourceTypes/aliases. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="ArgumentNullException"> <paramref name="resourceProviderNamespace"/> is null. </exception>
public virtual Response<ProviderInfo> GetProvider(string resourceProviderNamespace, string expand = null, CancellationToken cancellationToken = default) => _tenant.GetProvider(resourceProviderNamespace, expand, cancellationToken);

/// <summary> Gets the specified resource provider at the tenant level. </summary>
/// <param name="resourceProviderNamespace"> The namespace of the resource provider. </param>
/// <param name="expand"> The $expand query parameter. For example, to include property aliases in response, use $expand=resourceTypes/aliases. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="ArgumentNullException"> <paramref name="resourceProviderNamespace"/> is null. </exception>
public virtual async Task<Response<ProviderInfo>> GetProviderAsync(string resourceProviderNamespace, string expand = null, CancellationToken cancellationToken = default) => await _tenant.GetProviderAsync(resourceProviderNamespace, expand, cancellationToken).ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// <auto-generated/>

#nullable disable

using System.Collections.Generic;
using System.Text.Json;
using Azure.Core;

namespace Azure.ResourceManager.Core
{
public partial class ProviderInfo
{
internal static ProviderInfo DeserializeProviderInfo(JsonElement element)
{
Optional<string> @namespace = default;
Optional<IReadOnlyList<ProviderResourceType>> resourceTypes = default;
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("namespace"))
{
@namespace = property.Value.GetString();
continue;
}
if (property.NameEquals("resourceTypes"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
property.ThrowNonNullablePropertyIsNull();
continue;
}
List<ProviderResourceType> array = new List<ProviderResourceType>();
foreach (var item in property.Value.EnumerateArray())
{
array.Add(ProviderResourceType.DeserializeProviderResourceType(item));
}
resourceTypes = array;
continue;
}
}
return new ProviderInfo(@namespace.Value, Optional.ToList(resourceTypes));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// <auto-generated/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove // <auto-generated/> from ProviderInfo and ProviderInfoListResult


#nullable disable

using System.Collections.Generic;
using Azure.Core;

namespace Azure.ResourceManager.Core
{
/// <summary> Resource provider information. </summary>
public partial class ProviderInfo
{
/// <summary> Initializes a new instance of Provider. </summary>
internal ProviderInfo()
{
ResourceTypes = new ChangeTrackingList<ProviderResourceType>();
}

/// <summary> Initializes a new instance of Provider. </summary>
/// <param name="namespace"> The namespace of the resource provider. </param>
/// <param name="resourceTypes"> The collection of provider resource types. </param>
internal ProviderInfo(string @namespace, IReadOnlyList<ProviderResourceType> resourceTypes)
{
Namespace = @namespace;
ResourceTypes = resourceTypes;
}

/// <summary> The namespace of the resource provider. </summary>
public string Namespace { get; }
/// <summary> The collection of provider resource types. </summary>
public IReadOnlyList<ProviderResourceType> ResourceTypes { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// <auto-generated/>

#nullable disable

using System.Collections.Generic;
using System.Text.Json;
using Azure.Core;

namespace Azure.ResourceManager.Core
{
internal partial class ProviderInfoListResult
{
internal static ProviderInfoListResult DeserializeProviderInfoListResult(JsonElement element)
{
Optional<IReadOnlyList<ProviderInfo>> value = default;
Optional<string> nextLink = default;
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("value"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
property.ThrowNonNullablePropertyIsNull();
continue;
}
List<ProviderInfo> array = new List<ProviderInfo>();
foreach (var item in property.Value.EnumerateArray())
{
array.Add(ProviderInfo.DeserializeProviderInfo(item));
}
value = array;
continue;
}
if (property.NameEquals("nextLink"))
{
nextLink = property.Value.GetString();
continue;
}
}
return new ProviderInfoListResult(Optional.ToList(value), nextLink.Value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// <auto-generated/>

#nullable disable

using System.Collections.Generic;
using Azure.Core;

namespace Azure.ResourceManager.Core
{
/// <summary> List of resource providers. </summary>
internal partial class ProviderInfoListResult
{
/// <summary> Initializes a new instance of ProviderInfoListResult. </summary>
internal ProviderInfoListResult()
{
Value = new ChangeTrackingList<ProviderInfo>();
}

/// <summary> Initializes a new instance of ProviderInfoListResult. </summary>
/// <param name="value"> An array of resource providers. </param>
/// <param name="nextLink"> The URL to use for getting the next set of results. </param>
internal ProviderInfoListResult(IReadOnlyList<ProviderInfo> value, string nextLink)
{
Value = value;
NextLink = nextLink;
}

/// <summary> An array of resource providers. </summary>
public IReadOnlyList<ProviderInfo> Value { get; }
/// <summary> The URL to use for getting the next set of results. </summary>
public string NextLink { get; }
}
}
Loading