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

Config code #2942

Merged
merged 33 commits into from Feb 15, 2023
Merged

Config code #2942

merged 33 commits into from Feb 15, 2023

Conversation

JohnMcPMS
Copy link
Member

@JohnMcPMS JohnMcPMS commented Feb 9, 2023

This work is a small part of #2845

Change

Introduces a new component, Microsoft.Management.Configuration. This is the API surface for controlling the configuration of the system for a user (with the intention that any user can run it, including SYSTEM). There are extensive details on the API in this document, so I will not repeat them here.

The API is not fully implemented by this change, only the baseline functionality for reading configuration files and acting on them immediately. None of the history functionality is present, nor any ability to serialize files. However, this should be sufficient to create an initial, golden path implementation of user interactive surfaces.

Speaking of the user interface, the plan is to add functionality to both winget and PowerShell. The winget implementation will come first, if only because it is easier to integrate there in general. The PowerShell module is expected to ship simultaneously with a supported release.

In addition to this portion, the back-end functionality is coming soon in a separate PR.

Validation

New unit tests are added specifically for this component.

Microsoft Reviewers: Open in CodeFlow
Microsoft Reviewers: Open in CodeFlow

@JohnMcPMS JohnMcPMS requested a review from a team as a code owner February 9, 2023 03:36
@github-actions

This comment has been minimized.

SemanticVersion(const std::string& version) :
SemanticVersion(std::string(version)) {}

void Assign(std::string version, std::string_view splitChars = DefaultSplitChars) override;
Copy link
Member

Choose a reason for hiding this comment

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

Not std::string&& or const std::string& ?

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 is the signature of the virtual Assign method. I do move version in the implementation.

There is an argument for the non-constructor based call to Assign to also allow a const& version to maximize efficiency, but it isn't really worth the effort to keep two versions of the same method that only differ in how they assign to m_version.

Comment on lines +1 to +5
// -----------------------------------------------------------------------------
// <copyright file="UnitTestCollection.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
// </copyright>
// -----------------------------------------------------------------------------
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// -----------------------------------------------------------------------------
// <copyright file="UnitTestCollection.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
// </copyright>
// -----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

Copy link
Member Author

Choose a reason for hiding this comment

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

We use the C# standard header in our other C# files. Not sure if that is "the right thing to do", but it is the current convention.

/// <summary>
/// Gets the message sink for the fixture.
/// </summary>
public IMessageSink MessageSink { 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.

Suggested change
public IMessageSink MessageSink { get; private set; }
public IMessageSink MessageSink { get; init; }

Not sure if we're on the right version for this, or if it does what I think it does...

Copy link
Member Author

Choose a reason for hiding this comment

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

It does, but I still want private init because I want the constructor path to be used. public init would be a good way to provide optional construction-time parameters though.

#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Storage.Streams.h>

// TODO: Is this needed?
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?

Copy link
Member Author

Choose a reason for hiding this comment

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

The comment, no. What it was referring to, honestly I have no idea 😉

Comment on lines 12 to 15
Unknown,
Pending,
InProgress,
Completed,
Copy link
Member

Choose a reason for hiding this comment

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

Do we need/want to add comments to each value? I thought the docs were automagically generated from the IDL for English.

Copy link
Member Author

@JohnMcPMS JohnMcPMS Feb 10, 2023

Choose a reason for hiding this comment

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

I'm not aware of automagic documentation, but I can add comments.

Windows.Foundation.Collections.ValueSet Directives{ get; };

// Contains the values that are for use by the configuration unit itself.
Windows.Foundation.Collections.ValueSet Settings{ get; };
Copy link
Member

Choose a reason for hiding this comment

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

How is this different from IConfigurationUnitSettingDetails?

Copy link
Member Author

Choose a reason for hiding this comment

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

These are the settings values to use for the particular unit of configuration being described by the object. IConfigurationUnitSettingDetails is a description of the settings value available for the configuration unit.

Basically the difference between the actual values passed in to the command line for winget (this Settings) and the help output by winget for the command (IConfigurationUnitSettingDetails).

Comment on lines +193 to +197
// The state of the configuration set for this event (the ConfigurationSet can be used to get the current state, which may be different).
ConfigurationSetState SetState{ get; };

// The state of the configuration unit for this event (the ConfigurationUnit can be used to get the current state, which may be different).
ConfigurationUnitState UnitState{ get; };
Copy link
Member

Choose a reason for hiding this comment

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

We only have one of those at a time depending on the type?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, and it doesn't seem worthwhile to create three runtime classes and require a QI to get any useful data out.

// The state that the set is in.
ConfigurationSetState State{ get; };
// The time that this set was recorded with intent to apply.
Windows.Foundation.DateTime InitialIntent{ get; };
Copy link
Member

Choose a reason for hiding this comment

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

The name of this property makes me think "what was the initial intent", not "when was the initial intent"

Copy link
Member Author

Choose a reason for hiding this comment

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

True, I wrote this "intent" before I added the other "intent" property. Changed to FirstApply unless there are other suggestions.

Comment on lines +319 to +325
TestSettingsResult TestSettings();

// Gets the current system state for the configuration unit.
GetSettingsResult GetSettings();

// Applies the state described in the configuration unit.
ApplySettingsResult ApplySettings();
Copy link
Member

Choose a reason for hiding this comment

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

Here we use Test/Get/Apply, but elsewhere it was Assert/Inform/Apply

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 wanted to separate the semantics, but maybe it is also confusing...


// The result of applying the settings for a configuration unit.
[contract(Microsoft.Management.Configuration.Contract, 1)]
runtimeclass ApplyConfigurationUnitResult
Copy link
Member

Choose a reason for hiding this comment

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

What's the difference with ApplySettingsResult?

Copy link
Member Author

Choose a reason for hiding this comment

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

ApplyConfigurationUnitResult is the interface for users of Microsoft.Management.Configuration. ApplySettingsResult is the interface for implementors of IConfigurationUnitProcessor.

Copy link
Contributor

@msftrubengu msftrubengu left a comment

Choose a reason for hiding this comment

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

:shipit:

<IntDir>$(PlatformTarget)\$(Configuration)\</IntDir>
<TargetName>$(RootNamespace)</TargetName>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
<RunCodeAnalysis>false</RunCodeAnalysis>
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 we should turn it on in debug builds to match other libs we build

{CA460806-5E41-4E97-9A3D-1D74B433B663}.TestRelease|x86.Build.0 = Release|Win32
{E8454BF1-2068-4513-A525-ABF55CC8742C}.Debug|Any CPU.ActiveCfg = Debug|x64
{E8454BF1-2068-4513-A525-ABF55CC8742C}.Debug|ARM.ActiveCfg = Debug|Any CPU
{E8454BF1-2068-4513-A525-ABF55CC8742C}.Debug|ARM.Build.0 = Debug|Any CPU
Copy link
Contributor

Choose a reason for hiding this comment

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

ARM should point to ARM?

I saw Release and TestRelease below all point to Any Cpu by the way

{EE43C990-7789-4A60-B077-BF0ED3D093A1}.Debug|Any CPU.ActiveCfg = Debug|x64
{EE43C990-7789-4A60-B077-BF0ED3D093A1}.Debug|ARM.ActiveCfg = Debug|x64
{EE43C990-7789-4A60-B077-BF0ED3D093A1}.Debug|ARM.Build.0 = Debug|x64
{EE43C990-7789-4A60-B077-BF0ED3D093A1}.Debug|ARM64.ActiveCfg = Debug|arm64
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Arm should point to Arm for consistency

{EE43C990-7789-4A60-B077-BF0ED3D093A1}.Debug|x86.Build.0 = Debug|x86
{EE43C990-7789-4A60-B077-BF0ED3D093A1}.Fuzzing|Any CPU.ActiveCfg = Debug|x64
{EE43C990-7789-4A60-B077-BF0ED3D093A1}.Fuzzing|Any CPU.Build.0 = Debug|x64
{EE43C990-7789-4A60-B077-BF0ED3D093A1}.Fuzzing|ARM.ActiveCfg = Debug|x64
Copy link
Contributor

Choose a reason for hiding this comment

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

Arm -> Arm

And all below instances

@JohnMcPMS JohnMcPMS merged commit 6e43f91 into microsoft:master Feb 15, 2023
@JohnMcPMS JohnMcPMS deleted the config-code branch February 15, 2023 04:37
msftrubengu added a commit that referenced this pull request Mar 1, 2023
Microsoft.Management.Configuration.Process is a cswinrt component that provides implementation of `IConfigurationSetProcessor`, `IConfigurationUnitProcessor`, `IConfigurationUnitProcessorDetails`, `IConfigurationUnitSettingDetails` and `IConfigurationProcessorFactory` defined in #2942 as well as new runtime classes and an interface.

`ConfigurationSetProcessorFactory` implements `IConfigurationProcessorFactory`, which takes the type of configuration and optional `IConfigurationProcessorFactoryProperties` with additional properties that need to be defined for the processor set. An implementation of `IConfigurationProcessorFactoryProperties` is also provided.

Internally, it uses PowerShell Host to find and install DSC modules and apply them via InvokeDscResource.

Requires [PSDesiredStateConfiguration 2.0.6](https://www.powershellgallery.com/packages/PSDesiredStateConfiguration/2.0.6)
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.

None yet

4 participants