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 exporter kind of resource #682

Merged
merged 4 commits into from
Mar 11, 2025
Merged

Conversation

SteveL-MSFT
Copy link
Member

PR Summary

Add a new kind of resource called exporter kind. This resource should only implement export method and returns JSONLines that would be a complete instance of a resource in the resources member of a configuration.

The test exporter resource would emit:

PS> dsctest exporter --input '{"typeNames":["Test/foo","Test/bar"]}'
{"name":"test","type":"Test/foo","properties":{"foo":"bar","hello":"world"}}
{"name":"test","type":"Test/bar","properties":{"foo":"bar","hello":"world"}}

This configuration:

$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json
resources:
  - name: export this
    type: Test/Exporter
    properties:
      typeNames:
        - Test/Foo
        - Test/Bar

results in:

$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
contentVersion: 1.0.0
resources:
- type: Test/Foo
  name: test
  properties:
    foo: bar
    hello: world
- type: Test/Bar
  name: test
  properties:
    foo: bar
    hello: world
metadata:
  Microsoft.DSC:
    version: 3.0.0
    operation: export
    executionType: actual
    startDatetime: 2025-03-07T11:48:49.888301-08:00
    endDatetime: 2025-03-07T11:48:49.930490-08:00
    duration: PT0.042189S
    securityContext: restricted

A normal export from a resource would only provide the contents of properties, but an exporter needs to fill in the entire resource (and optionally include things like dependsOn.

Only the input to an exporter is validated, the output only needs to conform to a proper resource within a configuration (so none of the properties are validated against a schema).

PR Context

Fix #515

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR introduces a new resource kind, "exporter", that generates complete resource instances as JSONLines when exporting a configuration. Key changes include:

  • Adding a new module (exporter.rs) with definitions for Exporter and Resource.
  • Extending the CLI (main.rs and args.rs) to support an exporter subcommand and schema.
  • Updating configuration processing (configure/mod.rs) and resource manifest (resource_manifest.rs) to incorporate the new Exporter kind.

Reviewed Changes

File Description
tools/dsctest/src/exporter.rs Adds the Exporter and Resource structs for handling exporter-specific behavior.
tools/dsctest/src/main.rs Implements the exporter subcommand, including JSON parsing and printing of resources.
dsc_lib/src/configure/mod.rs Updates configuration logic to support exporter resources by deserializing full resources.
tools/dsctest/src/args.rs Adds CLI support for the exporter subcommand and its associated schema.
dsc_lib/src/dscresources/resource_manifest.rs Introduces the Exporter variant in the resource Kind enum.

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

dsc_lib/src/configure/mod.rs:67

  • [nitpick] The inner variable 'resource' shadows an outer variable with the same name, which can be confusing. Consider renaming the inner variable (e.g., to 'parsed_resource') to improve clarity.
            let resource = serde_json::from_value::<Resource>(instance.clone())?;

@SteveL-MSFT SteveL-MSFT added this to the 3.1-Approved milestone Mar 7, 2025
@SteveL-MSFT SteveL-MSFT added this pull request to the merge queue Mar 11, 2025
Merged via the queue into PowerShell:main with commit 5e860e2 Mar 11, 2025
4 checks passed
@SteveL-MSFT SteveL-MSFT deleted the exporter branch March 11, 2025 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

exporter kind of resource
2 participants