Public/Start-DuneActionAssignment.ps1
|
<# .SYNOPSIS Start an action-assignment run. .DESCRIPTION POST to the `/start` endpoint for an action-assignment. Optional `Parameters` will be provided to the run and inherit from the assignment when omitted. #> function Start-DuneActionAssignment { [CmdletBinding( SupportsShouldProcess, ConfirmImpact = 'High', DefaultParameterSetName = 'Object' )] param( [Parameter(ParameterSetName = 'Object', ValueFromPipeline)] [DuneActionAssignment]$ActionAssignment, [Parameter(ParameterSetName = 'Id')] [guid]$ActionAssignmentId, [Parameter()] [object[]]$Parameters, [Parameter()] [bool]$Force = $False ) begin {} process { if ($PSCmdlet.ParameterSetName -eq 'Id') { $ActionAssignment = Get-DuneActionAssignment -Id $ActionAssignmentId } $Method = 'POST' $Uri = 'action-assignments/{0}/start' -f $ActionAssignment.Id $Body = @{ Force = $Force Parameters = @() } if ($PSBoundParameters.ContainsKey('Parameters')) { $Body.Parameters = $Parameters } else { foreach ($ActionParameter in $ActionAssignment.Parameters) { $Parameter = @{ Name = $ActionParameter.Name Description = $ActionParameter.Description Type = $ActionParameter.Type } $Value = $Null while (-not $Value) { $Value = if ($Parameters.($ActionParameter.Name)) { $Parameters.($ActionParameter.Name) } else { $ReadHost = @{ Prompt = if ($ActionParameter.value) { "{0} (Description: {1}, Type: {2}, Default: {3})" -f $ActionParameter.Name, $ActionParameter.Description, $ActionParameter.Type, $ActionParameter.value } else { "{0} (Description: {1}, Type: {2})" -f $ActionParameter.Name, $ActionParameter.Description, $ActionParameter.Type } } if ($ActionParameter.Type -eq 'securestring') { $Readhost.MaskInput = $True } $ReadHostValue = Read-Host @ReadHost if (-not $ReadHostValue -and $ActionParameter.value) { $ActionParameter.value } else { $ReadHostValue } } } $Parameter.Value = if ($ActionParameter.Type -eq 'Number') { $Value } else { ConvertTo-Json -InputObject $Value } $Body.Parameters += $Parameter } } if ($PSCmdlet.ShouldProcess(($Body | ConvertTo-Json -Depth 16))) { $Return = Invoke-DuneApiRequest -Uri $Uri -Method $Method -Body $Body $ReturnObject = if ($Return.Content) { $Return.Content | ConvertFrom-Json | ConvertTo-DuneClassObject -Class DuneJob } return $ReturnObject } } end {} } |