Skip to content

Commit

Permalink
Resources: support api version when listing generic resources (#1015)
Browse files Browse the repository at this point in the history
* Resources: support api version when listing generic resources

* Resources: update GetById operation in genericResouces

* Resources: update session record
  • Loading branch information
xseeseesee authored Mar 19, 2020
1 parent 1cf6a9f commit a1771c0
Show file tree
Hide file tree
Showing 4 changed files with 721 additions and 650 deletions.
2 changes: 2 additions & 0 deletions Tests/Fluent.Tests/ResourceManager/GenericResourcesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,15 @@ public async Task CanCRUDWithProviderApiVersion()
where string.Equals(r.Name, resourceName, StringComparison.OrdinalIgnoreCase)
select r).FirstOrDefault();
Assert.NotNull(found);
Assert.NotNull(found.ApiVersion);

// Get
resource = genericResources.Get(rgName,
resource.ResourceProviderNamespace,
resource.ParentResourceId,
resource.ResourceType,
resource.Name);
Assert.NotNull(resource.ApiVersion);

// Move
IResourceGroup newGroup = resourceManager
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public string ApiVersion
{
get
{
if (string.IsNullOrEmpty(apiVersion))
{
apiVersion = GenericResourcesImpl.GetApiVersion(Id, Manager);
}
return apiVersion;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,7 @@ await DeleteAsync(
resourceType,
resourceName,
apiVersion);
GenericResourceImpl resource = new GenericResourceImpl(
resourceName,
inner,
Manager)
{
resourceProviderNamespace = resourceProviderNamespace,
parentResourceId = parentResourcePath,
resourceType = resourceType,
apiVersion = apiVersion
};

return resource;
return WrapModelWithApiVersion(inner, apiVersion);
}

public IGenericResource GetById(string id, string apiVersion = default(string))
Expand All @@ -169,14 +158,8 @@ await DeleteAsync(
{
apiVersion = await GetApiVersionAsync(id, Manager, cancellationToken);
}
return await GetAsync(
ResourceUtils.GroupFromResourceId(id),
ResourceUtils.ResourceProviderFromResourceId(id),
ResourceUtils.ParentResourcePathFromResourceId(id),
ResourceUtils.ResourceTypeFromResourceId(id),
ResourceUtils.NameFromResourceId(id),
apiVersion,
cancellationToken);
var inner = await Inner.GetByIdAsync(id, apiVersion, cancellationToken);
return WrapModelWithApiVersion(inner, apiVersion);
}

protected override Task<GenericResourceInner> GetInnerByGroupAsync(string groupName, string name, CancellationToken cancellation)
Expand Down Expand Up @@ -292,5 +275,29 @@ internal static async Task<string> GetApiVersionAsync(string id, IResourceManage
}
return await Task.FromResult(apiVersionValue);
}

internal static string GetApiVersion(string id, IResourceManager resourceManager)
{
return Extensions.Synchronize(() => GetApiVersionAsync(id, resourceManager, CancellationToken.None));
}

protected IGenericResource WrapModelWithApiVersion(GenericResourceInner inner, string apiVersion)
{
if (inner == null)
{
return null;
}
GenericResourceImpl resource = new GenericResourceImpl(
inner.Name,
inner,
Manager)
{
resourceProviderNamespace = ResourceUtils.ResourceProviderFromResourceId(inner.Id),
parentResourceId = ResourceUtils.ParentResourcePathFromResourceId(inner.Id),
resourceType = ResourceUtils.ResourceTypeFromResourceId(inner.Id),
apiVersion = apiVersion
};
return resource;
}
}
}

0 comments on commit a1771c0

Please sign in to comment.