Skip to content
Merged
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
15 changes: 14 additions & 1 deletion src/code/ContainerRegistryServerAPICalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ internal class ContainerRegistryServerAPICalls : ServerApiCall

const string containerRegistryRepositoryListTemplate = "https://{0}/v2/_catalog"; // 0 - registry

private string _cachedContainterRegistryToken = null;

#endregion

#region Constructor
Expand All @@ -68,6 +70,8 @@ public ContainerRegistryServerAPICalls(PSRepositoryInfo repository, PSCmdlet cmd
Credentials = networkCredential
};

_cachedContainterRegistryToken = null;

_sessionClient = new HttpClient(handler);
_sessionClient.Timeout = TimeSpan.FromMinutes(10);
_sessionClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", userAgentString);
Expand Down Expand Up @@ -384,6 +388,12 @@ internal string GetContainerRegistryAccessToken(bool needCatalogAccess, out Erro
string tenantID = string.Empty;
errRecord = null;

if (!string.IsNullOrEmpty(_cachedContainterRegistryToken))
{
_cmdletPassedIn.WriteVerbose("Using cached container registry access token.");
return _cachedContainterRegistryToken;
}

var repositoryCredentialInfo = Repository.CredentialInfo;
if (repositoryCredentialInfo != null)
{
Expand Down Expand Up @@ -445,6 +455,9 @@ internal string GetContainerRegistryAccessToken(bool needCatalogAccess, out Erro
return null;
}

_cmdletPassedIn.WriteVerbose("Container registry access token retrieved.");
_cachedContainterRegistryToken = containerRegistryAccessToken;

return containerRegistryAccessToken;
}

Expand Down Expand Up @@ -739,7 +752,7 @@ internal Hashtable GetContainerRegistryMetadata(string packageName, string exact
{
using (JsonDocument metadataJSONDoc = JsonDocument.Parse(serverPkgInfo.Metadata))
{
string pkgVersionString = String.Empty;
string pkgVersionString = String.Empty;
JsonElement rootDom = metadataJSONDoc.RootElement;

if (rootDom.TryGetProperty("ModuleVersion", out JsonElement pkgVersionElement))
Expand Down
Loading