Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Search-TssSecretAccessRequest - new command
- Loading branch information
Showing
9 changed files
with
383 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
docs/commands/secret-access-requests/Search-TssSecretAccessRequest.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# Search-TssSecretAccessRequest | ||
|
||
## SYNOPSIS | ||
Search Access Request for Secrets by status for current user. | ||
|
||
## SYNTAX | ||
|
||
``` | ||
Search-TssSecretAccessRequest [-TssSession] <Session> [-Status] <String> [-IsMyRequest] [-SortBy <String>] | ||
[<CommonParameters>] | ||
``` | ||
|
||
## DESCRIPTION | ||
Search Access Request for Secrets by status for current user. | ||
|
||
## EXAMPLES | ||
|
||
### EXAMPLE 1 | ||
``` | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
Search-TssAccessRequest -TssSession $session -IsMyRequest | ||
``` | ||
|
||
Return all Access Requests that the connected user submitted | ||
|
||
### EXAMPLE 2 | ||
``` | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
Search-TssAccessRequest -TssSession $session -Status Pending | ||
``` | ||
|
||
Return all pending Access Requests where connected user is submitter or an approver | ||
|
||
## PARAMETERS | ||
|
||
### -TssSession | ||
TssSession object created by New-TssSession for auth | ||
|
||
```yaml | ||
Type: Session | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: True | ||
Position: 1 | ||
Default value: None | ||
Accept pipeline input: True (ByValue) | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### -Status | ||
Status of the request | ||
|
||
```yaml | ||
Type: String | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: True | ||
Position: 2 | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### -IsMyRequest | ||
Is request submitted by connecting user | ||
|
||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: False | ||
Position: Named | ||
Default value: False | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### -SortBy | ||
Sort by specific property, default SecretId | ||
|
||
```yaml | ||
Type: String | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: False | ||
Position: Named | ||
Default value: SecretId | ||
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.AccessRequests.Request | ||
## NOTES | ||
Requires TssSession object returned by New-TssSession | ||
|
||
## RELATED LINKS | ||
|
||
[https://thycotic-ps.github.io/thycotic.secretserver/commands/Search-TssAccessRequest](https://thycotic-ps.github.io/thycotic.secretserver/commands/Search-TssAccessRequest) | ||
|
||
[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-access-requests/Search-TssAccessRequest.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-access-requests/Search-TssAccessRequest.ps1) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/functions/secret-access-requests/Search-TssSecretAccessRequest.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
function Search-TssSecretAccessRequest { | ||
<# | ||
.SYNOPSIS | ||
Search Access Request for Secrets by status for current user. | ||
.DESCRIPTION | ||
Search Access Request for Secrets by status for current user. | ||
.LINK | ||
https://thycotic-ps.github.io/thycotic.secretserver/commands/Search-TssAccessRequest | ||
.LINK | ||
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-access-requests/Search-TssAccessRequest.ps1 | ||
.EXAMPLE | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
Search-TssAccessRequest -TssSession $session -IsMyRequest | ||
Return all Access Requests that the connected user submitted | ||
.EXAMPLE | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
Search-TssAccessRequest -TssSession $session -Status Pending | ||
Return all pending Access Requests where connected user is submitter or an approver | ||
.NOTES | ||
Requires TssSession object returned by New-TssSession | ||
#> | ||
[CmdletBinding()] | ||
[OutputType('Thycotic.PowerShell.AccessRequests.Request')] | ||
param ( | ||
# TssSession object created by New-TssSession for auth | ||
[Parameter(Mandatory,ValueFromPipeline, Position = 0)] | ||
[Thycotic.PowerShell.Authentication.Session] | ||
$TssSession, | ||
|
||
# Status of the request | ||
[Parameter(Mandatory, Position = 1)] | ||
[ValidateSet('WaitingForRequest','Pending','Approved','Denied','Canceled','Expired')] | ||
[string] | ||
$Status, | ||
|
||
# Is request submitted by connecting user | ||
[switch] | ||
$IsMyRequest, | ||
|
||
# Sort by specific property, default SecretId | ||
[string] | ||
$SortBy = 'SecretId' | ||
) | ||
begin { | ||
$tssParams = $PSBoundParameters | ||
$invokeParams = . $GetInvokeTssParams $TssSession | ||
} | ||
process { | ||
Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)" | ||
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) { | ||
. $CheckVersion $TssSession '10.9.000000' $PSCmdlet.MyInvocation | ||
$uri = $TssSession.ApiUrl, 'secret-access-requests' -join '/' | ||
$uri = $uri, "sortBy[0].direction=asc&sortBy[0].name=$SortBy&take=$($TssSession.Take)" -join '?' | ||
$invokeParams.Method = 'GET' | ||
|
||
$filters = @() | ||
switch ($tssParams.Keys) { | ||
'IsMyRequest' { $filters += "filter.IsMyRequest=$([boolean]$IsMyRequest)" } | ||
'Status' { $filters += "filter.status=$Status" } | ||
} | ||
if ($filters) { | ||
$uriFilter = $filters -join '&' | ||
Write-Verbose "Filters: $uriFilter" | ||
$uri = $uri, $uriFilter -join '&' | ||
} | ||
$invokeParams.Uri = $uri | ||
|
||
Write-Verbose "Performing the operation $($invokeParams.Method) $uri" | ||
try { | ||
$restResponse = . $InvokeApi @invokeParams | ||
} catch { | ||
Write-Warning "Issue on search request" | ||
$err = $_ | ||
. $ErrorHandling $err | ||
} | ||
|
||
if ($restResponse.records.Count -le 0 -and $restResponse.records.Length -eq 0) { | ||
Write-Warning "No AccessRequest found" | ||
} | ||
if ($restResponse.records) { | ||
[Thycotic.PowerShell.AccessRequests.Request[]]$restResponse.records | ||
} | ||
} else { | ||
Write-Warning "No valid session found" | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
tests/event-pipeline-policy/Get-TssEventPipelineList.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
BeforeDiscovery { | ||
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf | ||
} | ||
Describe "$commandName verify parameters" { | ||
BeforeDiscovery { | ||
[object[]]$knownParameters = 'TssSession', 'FolderId', 'IncludeInactive', '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.EventPipelinePolicy.List" -TestCases $commandDetails { | ||
$_.OutputType.Name | Should -Be 'Thycotic.PowerShell.EventPipelinePolicy.List' | ||
} | ||
} | ||
} | ||
Describe "$commandName functions" { | ||
Context "Checking" { | ||
BeforeAll { | ||
$session = [pscustomobject]@{ | ||
ApiVersion = 'api/v1' | ||
Take = 2147483647 | ||
SecretServer = 'http://alpha/' | ||
SecretServerVersion= '10.9.000000' | ||
ApiUrl = 'http://alpha/api/v1' | ||
AccessToken = 'AgJf5YLChrisPine312UcBrM1s1KB2BGZ5Ufc4qLZ' | ||
RefreshToken = '9oacYeah0YqgBNg0L7VinDiesel6-Z9ITE51Humus' | ||
TokenType = 'bearer' | ||
ExpiresIn = 1199 | ||
} | ||
|
||
Mock -Verifiable -CommandName Invoke-RestMethod -ParameterFilter { $Uri -match '/Endpoint' } -MockWith { | ||
return [pscustomobject]@{ | ||
# Object expected by REST API call | ||
} | ||
} | ||
$object = Endpoint -TssSession $session Parameters | ||
Assert-VerifiableMock | ||
} | ||
It "Should not be empty" { | ||
$object | Should -Not -BeNullOrEmpty | ||
} | ||
It "Should have property <_>" -TestCases Properties { | ||
$object[0].PSObject.Properties.Name | Should -Contain $_ | ||
} | ||
It "Should have property Property equal value" { | ||
$object.Property | Should -Be value | ||
} | ||
It "Should have called Invoke-RestMethod 2 times" { | ||
Assert-MockCalled -CommandName Invoke-RestMethod -Times 2 -Scope Describe | ||
} | ||
} | ||
} |
Oops, something went wrong.