Skip to content

Class-based resource capabilities in module manifest #852

@ThomasNieto

Description

@ThomasNieto

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

Summary

There is an option in the module manifest to set which capabilities are present for a resource however that applies to all resources in the module and not to individual resources.

# Provide a way for existing resources to specify their capabilities, or default to Get, Set, Test
# TODO: for perf, it is better to take capabilities from psd1 in Invoke-DscCacheRefresh, not by extra call to Get-Module
if ($DscResourceInfo.ModuleName) {
$module = Get-Module -Name $DscResourceInfo.ModuleName -ListAvailable | Sort-Object -Property Version -Descending | Select-Object -First 1
if ($module.PrivateData.PSData.DscCapabilities) {
$capabilities = $module.PrivateData.PSData.DscCapabilities
}
else {
$capabilities = @('get', 'set', 'test')
}
}

The schema should be updated to allow individual resources to specify their capabilities.

PSData = @{
  DscCapabilities = @{
    TestClassResource = @('get', test', 'export)
    NoExport = @('get', test')
  }
}

The ideal state is to allow class-based resources to not have to implement all methods. This could be done by checking the AST if the method contains a throw [NotImplementedException]::new() so that the code and capabilities match at all times.

Steps to reproduce

n/a

Expected behavior

n/a

Actual behavior

n/a

Error details

Environment data

n/a

Version

3.1-preview6

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Reviewed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions