Skip to content

Commit

Permalink
Folder Functions - code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Mar 13, 2021
1 parent dc88291 commit b98dc96
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 232 deletions.
2 changes: 1 addition & 1 deletion src/classes/folders/TssFolderLookup.class.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ class TssFolderLookup {
$Id

[string]
$FolderName
$Value
}
4 changes: 4 additions & 0 deletions src/classes/general/TssDelete.class.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ class TssDelete {

[string]
$ObjectType

hidden
[string[]]
$ResponseCodes
}
9 changes: 4 additions & 5 deletions src/functions/folders/Find-Folder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ function Find-Folder {
[OutputType('TssFolderLookup')]
param (
# TssSession object created by New-TssSession for auth
[Parameter(Mandatory,
ValueFromPipeline,
Position = 0)]
[TssSession]$TssSession,
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[TssSession]
$TssSession,

# Parent Folder Id
[Alias("FolderId")]
Expand Down Expand Up @@ -98,7 +97,7 @@ function Find-Folder {
Write-Warning "No Folder found"
}
if ($restResponse.records) {
. $TssFolderLookupObject $restResponse.records
[TssFolderLookup[]]$restResponse.records
}
} else {
Write-Warning "No valid session found"
Expand Down
9 changes: 4 additions & 5 deletions src/functions/folders/Get-Folder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ function Get-Folder {
[OutputType('TssFolder')]
param(
# TssSession object created by New-TssSession for auth
[Parameter(Mandatory,
ValueFromPipeline,
Position = 0)]
[TssSession]$TssSession,
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[TssSession]
$TssSession,

# Folder ID to retrieve
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
Expand Down Expand Up @@ -83,7 +82,7 @@ function Get-Folder {
}

if ($restResponse) {
. $TssFolderObject $restResponse
[TssFolder[]]$restResponse
}
}
} else {
Expand Down
9 changes: 4 additions & 5 deletions src/functions/folders/Get-FolderAudit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ function Get-FolderAudit {
[OutputType('TssFolderAuditSummary')]
param (
# TssSession object created by New-TssSession for auth
[Parameter(Mandatory,
ValueFromPipeline,
Position = 0)]
[TssSession]$TssSession,
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[TssSession]
$TssSession,

# Short description for parameter
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
Expand Down Expand Up @@ -59,7 +58,7 @@ function Get-FolderAudit {
}

if ($restResponse.records) {
. $TssFolderAuditSummaryObject $restResponse.records
[TssFolderAuditSummary[]]$restResponse.records
}
}
} else {
Expand Down
9 changes: 4 additions & 5 deletions src/functions/folders/Get-FolderStub.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ function Get-FolderStub {
[OutputType('TssFolder')]
param (
# TssSession object created by New-TssSession for auth
[Parameter(Mandatory,
ValueFromPipeline,
Position = 0)]
[TssSession]$TssSession
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[TssSession]
$TssSession
)
begin {
$tssParams = $PSBoundParameters
Expand All @@ -52,7 +51,7 @@ function Get-FolderStub {
}

if ($restResponse) {
. $TssFolderObject $restResponse
[TssFolder]$restResponse
}
} else {
Write-Warning "No valid session found"
Expand Down
69 changes: 20 additions & 49 deletions src/functions/folders/New-Folder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,31 @@ function New-Folder {
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
$folderStub = Get-TssFolderStub -TssSession $session
New-TssFolder -TssSession $session -FolderStub $folderStub -FolderName 'tssNewFolder' -ParentFolderId -1
$folderStub.FolderName = 'tssNewFolder'
$folderStub.ParentFolderId = -1
New-TssFolder -TssSession $session -FolderStub $folderStub
Creates a folder named "tssNewFolder" at the root of Secret Server application
Creates a new root folder, named "tssNewFolder"
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
$folderStub = Get-TssFolderStub -TssSession $session
New-TssFolder -TssSession $session -FolderStub $folderStub -FolderName 'IT Dept' -ParentFolderId 27 -InheritPermissions:$false
$folderStub.FolderName 'IT Dept'
$folderStub.ParentFolderId = 27
$folderStub.InheritPermissions = $false
New-TssFolder -TssSession $session -FolderStub $folderStub
Creates a folder named "IT Dept" under parent folder 27 with Inherit Permissins disabled (set to No if viewed in the UI)
Creates a folder named "IT Dept" under parent folder 27 with Inherit Permissins disabled
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Get-TssFolderStub -TssSession $session | New-TssFolder -TssSession $session -FolderName 'Marketing Dept' -ParentFolderId 27 -InheritPermissions -InheritSecretPolicy
$folderStub.FolderName 'Marketing Dept'
$folderStub.ParentFolderId = 27
$folderStub.InheritPermissions = $true
$folderStub.InheritSecretPolicy = $true
New-TssFolder -TssSession $session -FolderStub $folderStub
Creates a folder named "Marketing Dept" under parent folder 27 with inheritance enabled for Permissions and Secret Policy
Creates a folder named "Marketing Dept" under parent folder 27 with Inheritance enabled for Permissions and Secret Policy
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/New-TssFolder
Expand All @@ -36,39 +45,14 @@ function New-Folder {
[OutputType('TssFolder')]
param (
# TssSession object created by New-TssSession for auth
[Parameter(Mandatory,
ValueFromPipeline,
Position = 0)]
[TssSession]$TssSession,
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[TssSession]
$TssSession,

# Input object obtained via Get-TssFolderStub
[Parameter(Mandatory, Position = 1, ValueFromPipeline)]
[TssFolder]
$FolderStub,

# Folder Name
[Parameter(Mandatory)]
[string]
$FolderName,

# Parent Folder ID, use -1 to create root folder
[Parameter(Mandatory)]
[Alias('ParentFolder')]
[int]
$ParentFolderId,

# Secret Policy ID
[Alias('SecretPolicy')]
[int]
$SecretPolicyId,

# Inherit Permissions
[switch]
$InheritPermissions,

# Inherit Secret Policy
[switch]
$InheritSecretPolicy
$FolderStub
)

begin {
Expand All @@ -85,19 +69,6 @@ function New-Folder {
$invokeParams.Uri = $uri
$invokeParams.Method = 'POST'

$FolderStub.FolderName = $FolderName
$FolderStub.ParentFolderId = $ParentFolderId

if ($tssParams.ContainsKey('SecretPolicyId')) {
$FolderStub.SecretPolicyId = $SecretPolicyId
}
if ($tssParams.ContainsKey('InheritPermissions')) {
$FolderStub.InheritPermissions = $InheritPermissions
}
if ($tssParams.ContainsKey('InheritSecretPolicy')) {
$FolderStub.InheritSecretPolicy = $InheritSecretPolicy
}

$invokeParams.Body = ($FolderStub | ConvertTo-Json)

Write-Verbose "$($invokeParams.Method) $uri with:`n $FolderStub"
Expand All @@ -110,7 +81,7 @@ function New-Folder {
. $ErrorHandling $err
}
if ($restResponse) {
. $TssFolderObject $restResponse
[TssFolder]$restResponse
}
} else {
Write-Warning "No valid session found"
Expand Down
12 changes: 4 additions & 8 deletions src/functions/folders/Remove-Folder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ function Remove-Folder {
[OutputType('TssDelete')]
param (
# TssSession object created by New-TssSession for auth
[Parameter(Mandatory,
ValueFromPipeline,
Position = 0)]
[TssSession]$TssSession,
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[TssSession]
$TssSession,

# Short description for parameter
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
Expand Down Expand Up @@ -60,10 +59,7 @@ function Remove-Folder {
}

if ($restResponse) {
[TssDelete]@{
Id = $restResponse.id
ObjectType = $restResponse.objectType
}
[TssDelete]$restResponse
}
}
} else {
Expand Down
12 changes: 4 additions & 8 deletions src/functions/folders/Remove-FolderTemplate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ function Remove-FolderTemplate {
[OutputType('TssDelete')]
param (
# TssSession object created by New-TssSession for auth
[Parameter(Mandatory,
ValueFromPipeline,
Position = 0)]
[TssSession]$TssSession,
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[TssSession]
$TssSession,

# Short description for parameter
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
Expand Down Expand Up @@ -65,10 +64,7 @@ function Remove-FolderTemplate {
}

if ($restResponse) {
[TssDelete]@{
Id = $restResponse.id
ObjectType = $restResponse.objectType
}
[TssDelete]$restResponse
}
}
} else {
Expand Down
10 changes: 4 additions & 6 deletions src/functions/folders/Search-Folder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ function Search-Folder {
[OutputType('TssFolderSummary')]
param (
# TssSession object created by New-TssSession for auth
[Parameter(Mandatory,
ValueFromPipeline,
Position = 0)]
[TssSession]$TssSession,
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[TssSession]
$TssSession,

# Parent Folder Id
[Alias("FolderId")]
Expand Down Expand Up @@ -77,7 +76,6 @@ function Search-Folder {
$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'


Write-Verbose "$($invokeParams.Method) $uri with $body"
try {
$restResponse = Invoke-TssRestApi @invokeParams
Expand All @@ -91,7 +89,7 @@ function Search-Folder {
Write-Warning "No Folder found"
}
if ($restResponse.records) {
. $TssFolderSummaryObject $restResponse.records
[TssFolderSummary[]]$restResponse.records
}
} else {
Write-Warning "No valid session found"
Expand Down
7 changes: 3 additions & 4 deletions src/functions/folders/Set-Folder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ function Set-Folder {
[cmdletbinding(SupportsShouldProcess, DefaultParameterSetName = 'all')]
param(
# TssSession object created by New-TssSession for auth
[Parameter(Mandatory,
ValueFromPipeline,
Position = 0)]
[TssSession]$TssSession,
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[TssSession]
$TssSession,

# Folder Id to modify
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
Expand Down
27 changes: 0 additions & 27 deletions src/parts/TssFolderAuditSummaryObject.ps1

This file was deleted.

24 changes: 0 additions & 24 deletions src/parts/TssFolderLookupObject.ps1

This file was deleted.

Loading

0 comments on commit b98dc96

Please sign in to comment.