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

Resources: support api version when listing generic resources #1015

Merged
merged 3 commits into from
Mar 19, 2020
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
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;
}
}
}