Skip to content

Commit c64719e

Browse files
authored
Remove InstallName() (#1506)
* remove InstallName dead code * code cleanup
1 parent e511b71 commit c64719e

File tree

5 files changed

+49
-106
lines changed

5 files changed

+49
-106
lines changed

src/code/ACRServerAPICalls.cs

Lines changed: 9 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ public override FindResults FindVersionWithTag(string packageName, string versio
530530

531531
/// <summary>
532532
/// Installs a specific package.
533+
/// 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.
534+
/// Therefore, package version should not be null in this method.
533535
/// Name: no wildcard support.
534536
/// Examples: Install "PowerShellGet"
535537
/// Install "PowerShellGet" -Version "3.0.0"
@@ -540,76 +542,17 @@ public override Stream InstallPackage(string packageName, string packageVersion,
540542
Stream results = new MemoryStream();
541543
if (string.IsNullOrEmpty(packageVersion))
542544
{
543-
results = InstallName(packageName, out errRecord);
544-
}
545-
else
546-
{
547-
results = InstallVersion(packageName, packageVersion, out errRecord);
548-
}
549-
550-
return results;
551-
}
552-
553-
private Stream InstallName(
554-
string moduleName,
555-
out ErrorRecord errRecord)
556-
{
557-
errRecord = null;
558-
string accessToken = string.Empty;
559-
string tenantID = string.Empty;
560-
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
561-
Directory.CreateDirectory(tempPath);
562-
string moduleVersion = String.Empty;
563-
564-
var repositoryCredentialInfo = Repository.CredentialInfo;
565-
if (repositoryCredentialInfo != null)
566-
{
567-
accessToken = Utils.GetACRAccessTokenFromSecretManagement(
568-
Repository.Name,
569-
repositoryCredentialInfo,
545+
errRecord = new ErrorRecord(
546+
exception: new ArgumentNullException($"Package version could not be found for {packageName}"),
547+
"PackageVersionNullOrEmptyError",
548+
ErrorCategory.InvalidArgument,
570549
_cmdletPassedIn);
571550

572-
_cmdletPassedIn.WriteVerbose("Access token retrieved.");
573-
574-
tenantID = repositoryCredentialInfo.SecretName;
575-
_cmdletPassedIn.WriteVerbose($"Tenant ID: {tenantID}");
576-
}
577-
578-
// Call asynchronous network methods in a try/catch block to handle exceptions.
579-
string registry = Repository.Uri.Host;
580-
581-
_cmdletPassedIn.WriteVerbose("Getting acr refresh token");
582-
var acrRefreshToken = GetAcrRefreshToken(registry, tenantID, accessToken, out errRecord);
583-
if (errRecord != null)
584-
{
585-
return null;
586-
}
587-
588-
_cmdletPassedIn.WriteVerbose("Getting acr access token");
589-
var acrAccessToken = GetAcrAccessToken(registry, acrRefreshToken, out errRecord);
590-
if (errRecord != null)
591-
{
592-
return null;
593-
}
594-
595-
_cmdletPassedIn.WriteVerbose($"Getting manifest for {moduleName} - {moduleVersion}");
596-
var manifest = GetAcrRepositoryManifestAsync(registry, moduleName, moduleVersion, acrAccessToken, out errRecord);
597-
if (errRecord != null)
598-
{
599-
return null;
600-
}
601-
602-
string digest = GetDigestFromManifest(manifest, out errRecord);
603-
if (errRecord != null)
604-
{
605-
return null;
551+
return results;
606552
}
607553

608-
_cmdletPassedIn.WriteVerbose($"Downloading blob for {moduleName} - {moduleVersion}");
609-
// TODO: error handling here?
610-
var responseContent = GetAcrBlobAsync(registry, moduleName, digest, acrAccessToken).Result;
611-
612-
return responseContent.ReadAsStreamAsync().Result;
554+
results = InstallVersion(packageName, packageVersion, out errRecord);
555+
return results;
613556
}
614557

615558
private Stream InstallVersion(

src/code/LocalServerApiCalls.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ public override FindResults FindVersionWithTag(string packageName, string versio
218218

219219
/// <summary>
220220
/// Installs a specific package.
221+
/// 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.
222+
/// Therefore, package version should not be null in this method.
221223
/// Name: no wildcard support.
222224
/// Examples: Install "PowerShellGet"
223225
/// Install "PowerShellGet" -Version "3.0.0"
@@ -227,12 +229,16 @@ public override Stream InstallPackage(string packageName, string packageVersion,
227229
Stream results = new MemoryStream();
228230
if (string.IsNullOrEmpty(packageVersion))
229231
{
230-
results = InstallName(packageName, includePrerelease, out errRecord);
231-
}
232-
else {
233-
results = InstallVersion(packageName, packageVersion, out errRecord);
232+
errRecord = new ErrorRecord(
233+
exception: new ArgumentNullException($"Package version could not be found for {packageName}"),
234+
"PackageVersionNullOrEmptyError",
235+
ErrorCategory.InvalidArgument,
236+
_cmdletPassedIn);
237+
238+
return results;
234239
}
235240

241+
results = InstallVersion(packageName, packageVersion, out errRecord);
236242
return results;
237243
}
238244

src/code/NuGetServerAPICalls.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ public override FindResults FindVersionWithTag(string packageName, string versio
394394

395395
/// <summary>
396396
/// Installs a specific package.
397+
/// 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.
398+
/// Therefore, package version should not be null in this method.
397399
/// Name: no wildcard support.
398400
/// Examples: Install "PowerShellGet"
399401
/// Install "PowerShellGet" -Version "3.0.0"
@@ -403,12 +405,16 @@ public override Stream InstallPackage(string packageName, string packageVersion,
403405
Stream results = new MemoryStream();
404406
if (string.IsNullOrEmpty(packageVersion))
405407
{
406-
results = InstallName(packageName, out errRecord);
407-
}
408-
else {
409-
results = InstallVersion(packageName, packageVersion, out errRecord);
408+
errRecord = new ErrorRecord(
409+
exception: new ArgumentNullException($"Package version could not be found for {packageName}"),
410+
"PackageVersionNullOrEmptyError",
411+
ErrorCategory.InvalidArgument,
412+
_cmdletPassedIn);
413+
414+
return results;
410415
}
411416

417+
results = InstallVersion(packageName, packageVersion, out errRecord);
412418
return results;
413419
}
414420

src/code/V2ServerAPICalls.cs

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,8 @@ public override FindResults FindVersionWithTag(string packageName, string versio
666666

667667
/// <summary>
668668
/// Installs a specific package.
669+
/// 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.
670+
/// Therefore, package version should not be null in this method.
669671
/// Name: no wildcard support.
670672
/// Examples: Install "PowerShellGet"
671673
/// Install "PowerShellGet" -Version "3.0.0"
@@ -675,13 +677,16 @@ public override Stream InstallPackage(string packageName, string packageVersion,
675677
Stream results = new MemoryStream();
676678
if (string.IsNullOrEmpty(packageVersion))
677679
{
678-
results = InstallName(packageName, out errRecord);
679-
}
680-
else
681-
{
682-
results = InstallVersion(packageName, packageVersion, out errRecord);
680+
errRecord = new ErrorRecord(
681+
exception: new ArgumentNullException($"Package version could not be found for {packageName}"),
682+
"PackageVersionNullOrEmptyError",
683+
ErrorCategory.InvalidArgument,
684+
_cmdletPassedIn);
685+
686+
return results;
683687
}
684688

689+
results = InstallVersion(packageName, packageVersion, out errRecord);
685690
return results;
686691
}
687692

@@ -1112,28 +1117,6 @@ private string FindVersionGlobbing(string packageName, VersionRange versionRange
11121117
return HttpRequestCall(requestUrlV2, out errRecord);
11131118
}
11141119

1115-
/// <summary>
1116-
/// Installs specific package.
1117-
/// Name: no wildcard support.
1118-
/// Examples: Install "PowerShellGet"
1119-
/// Implementation Note: if not prerelease: https://www.powershellgallery.com/api/v2/package/powershellget (Returns latest stable)
1120-
/// if prerelease, call into InstallVersion instead.
1121-
/// </summary>
1122-
private Stream InstallName(string packageName, out ErrorRecord errRecord)
1123-
{
1124-
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::InstallName()");
1125-
var requestUrlV2 = $"{Repository.Uri}/package/{packageName}";
1126-
var response = HttpRequestCallForContent(requestUrlV2, out errRecord);
1127-
if (errRecord != null)
1128-
{
1129-
return new MemoryStream();
1130-
}
1131-
1132-
var responseStream = response.ReadAsStreamAsync().Result;
1133-
1134-
return responseStream;
1135-
}
1136-
11371120
/// <summary>
11381121
/// Installs package with specific name and version.
11391122
/// Name: no wildcard support.

src/code/V3ServerAPICalls.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ public override FindResults FindVersionWithTag(string packageName, string versio
285285

286286
/// <summary>
287287
/// Installs a specific package.
288+
/// 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.
289+
/// Therefore, package version should not be null in this method.
288290
/// Name: no wildcard support.
289291
/// Examples: Install "PowerShellGet"
290292
/// Install "PowerShellGet" -Version "3.0.0"
@@ -295,13 +297,16 @@ public override Stream InstallPackage(string packageName, string packageVersion,
295297
Stream results = new MemoryStream();
296298
if (string.IsNullOrEmpty(packageVersion))
297299
{
298-
results = InstallName(packageName, out errRecord);
299-
}
300-
else
301-
{
302-
results = InstallVersion(packageName, packageVersion, out errRecord);
300+
errRecord = new ErrorRecord(
301+
exception: new ArgumentNullException($"Package version could not be found for {packageName}"),
302+
"PackageVersionNullOrEmptyError",
303+
ErrorCategory.InvalidArgument,
304+
_cmdletPassedIn);
305+
306+
return results;
303307
}
304308

309+
results = InstallVersion(packageName, packageVersion, out errRecord);
305310
return results;
306311
}
307312

0 commit comments

Comments
 (0)