Skip to content

Commit

Permalink
Write-TssSecretAccessRequestViewComment - new command
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Aug 5, 2021
1 parent 085a8b6 commit c537ce5
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 6 deletions.
@@ -0,0 +1,149 @@
# Write-TssSecretAccessRequestViewComment

## SYNOPSIS
Write a View Comment to a Secret

## SYNTAX

```
Write-TssSecretAccessRequestViewComment [-TssSession] <Session> -Id <Int32[]> [-Comment <String>]
[-TicketNumber <String>] [-TicketSystemId <Int32>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Write a View Comment to a Secret, will be an Audit Action VIEW.

## EXAMPLES

### EXAMPLE 1
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Write-TssSecretAccessRequestViewComment -TssSession $session -Id 46 -Comment "A test comment"
```

Writes the comment "A test comment" to Secret ID 46

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

### -Id
Secret ID

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

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

### -Comment
Comment to provide for restricted secret (Require Comment is enabled)

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

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -TicketNumber
Associated ticket number (required for ticket integrations)

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

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -TicketSystemId
Associated ticket system ID (required for ticket integrations)

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

Required: False
Position: Named
Default value: 0
Accept pipeline input: False
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/secret-access-requests/Write-TssSecretAccessRequestViewComment](https://thycotic-ps.github.io/thycotic.secretserver/commands/secret-access-requests/Write-TssSecretAccessRequestViewComment)

[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-access-requests/Write-TssSecretAccessRequestViewComment.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-access-requests/Write-TssSecretAccessRequestViewComment.ps1)

6 changes: 3 additions & 3 deletions docs/commands/secrets/Get-TssSecret.md
Expand Up @@ -76,15 +76,15 @@ Get Secret via absolute path.

### EXAMPLE 6
```
$session = tssnts https://alpha $ssCred
(tssgts $session 330).GetCredential($null,'username','password')
$session = nts https://alpha $ssCred
(gts $session 330).GetCredential($null,'username','password')
```

Get PSCredential object for Secret ID 330, using alias for the function names

### EXAMPLE 7
```
$session = tssnts https://alpha $ssCred
$session = nts https://alpha $ssCred
$secret = Get-TssSecret $session 330
$secret.GetFileFields().Foreach({Get-TssSecretField -Id $secret.Id -Slug $_.SlugName})
```
Expand Down
4 changes: 2 additions & 2 deletions docs/commands/secrets/Get-TssSecretState.md
Expand Up @@ -6,7 +6,7 @@ Get details on state of the Secret
## SYNTAX

```
Get-TssSecretState [-TssSession] <Session> -Id <Int32[]> [<CommonParameters>]
Get-TssSecretState [-TssSession] <Session> [-Id] <Int32[]> [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -48,7 +48,7 @@ Parameter Sets: (All)
Aliases: SecretId

Required: True
Position: Named
Position: 2
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Expand Down
2 changes: 1 addition & 1 deletion src/Thycotic.SecretServer.psd1
Expand Up @@ -135,7 +135,7 @@ FunctionsToExport = 'Add-TssEventPipeline', 'Add-TssFolderPermission',
'Update-TssGroupMember', 'Update-TssSecret', 'Update-TssSecretHook',
'Update-TssSecretPermission', 'Update-TssSecretRdpLauncherSetting',
'Update-TssSecretTemplateField', 'Update-TssUser',
'Update-TssUserPassword'
'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.
CmdletsToExport = 'Start-TssLog', 'Stop-TssLog', 'Write-TssLog'
Expand Down
@@ -0,0 +1,89 @@
function Write-TssSecretAccessRequestViewComment {
<#
.SYNOPSIS
Write a View Comment to a Secret
.DESCRIPTION
Write a View Comment to a Secret, will be an Audit Action VIEW.
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Write-TssSecretAccessRequestViewComment -TssSession $session -Id 46 -Comment "A test comment"
Writes the comment "A test comment" to Secret ID 46
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/secret-access-requests/Write-TssSecretAccessRequestViewComment
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-access-requests/Write-TssSecretAccessRequestViewComment.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,

# Secret ID
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[Alias('SecretId')]
[int[]]
$Id,

# Comment to provide for restricted secret (Require Comment is enabled)
[string]
$Comment,

# Associated ticket number (required for ticket integrations)
[string]
$TicketNumber,

# Associated ticket system ID (required for ticket integrations)
[int]
$TicketSystemId
)
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.000000' $PSCmdlet.MyInvocation
foreach ($secret in $Id) {
$uri = $TssSession.ApiUrl, 'secret-access-requests', 'secrets', $secret, 'view-comment' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'POST'

$writeViewBody = @{}
switch ($tssParams.Keys) {
'Comment' { $writeViewBody.Add('comment', $Comment) }
'TicketNumber' { $writeViewBody.Add('ticketNumber', $TicketNumber) }
'TicketSystemId' { $writeViewBody.Add('ticketSystemId', $TicketSystemId) }
}
$invokeParams.Body = $writeViewBody | ConvertTo-Json
if ($PSCmdlet.ShouldProcess("Secret ID: $secret", "$($invokeParams.Method) $uri with: `n$($invokeParams.Body)")) {
Write-Verbose "$($invokeParams.Method) $uri with: `n$($invokeParams.Body)"
try {
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue writing view comment to Secret [$secret]"
$err = $_
. $ErrorHandling $err
}

if ($restResponse) {
Write-Verbose "Comment successfully written to Secret [$secret]"
}
}
}
} else {
Write-Warning 'No valid session found'
}
}
}
@@ -0,0 +1,19 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
[object[]]$knownParameters = 'TssSession', 'Id', 'Comment', 'TicketNumber', 'TicketSystemId'
[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
}
}
}

0 comments on commit c537ce5

Please sign in to comment.