internal/functions/Get-ProviderContent.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function Get-ProviderContent {
  <#
  .SYNOPSIS
    Return the text for a Puppet Resource API provider given a DSC Resouce.
  .DESCRIPTION
    Return the text for a Puppet Resource API provider given a DSC Resouce.
    It will return the text but _not_ directly write out the file.
  .PARAMETER DscResource
    A DSCResourceInfo object, as retrieved by Get-DscResource.
  .EXAMPLE
    Get-DscResource -Name PSRepository | Get-ProviderContent
 
    This will retrieve a DSC resource from the PSModulePath and return the
    representation of that DSC resource appropriate for the Puppet Resource API.
  #>

  [cmdletbinding()]
  param (
    [Parameter(ValueFromPipeline)]
    [Microsoft.PowerShell.DesiredStateConfiguration.DscResourceInfo[]]$DscResource
  )

  Begin {}

  Process {
    ForEach ($Resource in $DscResource) {
      # Ensure the Name is lower case except for the first character to conform to puppet/ruby naming conventions;
      # Prepend with Dsc for namespacing considerations.
      $Name = 'Dsc' + (Get-Culture).TextInfo.ToTitleCase($Resource.Name)
      $Name = $Name -replace '[_]'
      New-Object -TypeName System.String @"
require 'puppet/provider/dsc_base_provider/dsc_base_provider'
 
# Implementation for the dsc_type type using the Resource API.
class Puppet::Provider::$Name::$Name < Puppet::Provider::DscBaseProvider
end
"@

    }
  }

  End {}

}