-
Notifications
You must be signed in to change notification settings - Fork 102
Prevent users from setting ApiVersion to 'Unknown' in Set-PSResourceRepository and Register-PSResourceRepository #1892
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
Conversation
…urceRepository Co-authored-by: alerickson <[email protected]>
|
@copilot add [ValidateSet("V2", "V3". "Local", "NugetServer", "ContainerRegistry" )] |
…SResourceRepository Co-authored-by: alerickson <[email protected]>
Added validation to Register-PSResourceRepository to prevent setting ApiVersion to 'Unknown'. Since we're using an enum type in C#, I applied the same validation pattern used in Set-PSResourceRepository rather than using ValidateSet. The validation throws a clear error message listing the valid values (V2, V3, Local, NugetServer, ContainerRegistry) when users attempt to use Unknown. Changes in commit 4fe3725:
|
|
@copilot In RegisterPSResourceRepository, add the following in the line before "public PSRepositoryInfo.APIVersion ApiVersion { get; set; }" : |
…t validation code Co-authored-by: alerickson <[email protected]>
Added Changes in commit c0547b6. |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Summary
This PR prevents users from explicitly setting
ApiVersiontoUnknownwhen using theSet-PSResourceRepositoryandRegister-PSResourceRepositorycmdlets. TheUnknownvalue is reserved for internal use when the system cannot automatically determine a repository's type, and allowing users to set it explicitly would create non-functional repositories.Problem
Previously, users could set a repository's ApiVersion to "unknown":
When a repository has
ApiVersion.Unknown, cmdlets likeFind-PSResourceandInstall-PSResourcedetect this and throw errors indicating the repository type is not supported, making the repository completely non-functional.Changes
Code Changes
[ValidateSet("V2", "V3", "Local", "NugetServer", "ContainerRegistry")]attribute to theApiVersionparameter to restrict valid values at parameter binding time[ValidateSet("V2", "V3", "Local", "NugetServer", "ContainerRegistry")]attribute to theApiVersionparameter to restrict valid values at parameter binding timeTest Changes
ParameterArgumentValidationErrorand leaves the repository unchangedParameterArgumentValidationErrorand the repository is not createdNew Behavior
The
ValidateSetattribute provides automatic parameter validation at binding time, which is more idiomatic for PowerShell cmdlets. This approach:All other ApiVersion values continue to work as expected.
Fixes
Fixes #1419
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.