Skip to content
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

Microsoft.WinGet.DSC improvements (and breaking change) #4795

Merged
merged 14 commits into from
Sep 10, 2024

Conversation

JohnMcPMS
Copy link
Member

@JohnMcPMS JohnMcPMS commented Sep 5, 2024

The goal of this PR is to get these resources to a state where we feel ready to release the module without the prerelease tag. The WinGetUserSettings, WinGetAdminSettings, and WinGetPackageManager resources were deemed acceptable in their current state. The WinGetSources resource was decided to be overly complicated and likely not heavily used yet (and containing some bugs), so it was removed in favor of a new WinGetSource resource for managing individual sources. The WinGetPackage resource was updated to be better in line with best practices but should still be compatible unless one was using Get.

Change

The WinGetSources resource was replaced with a WinGetSource resource that manages a single source. The WinGetSources resource can continue to be used by specifying one of the module versions that contains it, but once released, new configurations should prefer the WinGetSource resource from the latest module.

While there is no way to include or discover help via the module, I documented the resources similarly to the cmdlet documentation format. These can be used as the basis for official documentation, or we can put a link to them in the PowerShell Gallery listing (maybe updating the Project Site to point to a new landing page for the DSC resources).

The updates to WinGetPackage aim to have it follow best practices and make general improvements:

  • Mark Source as a Key
  • Validate with existing attributes where possible
  • Not updating $this in calls to Get/Set/Test
  • Using the configurable properties to report values with Get
    • IsInstalled is reported via Ensure (true => Present, false => Absent)
    • InstalledVersion is reported via Version
    • IsUpdateAvailable is reported via UseLatest (they will have the opposite boolean value from each other)

Any existing (non-Get) uses of the resource should continue to work as they did before.

Smaller updates worth mentioning:

  • Updated the winget configure validate functionality to handle the new WinGetSource resource instead of WinGetSources.
  • Removed the error when giving both a Version and UseLatest to the WinGetPackage resource. UseLatest will override any Version provided if it is true.
  • Fixed a bug with COM PackageCatalogInfo::TrustLevel property reporting None improperly if the internal trust level contained both Trusted and another flag.
  • Renamed all of the enums in the module as there is no namespacing for enums/classes in PowerShell.

Validation

Manual verification of basics locally to ensure golden path functionality.
Updated existing tests to cover changes, including adding new fields.

Microsoft Reviewers: Open in CodeFlow

@JohnMcPMS JohnMcPMS requested a review from a team as a code owner September 5, 2024 22:48
context.Reporter.Error() << Resource::String::WinGetResourceUnitMissingRequiredArg(Utility::LocIndView{ UnitType_WinGetSource }, "Name"_liv) << std::endl;
foundIssues = true;
}
if (source.Arg.empty())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this require arg even when ensuring the source is absent?

I'm just thinking about how that may be inconsistent with winget source remove <name>. Although, for DSC, requiring the arg may be a good thing in case a user wants to remove a source and replace it with a new source of the same name but with a different arg. . .

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code wasn't originally written to be Ensure aware. You are correct that during Absent only the Name is required.

{
$removeSource = $true
}
else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I like more the else comment like 265, but at least both should be consistent

# Sets the desired properties.
[void] Set()

[bool] hidden TestAgainstCurrent([WinGetSource]$currentSource)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to go back on why there's no comparison of Name. You don't want to call Get here because you don't want two Get-WinGetSource in Set. Maybe add a comment?

[DscProperty(Mandatory)]
[Hashtable[]]$Sources

[string]$Argument
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need [ValidateNotNullOrWhiteSpace()] here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because if Ensure = Absent we don't want to require an argument value (although from my testing it seems like the validation only happens during assignment). If someone provides an empty argument they will still get an error, just from deeper in the stack.

@@ -52,7 +52,7 @@ else
{
Write-Host "PowerToys 0.65.0 is not installed."

Invoke-DscResource @resource -Method Set
#Invoke-DscResource @resource -Method Set
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't want the sample to install PowerToys?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to revert that after testing the script.

msftrubengu
msftrubengu previously approved these changes Sep 6, 2024
@JohnMcPMS JohnMcPMS merged commit 9116d5d into microsoft:master Sep 10, 2024
9 checks passed
@JohnMcPMS JohnMcPMS deleted the dsc-ready branch September 10, 2024 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants