Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
function Set-SecretTemplate { | ||
<# | ||
.SYNOPSIS | ||
Set Secret Template active or inactive | ||
.DESCRIPTION | ||
Set Secret Template active or inactive | ||
.EXAMPLE | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
Set-TssSecretTemplate -TssSession $session -Id 6093 -Active:$false | ||
Sets Secret Template 6093 Active to false or90 | ||
.LINK | ||
https://thycotic-ps.github.io/thycotic.secretserver/commands/Set-TssSecretTemplate | ||
.LINK | ||
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/Folder name/Set-SecretTemplate.ps1 | ||
.NOTES | ||
Requires TssSession object returned by New-TssSession | ||
#> | ||
[cmdletbinding(SupportsShouldProcess)] | ||
param( | ||
# TssSession object created by New-TssSession for auth | ||
[Parameter(Mandatory,ValueFromPipeline,Position = 0)] | ||
[TssSession] | ||
$TssSession, | ||
|
||
# Secret Template ID | ||
[Parameter(Mandatory,ValueFromPipelineByPropertyName)] | ||
[Alias("TemplateId")] | ||
[int[]] | ||
$Id, | ||
|
||
# Set template active | ||
[Parameter(Mandatory)] | ||
[switch] | ||
$Active | ||
) | ||
begin { | ||
$setParams = $PSBoundParameters | ||
$invokeParams = . $GetInvokeTssParams $TssSession | ||
} | ||
process { | ||
Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)" | ||
if ($setParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) { | ||
. $CheckVersion $TssSession '10.9.000000' $PSCmdlet.MyInvocation | ||
foreach ($template in $Id) { | ||
$restResponse = $null | ||
$uri = $TssSession.ApiUrl, 'secret-templates', $template -join '/' | ||
$invokeParams.Uri = $uri | ||
$invokeParams.Method = 'PATCH' | ||
|
||
$setBody = @{ | ||
data = @{ | ||
active = @{ | ||
dirty = $true | ||
value = [boolean]$Active | ||
} | ||
} | ||
} | ||
$invokeParams.Body = $setBody | ConvertTo-Json | ||
|
||
if ($PSCmdlet.ShouldProcess("Secret Template ID: $template", "$($invokeParams.Method) $uri with:`n$($invokeParams.Body)`n")) { | ||
Write-Verbose "Performing the operation $($invokeParams.Method) $uri with:`n$($invokeParams.Body)`n" | ||
try { | ||
$restResponse = . $InvokeApi @invokeParams | ||
} catch { | ||
Write-Warning "Issue setting Secret Template [$template]" | ||
$err = $_ | ||
. $ErrorHandling $err | ||
} | ||
if ($restResponse.success) { | ||
Write-Verbose "Secret Template [$template] set to $Active" | ||
} else { | ||
Write-Warning "Secret Template [$template] not updated" | ||
} | ||
} | ||
} | ||
} else { | ||
Write-Warning "No valid session found" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
BeforeDiscovery { | ||
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf | ||
} | ||
Describe "$commandName verify parameters" { | ||
BeforeDiscovery { | ||
[object[]]$knownParameters = 'TssSession', 'Id', 'Active' | ||
[object[]]$currentParams = ([Management.Automation.CommandMetaData]$ExecutionContext.SessionState.InvokeCommand.GetCommand($commandName,'Function')).Parameters.Keys | ||
[object[]]$commandDetails = [System.Management.Automation.CommandInfo]$ExecutionContext.SessionState.InvokeCommand.GetCommand($commandName,'Function') | ||
$unknownParameters = Compare-Object -ReferenceObject $knownParameters -DifferenceObject $currentParams -PassThru | ||
} | ||
Context "Verify parameters" -Foreach @{currentParams = $currentParams } { | ||
It "$commandName should contain <_> parameter" -TestCases $knownParameters { | ||
$_ -in $currentParams | Should -Be $true | ||
} | ||
It "$commandName should not contain parameter: <_>" -TestCases $unknownParameters { | ||
$_ | Should -BeNullOrEmpty | ||
} | ||
} | ||
} |