Skip to content

Commit 2644183

Browse files
committed
Update dynamic parameters for Set and Register repositories
1 parent bfeb5e0 commit 2644183

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/code/RegisterPSResourceRepository.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ class RegisterPSResourceRepository : PSCmdlet, IDynamicParameters
117117

118118
public object GetDynamicParameters()
119119
{
120-
if(Uri.EndsWith(".azurecr.io") || Uri.EndsWith(".azurecr.io/") || Uri.Contains("mcr.microsoft.com"))
120+
// Dynamic parameter '-CredentialProvider' should not appear for PSGallery, or any container registry repository.
121+
if (ParameterSetName.Equals("PSGalleryParameterSet") || Uri.EndsWith(".azurecr.io") || Uri.EndsWith(".azurecr.io/") || Uri.Contains("mcr.microsoft.com"))
121122
{
122123
return null;
123124
}

src/code/SetPSResourceRepository.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ public SwitchParameter Trusted
109109
public object GetDynamicParameters()
110110
{
111111
PSRepositoryInfo repository = RepositorySettings.Read(new[] { Name }, out string[] _).FirstOrDefault();
112-
if (repository is not null &&
112+
// Dynamic parameter '-CredentialProvider' should not appear for PSGallery, or any container registry repository.
113+
if (repository is not null && repository.Name.Equals("PSGallery", StringComparison.OrdinalIgnoreCase) ||
113114
(repository.Uri.AbsoluteUri.EndsWith(".azurecr.io") || repository.Uri.AbsoluteUri.EndsWith(".azurecr.io/") || repository.Uri.AbsoluteUri.Contains("mcr.microsoft.com")))
114115
{
115116
return null;

test/ResourceRepositoryTests/SetPSResourceRepository.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Describe "Test Set-PSResourceRepository" -tags 'CI' {
154154
$hashtable4 = @{Name = $PSGalleryName; Trusted = $True};
155155
$arrayOfHashtables = $hashtable1, $hashtable2, $hashtable3, $hashtable4
156156

157-
Set-PSResourceRepository -Repository $arrayOfHashtables
157+
Set-PSResourceRepository -Repository $arrayOfHashtables -Verbose
158158
$res = Get-PSResourceRepository -Name $TestRepoName1
159159
$res.Name | Should -Be $TestRepoName1
160160
$Res.Uri.LocalPath | Should -Contain $tmpDir2Path
@@ -189,7 +189,7 @@ Describe "Test Set-PSResourceRepository" -tags 'CI' {
189189
It "not set and throw error for trying to set PSGallery Uri (NameParameterSet)" {
190190
Unregister-PSResourceRepository -Name $PSGalleryName
191191
Register-PSResourceRepository -PSGallery
192-
{Set-PSResourceRepository -Name $PSGalleryName -Uri $tmpDir1Path -ErrorAction Stop} | Should -Throw -ErrorId "ErrorInNameParameterSet,Microsoft.PowerShell.PSResourceGet.Cmdlets.SetPSResourceRepository"
192+
{Set-PSResourceRepository -Name $PSGalleryName -Uri $tmpDir1Path -Verbose -ErrorAction Stop} | Should -Throw -ErrorId "ErrorInNameParameterSet,Microsoft.PowerShell.PSResourceGet.Cmdlets.SetPSResourceRepository"
193193
}
194194

195195
It "not set and throw error for trying to set PSGallery CredentialInfo (NameParameterSet)" {

0 commit comments

Comments
 (0)