Skip to content

Update priority range for PSResourceRepository to 0-100 #741

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

Merged
merged 3 commits into from
Aug 12, 2022
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
4 changes: 2 additions & 2 deletions help/Register-PSResourceRepository.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ Accept wildcard characters: False

### -Priority

Specifies the priority ranking of the repository. Valid priority values range from 0 to 50. Lower
values have a higher priority ranking. The default value is `50`.
Specifies the priority ranking of the repository. Valid priority values range from 0 to 100. Lower
values have a higher priority ranking. The default value is `100`.

Repositories are searched in priority order (highest first).

Expand Down
8 changes: 4 additions & 4 deletions help/en-US/PowerShellGet.dll-Help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1933,7 +1933,7 @@
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Priority</maml:name>
<maml:description>
<maml:para>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.</maml:para>
<maml:para>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.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">Int32</command:parameterValue>
<dev:type>
Expand Down Expand Up @@ -2788,7 +2788,7 @@ PS C:\&gt; Get-PSResourceRepository
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Priority</maml:name>
<maml:description>
<maml:para>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).</maml:para>
<maml:para>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).</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">System.Int32</command:parameterValue>
<dev:type>
Expand Down Expand Up @@ -2884,7 +2884,7 @@ PS C:\&gt; Get-PSResourceRepository
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Priority</maml:name>
<maml:description>
<maml:para>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).</maml:para>
<maml:para>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).</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">System.Int32</command:parameterValue>
<dev:type>
Expand Down Expand Up @@ -3026,7 +3026,7 @@ PS C:\&gt; Set-PSResourceRepository -Name "PSGallery" -Priority 25 -Trusted -Pas
---- --- ------- --------
PSGallery https://www.powershellgallery.com/api/v2 True 25</dev:code>
<dev:remarks>
<maml:para>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.</maml:para>
<maml:para>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.</maml:para>
</dev:remarks>
</command:example>
<command:example>
Expand Down
2 changes: 1 addition & 1 deletion src/code/PSRepositoryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public PSRepositoryInfo(string name, Uri uri, int priority, bool trusted, PSCred
/// <summary>
/// the priority of the repository
/// </summary>
[ValidateRange(0, 50)]
[ValidateRange(0, 100)]
public int Priority { get; }

/// <summary>
Expand Down
18 changes: 9 additions & 9 deletions src/code/RegisterPSResourceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,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";
Expand Down Expand Up @@ -77,13 +77,13 @@ class RegisterPSResourceRepository : PSCmdlet
/// <summary>
/// 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.
/// </summary>
[Parameter(ParameterSetName = NameParameterSet)]
[Parameter(ParameterSetName = PSGalleryParameterSet)]
[ValidateRange(0, 50)]
public int Priority { get; set; } = defaultPriority;
[ValidateRange(0, 100)]
public int Priority { get; set; } = DefaultPriority;

/// <summary>
/// Specifies vault and secret names as PSCredentialInfo for the repository.
Expand Down Expand Up @@ -289,8 +289,8 @@ private List<PSRepositoryInfo> 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)
{
Expand Down Expand Up @@ -371,8 +371,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)
Expand Down
6 changes: 3 additions & 3 deletions src/code/RepositorySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/code/SetPSResourceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ public SwitchParameter Trusted
/// <summary>
/// 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).
/// </summary>
[Parameter(ParameterSetName = NameParameterSet)]
[ValidateNotNullOrEmpty]
[ValidateRange(0, 50)]
[ValidateRange(0, 100)]
public int Priority { get; set; } = DefaultPriority;

/// <summary>
Expand Down