Skip to content

Commit

Permalink
Update to use common rest api for OperationsList (#22343)
Browse files Browse the repository at this point in the history
* wip changes to add common rest api

* update variable name

* address pr comments

* update recording
  • Loading branch information
m-nash authored Jul 6, 2021
1 parent 26e768b commit 9e01b40
Show file tree
Hide file tree
Showing 19 changed files with 122,658 additions and 5 deletions.
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)
{
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

0 comments on commit 9e01b40

Please sign in to comment.