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

Update to use common rest api for OperationsList #22343

Merged
merged 5 commits into from
Jul 6, 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
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ public void Intercept(IInvocation invocation)
{
invocation.ReturnValue = s_proxyGenerator.CreateClassProxyWithTarget(type, result, new IInterceptor[] { new ManagementInterceptor(_testBase) });
}
else if (invocation.Method.Name.StartsWith("Get") && invocation.Method.Name.EndsWith("Enumerator"))
else if (invocation.Method.Name.StartsWith("Get") &&
invocation.Method.Name.EndsWith("Enumerator") &&
type.IsGenericType &&
type.GenericTypeArguments.FirstOrDefault(t => t.Name == "RestApi") == null)
{
var wrapperType = typeof(AsyncPageableInterceptor<>);
var genericType = wrapperType.MakeGenericType(type.GetGenericArguments()[0]);
Expand Down
31 changes: 29 additions & 2 deletions sdk/resourcemanager/Azure.ResourceManager.Core/src/ApiVersions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -41,6 +42,7 @@ internal void SetProviderClient(ArmClient armClient)

private ConcurrentDictionary<string, PropertyWrapper> _loadedResourceToApiVersions = new ConcurrentDictionary<string, PropertyWrapper>();
private ConcurrentDictionary<string, string> _nonLoadedResourceToApiVersion = new ConcurrentDictionary<string, string>();
private ConcurrentDictionary<string, string> _apiForNamespaceCache = new ConcurrentDictionary<string, string>();

private void BuildApiTable(ArmClientOptions clientOptions)
{
Expand All @@ -63,12 +65,37 @@ private void BuildApiTable(ArmClientOptions clientOptions)
}
}

internal string GetApiVersionForNamespace(string nameSpace)
{
string version;
if (!_apiForNamespaceCache.TryGetValue(nameSpace, out version))
{
DateTime maxVersion = new DateTime(1, 1, 1);
Provider results = _armClient.DefaultSubscription.GetProviders().Get(nameSpace, null);
foreach (var type in results.Data.ResourceTypes)
{
string[] parts = type.ApiVersions[0].Split('-');
DateTime current = new DateTime(
Convert.ToInt32(parts[0], CultureInfo.InvariantCulture.NumberFormat),
Convert.ToInt32(parts[1], CultureInfo.InvariantCulture.NumberFormat),
Convert.ToInt32(parts[2], CultureInfo.InvariantCulture.NumberFormat));
maxVersion = current > maxVersion ? current : maxVersion;
}
string month = maxVersion.Month < 10 ? "0" : string.Empty;
month += maxVersion.Month;
string day = maxVersion.Day < 10 ? "0" : string.Empty;
day += maxVersion.Day;
version = $"{maxVersion.Year}-{month}-{day}";
_apiForNamespaceCache[nameSpace] = version;
}
return version;
}

private static IEnumerable<MethodInfo> GetExtensionMethods()
{
// See TODO ADO #5692
var results =
from assembly in AppDomain.CurrentDomain.GetAssemblies()
where assembly.GetName().ToString().StartsWith("Azure.", StringComparison.Ordinal) || assembly.GetName().ToString().StartsWith("Proto.", StringComparison.Ordinal)
where assembly.GetName().ToString().StartsWith("Azure.", StringComparison.Ordinal)
from type in assembly.GetTypes()
where type.IsSealed && !type.IsGenericType && !type.IsNested && type.Name.Equals("AzureResourceManagerClientOptionsExtensions", StringComparison.Ordinal)
from method in type.GetMethods(BindingFlags.Static | BindingFlags.Public)
Expand Down
14 changes: 12 additions & 2 deletions sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public T GetContainer<T>(Func<ArmClientOptions, TokenCredential, Uri, HttpPipeli
/// Get the operations for a list of specific resources.
/// </summary>
/// <param name="ids"> A list of the IDs of the resources to retrieve. </param>
/// <returns></returns>
/// <returns> The list of operations that can be performed over the GenericResources. </returns>
public virtual IList<GenericResourceOperations> GetGenericResourceOperations(IEnumerable<string> ids)
{
if (ids == null)
Expand All @@ -199,7 +199,7 @@ public virtual IList<GenericResourceOperations> GetGenericResourceOperations(IEn
/// Get the operations for an specific resource.
/// </summary>
/// <param name="id"> The id of the resource to retrieve. </param>
/// <returns></returns>
/// <returns> The operations that can be performed over a specific GenericResource. </returns>
public virtual GenericResourceOperations GetGenericResourceOperations(string id)
{
if (id == null)
Expand All @@ -209,5 +209,15 @@ public virtual GenericResourceOperations GetGenericResourceOperations(string id)

return new GenericResourceOperations(DefaultSubscription, id);
}

/// <summary>
/// Gets the RestApi definition for a given Azure namespace.
/// </summary>
/// <param name="nameSpace"> The namespace to get the rest API for. </param>
/// <returns> A container representing the rest apis for the namespace. </returns>
public virtual RestApiContainer GetRestApis(string nameSpace)
m-nash marked this conversation as resolved.
Show resolved Hide resolved
{
return new RestApiContainer(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline), nameSpace);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading