Skip to content

Commit

Permalink
Add verbose and debug messages for Container Registry Server (PowerSh…
Browse files Browse the repository at this point in the history
…ell#1615)

Add Name and Repository pipeline by property name (PowerShell#1451)

Bugfix script parse whitespace (PowerShell#1457)

Bug fix for Import-PSGetRepository in Windows PS (PowerShell#1460)

Update README.md (PowerShell#1458)

update chANGELOG, psd1, csproj for release 1.0.1 (PowerShell#1473)

Bump System.Text.Json from 6.0.0 to 8.0.0 in /src/code (PowerShell#1475)

Verify whether SourceLocation is a UNC path and select the appropriate ApiVersion (PowerShell#1479)

TryConvertFromXml: Prevent NRE when NormalizedVersion is missing (PowerShell#1503)

Update InstallHelper.cs (PowerShell#1510)

Bump BenchmarkDotNet.Diagnostics.Windows in /test/perf/benchmarks (PowerShell#1528)

enable isJFrogRepo flag for domains containing `artifactory` (PowerShell#1532)

Fix 'name' bug with v2 JFrog Artifactory (PowerShell#1535)

Bugfix Update-ModuleManifest throws null pointer exception (PowerShell#1538)

Add tests for ADO v2 server (PowerShell#1539)

Bugfix - Test if InstalledScriptInfos folder exists and create if needed (PowerShell#1542)

* Test InstalledScriptInfos folder and create if needed

* Update src/code/InstallHelper.cs

Co-authored-by: Aditya Patwardhan <[email protected]>

* Update src/code/InstallHelper.cs

Co-authored-by: Aditya Patwardhan <[email protected]>

---------

Co-authored-by: Aditya Patwardhan <[email protected]>

Remove redeclaration of s_tempHome (PowerShell#1544)

Bug fix for Update-PSResource not updating from correct repository (PowerShell#1549)

Update changelog, version, releasenotes
  • Loading branch information
anamnavi authored and alerickson committed Apr 1, 2024
1 parent abfbf42 commit 0700ff2
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
The change logs have been split by version and moved to [CHANGELOG](./CHANGELOG).
The change logs have been split by version and moved to [CHANGELOG](./CHANGELOG).
27 changes: 26 additions & 1 deletion src/Microsoft.PowerShell.PSResourceGet.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@{
RootModule = './Microsoft.PowerShell.PSResourceGet.dll'
NestedModules = @('./Microsoft.PowerShell.PSResourceGet.psm1')
ModuleVersion = '1.0.0'
ModuleVersion = '1.0.2'
CompatiblePSEditions = @('Core', 'Desktop')
GUID = 'e4e0bda1-0703-44a5-b70d-8fe704cd0643'
Author = 'Microsoft Corporation'
Expand Down Expand Up @@ -55,6 +55,31 @@
ProjectUri = 'https://go.microsoft.com/fwlink/?LinkId=828955'
LicenseUri = 'https://go.microsoft.com/fwlink/?LinkId=829061'
ReleaseNotes = @'
## 1.0.2
### Bug Fixes
- Bug fix for `Update-PSResource` not updating from correct repository (#1549)
- Bug fix for creating temp home directory on Unix (#1544)
- Bug fix for creating `InstalledScriptInfos` directory when it does not exist (#1542)
- Bug fix for `Update-ModuleManifest` throwing null pointer exception (#1538)
- Bug fix for `name` property not populating in `PSResourceInfo` object when using `Find-PSResource` with JFrog Artifactory (#1535)
- Bug fix for incorrect configuration of requests to JFrog Artifactory v2 endpoints (#1533 Thanks @sean-r-williams!)
- Bug fix for determining JFrog Artifactory repositories (#1532 Thanks @sean-r-williams!)
- Bug fix for v2 server repositories incorrectly adding script endpoint (1526)
- Bug fixes for null references (#1525)
- Typo fixes in message prompts in `Install-PSResource` (#1510 Thanks @NextGData!)
- Bug fix to add `NormalizedVersion` property to `AdditionalMetadata` only when it exists (#1503 Thanks @sean-r-williams!)
- Bug fix to verify whether `Uri` is a UNC path and set respective `ApiVersion` (#1479 Thanks @kborowinski!)
## 1.0.1
### Bug Fixes
- Bugfix to update Unix local user installation paths to be compatible with .NET 7 and .NET 8 (#1464)
- Bugfix for Import-PSGetRepository in Windows PowerShell (#1460)
- Bugfix for Test-PSScriptFileInfo to be less sensitive to whitespace (#1457)
- Bugfix to overwrite rels/rels directory on net472 when extracting nupkg to directory (#1456)
- Bugfix to add pipeline by property name support for Name and Repository properties for Find-PSResource (#1451 Thanks @ThomasNieto!)
## 1.0.0
### New Features
Expand Down
34 changes: 31 additions & 3 deletions src/code/ContainerRegistryServerAPICalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ private Stream InstallVersion(
string packageVersion,
out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::InstallVersion()");
errRecord = null;
string packageNameLowercase = packageName.ToLower();
string accessToken = string.Empty;
Expand Down Expand Up @@ -371,6 +372,7 @@ private Stream InstallVersion(
/// </summary>
internal string GetContainerRegistryAccessToken(out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::GetContainerRegistryAccessToken()");
string accessToken = string.Empty;
string containerRegistryAccessToken = string.Empty;
string tenantID = string.Empty;
Expand All @@ -387,7 +389,6 @@ internal string GetContainerRegistryAccessToken(out ErrorRecord errRecord)
_cmdletPassedIn.WriteVerbose("Access token retrieved.");

tenantID = repositoryCredentialInfo.SecretName;
_cmdletPassedIn.WriteVerbose($"Tenant ID: {tenantID}");
}
else
{
Expand Down Expand Up @@ -437,6 +438,7 @@ internal string GetContainerRegistryAccessToken(out ErrorRecord errRecord)
/// </summary>
internal bool IsContainerRegistryUnauthenticated(string containerRegistyUrl, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::IsContainerRegistryUnauthenticated()");
errRecord = null;
string endpoint = $"{containerRegistyUrl}/v2/";
HttpResponseMessage response;
Expand All @@ -463,6 +465,7 @@ internal bool IsContainerRegistryUnauthenticated(string containerRegistyUrl, out
/// </summary>
internal string GetContainerRegistryRefreshToken(string tenant, string accessToken, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::GetContainerRegistryRefreshToken()");
string content = string.Format(containerRegistryRefreshTokenTemplate, Registry, tenant, accessToken);
var contentHeaders = new Collection<KeyValuePair<string, string>> { new KeyValuePair<string, string>("Content-Type", "application/x-www-form-urlencoded") };
string exchangeUrl = string.Format(containerRegistryOAuthExchangeUrlTemplate, Registry);
Expand All @@ -480,6 +483,7 @@ internal string GetContainerRegistryRefreshToken(string tenant, string accessTok
/// </summary>
internal string GetContainerRegistryAccessTokenByRefreshToken(string refreshToken, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::GetContainerRegistryAccessTokenByRefreshToken()");
string content = string.Format(containerRegistryAccessTokenTemplate, Registry, refreshToken);
var contentHeaders = new Collection<KeyValuePair<string, string>> { new KeyValuePair<string, string>("Content-Type", "application/x-www-form-urlencoded") };
string tokenUrl = string.Format(containerRegistryOAuthTokenUrlTemplate, Registry);
Expand All @@ -501,6 +505,7 @@ internal string GetContainerRegistryAccessTokenByRefreshToken(string refreshToke
/// </summary>
private string GetDigestFromManifest(JObject manifest, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::GetDigestFromManifest()");
errRecord = null;
string digest = String.Empty;

Expand Down Expand Up @@ -544,6 +549,7 @@ private string GetDigestFromManifest(JObject manifest, out ErrorRecord errRecord
/// </summary>
internal JObject GetContainerRegistryRepositoryManifest(string packageName, string version, string containerRegistryAccessToken, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::GetContainerRegistryRepositoryManifest()");
// example of manifestUrl: https://psgetregistry.azurecr.io/hello-world:3.0.0
string manifestUrl = string.Format(containerRegistryManifestUrlTemplate, Registry, packageName, version);
var defaultHeaders = GetDefaultHeaders(containerRegistryAccessToken);
Expand All @@ -556,6 +562,7 @@ internal JObject GetContainerRegistryRepositoryManifest(string packageName, stri
/// </summary>
internal async Task<HttpContent> GetContainerRegistryBlobAsync(string packageName, string digest, string containerRegistryAccessToken)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::GetContainerRegistryBlobAsync()");
string blobUrl = string.Format(containerRegistryBlobDownloadUrlTemplate, Registry, packageName, digest);
var defaultHeaders = GetDefaultHeaders(containerRegistryAccessToken);
return await GetHttpContentResponseJObject(blobUrl, defaultHeaders);
Expand Down Expand Up @@ -585,6 +592,7 @@ internal JObject FindContainerRegistryImageTags(string packageName, string versi
* }
* }]
*/
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::FindContainerRegistryImageTags()");
string resolvedVersion = string.Equals(version, "*", StringComparison.OrdinalIgnoreCase) ? null : $"/{version}";
string findImageUrl = string.Format(containerRegistryFindImageVersionUrlTemplate, Registry, packageName, resolvedVersion);
var defaultHeaders = GetDefaultHeaders(containerRegistryAccessToken);
Expand All @@ -596,6 +604,7 @@ internal JObject FindContainerRegistryImageTags(string packageName, string versi
/// </summary>
internal Hashtable GetContainerRegistryMetadata(string packageName, string exactTagVersion, string containerRegistryAccessToken, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::GetContainerRegistryMetadata()");
Hashtable requiredVersionResponse = new Hashtable();

var foundTags = FindContainerRegistryManifest(packageName, exactTagVersion, containerRegistryAccessToken, out errRecord);
Expand Down Expand Up @@ -712,6 +721,7 @@ internal Hashtable GetContainerRegistryMetadata(string packageName, string exact
/// </summary>
internal JObject FindContainerRegistryManifest(string packageName, string version, string containerRegistryAccessToken, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::FindContainerRegistryManifest()");
var createManifestUrl = string.Format(containerRegistryManifestUrlTemplate, Registry, packageName, version);
_cmdletPassedIn.WriteDebug($"GET manifest url: {createManifestUrl}");

Expand All @@ -724,6 +734,7 @@ internal JObject FindContainerRegistryManifest(string packageName, string versio
/// </summary>
internal ContainerRegistryInfo GetMetadataProperty(JObject foundTags, string packageName, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::GetMetadataProperty()");
errRecord = null;
ContainerRegistryInfo serverPkgInfo = null;

Expand Down Expand Up @@ -803,6 +814,7 @@ internal ContainerRegistryInfo GetMetadataProperty(JObject foundTags, string pac
/// </summary>
internal async Task<HttpResponseMessage> UploadManifest(string packageName, string packageVersion, string configPath, bool isManifest, string containerRegistryAccessToken)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::UploadManifest()");
try
{
var createManifestUrl = string.Format(containerRegistryManifestUrlTemplate, Registry, packageName, packageVersion);
Expand All @@ -817,6 +829,7 @@ internal async Task<HttpResponseMessage> UploadManifest(string packageName, stri

internal async Task<HttpContent> GetHttpContentResponseJObject(string url, Collection<KeyValuePair<string, string>> defaultHeaders)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::GetHttpContentResponseJObject()");
try
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);
Expand All @@ -834,6 +847,7 @@ internal async Task<HttpContent> GetHttpContentResponseJObject(string url, Colle
/// </summary>
internal JObject GetHttpResponseJObjectUsingDefaultHeaders(string url, HttpMethod method, Collection<KeyValuePair<string, string>> defaultHeaders, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::GetHttpResponseJObjectUsingDefaultHeaders()");
try
{
errRecord = null;
Expand Down Expand Up @@ -883,6 +897,7 @@ internal JObject GetHttpResponseJObjectUsingDefaultHeaders(string url, HttpMetho
/// </summary>
internal JObject GetHttpResponseJObjectUsingContentHeaders(string url, HttpMethod method, string content, Collection<KeyValuePair<string, string>> contentHeaders, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::GetHttpResponseJObjectUsingContentHeaders()");
errRecord = null;
try
{
Expand Down Expand Up @@ -1122,17 +1137,20 @@ internal bool PushNupkgContainerRegistry(string psd1OrPs1File,
Hashtable dependencies,
out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::PushNupkgContainerRegistry()");
string fullNupkgFile = System.IO.Path.Combine(outputNupkgDir, packageName + "." + packageVersion.ToNormalizedString() + ".nupkg");
string packageNameLowercase = packageName.ToLower();

// Get access token (includes refresh tokens)
_cmdletPassedIn.WriteVerbose($"Get access token for container registry server.");
var containerRegistryAccessToken = GetContainerRegistryAccessToken(out errRecord);
if (errRecord != null)
{
return false;
}

// Upload .nupkg
_cmdletPassedIn.WriteVerbose($"Upload .nupkg file: {fullNupkgFile}");
string nupkgDigest = UploadNupkgFile(packageNameLowercase, containerRegistryAccessToken, fullNupkgFile, out errRecord);
if (errRecord != null)
{
Expand All @@ -1148,6 +1166,7 @@ internal bool PushNupkgContainerRegistry(string psd1OrPs1File,

// Create config.json file
var configFilePath = System.IO.Path.Combine(outputNupkgDir, "config.json");
_cmdletPassedIn.WriteVerbose($"Create config.json file at path: {configFilePath}");
string configDigest = CreateConfigFile(configFilePath, out errRecord);
if (errRecord != null)
{
Expand Down Expand Up @@ -1178,6 +1197,7 @@ internal bool PushNupkgContainerRegistry(string psd1OrPs1File,
/// </summary>
private string UploadNupkgFile(string packageNameLowercase, string containerRegistryAccessToken, string fullNupkgFile, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::UploadNupkgFile()");
_cmdletPassedIn.WriteVerbose("Start uploading blob");
string nupkgDigest = string.Empty;
errRecord = null;
Expand Down Expand Up @@ -1240,6 +1260,7 @@ private string UploadNupkgFile(string packageNameLowercase, string containerRegi
/// </summary>
private void CreateAndUploadEmptyFile(string outputNupkgDir, string pkgNameLower, string containerRegistryAccessToken, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::CreateAndUploadEmptyFile()");
_cmdletPassedIn.WriteVerbose("Create an empty file");
string emptyFileName = "empty" + Guid.NewGuid().ToString() + ".txt";
var emptyFilePath = System.IO.Path.Combine(outputNupkgDir, emptyFileName);
Expand Down Expand Up @@ -1290,6 +1311,7 @@ private void CreateAndUploadEmptyFile(string outputNupkgDir, string pkgNameLower
/// </summary>
private string CreateConfigFile(string configFilePath, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::CreateConfigFile()");
string configFileDigest = string.Empty;
_cmdletPassedIn.WriteVerbose("Create the config file");
while (File.Exists(configFilePath))
Expand Down Expand Up @@ -1336,6 +1358,7 @@ private bool TryCreateAndUploadManifest(string fullNupkgFile,
string containerRegistryAccessToken,
out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::TryCreateAndUploadManifest()");
errRecord = null;
string packageNameLowercase = packageName.ToLower();
FileInfo nupkgFile = new FileInfo(fullNupkgFile);
Expand Down Expand Up @@ -1377,6 +1400,7 @@ private string CreateManifestContent(
ResourceType resourceType,
string metadata)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::CreateManifestContent()");
StringBuilder stringBuilder = new StringBuilder();
StringWriter stringWriter = new StringWriter(stringBuilder);
JsonTextWriter jsonWriter = new JsonTextWriter(stringWriter);
Expand Down Expand Up @@ -1436,6 +1460,7 @@ private string CreateManifestContent(
/// </summary>
private string CreateDigest(string fileName, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::CreateDigest()");
errRecord = null;
string digest = string.Empty;
FileInfo fileInfo = new FileInfo(fileName);
Expand All @@ -1457,8 +1482,6 @@ private string CreateDigest(string fileName, out ErrorRecord errRecord)
}

digest = stringBuilder.ToString();
// Write the name and hash value of the file to the console.
_cmdletPassedIn.WriteVerbose($"{fileInfo.Name}: {digest}");
}
catch (IOException ex)
{
Expand Down Expand Up @@ -1490,6 +1513,7 @@ private string CreateDigest(string fileName, out ErrorRecord errRecord)
/// </summary>
private string CreateMetadataContent(ResourceType resourceType, Hashtable parsedMetadata, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::CreateMetadataContent()");
errRecord = null;
string jsonString = string.Empty;

Expand Down Expand Up @@ -1533,6 +1557,7 @@ private string CreateMetadataContent(ResourceType resourceType, Hashtable parsed
/// </summary>
internal async Task<string> GetStartUploadBlobLocation(string packageName, string containerRegistryAccessToken)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::GetStartUploadBlobLocation()");
try
{
var defaultHeaders = GetDefaultHeaders(containerRegistryAccessToken);
Expand All @@ -1550,6 +1575,7 @@ internal async Task<string> GetStartUploadBlobLocation(string packageName, strin
/// </summary>
internal async Task<HttpResponseMessage> EndUploadBlob(string location, string filePath, string digest, bool isManifest, string containerRegistryAccessToken)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::EndUploadBlob()");
try
{
var endUploadUrl = string.Format(containerRegistryEndUploadTemplate, Registry, location, digest);
Expand All @@ -1571,6 +1597,7 @@ internal async Task<HttpResponseMessage> EndUploadBlob(string location, string f
/// </summary>
private Hashtable[] FindPackagesWithVersionHelper(string packageName, VersionType versionType, VersionRange versionRange, NuGetVersion requiredVersion, bool includePrerelease, bool getOnlyLatest, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::FindPackagesWithVersionHelper()");
string accessToken = string.Empty;
string tenantID = string.Empty;
string registryUrl = Repository.Uri.ToString();
Expand Down Expand Up @@ -1624,6 +1651,7 @@ private Hashtable[] FindPackagesWithVersionHelper(string packageName, VersionTyp
/// </summary>
private SortedDictionary<NuGet.Versioning.SemanticVersion, string> GetPackagesWithRequiredVersion(List<JToken> allPkgVersions, VersionType versionType, VersionRange versionRange, NuGetVersion specificVersion, string packageName, bool includePrerelease, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::GetPackagesWithRequiredVersion()");
errRecord = null;
// we need NuGetVersion to sort versions by order, and string pkgVersionString (which is the exact tag from the server) to call GetContainerRegistryMetadata() later with exact version tag.
SortedDictionary<NuGet.Versioning.SemanticVersion, string> sortedPkgs = new SortedDictionary<SemanticVersion, string>(VersionComparer.Default);
Expand Down
Loading

0 comments on commit 0700ff2

Please sign in to comment.