-
Notifications
You must be signed in to change notification settings - Fork 99
WIP: DSC v3 resource for PSResourceGet #1852
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick review pass on the manifests, looking at resource implementation next.
Add-Type -AssemblyName "$PSScriptRoot/dependencies/NuGet.Versioning.dll" | ||
|
||
foreach ($resource in $allPSResources) { | ||
foreach ($inputResource in $inputObj.resources) { | ||
if ($resource.Name -eq $inputResource.Name) { | ||
if ($inputResource.Version) { | ||
# Use the NuGet.Versioning package if available, otherwise do a simple comparison | ||
try { | ||
$versionRange = [NuGet.Versioning.VersionRange]::Parse($inputResource.Version) | ||
$resourceVersion = [NuGet.Versioning.NuGetVersion]::Parse($resource.Version.ToString()) | ||
if ($versionRange.Satisfies($resourceVersion)) { | ||
$resourcesExist += $resource | ||
} | ||
} | ||
catch { | ||
# Fallback: simple string comparison (not full NuGet range support) | ||
if ($resource.Version.ToString() -eq $inputResource.Version) { | ||
$resourcesExist += $resource | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code seems very similar across different operations, can it be a helper function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are subtle differences, but I will see if I can refactor
if ($inputObj.Name) { | ||
$splatt['Name'] = $inputObj.Name | ||
} | ||
|
||
if ($inputObj.Uri) { | ||
$splatt['Uri'] = $inputObj.Uri | ||
} | ||
|
||
if ($inputObj.Trusted) { | ||
$splatt['Trusted'] = $inputObj.Trusted | ||
} | ||
|
||
if ($null -ne $inputObj.Priority ) { | ||
$splatt['Priority'] = $inputObj.Priority | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this just be a loop like:
$properties = @('Name', 'Uri', 'Trusted', 'Priority')
for ($property in $properties) {
if ($null -ne $inputObject.$property) {
$splatt[$property] = $inputObject.$property
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more comments on the schema and implementation.
[string]$ResourceType | ||
) | ||
|
||
$inputObj = $stdinput | ConvertFrom-Json -ErrorAction Stop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably recommend defining a class for both the various input types and a function to handle both converting the input into the appropriate type and validating the input.
Right now reading $inputObj.<property>
and trying to keep track is very difficult, plus we lose the IntelliSense/etc we would get from stronger typing.
# catch any un-caught exception and write it to the error stream | ||
trap { | ||
Write-Trace -Level Error -message $_.Exception.Message | ||
exit 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Future enhancement - specific exit codes for specific issues/exceptions.
Is the plan to add a discover extension in DSC to be able to find these resource manifests? If so, is there an issue/pr for that? |
"type": "Microsoft.PowerShell.PSResourceGet/PSResources", | ||
"version": "0.0.1", | ||
"get": { | ||
"executable": "pwsh", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is Windows PowerShell handled? PSResourceGet supports both. For PSScript DSC v3 resource there are actually two different resources to account for different versions of PowerShell.
"type": "Microsoft.PowerShell.PSResourceGet/Repository", | ||
"version": "0.0.1", | ||
"get": { | ||
"executable": "pwsh", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is Windows PowerShell handled? PSResourceGet supports both. For PSScript DSC v3 resource there are actually two different resources to account for different versions of PowerShell.
@ThomasNieto yup! PowerShell/DSC#913 proposes a discovery extension for finding resource and extension manifests through the |
PR Summary
The initial implementation of DSC v3 resource for PSResourceGet. It include two resources, Repository and PSResources.
PR Context
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.