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

Remove InstallName() #1506

Merged
merged 2 commits into from
Jan 8, 2024
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
75 changes: 9 additions & 66 deletions src/code/ACRServerAPICalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,8 @@ public override FindResults FindVersionWithTag(string packageName, string versio

/// <summary>
/// Installs a specific package.
/// User may request to install package with or without providing version (as seen in examples below), but prior to calling this method the package is located and package version determined.
/// Therefore, package version should not be null in this method.
/// Name: no wildcard support.
/// Examples: Install "PowerShellGet"
/// Install "PowerShellGet" -Version "3.0.0"
Expand All @@ -540,76 +542,17 @@ public override Stream InstallPackage(string packageName, string packageVersion,
Stream results = new MemoryStream();
if (string.IsNullOrEmpty(packageVersion))
{
results = InstallName(packageName, out errRecord);
}
else
{
results = InstallVersion(packageName, packageVersion, out errRecord);
}

return results;
}

private Stream InstallName(
string moduleName,
out ErrorRecord errRecord)
{
errRecord = null;
string accessToken = string.Empty;
string tenantID = string.Empty;
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
string moduleVersion = String.Empty;

var repositoryCredentialInfo = Repository.CredentialInfo;
if (repositoryCredentialInfo != null)
{
accessToken = Utils.GetACRAccessTokenFromSecretManagement(
Repository.Name,
repositoryCredentialInfo,
errRecord = new ErrorRecord(
exception: new ArgumentNullException($"Package version could not be found for {packageName}"),
"PackageVersionNullOrEmptyError",
ErrorCategory.InvalidArgument,
_cmdletPassedIn);

_cmdletPassedIn.WriteVerbose("Access token retrieved.");

tenantID = repositoryCredentialInfo.SecretName;
_cmdletPassedIn.WriteVerbose($"Tenant ID: {tenantID}");
}

// Call asynchronous network methods in a try/catch block to handle exceptions.
string registry = Repository.Uri.Host;

_cmdletPassedIn.WriteVerbose("Getting acr refresh token");
var acrRefreshToken = GetAcrRefreshToken(registry, tenantID, accessToken, out errRecord);
if (errRecord != null)
{
return null;
}

_cmdletPassedIn.WriteVerbose("Getting acr access token");
var acrAccessToken = GetAcrAccessToken(registry, acrRefreshToken, out errRecord);
if (errRecord != null)
{
return null;
}

_cmdletPassedIn.WriteVerbose($"Getting manifest for {moduleName} - {moduleVersion}");
var manifest = GetAcrRepositoryManifestAsync(registry, moduleName, moduleVersion, acrAccessToken, out errRecord);
if (errRecord != null)
{
return null;
}

string digest = GetDigestFromManifest(manifest, out errRecord);
if (errRecord != null)
{
return null;
return results;
}

_cmdletPassedIn.WriteVerbose($"Downloading blob for {moduleName} - {moduleVersion}");
// TODO: error handling here?
var responseContent = GetAcrBlobAsync(registry, moduleName, digest, acrAccessToken).Result;

return responseContent.ReadAsStreamAsync().Result;
results = InstallVersion(packageName, packageVersion, out errRecord);
return results;
}

private Stream InstallVersion(
Expand Down
14 changes: 10 additions & 4 deletions src/code/LocalServerApiCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ public override FindResults FindVersionWithTag(string packageName, string versio

/// <summary>
/// Installs a specific package.
/// User may request to install package with or without providing version (as seen in examples below), but prior to calling this method the package is located and package version determined.
/// Therefore, package version should not be null in this method.
/// Name: no wildcard support.
/// Examples: Install "PowerShellGet"
/// Install "PowerShellGet" -Version "3.0.0"
Expand All @@ -227,12 +229,16 @@ public override Stream InstallPackage(string packageName, string packageVersion,
Stream results = new MemoryStream();
if (string.IsNullOrEmpty(packageVersion))
{
results = InstallName(packageName, includePrerelease, out errRecord);
}
else {
results = InstallVersion(packageName, packageVersion, out errRecord);
errRecord = new ErrorRecord(
exception: new ArgumentNullException($"Package version could not be found for {packageName}"),
"PackageVersionNullOrEmptyError",
ErrorCategory.InvalidArgument,
_cmdletPassedIn);

return results;
}

results = InstallVersion(packageName, packageVersion, out errRecord);
return results;
}

Expand Down
14 changes: 10 additions & 4 deletions src/code/NuGetServerAPICalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ public override FindResults FindVersionWithTag(string packageName, string versio

/// <summary>
/// Installs a specific package.
/// User may request to install package with or without providing version (as seen in examples below), but prior to calling this method the package is located and package version determined.
/// Therefore, package version should not be null in this method.
/// Name: no wildcard support.
/// Examples: Install "PowerShellGet"
/// Install "PowerShellGet" -Version "3.0.0"
Expand All @@ -403,12 +405,16 @@ public override Stream InstallPackage(string packageName, string packageVersion,
Stream results = new MemoryStream();
if (string.IsNullOrEmpty(packageVersion))
{
results = InstallName(packageName, out errRecord);
}
else {
results = InstallVersion(packageName, packageVersion, out errRecord);
errRecord = new ErrorRecord(
exception: new ArgumentNullException($"Package version could not be found for {packageName}"),
"PackageVersionNullOrEmptyError",
ErrorCategory.InvalidArgument,
_cmdletPassedIn);

return results;
}

results = InstallVersion(packageName, packageVersion, out errRecord);
return results;
}

Expand Down
37 changes: 10 additions & 27 deletions src/code/V2ServerAPICalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,8 @@ public override FindResults FindVersionWithTag(string packageName, string versio

/// <summary>
/// Installs a specific package.
/// User may request to install package with or without providing version (as seen in examples below), but prior to calling this method the package is located and package version determined.
/// Therefore, package version should not be null in this method.
/// Name: no wildcard support.
/// Examples: Install "PowerShellGet"
/// Install "PowerShellGet" -Version "3.0.0"
Expand All @@ -675,13 +677,16 @@ public override Stream InstallPackage(string packageName, string packageVersion,
Stream results = new MemoryStream();
if (string.IsNullOrEmpty(packageVersion))
{
results = InstallName(packageName, out errRecord);
}
else
{
results = InstallVersion(packageName, packageVersion, out errRecord);
errRecord = new ErrorRecord(
exception: new ArgumentNullException($"Package version could not be found for {packageName}"),
"PackageVersionNullOrEmptyError",
ErrorCategory.InvalidArgument,
_cmdletPassedIn);

return results;
}

results = InstallVersion(packageName, packageVersion, out errRecord);
return results;
}

Expand Down Expand Up @@ -1112,28 +1117,6 @@ private string FindVersionGlobbing(string packageName, VersionRange versionRange
return HttpRequestCall(requestUrlV2, out errRecord);
}

/// <summary>
/// Installs specific package.
/// Name: no wildcard support.
/// Examples: Install "PowerShellGet"
/// Implementation Note: if not prerelease: https://www.powershellgallery.com/api/v2/package/powershellget (Returns latest stable)
/// if prerelease, call into InstallVersion instead.
/// </summary>
private Stream InstallName(string packageName, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::InstallName()");
var requestUrlV2 = $"{Repository.Uri}/package/{packageName}";
var response = HttpRequestCallForContent(requestUrlV2, out errRecord);
if (errRecord != null)
{
return new MemoryStream();
}

var responseStream = response.ReadAsStreamAsync().Result;

return responseStream;
}

/// <summary>
/// Installs package with specific name and version.
/// Name: no wildcard support.
Expand Down
15 changes: 10 additions & 5 deletions src/code/V3ServerAPICalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ public override FindResults FindVersionWithTag(string packageName, string versio

/// <summary>
/// Installs a specific package.
/// User may request to install package with or without providing version (as seen in examples below), but prior to calling this method the package is located and package version determined.
/// Therefore, package version should not be null in this method.
/// Name: no wildcard support.
/// Examples: Install "PowerShellGet"
/// Install "PowerShellGet" -Version "3.0.0"
Expand All @@ -295,13 +297,16 @@ public override Stream InstallPackage(string packageName, string packageVersion,
Stream results = new MemoryStream();
if (string.IsNullOrEmpty(packageVersion))
{
results = InstallName(packageName, out errRecord);
}
else
{
results = InstallVersion(packageName, packageVersion, out errRecord);
errRecord = new ErrorRecord(
exception: new ArgumentNullException($"Package version could not be found for {packageName}"),
"PackageVersionNullOrEmptyError",
ErrorCategory.InvalidArgument,
_cmdletPassedIn);

return results;
}

results = InstallVersion(packageName, packageVersion, out errRecord);
return results;
}

Expand Down
Loading