From 2991b7e4277b79eced652659c6d9e26b79dbfc41 Mon Sep 17 00:00:00 2001 From: Shawn Melton <11204251+wsmelton@users.noreply.github.com> Date: Mon, 30 Aug 2021 18:55:51 -0500 Subject: [PATCH] Start-TssConfigurationBackup - new command --- .../Start-TssConfigurationBackup.md | 88 +++++++++ src/Thycotic.SecretServer.psd1 | 168 +++++++++--------- .../Start-TssConfigurationBackup.ps1 | 60 +++++++ .../Start-TssConfigurationBackup.Tests.ps1 | 19 ++ 4 files changed, 252 insertions(+), 83 deletions(-) create mode 100644 docs/commands/configurations/Start-TssConfigurationBackup.md create mode 100644 src/functions/configurations/Start-TssConfigurationBackup.ps1 create mode 100644 tests/configurations/Start-TssConfigurationBackup.Tests.ps1 diff --git a/docs/commands/configurations/Start-TssConfigurationBackup.md b/docs/commands/configurations/Start-TssConfigurationBackup.md new file mode 100644 index 00000000..0afc4de3 --- /dev/null +++ b/docs/commands/configurations/Start-TssConfigurationBackup.md @@ -0,0 +1,88 @@ +# Start-TssConfigurationBackup + +## SYNOPSIS +Start the database backup as configured + +## SYNTAX + +``` +Start-TssConfigurationBackup [-TssSession] [-WhatIf] [-Confirm] [] +``` + +## DESCRIPTION +Start the database backup as configured + +## EXAMPLES + +### EXAMPLE 1 +``` +$session = New-TssSession -SecretServer https://alpha -Credential $ssCred +Start-TssConfigurationBackup -TssSession $session +``` + +Run the backup for the Secret Server as configured + +## PARAMETERS + +### -TssSession +TssSession object created by New-TssSession for authentication + +```yaml +Type: Session +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES +Requires TssSession object returned by New-TssSession + +## RELATED LINKS + +[https://thycotic-ps.github.io/thycotic.secretserver/commands/configurations/Start-TssConfigurationBackup](https://thycotic-ps.github.io/thycotic.secretserver/commands/configurations/Start-TssConfigurationBackup) + +[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/configurations/Start-TssConfigurationBackup.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/configurations/Start-TssConfigurationBackup.ps1) + diff --git a/src/Thycotic.SecretServer.psd1 b/src/Thycotic.SecretServer.psd1 index 903b1f73..9a61ffaa 100644 --- a/src/Thycotic.SecretServer.psd1 +++ b/src/Thycotic.SecretServer.psd1 @@ -3,7 +3,7 @@ # # Generated by: Shawn Melton # -# Generated on: 8/26/2021 +# Generated on: 8/30/2021 # @{ @@ -69,88 +69,90 @@ FormatsToProcess = 'Thycotic.SecretServer.Format.ps1xml' NestedModules = @('bin\Thycotic.SecretServer.dll') # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. -FunctionsToExport = 'Add-TssEventPipeline', 'Add-TssFolderPermission', - 'Add-TssGroupMember', 'Add-TssSecretPermission', - 'Add-TssSecretTemplateField', 'Close-TssSecret', 'Close-TssSession', - 'Disable-TssEventPipeline', 'Disable-TssEventPipelinePolicy', - 'Disable-TssSecretCheckout', 'Disable-TssSecretEmail', - 'Disable-TssUnlimitedAdmin', 'Disable-TssUser', - 'Enable-TssEventPipeline', 'Enable-TssEventPipelinePolicy', - 'Enable-TssSecretCheckout', 'Enable-TssSecretEmail', - 'Enable-TssUnlimitedAdmin', 'Enable-TssUser', - 'Export-TssAutoExportStorageItem', 'Export-TssReport', - 'Find-TssFolder', 'Find-TssGroup', 'Find-TssReport', 'Find-TssSecret', - 'Find-TssUser', 'Get-TssConfiguration', - 'Get-TssConfigurationAutoExport', - 'Get-TssConfigurationLocalUserPassword', - 'Get-TssConfigurationLogin', 'Get-TssConfigurationRpc', - 'Get-TssConfigurationSaml', 'Get-TssConfigurationSecretIndexer', - 'Get-TssConfigurationSecurity', 'Get-TssConfigurationSiteConnector', - 'Get-TssEventPipeline', 'Get-TssEventPipelinePolicy', - 'Get-TssEventPipelinePolicyActivity', 'Get-TssEventPipelineRun', - 'Get-TssFolder', 'Get-TssFolderAudit', 'Get-TssFolderPermission', - 'Get-TssFolderState', 'Get-TssGroup', 'Get-TssGroupMember', - 'Get-TssGroupRole', 'Get-TssGroupUser', 'Get-TssMetadataField', - 'Get-TssReport', 'Get-TssReportCategory', 'Get-TssReportParameter', - 'Get-TssReportSchedule', 'Get-TssRpcAssociatedSecret', - 'Get-TssRpcPasswordType', 'Get-TssScript', 'Get-TssSecret', - 'Get-TssSecretAccessRequest', 'Get-TssSecretAccessRequestOption', - 'Get-TssSecretAccessRequestSecret', 'Get-TssSecretAttachment', - 'Get-TssSecretAudit', 'Get-TssSecretDependency', - 'Get-TssSecretDependencyGroup', 'Get-TssSecretDependencyRunStatus', - 'Get-TssSecretDependencyStub', 'Get-TssSecretDependencyTemplate', - 'Get-TssSecretField', 'Get-TssSecretHeartbeatStatus', - 'Get-TssSecretHook', 'Get-TssSecretHookStub', - 'Get-TssSecretPasswordStatus', 'Get-TssSecretPolicy', - 'Get-TssSecretSetting', 'Get-TssSecretState', 'Get-TssSecretStub', - 'Get-TssSecretSummary', 'Get-TssSecretTemplate', - 'Get-TssSecretTemplateFolder', 'Get-TssSite', 'Get-TssUser', - 'Get-TssUserAudit', 'Get-TssUserGroup', 'Get-TssUserOwner', - 'Get-TssUserRole', 'Get-TssUserRoleAssigned', 'Get-TssVersion', - 'Initialize-TssSdkClient', 'Invoke-TssReport', 'Invoke-TssRestApi', - 'Invoke-TssSecretGeneratePassword', 'Lock-TssUser', 'New-TssFolder', - 'New-TssFolderPermission', 'New-TssGroup', 'New-TssMetadataField', - 'New-TssReport', 'New-TssReportSchedule', 'New-TssScript', - 'New-TssSecret', 'New-TssSecretDependency', - 'New-TssSecretDependencyGroup', 'New-TssSecretHook', - 'New-TssSecretPermission', 'New-TssSecretTemplate', - 'New-TssSecretTemplateField', 'New-TssSession', 'New-TssUser', - 'Open-TssSecret', 'Remove-TssEventPipeline', 'Remove-TssFolder', - 'Remove-TssFolderPermission', 'Remove-TssFolderTemplate', - 'Remove-TssGroupMember', 'Remove-TssMetadata', 'Remove-TssReport', - 'Remove-TssReportCategory', 'Remove-TssReportSchedule', - 'Remove-TssSecret', 'Remove-TssSecretDependency', - 'Remove-TssSecretHook', 'Remove-TssSecretPermission', - 'Remove-TssUserPii', 'Reset-TssUserPassword', 'Restore-TssSecret', - 'Revoke-TssSecret', 'Search-TssAutoExportStorage', - 'Search-TssConfigurationAudit', 'Search-TssDirectoryServiceDomain', - 'Search-TssDistributedEngineSite', 'Search-TssEventPipeline', - 'Search-TssEventPipelinePolicy', 'Search-TssFolder', - 'Search-TssFolderPermission', 'Search-TssGroup', 'Search-TssMetadata', - 'Search-TssMetadataHistory', 'Search-TssMetadataSection', - 'Search-TssReport', 'Search-TssReportSchedule', 'Search-TssRole', - 'Search-TssRpcPasswordType', 'Search-TssScript', 'Search-TssSecret', - 'Search-TssSecretAccessRequest', 'Search-TssSecretDependency', - 'Search-TssSecretHook', 'Search-TssSecretPermission', - 'Search-TssSecretPolicy', 'Search-TssSecretTemplate', - 'Search-TssSystemLog', 'Search-TssUser', 'Search-TssWorkflowTemplate', - 'Set-TssConfigurationAutoExport', 'Set-TssConfigurationGeneral', - 'Set-TssFolder', 'Set-TssSecret', 'Set-TssSecretExpiration', - 'Set-TssSecretField', 'Set-TssSecretPolicy', - 'Set-TssSecretRpcAssociated', 'Set-TssSecretRpcPrivileged', - 'Set-TssSecretSecurity', 'Set-TssSecretTemplate', - 'Show-TssCurrentUser', 'Start-TssDiscovery', - 'Start-TssSecretChangePassword', 'Start-TssSecretDependency', - 'Start-TssSecretHeartbeat', 'Stop-TssSecretChangePassword', - 'Test-TssFolderAction', 'Test-TssSdkClient', 'Test-TssSecretAction', - 'Test-TssSecretState', 'Test-TssSession', 'Test-TssVersion', - 'Unlock-TssUser', 'Update-TssFolder', 'Update-TssFolderPermission', - 'Update-TssGroupMember', 'Update-TssMetadataField', - 'Update-TssMetadataSection', 'Update-TssSecret', - 'Update-TssSecretAccessRequest', 'Update-TssSecretHook', - 'Update-TssSecretPermission', 'Update-TssSecretPolicy', - 'Update-TssSecretRdpLauncherSetting', - 'Update-TssSecretTemplateField', 'Update-TssUser', +FunctionsToExport = 'Add-TssEventPipeline', 'Add-TssFolderPermission', + 'Add-TssGroupMember', 'Add-TssSecretPermission', + 'Add-TssSecretTemplateField', 'Close-TssSecret', 'Close-TssSession', + 'Disable-TssEventPipeline', 'Disable-TssEventPipelinePolicy', + 'Disable-TssSecretCheckout', 'Disable-TssSecretEmail', + 'Disable-TssUnlimitedAdmin', 'Disable-TssUser', + 'Enable-TssEventPipeline', 'Enable-TssEventPipelinePolicy', + 'Enable-TssSecretCheckout', 'Enable-TssSecretEmail', + 'Enable-TssUnlimitedAdmin', 'Enable-TssUser', + 'Export-TssAutoExportStorageItem', 'Export-TssReport', + 'Find-TssFolder', 'Find-TssGroup', 'Find-TssReport', 'Find-TssSecret', + 'Find-TssUser', 'Get-TssConfiguration', + 'Get-TssConfigurationAutoExport', 'Get-TssConfigurationBackup', + 'Get-TssConfigurationLocalUserPassword', + 'Get-TssConfigurationLogin', 'Get-TssConfigurationRpc', + 'Get-TssConfigurationSaml', 'Get-TssConfigurationSecretIndexer', + 'Get-TssConfigurationSecurity', 'Get-TssConfigurationSiteConnector', + 'Get-TssEventPipeline', 'Get-TssEventPipelinePolicy', + 'Get-TssEventPipelinePolicyActivity', 'Get-TssEventPipelineRun', + 'Get-TssFolder', 'Get-TssFolderAudit', 'Get-TssFolderPermission', + 'Get-TssFolderState', 'Get-TssGroup', 'Get-TssGroupMember', + 'Get-TssGroupRole', 'Get-TssGroupUser', 'Get-TssMetadataField', + 'Get-TssReport', 'Get-TssReportCategory', 'Get-TssReportParameter', + 'Get-TssReportSchedule', 'Get-TssRpcAssociatedSecret', + 'Get-TssRpcPasswordType', 'Get-TssScript', 'Get-TssSecret', + 'Get-TssSecretAccessRequest', 'Get-TssSecretAccessRequestOption', + 'Get-TssSecretAccessRequestSecret', 'Get-TssSecretAttachment', + 'Get-TssSecretAudit', 'Get-TssSecretDependency', + 'Get-TssSecretDependencyGroup', 'Get-TssSecretDependencyRunStatus', + 'Get-TssSecretDependencyStub', 'Get-TssSecretDependencyTemplate', + 'Get-TssSecretField', 'Get-TssSecretHeartbeatStatus', + 'Get-TssSecretHook', 'Get-TssSecretHookStub', + 'Get-TssSecretPasswordStatus', 'Get-TssSecretPolicy', + 'Get-TssSecretSetting', 'Get-TssSecretState', 'Get-TssSecretStub', + 'Get-TssSecretSummary', 'Get-TssSecretTemplate', + 'Get-TssSecretTemplateFolder', 'Get-TssSite', 'Get-TssUser', + 'Get-TssUserAudit', 'Get-TssUserGroup', 'Get-TssUserOwner', + 'Get-TssUserRole', 'Get-TssUserRoleAssigned', 'Get-TssVersion', + 'Initialize-TssSdkClient', 'Invoke-TssReport', 'Invoke-TssRestApi', + 'Invoke-TssSecretGeneratePassword', 'Lock-TssUser', 'New-TssFolder', + 'New-TssFolderPermission', 'New-TssGroup', 'New-TssMetadataField', + 'New-TssReport', 'New-TssReportSchedule', 'New-TssScript', + 'New-TssSecret', 'New-TssSecretDependency', + 'New-TssSecretDependencyGroup', 'New-TssSecretHook', + 'New-TssSecretPermission', 'New-TssSecretPolicy', + 'New-TssSecretTemplate', 'New-TssSecretTemplateField', + 'New-TssSession', 'New-TssUser', 'Open-TssSecret', + 'Remove-TssEventPipeline', 'Remove-TssFolder', + 'Remove-TssFolderPermission', 'Remove-TssFolderTemplate', + 'Remove-TssGroupMember', 'Remove-TssMetadata', 'Remove-TssReport', + 'Remove-TssReportCategory', 'Remove-TssReportSchedule', + 'Remove-TssSecret', 'Remove-TssSecretDependency', + 'Remove-TssSecretHook', 'Remove-TssSecretPermission', + 'Remove-TssUserPii', 'Reset-TssUserPassword', 'Restore-TssSecret', + 'Revoke-TssSecret', 'Search-TssAutoExportStorage', + 'Search-TssConfigurationAudit', 'Search-TssConfigurationBackupLog', + 'Search-TssDirectoryServiceDomain', + 'Search-TssDistributedEngineSite', 'Search-TssEventPipeline', + 'Search-TssEventPipelinePolicy', 'Search-TssFolder', + 'Search-TssFolderPermission', 'Search-TssGroup', 'Search-TssMetadata', + 'Search-TssMetadataHistory', 'Search-TssMetadataSection', + 'Search-TssReport', 'Search-TssReportSchedule', 'Search-TssRole', + 'Search-TssRpcPasswordType', 'Search-TssScript', 'Search-TssSecret', + 'Search-TssSecretAccessRequest', 'Search-TssSecretDependency', + 'Search-TssSecretHook', 'Search-TssSecretPermission', + 'Search-TssSecretPolicy', 'Search-TssSecretTemplate', + 'Search-TssSystemLog', 'Search-TssUser', 'Search-TssWorkflowTemplate', + 'Set-TssConfigurationAutoExport', 'Set-TssConfigurationGeneral', + 'Set-TssFolder', 'Set-TssSecret', 'Set-TssSecretExpiration', + 'Set-TssSecretField', 'Set-TssSecretPolicy', + 'Set-TssSecretRpcAssociated', 'Set-TssSecretRpcPrivileged', + 'Set-TssSecretSecurity', 'Set-TssSecretTemplate', + 'Show-TssCurrentUser', 'Start-TssConfigurationBackup', + 'Start-TssDiscovery', 'Start-TssSecretChangePassword', + 'Start-TssSecretDependency', 'Start-TssSecretHeartbeat', + 'Stop-TssSecretChangePassword', 'Test-TssFolderAction', + 'Test-TssSdkClient', 'Test-TssSecretAction', 'Test-TssSecretState', + 'Test-TssSession', 'Test-TssVersion', 'Unlock-TssUser', + 'Update-TssFolder', 'Update-TssFolderPermission', + 'Update-TssGroupMember', 'Update-TssMetadataField', + 'Update-TssMetadataSection', 'Update-TssSecret', + 'Update-TssSecretAccessRequest', 'Update-TssSecretHook', + 'Update-TssSecretPermission', 'Update-TssSecretRdpLauncherSetting', + 'Update-TssSecretTemplateField', 'Update-TssUser', 'Update-TssUserPassword', 'Write-TssSecretAccessRequestViewComment' # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. diff --git a/src/functions/configurations/Start-TssConfigurationBackup.ps1 b/src/functions/configurations/Start-TssConfigurationBackup.ps1 new file mode 100644 index 00000000..d8c34034 --- /dev/null +++ b/src/functions/configurations/Start-TssConfigurationBackup.ps1 @@ -0,0 +1,60 @@ +function Start-TssConfigurationBackup { + <# + .SYNOPSIS + Start the database backup as configured + + .DESCRIPTION + Start the database backup as configured + + .EXAMPLE + $session = New-TssSession -SecretServer https://alpha -Credential $ssCred + Start-TssConfigurationBackup -TssSession $session + + Run the backup for the Secret Server as configured + + .LINK + https://thycotic-ps.github.io/thycotic.secretserver/commands/configurations/Start-TssConfigurationBackup + + .LINK + https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/configurations/Start-TssConfigurationBackup.ps1 + + .NOTES + Requires TssSession object returned by New-TssSession + #> + [CmdletBinding(SupportsShouldProcess)] + param ( + # TssSession object created by New-TssSession for authentication + [Parameter(Mandatory, ValueFromPipeline, Position = 0)] + [Thycotic.PowerShell.Authentication.Session] + $TssSession + ) + begin { + $tssParams = $PSBoundParameters + $invokeParams = . $GetInvokeApiParams $TssSession + } + process { + Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)" + if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) { + . $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation + $uri = $TssSession.ApiUrl, 'configuration', 'backup', 'run-now' -join '/' + $invokeParams.Uri = $uri + $invokeParams.Method = 'POST' + + if (-not $PSCmdlet.ShouldProcess("SecretId: $user", "$($invokeParams.Method) $($invokeParams.Uri)")) { return } + Write-Verbose "Performing the operation: $($invokeParams.Method) $($invokeParams.Uri)" + try { + $apiResponse = Invoke-TssApi @invokeParams + $restResponse = . $ProcessResponse $apiResponse + } catch { + $err = $_ + . $ErrorHandling $err + } + + if ($restResponse) { + Write-Verbose "Database Backup started successfully" + } + } else { + Write-Warning 'No valid session found' + } + } +} \ No newline at end of file diff --git a/tests/configurations/Start-TssConfigurationBackup.Tests.ps1 b/tests/configurations/Start-TssConfigurationBackup.Tests.ps1 new file mode 100644 index 00000000..de9c06ad --- /dev/null +++ b/tests/configurations/Start-TssConfigurationBackup.Tests.ps1 @@ -0,0 +1,19 @@ +BeforeDiscovery { + $commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf +} +Describe "$commandName verify parameters" { + BeforeDiscovery { + [object[]]$knownParameters = 'TssSession' + [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 + } + } +} \ No newline at end of file