Add Registry Adapter and Microsoft.Windows/Personalization resource#1550
Add Registry Adapter and Microsoft.Windows/Personalization resource#1550SteveL-MSFT wants to merge 17 commits into
Microsoft.Windows/Personalization resource#1550Conversation
41f6226 to
e604361
Compare
There was a problem hiding this comment.
Pull request overview
Adds a new Windows Registry adapter (Microsoft.Windows.Adapter/Registry) plus an inline content shape for adapted resource manifests so adapters can receive structured mapping data directly. Uses the new mechanism to ship a Microsoft.Windows/Personalization adapted resource, and refactors command invocation in dsc-lib to pass DscResource directly instead of a separate CommandResourceInfo struct.
Changes:
- New manifest enum
AdaptedPathOrContent(path or inlinecontent), plumbed through discovery and stored onDscResource.adapted_content; newadaptedContentArgarg kind for get/set/delete;Adapter.listmade optional. - New registry adapter (
adapter.rs,adaptersubcommand, locale strings, manifest entry, error type) with JSON↔registry conversions for a subset of value types. - New
Microsoft.Windows/Personalizationadapted YAML manifest, project data, and Pester get/set/export tests; refactor ofcommand_resource.rs/extensions/discover.rsto dropCommandResourceInfo;get_schemanow prefers the target resource’s schema.
Reviewed changes
Copilot reviewed 21 out of 22 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/dsc-lib/src/dscresources/adapted_resource_manifest.rs | Adds AdaptedPathOrContent enum and flattens into manifest. |
| lib/dsc-lib/src/dscresources/dscresource.rs | Adds adapted_content field to DscResource. |
| lib/dsc-lib/src/dscresources/resource_manifest.rs | Adds AdaptedContent arg kinds; makes Adapter.list optional. |
| lib/dsc-lib/src/dscresources/command_resource.rs | Drops CommandResourceInfo, threads DscResource directly; handles new arg kinds; reworks get_schema. |
| lib/dsc-lib/src/discovery/command_discovery.rs | Loads content vs path; gates list invocation on optional list. |
| lib/dsc-lib/src/extensions/discover.rs | Switches to passing a DscResource for arg processing. |
| lib/dsc-lib/locales/en-us.toml | Adds noAdaptedContent localization string. |
| lib/dsc-lib-jsonschema/.versions.json | Bumps latest patch to V3_2_1. |
| tools/test_group_resource/src/main.rs | Initializes new adapted_content field. |
| resources/registry/Cargo.toml, Cargo.lock | Version bump to 1.1.0. |
| resources/registry/src/main.rs | Wires up new adapter subcommand. |
| resources/registry/src/args.rs | Adds AdapterSubCommand and SubCommand::Adapter. |
| resources/registry/src/adapter.rs | New adapter implementation and JSON↔registry conversions. |
| resources/registry/src/error.rs | New RegistryResourceError type. |
| resources/registry/registry.dsc.manifests.json | Adds Microsoft.Windows.Adapter/Registry adapter manifest. |
| resources/registry/locales/en-us.toml | Adds adapter localization strings. |
| resources/windows_personalization/windows_personalization.dsc.adaptedResource.yaml | New Personalization adapted resource with content map and embedded schema. |
| resources/windows_personalization/.project.data.json | Build copy-files entry for Windows. |
| resources/windows_personalization/personalization_{get,set,export}.tests.ps1 | New Pester tests for the Personalization resource. |
Microsoft.Windows/Personalization resource
| #[derive(Debug, Deserialize)] | ||
| enum RegistryDataType { | ||
| #[serde(rename = "REG_BINARY")] | ||
| Binary, | ||
| #[serde(rename = "REG_DWORD")] | ||
| Dword, | ||
| #[serde(rename = "REG_EXPAND_SZ")] | ||
| ExpandString, | ||
| #[serde(rename = "REG_MULTI_SZ")] | ||
| MultiString, | ||
| #[serde(rename = "REG_SZ")] | ||
| String, | ||
| #[serde(rename = "REG_QWORD")] | ||
| Qword, | ||
| } |
There was a problem hiding this comment.
This holds for all of the new structs, but I think we need to derive JSON Schema for these types and make sure we can export those / surface from the CLI / document them.
Eventually we want to be able to define this in the adapter's manifest so tools can validate the adapted resource manifest.
There was a problem hiding this comment.
Added registry adapter schema subcommand
| getProcessingKey = "Processing key: %{key}" | ||
| getNoAdaptedRegistryValueFound = "No adapted registry value found for key: %{key}" | ||
| setProcessingKey = "Setting key: %{key}" | ||
| setNoAdaptedRegistryValueFound = "No adapted registry value found for key: %{key}" |
There was a problem hiding this comment.
Can getNoAdaptedRegistryValueFound and setNoAdaptedRegistryValueFound be consolidated into a single noAdaptedRegistryValueFound since they have the exact same message?
| use tracing::{debug, trace, warn}; | ||
|
|
||
| #[derive(Deserialize)] | ||
| struct AdaptedRegistryResource { |
There was a problem hiding this comment.
Is the AdaptedRegistryResource struct definition necessary here for just a Map<String, Value> since properties is being flattened?
PR Summary
validatefunction of adapterDscResourceinstead of a different structCommandResourceInfowhen invoking a native resource as information for specific arg types comes from the resource properties, this simplifies the code and future extensibility (basically all thecommand_resourcechanges are this which was needed to add the newadaptedContentArgtypecontentproperty that can be used in adapted resource manifest instead ofpathto have inline structured content for an adapteradaptermode to Registry resource that uses thiscontentpropertyMicrosoft.Windows/Personalizationresource that uses the registry adapterPersonalizationresource. More conversions will be added if we have real use cases for them.The
Microsoft.Windows/Personalizationadapted resource manifest best shows how to use this adapter:The
contentis used by the registry adapter to map the JSON to registry key path/value/valueName/type. There is also a default value used if the key or value doesn't exist in the registry. The JSONSchema is used to enforce what is allowed.Schema for content retrieved via
registry adapter schema:{ "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "AdaptedRegistryValue", "type": "object", "properties": { "keyPath": { "type": "string" }, "valueName": { "type": "string" }, "valueType": { "$ref": "#/$defs/RegistryDataType" }, "jsonType": { "$ref": "#/$defs/JsonType" }, "mapJsonToRegistry": true, "defaultValueIfNotFound": true }, "required": [ "keyPath", "valueName", "valueType", "jsonType", "mapJsonToRegistry", "defaultValueIfNotFound" ], "$defs": { "RegistryDataType": { "type": "string", "enum": [ "REG_BINARY", "REG_DWORD", "REG_EXPAND_SZ", "REG_MULTI_SZ", "REG_SZ", "REG_QWORD" ] }, "JsonType": { "type": "string", "enum": [ "boolean", "booleanArray", "number", "numberArray", "string", "stringArray" ] } } }PR Context