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

Export support for PS class-based resources #307

Merged
merged 7 commits into from
Feb 6, 2024

Conversation

anmenaga
Copy link
Collaborator

@anmenaga anmenaga commented Feb 6, 2024

PR Summary

Fix #183

2 updates:

  1. Adds Export support for provider-based resources.
    It is done using export node in *.dsc.resource.json file similar to get/set/test.
  2. Adds Export support to class-based PS resources.
    To support this a DscResource class has to implement a static Export function like so:
using namespace System.Collections.Generic

[DscResource()]
class TestClassResource
{
# omitting properties and Get,Set,Test methods here

    static [TestClassResource[]] Export()
    {
        $resultList = [List[TestClassResource]]::new()
        1..5 | %{
            $obj = New-Object TestClassResource
            $obj.Name = "Object$_"
            $obj.Prop1 = "Property of object$_"
            $resultList.Add($obj)
        }
        
        return $resultList.ToArray()
    }
}

Copy link
Member

@SteveL-MSFT SteveL-MSFT left a comment

Choose a reason for hiding this comment

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

Fix build issues. This design will allow class based resources implementing export to still work with DSC v2, right? v2 should just ignore the new export method? Ideally we should have a test to ensure we aren't breaking compat.

dsc/src/resource_command.rs Outdated Show resolved Hide resolved
dsc/src/resource_command.rs Outdated Show resolved Hide resolved
dsc/src/resource_command.rs Outdated Show resolved Hide resolved
dsc/src/resource_command.rs Outdated Show resolved Hide resolved
@anmenaga
Copy link
Collaborator Author

anmenaga commented Feb 6, 2024

This design will allow class based resources implementing export to still work with DSC v2, right?

Yes.

v2 should just ignore the new export method?

Correct.

Ideally we should have a test to ensure we aren't breaking compat.

We already test that implicitly. We are using v2 throughout PowerShellGroup resource tests.

@SteveL-MSFT SteveL-MSFT added this pull request to the merge queue Feb 6, 2024
Merged via the queue into PowerShell:main with commit b8a71fb Feb 6, 2024
4 checks passed
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.

Export support for provider-based resources
2 participants