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

Add pwsh support for trust level and explicit #4750

Merged
merged 5 commits into from
Sep 5, 2024

Conversation

ryfu-msft
Copy link
Contributor

@ryfu-msft ryfu-msft commented Aug 22, 2024

Adds support for -TrustLevel and -Explicit.

The pwsh tests can now use the Add-winGetsource cmdlet to modify the trust level.

Updated Get-WinGetsource to report the TrustLevel and Explicit flag.

Updated tests and docs to reflect these changes.

Microsoft Reviewers: Open in CodeFlow

@ryfu-msft ryfu-msft requested a review from a team as a code owner August 22, 2024 19:21
@ryfu-msft ryfu-msft marked this pull request as draft August 22, 2024 19:21

This comment has been minimized.

@ryfu-msft
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines could not run because the pipeline triggers exclude this branch/path.

@ryfu-msft ryfu-msft marked this pull request as ready for review August 22, 2024 19:50
@ryfu-msft
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines could not run because the pipeline triggers exclude this branch/path.

@ryfu-msft ryfu-msft marked this pull request as draft August 22, 2024 19:51
@@ -262,6 +262,12 @@ namespace Microsoft.Management.Deployment
PackageCatalogOrigin Origin { get; };
/// The trust level of the package catalog
PackageCatalogTrustLevel TrustLevel { get; };

[contract(Microsoft.Management.Deployment.WindowsPackageManagerContract, 10)]
Copy link
Member

Choose a reason for hiding this comment

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

You can't add things to contract 10, it shipped with 1.7.

On a related note, when you add contract 11 at the top of the file, put a comment above it like // For version 1.9

@florelis
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ryfu-msft
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

if (string.IsNullOrEmpty(type))
{
_ = this.Run("source", $"add --name {name} --arg {arg}", 300000);
parameters = $"add --name {name} --arg {arg}";
Copy link
Member

Choose a reason for hiding this comment

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

Not related to this change, but this code is not resilient to spaces in the arguments.

/// <summary>
/// Gets the trust level of the source.
/// </summary>
public string TrustLevel { get; private set; }
Copy link
Member

Choose a reason for hiding this comment

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

Why is this a string and not a PSSourceTrustLevel?

Maybe that is normal in PowerShell, it just seems odd to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

The main reason is not load any dependency when the CLR loads this binary as the ALC hasn't been being configured yet at this point. For cswinrt enums, there are PSSomething equivalents that get converted to string and then converted to the cswinrt representation in the engine module. Since this doesn't have it he had to go with strings,

Copy link
Member

Choose a reason for hiding this comment

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

Is it that we can't have a dependency inversion with Engine taking a dependency on Cmdlets? And we can't have this kind of immediate dependency on Engine in types exposed on the interface of any cmdlet because we don't have the ALC yet to resolve it (thus preventing us from putting PSSourceTrustLevel in Engine)?

In any case, I don't have a problem with it being a string. Just wasn't clear why.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, we don't want to have the dependency on Engine until the ALC is setup

@JohnMcPMS
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@JohnMcPMS JohnMcPMS marked this pull request as ready for review September 4, 2024 23:24
switch (trustLevel)
{
case PSSourceTrustLevel.None:
trustLevelString = "None";
Copy link
Contributor

Choose a reason for hiding this comment

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

You could do switch return with PSSourceTrusLevel.Default => string.Empty and _ being trustLevel.ToString()

Copy link
Member

Choose a reason for hiding this comment

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

Changed it to your fancy switch pattern syntax.

/// <summary>
/// Gets the trust level of the source.
/// </summary>
public string TrustLevel { get; private set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

The main reason is not load any dependency when the CLR loads this binary as the ALC hasn't been being configured yet at this point. For cswinrt enums, there are PSSomething equivalents that get converted to string and then converted to the cswinrt representation in the engine module. Since this doesn't have it he had to go with strings,

@JohnMcPMS JohnMcPMS merged commit 19b3b5e into microsoft:master Sep 5, 2024
9 checks passed
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.

4 participants