From efd0e6426fed87ea42b3e70ea03f877759ddd2fb Mon Sep 17 00:00:00 2001 From: Amber Erickson Date: Mon, 1 Aug 2022 14:10:10 -0700 Subject: [PATCH 1/2] Update priority range to 0-100 --- help/Register-PSResourceRepository.md | 2 +- help/Set-PSResourceRepository.md | 4 ++-- help/en-US/PowerShellGet.dll-Help.xml | 8 ++++---- src/code/PSRepositoryInfo.cs | 2 +- src/code/RegisterPSResourceRepository.cs | 4 ++-- src/code/SetPSResourceRepository.cs | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/help/Register-PSResourceRepository.md b/help/Register-PSResourceRepository.md index 9c7d3ac90..97ee9e957 100644 --- a/help/Register-PSResourceRepository.md +++ b/help/Register-PSResourceRepository.md @@ -90,7 +90,7 @@ Accept wildcard characters: False ### -Priority Specifies the priority ranking of the repository. -Repositories with higher ranking priority are searched before a lower ranking priority one, when searching for a repository item across multiple registered repositories. Valid priority values range from 0 to 50, such that a lower numeric value (i.e 10) corresponds to a higher priority ranking than a higher numeric value (i.e 40). Has default value of 50. +Repositories with higher ranking priority are searched before a lower ranking priority one, when searching for a repository item across multiple registered repositories. Valid priority values range from 0 to 100, such that a lower numeric value (i.e 10) corresponds to a higher priority ranking than a higher numeric value (i.e 40). Has default value of 50. ```yaml Type: Int32 diff --git a/help/Set-PSResourceRepository.md b/help/Set-PSResourceRepository.md index 658cb9174..0092310d9 100644 --- a/help/Set-PSResourceRepository.md +++ b/help/Set-PSResourceRepository.md @@ -53,7 +53,7 @@ PS C:\> Set-PSResourceRepository -Name "PSGallery" -Priority 25 -Trusted -PassTh PSGallery https://www.powershellgallery.com/api/v2 True 25 ``` -This example first checks if the PSGallery repository has been registered. We wish to set the `-Priority` and `-Trusted` values of this repository by running the Set-PSResourceRepository cmdlet with the `-Priority` parameter set to a value between 0 and 50 and by using the `-Trusted` parameter switch. We run the Get-PSResourceRepository cmdlet again to ensure that the `-Priority` and `-Trusted` values of the repository were changed. An important note here is that just for the default PSGallery repository, the `-Uri` value can't be changed/set. We also use the `-PassThru` parameter to see the changed repository. +This example first checks if the PSGallery repository has been registered. We wish to set the `-Priority` and `-Trusted` values of this repository by running the Set-PSResourceRepository cmdlet with the `-Priority` parameter set to a value between 0 and 100 and by using the `-Trusted` parameter switch. We run the Get-PSResourceRepository cmdlet again to ensure that the `-Priority` and `-Trusted` values of the repository were changed. An important note here is that just for the default PSGallery repository, the `-Uri` value can't be changed/set. We also use the `-PassThru` parameter to see the changed repository. ### Example 3 ```powershell @@ -92,7 +92,7 @@ Accept wildcard characters: False ``` ### -Priority -Specifies the priority ranking of the repository, such that repositories with higher ranking priority are searched before a lower ranking priority one, when searching for a repository item across multiple registered repositories. Valid priority values range from 0 to 50, such that a lower numeric value (i.e 10) corresponds to a higher priority ranking than a higher numeric value (i.e 40). +Specifies the priority ranking of the repository, such that repositories with higher ranking priority are searched before a lower ranking priority one, when searching for a repository item across multiple registered repositories. Valid priority values range from 0 to 100, such that a lower numeric value (i.e 10) corresponds to a higher priority ranking than a higher numeric value (i.e 40). ```yaml Type: System.Int32 diff --git a/help/en-US/PowerShellGet.dll-Help.xml b/help/en-US/PowerShellGet.dll-Help.xml index 6eb948e70..1a96ab66c 100644 --- a/help/en-US/PowerShellGet.dll-Help.xml +++ b/help/en-US/PowerShellGet.dll-Help.xml @@ -1933,7 +1933,7 @@ Priority - Specifies the priority ranking of the repository. Repositories with higher ranking priority are searched before a lower ranking priority one, when searching for a repository item across multiple registered repositories. Valid priority values range from 0 to 50, such that a lower numeric value (i.e 10) corresponds to a higher priority ranking than a higher numeric value (i.e 40). Has default value of 50. + Specifies the priority ranking of the repository. Repositories with higher ranking priority are searched before a lower ranking priority one, when searching for a repository item across multiple registered repositories. Valid priority values range from 0 to 100, such that a lower numeric value (i.e 10) corresponds to a higher priority ranking than a higher numeric value (i.e 40). Has default value of 50. Int32 @@ -2788,7 +2788,7 @@ PS C:\> Get-PSResourceRepository Priority - Specifies the priority ranking of the repository, such that repositories with higher ranking priority are searched before a lower ranking priority one, when searching for a repository item across multiple registered repositories. Valid priority values range from 0 to 50, such that a lower numeric value (i.e 10) corresponds to a higher priority ranking than a higher numeric value (i.e 40). + Specifies the priority ranking of the repository, such that repositories with higher ranking priority are searched before a lower ranking priority one, when searching for a repository item across multiple registered repositories. Valid priority values range from 0 to 100, such that a lower numeric value (i.e 10) corresponds to a higher priority ranking than a higher numeric value (i.e 40). System.Int32 @@ -2884,7 +2884,7 @@ PS C:\> Get-PSResourceRepository Priority - Specifies the priority ranking of the repository, such that repositories with higher ranking priority are searched before a lower ranking priority one, when searching for a repository item across multiple registered repositories. Valid priority values range from 0 to 50, such that a lower numeric value (i.e 10) corresponds to a higher priority ranking than a higher numeric value (i.e 40). + Specifies the priority ranking of the repository, such that repositories with higher ranking priority are searched before a lower ranking priority one, when searching for a repository item across multiple registered repositories. Valid priority values range from 0 to 100, such that a lower numeric value (i.e 10) corresponds to a higher priority ranking than a higher numeric value (i.e 40). System.Int32 @@ -3026,7 +3026,7 @@ PS C:\> Set-PSResourceRepository -Name "PSGallery" -Priority 25 -Trusted -Pas ---- --- ------- -------- PSGallery https://www.powershellgallery.com/api/v2 True 25 - This example first checks if the PSGallery repository has been registered. We wish to set the `-Priority` and `-Trusted` values of this repository by running the Set-PSResourceRepository cmdlet with the `-Priority` parameter set to a value between 0 and 50 and by using the `-Trusted` parameter switch. We run the Get-PSResourceRepository cmdlet again to ensure that the `-Priority` and `-Trusted` values of the repository were changed. An important note here is that just for the default PSGallery repository, the `-Uri` value can't be changed/set. We also use the `-PassThru` parameter to see the changed repository. + This example first checks if the PSGallery repository has been registered. We wish to set the `-Priority` and `-Trusted` values of this repository by running the Set-PSResourceRepository cmdlet with the `-Priority` parameter set to a value between 0 and 100 and by using the `-Trusted` parameter switch. We run the Get-PSResourceRepository cmdlet again to ensure that the `-Priority` and `-Trusted` values of the repository were changed. An important note here is that just for the default PSGallery repository, the `-Uri` value can't be changed/set. We also use the `-PassThru` parameter to see the changed repository. diff --git a/src/code/PSRepositoryInfo.cs b/src/code/PSRepositoryInfo.cs index d5fbebb25..39b42aadd 100644 --- a/src/code/PSRepositoryInfo.cs +++ b/src/code/PSRepositoryInfo.cs @@ -44,7 +44,7 @@ public PSRepositoryInfo(string name, Uri uri, int priority, bool trusted, PSCred /// /// the priority of the repository /// - [ValidateRange(0, 50)] + [ValidateRange(0, 100)] public int Priority { get; } /// diff --git a/src/code/RegisterPSResourceRepository.cs b/src/code/RegisterPSResourceRepository.cs index 6564f4d18..cce310333 100644 --- a/src/code/RegisterPSResourceRepository.cs +++ b/src/code/RegisterPSResourceRepository.cs @@ -76,12 +76,12 @@ class RegisterPSResourceRepository : PSCmdlet /// /// Specifies the priority ranking of the repository, such that repositories with higher ranking priority are searched /// before a lower ranking priority one, when searching for a repository item across multiple registered repositories. - /// Valid priority values range from 0 to 50, such that a lower numeric value (i.e 10) corresponds + /// Valid priority values range from 0 to 100, such that a lower numeric value (i.e 10) corresponds /// to a higher priority ranking than a higher numeric value (i.e 40). Has default value of 50. /// [Parameter(ParameterSetName = NameParameterSet)] [Parameter(ParameterSetName = PSGalleryParameterSet)] - [ValidateRange(0, 50)] + [ValidateRange(0, 100)] public int Priority { get; set; } = defaultPriority; /// diff --git a/src/code/SetPSResourceRepository.cs b/src/code/SetPSResourceRepository.cs index 2ada5bdee..758cb08fe 100644 --- a/src/code/SetPSResourceRepository.cs +++ b/src/code/SetPSResourceRepository.cs @@ -74,12 +74,12 @@ public SwitchParameter Trusted /// /// Specifies the priority ranking of the repository, such that repositories with higher ranking priority are searched /// before a lower ranking priority one, when searching for a repository item across multiple registered repositories. - /// Valid priority values range from 0 to 50, such that a lower numeric value (i.e 10) corresponds + /// Valid priority values range from 0 to 100, such that a lower numeric value (i.e 10) corresponds /// to a higher priority ranking than a higher numeric value (i.e 40). /// [Parameter(ParameterSetName = NameParameterSet)] [ValidateNotNullOrEmpty] - [ValidateRange(0, 50)] + [ValidateRange(0, 100)] public int Priority { get; set; } = DefaultPriority; /// From d1a9999841d61296e5798130de57b327eb39619d Mon Sep 17 00:00:00 2001 From: Amber Erickson Date: Wed, 10 Aug 2022 17:30:15 -0700 Subject: [PATCH 2/2] Incorporate code review suggestions --- src/code/RegisterPSResourceRepository.cs | 14 +++++++------- src/code/RepositorySettings.cs | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/code/RegisterPSResourceRepository.cs b/src/code/RegisterPSResourceRepository.cs index cce310333..904bfe9c2 100644 --- a/src/code/RegisterPSResourceRepository.cs +++ b/src/code/RegisterPSResourceRepository.cs @@ -28,8 +28,8 @@ class RegisterPSResourceRepository : PSCmdlet private readonly string PSGalleryRepoName = "PSGallery"; private readonly string PSGalleryRepoUri = "https://www.powershellgallery.com/api/v2"; - private const int defaultPriority = 50; - private const bool defaultTrusted = false; + private const int DefaultPriority = 50; + private const bool DefaultTrusted = false; private const string NameParameterSet = "NameParameterSet"; private const string PSGalleryParameterSet = "PSGalleryParameterSet"; private const string RepositoriesParameterSet = "RepositoriesParameterSet"; @@ -82,7 +82,7 @@ class RegisterPSResourceRepository : PSCmdlet [Parameter(ParameterSetName = NameParameterSet)] [Parameter(ParameterSetName = PSGalleryParameterSet)] [ValidateRange(0, 100)] - public int Priority { get; set; } = defaultPriority; + public int Priority { get; set; } = DefaultPriority; /// /// Specifies vault and secret names as PSCredentialInfo for the repository. @@ -288,8 +288,8 @@ private List RepositoriesParameterSetHelper() { WriteVerbose("(RepositoriesParameterSet): on repo: PSGallery. Registers PSGallery repository"); reposAddedFromHashTable.Add(PSGalleryParameterSetHelper( - repo.ContainsKey("Priority") ? (int)repo["Priority"] : defaultPriority, - repo.ContainsKey("Trusted") ? (bool)repo["Trusted"] : defaultTrusted)); + repo.ContainsKey("Priority") ? (int)repo["Priority"] : DefaultPriority, + repo.ContainsKey("Trusted") ? (bool)repo["Trusted"] : DefaultTrusted)); } catch (Exception e) { @@ -370,8 +370,8 @@ private PSRepositoryInfo RepoValidationHelper(Hashtable repo) WriteVerbose(String.Format("(RepositoriesParameterSet): on repo: {0}. Registers Name based repository", repo["Name"])); return NameParameterSetHelper(repo["Name"].ToString(), repoUri, - repo.ContainsKey("Priority") ? Convert.ToInt32(repo["Priority"].ToString()) : defaultPriority, - repo.ContainsKey("Trusted") ? Convert.ToBoolean(repo["Trusted"].ToString()) : defaultTrusted, + repo.ContainsKey("Priority") ? Convert.ToInt32(repo["Priority"].ToString()) : DefaultPriority, + repo.ContainsKey("Trusted") ? Convert.ToBoolean(repo["Trusted"].ToString()) : DefaultTrusted, repoCredentialInfo); } catch (Exception e) diff --git a/src/code/RepositorySettings.cs b/src/code/RepositorySettings.cs index dec5d2d15..76e68a27e 100644 --- a/src/code/RepositorySettings.cs +++ b/src/code/RepositorySettings.cs @@ -24,8 +24,8 @@ internal static class RepositorySettings // The repository store file's location is currently only at '%LOCALAPPDATA%\PowerShellGet' for the user account. private const string PSGalleryRepoName = "PSGallery"; private const string PSGalleryRepoUri = "https://www.powershellgallery.com/api/v2"; - private const int defaultPriority = 50; - private const bool defaultTrusted = false; + private const int DefaultPriority = 50; + private const bool DefaultTrusted = false; private const string RepositoryFileName = "PSResourceRepository.xml"; private static readonly string RepositoryPath = Path.Combine(Environment.GetFolderPath( Environment.SpecialFolder.LocalApplicationData), "PowerShellGet"); @@ -60,7 +60,7 @@ public static void CheckRepositoryStore() // Add PSGallery to the newly created store Uri psGalleryUri = new Uri(PSGalleryRepoUri); - Add(PSGalleryRepoName, psGalleryUri, defaultPriority, defaultTrusted, repoCredentialInfo: null); + Add(PSGalleryRepoName, psGalleryUri, DefaultPriority, DefaultTrusted, repoCredentialInfo: null); } // Open file (which should exist now), if cannot/is corrupted then throw error