Skip to content

Commit

Permalink
Get-TssFolderAudit - closes #61
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Feb 12, 2021
1 parent dfe9d9b commit e12c7ec
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 4 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Expand Up @@ -9,11 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* None
* `Get-TssFolderAudit` [#61](https://github.com/thycotic-ps/thycotic.secretserver/issues/61)

### Changed

* `New-TssSession` - fixed token type when AccessToken parameter is used. [26720ba](https://github.com/thycotic-ps/thycotic.secretserver/pull/73/commits/26720ba9d37b3f2c6c8986a2f1b2ed30dc5c20e7)
* `New-TssSession` - corrected TokenType with using `-AccessToken` parameter [26720ba](https://github.com/thycotic-ps/thycotic.secretserver/pull/73/commits/26720ba9d37b3f2c6c8986a2f1b2ed30dc5c20e7)
* `New-TssSession` updates to tests [dfe9d9b](https://github.com/thycotic-ps/thycotic.secretserver/commit/dfe9d9bc612421c777be5bd25d6f6abe26fe2ca3)

## [0.29.0] -- 2021-02-09

Expand Down
28 changes: 28 additions & 0 deletions docs/collections/_abouttopics/about_tssfolderauditsummary.md
@@ -0,0 +1,28 @@
---
category: folders
title: "TssFolderAuditSummary"
last_modified_at: 2021-02-11T00:00:00-00:00
---

# TOPIC
This help topic describes the TssFolderAuditSummary class in the Thycotic.SecretServer module

# CLASS
TssFolderAuditSummary

# INHERITANCE
None

# DESCRIPTION
The TssFolderAuditSummary class represents the FolderAuditSummary object returned by Secret Server endpoint /folders/{id}/audit

# CONSTRUCTORS
new()

# PROPERTIES
Documented in the REST API doc for Secret Server, see FolderAuditSummary definition

# METHODS

# RELATED LINKS:
Get-TssFolderAudit
77 changes: 77 additions & 0 deletions docs/collections/_commands/Get-TssFolderAudit.md
@@ -0,0 +1,77 @@
---
category: folders
external help file: Thycotic.SecretServer-help.xml
Module Name: Thycotic.SecretServer
online version:
schema: 2.0.0
title: Get-TssFolderAudit
---

# Get-TssFolderAudit

## SYNOPSIS
Get a list of audits

## SYNTAX

```
Get-TssFolderAudit [-TssSession] <TssSession> -Id <Int32[]> [<CommonParameters>]
```

## DESCRIPTION
Get a list of audit for Folder ID

## EXAMPLES

### EXAMPLE 1
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
PS> Get-TssFolderAudit -TssSession $session -Id 42
```

Gets the audit entries for Folder ID

## PARAMETERS

### -TssSession
TssSession object created by New-TssSession for auth

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

Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```

### -Id
Short description for parameter

```yaml
Type: Int32[]
Parameter Sets: (All)
Aliases: FolderAuditId

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
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

### TssFolderAuditSummary
## NOTES
Requires TssSession object returned by New-TssSession

## RELATED LINKS
5 changes: 4 additions & 1 deletion docs/collections/_pages/abouttopics.md
Expand Up @@ -2,7 +2,7 @@
title: "Thycotic.SecretServer About topics"
permalink: /abouttopics/
excerpt: "About Topics"
last_modified_at: 2021-02-10T00:00:00-00:00
last_modified_at: 2021-02-11T00:00:00-00:00
toc: false
layout: single-mod
classes: wide
Expand Down Expand Up @@ -45,6 +45,7 @@ About topics cover the [PowerShell classes](https://docs.microsoft.com/en-us/pow
[TssFolderTemplate][TssFolderTemplate] | [Get-TssFolder][Get-TssFolder]
[TssFolderLookup][TssFolderLookup] | [Find-TssFolder][Find-TssFolder]
[TssFolderSummary][TssFolderSummary] | [Search-TssFolder][Search-TssFolder]
[TssFolderAuditSummary][TssFolderAuditSummary] | [Get-TssFolderAudit][Get-TssFolderAudit]

## Reports

Expand Down Expand Up @@ -89,7 +90,9 @@ About topics cover the [PowerShell classes](https://docs.microsoft.com/en-us/pow
[Get-TssReport]:/thycotic.secretserver/commands/Get-TssReport
[Get-TssReportCategory]:/thycotic.secretserver/commands/Get-TssReportCategory
[Search-TssReportScheduleSummary]:/thycotic.secretserver/commands/Search-TssReportScheduleSummary
[Get-TssFolderAudit]:/thycotic.secretserver/commands/Get-TssFolderAudit

[TssFolderAuditSummary]:/thycotic.secretserver/abouttopics/about_tssfolderauditsummary
[TssSession]:/thycotic.secretserver/abouttopics/about_tsssession
[TssSecret]:/thycotic.secretserver/abouttopics/about_tsssecret
[TssSecretItem]:/thycotic.secretserver/abouttopics/about_tsssecretitem
Expand Down
5 changes: 4 additions & 1 deletion docs/collections/_pages/commands.md
Expand Up @@ -2,7 +2,7 @@
title: "Thycotic.SecretServer + API Command Reference"
permalink: /commands/
excerpt: "Command Reference"
last_modified_at: 2021-02-10T00:00:00-00:00
last_modified_at: 2021-02-11T00:00:00-00:00
toc: false
layout: single-mod
classes: wide
Expand Down Expand Up @@ -59,6 +59,7 @@ A Thycotic.SecretServer command may not appear in the below list due to it not b
[/folders][/folders] | POST | [New-TssFolder][New-TssFolder]
[/folders/{id}][/folders/{id}] | DELETE | [Remove-TssFolder][Remove-TssFolder]
[/folders/stub][/folders/stub] | GET | [Get-TssFolderStub][Get-TssFolderStub]
[/folders/{id}/audit][/folders/{id}/audit] | GET | [Get-TssFolderAuditSummary][Get-TssFolderAuditSummary]

## Reports

Expand Down Expand Up @@ -107,7 +108,9 @@ A Thycotic.SecretServer command may not appear in the below list due to it not b
[New-TssFolder]:/thycotic.secretserver/commands/New-TssFolder
[Get-TssFolderStub]:/thycotic.secretserver/commands/Get-TssFolderStub
[Remove-TssFolder]:/thycotic.secretserver/commands/Remove-TssFolder
[Get-TssFolderAudit]:/thycotic.secretserver/commands/Get-TssFolderAudit

[/folders/{id}/audit]:https://updates.thycotic.net/secretserver/restapiguide/10.9.33/TokenAuth/#operation--folders--id--audit-get
[/folders/{id}]:https://updates.thycotic.net/secretserver/restapiguide/10.9.33/TokenAuth/#operation--folders--id--delete
[/folders/stub]:https://updates.thycotic.net/secretserver/restapiguide/10.9.33/TokenAuth/#operation--folders-stub-get
[/folders]:https://updates.thycotic.net/secretserver/restapiguide/10.9.33/TokenAuth/#operation--folders-post
Expand Down
12 changes: 12 additions & 0 deletions src/classes/folders/TssFolderAuditSummary.class.ps1
@@ -0,0 +1,12 @@
class TssFolderAuditSummary {
# Action
[string]$Action
# Audit Folder Id
[int]$AuditFolderId
# Data recorded
[datetime]$DateRecorded
# Display Name
[string]$DisplayName
# Notes
[string]$Notes
}
22 changes: 22 additions & 0 deletions src/en-us/about_tssfolderauditsummary.help.txt
@@ -0,0 +1,22 @@
TOPIC
This help topic describes the TssFolderAuditSummary class in the Thycotic.SecretServer module

CLASS
TssFolderAuditSummary

INHERITANCE
None

DESCRIPTION
The TssFolderAuditSummary class represents the FolderAuditSummary object returned by Secret Server endpoint /folders/{id}/audit

CONSTRUCTORS
new()

PROPERTIES
Documented in the REST API doc for Secret Server, see FolderAuditSummary definition

METHODS

RELATED LINKS:
Get-TssFolderAudit
65 changes: 65 additions & 0 deletions src/functions/folders/Get-FolderAudit.ps1
@@ -0,0 +1,65 @@
function Get-FolderAudit {
<#
.SYNOPSIS
Get a list of audits
.DESCRIPTION
Get a list of audit for Folder ID
.EXAMPLE
PS> $session = New-TssSession -SecretServer https://alpha -Credential $ssCred
PS> Get-TssFolderAudit -TssSession $session -Id 42
Gets the audit entries for Folder ID
.NOTES
Requires TssSession object returned by New-TssSession
#>
[CmdletBinding()]
[OutputType('TssFolderAuditSummary')]
param (
# TssSession object created by New-TssSession for auth
[Parameter(Mandatory,
ValueFromPipeline,
Position = 0)]
[TssSession]$TssSession,

# Short description for parameter
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
[Alias("FolderAuditId")]
[int[]]
$Id
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = @{ }
}

process {
Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)"
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
foreach ($folder in $Id) {
$restResponse = $null
$uri = $TssSession.ApiUrl, 'folders', $folder, 'audit' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'

$invokeParams.PersonalAccessToken = $TssSession.AccessToken
Write-Verbose "$($invokeParams.Method) $uri"
try {
$restResponse = Invoke-TssRestApi @invokeParams
} catch {
Write-Warning "Issue getting folder [$folder]"
$err = $_
. $ErrorHandling $err
}

if ($restResponse) {
. $TssFolderAuditSummaryObject $restResponse.records
}
}
} else {
Write-Warning "No valid session found"
}
}
}
27 changes: 27 additions & 0 deletions src/parts/TssFolderAuditSummaryObject.ps1
@@ -0,0 +1,27 @@
<#
.Synopsis
Creates a TssFolderAuditSummary object to output the FolderAuditSummary object
#>
param(
[pscustomobject]$Object
)

begin {
$Properties = $Object[0].PSObject.Properties.Name
}

process {
$outObject = @()
foreach ($f in $Object) {
$currentObject = [TssFolderAuditSummary]::new()
foreach ($sProp in $Properties) {
if ($sProp -in $currentObject.PSObject.Properties.Name) {
$currentObject.$sProp = $f.$sProp
} else {
Write-Warning "Property $sProp does not exist in the TssFolderAuditSummary class. Please create a bug report at https://github.com/thycotic-ps/thycotic.secretserver/issues/new/choose"
}
}
$outObject += $currentObject
}
return $outObject
}
50 changes: 50 additions & 0 deletions tests/folders/Get-TssFolderAudit.Tests.ps1
@@ -0,0 +1,50 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
. ([IO.Path]::Combine([string]$PSScriptRoot, '..', 'constants.ps1'))
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
[object[]]$knownParameters = 'TssSession', 'Id'
[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 parmaeters" -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 TssFolderAuditSummary" -TestCases $commandDetails {
$_.OutputType.Name | Should -Be 'TssFolderAuditSummary'
}
}
}
Describe "$commandName works" {
BeforeDiscovery {
$session = New-TssSession -SecretServer $ss -Credential $ssCred
$invokeParams = @{
Uri = "$ss/api/v1/folders?take=$($session.take)"
ExpandProperty = 'records'
PersonalAccessToken = $session.AccessToken
}
$getFolders = Invoke-TssRestApi @invokeParams
$tssSecretFolder = $getFolders.Where({$_.folderPath -match 'tss_module_testing'})

$object = Get-TssFolderAudit -TssSession $session -Id $tssSecretFolder.id

$session.SessionExpire()
$props = 'Action', 'AuditFolderId', 'Notes'
}
Context "Checking" -Foreach @{object = $object} {
It "Should not be empty" {
$object | Should -Not -BeNullOrEmpty
}
It "Should output <_> property" -TestCases $props {
$object[0].PSObject.Properties.Name | Should -Contain $_
}
}
}

0 comments on commit e12c7ec

Please sign in to comment.