Add Group Policy template adapter - #1686
Open
Steve Lee (SteveL-MSFT) wants to merge 1 commit into
Open
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new Rust-based DSC adapter (Microsoft.Adapter/GroupPolicyTemplate) that discovers locally installed Windows Group Policy ADMX/ADML templates and exposes them as dynamically generated DSC resources, with get/set backed by registry operations.
Changes:
- Adds a new
adapters/group_policy_templatecrate implementing ADMX parsing, schema generation, and registry-backed get/set. - Registers the adapter in the workspace (members/default-members/Windows set) and adds required dependencies (
roxmltree, Windows globalization feature). - Adds Pester + Rust unit tests to validate discovery and a basic current-user mutation scenario.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| Cargo.toml | Adds the new adapter crate to workspace membership and adds dependencies/features needed for XML + locale support. |
| Cargo.lock | Locks the new adapter crate and roxmltree dependency. |
| adapters/group_policy_template/Cargo.toml | Defines the new adapter crate and its dependencies/targets. |
| adapters/group_policy_template/src/main.rs | Implements adapter CLI dispatch (list/get/set), stdout output, and structured JSON error reporting. |
| adapters/group_policy_template/src/admx.rs | Implements ADMX/ADML discovery, locale resolution, resource modeling, and JSON Schema generation. |
| adapters/group_policy_template/src/registry.rs | Implements policy state read/write logic by mapping scope to HKCU/HKLM and applying registry value semantics. |
| adapters/group_policy_template/locales/en-us.toml | Adds i18n strings for user-facing adapter messages. |
| adapters/group_policy_template/group_policy_template.dsc.resource.json | Adds the DSC adapter manifest wiring list/get/set to the new executable. |
| adapters/group_policy_template/tests/group_policy_template.tests.ps1 | Adds Pester coverage for discovery and an elevated current-user mutation test with restoration. |
| adapters/group_policy_template/.project.data.json | Registers the adapter in repo metadata/build packaging (binary + copy files). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+107
to
+122
| fn read_enabled(policy: &Policy, scope: &str) -> Result<Option<bool>, AdapterError> { | ||
| if state_matches(policy, scope, true)? { | ||
| Ok(Some(true)) | ||
| } else if state_matches(policy, scope, false)? { | ||
| Ok(Some(false)) | ||
| } else { | ||
| Err(AdapterError::Resource( | ||
| t!( | ||
| "registry.unrecognizedValue", | ||
| key = policy.key, | ||
| value_name = policy.value_name.as_deref().unwrap_or_default() | ||
| ) | ||
| .to_string(), | ||
| )) | ||
| } | ||
| } |
Comment on lines
+142
to
+145
| for entry in entries { | ||
| let path = entry | ||
| .map_err(|error| AdapterError::Resource(error.to_string()))? | ||
| .path(); |
| $LASTEXITCODE | Should -Be 0 | ||
| $admxFiles.Count | Should -BeGreaterThan 0 | ||
| $resources.Count | Should -BeGreaterThan 0 | ||
| $resources.requireAdapter | Should -Contain $adapterType |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Windows Group Policy templates vary by machine, so DSC needs a dynamic adapter that discovers the locally installed ADMX definitions and exposes them as manageable resources.
This adds the Rust-based
Microsoft.Adapter/GroupPolicyTemplateadapter. It scans%SystemRoot%\PolicyDefinitions, resolves localized ADML strings, groups policies into adaptedGPO.<parentCategory>/<category>resources, and generates JSON Schema for policy toggles and ADMX child elements. Get and set operations map user and machine scope to HKCU and HKLM while preserving ADMX registry value types, delete semantics, policy class restrictions, and enabled/disabled value lists.Pester coverage verifies adapter discovery against installed ADMX files and includes an elevated, current-user-only mutation test with state restoration. Rust unit tests cover naming, binary parsing, and scope-to-hive mapping.