Skip to content

Commit

Permalink
Search-TssConfigurationBackupLog - new command
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Aug 30, 2021
1 parent 7316419 commit 7c5bb0c
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 1 deletion.
73 changes: 73 additions & 0 deletions docs/commands/configurations/Search-TssConfigurationBackupLog.md
@@ -0,0 +1,73 @@
# Search-TssConfigurationBackupLog

## SYNOPSIS
Search logs for the Database Backup runs

## SYNTAX

```
Search-TssConfigurationBackupLog [-TssSession] <Session> [-SortBy <String>] [<CommonParameters>]
```

## DESCRIPTION
Search logs for the Database Backup runs

## EXAMPLES

### EXAMPLE 1
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Search-TssConfigurationBackupLog -TssSession $session
```

Returns the logs for the Database Backup processing

## 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
```

### -SortBy
Sort by specific property, default BackupTime

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: BackupTime
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

### Thycotic.PowerShell.Configuration.DbBackupLog
## NOTES
Requires TssSession object returned by New-TssSession

## RELATED LINKS

[https://thycotic-ps.github.io/thycotic.secretserver/commands/configurations/Search-TssConfigurationBackupLog](https://thycotic-ps.github.io/thycotic.secretserver/commands/configurations/Search-TssConfigurationBackupLog)

[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/configurations/Search-TssConfigurationBackupLog.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/configurations/Search-TssConfigurationBackupLog.ps1)

4 changes: 3 additions & 1 deletion docs/getting_started/compatibility.md
Expand Up @@ -31,6 +31,7 @@ Secret Server REST API was first released with version 9.0. The API has grown si
| [Remove-TssMetadata] | 11.0.000005 |
| [Remove-TssReportSchedule] | 10.9.000033 |
| [Search-TssAutoExportStorage] | 11.0.000005 |
| [Search-TssConfigurationBackupLog] | 11.0.000005 |
| [Search-TssDistributedEngineSite] | 10.9.000032 |
| [Search-TssMetadata] | 10.9.000064 |
| [Search-TssMetadataHistory] | 10.9.000064 |
Expand Down Expand Up @@ -58,4 +59,5 @@ Secret Server REST API was first released with version 9.0. The API has grown si
[Get-TssConfigurationAutoExport]:/thycotic.secretserver/commands/configurations/Get-TssConfigurationAutoExport
[Set-TssConfigurationAutoExport]:/thycotic.secretserver/commands/configurations/Set-TssConfigurationAutoExport
[Search-TssAutoExportStorage]:/thycotic.secretserver/commands/configurations/Search-TssAutoExportStorage
[Export-TssAutoExportStorageItem]:/thycotic.secretserver/commands/configurations/Export-TssAutoExportStorageItem
[Export-TssAutoExportStorageItem]:/thycotic.secretserver/commands/configurations/Export-TssAutoExportStorageItem
[Get-TssConfigurationBackupLog]:/thycotic.secretserver/commands/configurations/Get-TssConfigurationBackupLog
80 changes: 80 additions & 0 deletions src/Thycotic.SecretServer.Format.ps1xml
Expand Up @@ -3001,5 +3001,85 @@
</TableControl>
</View>

<!-- Thycotic.PowerShell.Configuration.Backup -->
<View>
<Name>Configuration.DbBackup</Name>
<ViewSelectedBy>
<TypeName>Thycotic.PowerShell.Configuration.Backup</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>BackupDatabasePath</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>BackupStartDateTime</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>EnableDatabaseBackup</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>EnableWebApplicationBackup</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>EnableScheduledBackup</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>NumberOfBackupsToKeep</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>BackupFailureNotification</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>

<!-- Thycotic.PowerShell.Configuration.BackupLog -->
<View>
<Name>Configuration.BackupLog</Name>
<ViewSelectedBy>
<TypeName>Thycotic.PowerShell.Configuration.BackupLog</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>BackupTime</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Success</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Notes</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>DisplayName</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>

</ViewDefinitions>
</Configuration>
15 changes: 15 additions & 0 deletions src/Thycotic.SecretServer/classes/configurations/BackupLog.cs
@@ -0,0 +1,15 @@
using System;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;

namespace Thycotic.PowerShell.Configuration
{
public class BackupLog
{
public DateTime? BackupTime {get;set;}
public string DisplayName {get;set;}
public string Notes {get;set;}
public bool Success {get;set;}
}
}
66 changes: 66 additions & 0 deletions src/functions/configurations/Search-TssConfigurationBackupLog.ps1
@@ -0,0 +1,66 @@
function Search-TssConfigurationBackupLog {
<#
.SYNOPSIS
Search logs for the Database Backup runs
.DESCRIPTION
Search logs for the Database Backup runs
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Search-TssConfigurationBackupLog -TssSession $session
Returns the logs for the Database Backup processing
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/configurations/Search-TssConfigurationBackupLog
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/configurations/Search-TssConfigurationBackupLog.ps1
.NOTES
Requires TssSession object returned by New-TssSession
#>
[CmdletBinding()]
[OutputType('Thycotic.PowerShell.Configuration.DbBackupLog')]
param (
# TssSession object created by New-TssSession for authentication
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[Thycotic.PowerShell.Authentication.Session]
$TssSession,

# Sort by specific property, default BackupTime
[string]
$SortBy = 'BackupTime'
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeApiParams $TssSession
}
process {
Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)"
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '11.0.000005' $PSCmdlet.MyInvocation
$uri = ($TssSession.ApiUrl -replace 'v1','v2'), 'configuration', 'backup-logs' -join '/'
$uri = $uri, "sortBy[0].direction=desc&sortBy[0].name=$SortBy&take=$($TssSession.Take)" -join '?'
$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'

Write-Verbose "Performing the operation $($invokeParams.Method) $($invokeParams.Uri)"
try {
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue on search request"
$err = $_
. $ErrorHandling $err
}

if ($restResponse.records) {
[Thycotic.PowerShell.Configuration.DbBackupLog[]]$restResponse.records
}
} else {
Write-Warning "No valid session found"
}
}
}
24 changes: 24 additions & 0 deletions tests/configurations/Search-TssConfigurationBackupLog.Tests.ps1
@@ -0,0 +1,24 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
[object[]]$knownParameters = 'TssSession', 'SortBy'
[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 Thycotic.PowerShell.Configuration.DbBackupLog" -TestCases $commandDetails {
$_.OutputType.Name | Should -Be 'Thycotic.PowerShell.Configuration.DbBackupLog'
}
}
}

0 comments on commit 7c5bb0c

Please sign in to comment.