Public/Save-Challenge.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function Save-Challenge {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory,Position=0)]
        [ValidateScript({Test-ValidPlugin $_ -ThrowOnFail})]
        [string]$Plugin,
        [Parameter(Position=1)]
        [hashtable]$PluginArgs
    )

    Write-Verbose "Saving changes for $Plugin plugin"

    # dot source the plugin file
    $pluginDetail = $script:Plugins.$Plugin
    . $pluginDetail.Path

    # All plugins in $script:Plugins should have been validated during module
    # load. So we're not going to do much plugin-specific validation here.

    # do stuff appropriate for the challenge type
    if ('dns-01' -eq $pluginDetail.ChallengeType) {

        Write-Debug "Calling $Plugin plugin to save"

        # call the function with the required parameters and splatting the rest
        Save-DnsTxt @PluginArgs

    } else { # http-01 is the only other challenge type we support at the moment

        Write-Debug "Calling $Plugin plugin to save"

        # call the function with the required parameters and splatting the rest
        Save-HttpChallenge @PluginArgs

    }



    <#
    .SYNOPSIS
        Commit changes made by Publish-Challenge or Unpublish-Challenge.
 
    .DESCRIPTION
        Some validation plugins require a finalization step after the Publish or Unpublish functionality to commit and make the changes live. This function should be called once after running all of the Publish-Challenge or Unpublish-Challenge commands.
 
        For plugins that don't require a commit step, this function may still be run without causing an error, but does nothing.
 
    .PARAMETER Plugin
        The name of the validation plugin to use. Use Get-PAPlugin to display a list of available plugins.
 
    .PARAMETER PluginArgs
        A hashtable containing the plugin arguments to use with the specified plugin. So if a plugin has a -MyText string and -MyNumber integer parameter, you could specify them as @{MyText='text';MyNumber=1234}.
 
    .EXAMPLE
        Save-Challenge Manual @{}
 
        Commit changes using the Manual DNS plugin that requires no plugin arguments.
 
    .EXAMPLE
        Save-Challenge MyPlugin @{Param1='asdf';Param2=1234}
 
        Commit changes for a set of challenges using a fictitious plugin and arguments.
 
    .LINK
        Project: https://github.com/rmbolger/Posh-ACME
 
    .LINK
        Publish-Challenge
 
    .LINK
        Unpublish-Challenge
 
    .LINK
        Get-PAPlugin
 
    #>

}