Skip to content

Commit

Permalink
Update-Folder - new command
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Jun 14, 2021
1 parent 1de3ed0 commit a4a59a8
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/functions/folders/Update-Folder.ps1
@@ -0,0 +1,71 @@
function Update-Folder {
<#
.SYNOPSIS
Update all members of a group
.DESCRIPTION
Update all members of a group
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
$folder = Get-TssFolder -TssSession $session -Id 77
$folder.SecretPolicyId = 15
Update-TssFolder -TssSession $session -Folder $folder
Updates Folder ID 77 setting Secret Policy ID 15
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/Update-TssFolder
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/folders/Update-Folder.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,

# Folder object, output from Get-TssFolder
[Parameter(Mandatory, Position = 1)]
[TssFolder]
$Folder
)
begin {
$updateParams = $PSBoundParameters
$invokeParams = . $GetInvokeTssParams $TssSession
}
process {
Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)"
if ($updateParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000000' $PSCmdlet.MyInvocation
$folderId = $Folder.Id
$restResponse = $null
$uri = $TssSession.ApiUrl, 'folders', $folderId -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'PUT'

$invokeParams.Body = $Folder | ConvertTo-Json
if ($PSCmdlet.ShouldProcess("Folder ID: $folderId", "$($invokeParams.Method) $uri with: `n$($invokeParams.Body)")) {
Write-Verbose "$($invokeParams.Method) $uri with: `n$($invokeParams.Body)"
try {
$restResponse = . $InvokeApi @invokeParams
} catch {
Write-Warning 'Issue updating folder [$folderId]'
$err = $_
. $ErrorHandling $err
}

if ($restResponse) {
[TssFolder]$restResponse
}
}
} else {
Write-Warning 'No valid session found'
}
}
}
24 changes: 24 additions & 0 deletions tests/folders/Update-Folder.Tests.ps1
@@ -0,0 +1,24 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
[object[]]$knownParameters = 'TssSession', 'Folder'
[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
}
}
Context "Command specific details" {
It "$commandName should set OutputType to TssFolder" -TestCases $commandDetails {
$_.OutputType.Name | Should -Be 'TssFolder'
}
}
}

0 comments on commit a4a59a8

Please sign in to comment.