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

Break DSC Splatted Resource out to its own repo #13

Open
1 task
VertigoRay opened this issue Apr 11, 2018 · 3 comments
Open
1 task

Break DSC Splatted Resource out to its own repo #13

VertigoRay opened this issue Apr 11, 2018 · 3 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed
Milestone

Comments

@VertigoRay
Copy link
Member

VertigoRay commented Apr 11, 2018

The is a resource function that should be managed and tested independently, but potentially with other tools:

This function was adapted from code I took from @gaelcolas's Get-DscSplattedResource function. Should likely rename to New-DscSplattedResource to avoid conflicts with the Datum function.

I'm thinking a new module called: DscSplattedResource. Alternatively, we could discuss adding it to gaelcolas/DscBuildHelpers (or somewhere else), but the documentation on that particular repo would have to be significantly improved.

Be sure to ...

  • Update REQUIREMENTS.psd1.
@gaelcolas
Copy link

Feel free to open an issue in the appropriate repo

@VertigoRay
Copy link
Member Author

It's an issue here because:

  • I've significantly changed the code from your function, although functionality should remain the same.
  • It's embedded within this repo's composite resource:
    function Get-DscSplattedResource
    {
    [CmdletBinding()]
    Param(
    [Parameter(Mandatory = $true)]
    [string]
    $ResourceName
    ,
    [Parameter(Mandatory = $true)]
    [string]
    $ExecutionName
    ,
    [Parameter()]
    [hashtable]
    $Usings
    ,
    [Parameter(Mandatory = $true)]
    [hashtable]
    $Properties
    ,
    [Parameter()]
    [switch]
    $NoInvoke
    )
    Write-Verbose "[OneDrive] Get-DscSplattedResource: $($PSBoundParameters | ConvertTo-Json -Compress)"
    $StringBuilder = [System.Text.StringBuilder]::new()
    $StringBuilder.AppendLine("`$Properties = @{") | Out-Null
    foreach ($Property in $Properties.GetEnumerator())
    {
    $PropertyStringBuilder = [System.Text.StringBuilder]::new()
    if ($Property.Value -is [scriptblock])
    {
    $PropertyStringBuilder.AppendLine(" $($Property.Name) = {") | Out-Null
    $PropertyStringBuilder.AppendLine($Property.Value) | Out-Null
    $PropertyStringBuilder.AppendLine(' };') | Out-Null
    }
    else
    {
    $PropertyStringBuilder.AppendLine(" $($Property.Name) = ('$($Property.Value | ConvertTo-Json -Compress)' | ConvertFrom-Json);") | Out-Null
    }
    $StringBuilder.AppendLine($PropertyStringBuilder.ToString()) | Out-Null
    }
    $StringBuilder.AppendLine("}") | Out-Null
    $StringBuilder.AppendLine() | Out-Null
    foreach ($u in $Usings.GetEnumerator())
    {
    if ($u -is [scriptblock])
    {
    $StringBuilder.AppendLine("`$$($u.Name) = {") | Out-Null
    $StringBuilder.AppendLine($u.Value) | Out-Null
    $StringBuilder.AppendLine("}") | Out-Null
    }
    else
    {
    $StringBuilder.AppendLine("`$$($u.Name) = '$($u.Value | ConvertTo-Json -Compress)' | ConvertFrom-Json") | Out-Null
    }
    }
    $StringBuilder.AppendLine() | Out-Null
    $StringBuilder.AppendLine("${ResourceName} ${ExecutionName} {") | Out-Null
    foreach ($PropertyName in $Properties.Keys)
    {
    $StringBuilder.AppendLine(" ${PropertyName} = `$Properties.$PropertyName") | Out-Null
    }
    $StringBuilder.AppendLine("}") | Out-Null
    Write-Verbose "[OneDrive] Get-DscSplattedResource StringBuilder:`n$($StringBuilder.ToString())"
    if ($NoInvoke)
    {
    Write-Verbose "[OneDrive] Get-DscSplattedResource Returning StringBuilder"
    return [scriptblock]::Create($StringBuilder.ToString())
    }
    else
    {
    Write-Verbose "[OneDrive] Get-DscSplattedResource Invoking: $($StringBuilder.ToString())"
    [scriptblock]::Create($StringBuilder.ToString()).Invoke()
    }
    }

After giving it much thought, I'd rather collaborate on it with you and will be making a PR on gaelcolas/DscBuildHelpers.

@VertigoRay
Copy link
Member Author

VertigoRay commented Apr 14, 2018

PR Submitted in DscBuildHelpers. If it gets merged, I'll close this one out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants