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

[WinGet DSC] Add WinGetConfigRoot cmdlet #4990

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ryfu-msft
Copy link
Contributor

@ryfu-msft ryfu-msft commented Nov 19, 2024

Added a new dsc resource for ensuring that the $WinGetConfigRoot environment variable exists and is set. Added pester tests to verify that variables are set for both user and machine scope.

Some commands I tried out:

Invoke-DscResource -Name WinGetConfigRoot -Method Get -ModuleName Microsoft.WinGet.DSC -Property @{ Exist=0; Path="C:\Foo\Bar"; WinGetScope='User' }

Microsoft Reviewers: Open in CodeFlow

@ryfu-msft ryfu-msft requested a review from a team as a code owner November 19, 2024 20:05
@ryfu-msft ryfu-msft changed the title Add WinGetConfigRoot cmdlet [WinGet DSC] Add WinGetConfigRoot cmdlet Nov 19, 2024
}
else
{
[System.Environment]::SetEnvironmentVariable($this.WinGetConfigRoot, "", $this.WinGetScope)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: this could set the variable to $null to delete it instead of setting it to the empty string. According to the docs, "" does not delete the variable since .NET 9 (no idea which one this uses...)

@@ -52,6 +52,12 @@ enum WinGetTrustLevel
Trusted
}

enum WinGetScope
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this needs to be a subset of EnvironmentVariableTarget. I didn't know you could use enums like that

Small nit: if it is related to the other enum, I would add a comment for the future

class WinGetConfigRoot
{
[DscProperty(Key)]
[string]$WinGetConfigRoot = "WinGetConfigRoot"
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this property is settable by a user, there should be a test for what happens if it isn't this specific string.
If it always needs to be that string, then the Path should be the key (since Get() doesn't cause the key to be required, and you would expect Test() and Set() would always have the path, and the string should be an internal string

$result.Path | Should -Be 'C:\Foo\Bar'
$result.WinGetScope | Should -Be $_

# Remove $WinGetConfigRoot variable.
Copy link
Contributor

Choose a reason for hiding this comment

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

Before you remove it, it may be a good idea to check that if a different Path is specified while the variable exists, then the test returns false.

$result = InvokeWinGetDSC -Name WinGetConfigRoot -Method Get -Property @{WinGetScope = $_}
$result.Exist | Should -Be $true
$result.Path | Should -Be 'C:\Foo\Bar'
$result.WinGetScope | Should -Be $_
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the expected result of test if the path is not specified, but the user has requested Exist: true?

[string]$WinGetConfigRoot = "WinGetConfigRoot"

[DscProperty()]
[string]$Path = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be validation that Exist: $true cannot be used with an empty path in Set, otherwise that results in a state conflict where the user has requested a Exist to be true, but the result of the setter will always result in Exist being false

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback Issue needs attention from issue or PR author label Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Author-Feedback Issue needs attention from issue or PR author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants