Skip to content

Commit

Permalink
Search-TssSecretsByUrl - new command to check which Secret(s) is retu…
Browse files Browse the repository at this point in the history
…rned for a given URL, endpoint used by WPF
  • Loading branch information
wsmelton committed Oct 19, 2021
1 parent e9962a1 commit 20dc14c
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 35 deletions.
73 changes: 73 additions & 0 deletions docs/commands/secret-extensions/Search-TssSecretsByUrl.md
@@ -0,0 +1,73 @@
# Search-TssSecretsByUrl

## SYNOPSIS
Search for Secrets that match a URL for Web Password Filler

## SYNTAX

```
Search-TssSecretsByUrl [-TssSession] <Session> [-Url <String>] [<CommonParameters>]
```

## DESCRIPTION
Search for Secrets that match a URL for Web Password Filler

## EXAMPLES

### EXAMPLE 1
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Search-TssWpfSecretsByUrl -TssSession $session -Url 'https://citibank.com/login'
```

Return Secrets that match the URL provided

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

### -Url
URL to search against

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

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

### Thycotic.PowerShell.SecretExtensions.Secret
## NOTES
Requires TssSession object returned by New-TssSession

## RELATED LINKS

[https://thycotic-ps.github.io/thycotic.secretserver/commands/secret-extensions/Search-TssSecretsByUrl](https://thycotic-ps.github.io/thycotic.secretserver/commands/secret-extensions/Search-TssSecretsByUrl)

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

98 changes: 63 additions & 35 deletions src/Thycotic.SecretServer.Format.ps1xml
Expand Up @@ -144,53 +144,21 @@
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>SecretTemplateFieldId</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>DisplayName</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>FieldSlugName</PropertyName>
<PropertyName>Id</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>IsRequired</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>IsFile</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>IsPassword</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>IsNotes</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>IsUrl</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>HideOnView</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>ExposeForDisplay</PropertyName>
<PropertyName>Fields</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>SortOrder</PropertyName>
<PropertyName>PasswordTypeId</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
Expand Down Expand Up @@ -3906,5 +3874,65 @@
</TableControl>
</View>

<!-- Thycotic.PowerShell.SecretExtensions.Secret -->
<View>
<Name>SecretExtensions.Secret</Name>
<ViewSelectedBy>
<TypeName>Thycotic.PowerShell.SecretExtensions.Secret</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Width>18</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>10</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>20</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>15</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>20</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>35</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>15</Width>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>SecretTemplateId</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>SecretId</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>SecretName</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>MatchOrderType</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>HasOwnerOrEditAccess</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>SecretUrl</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>RequireComment</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>

</ViewDefinitions>
</Configuration>
17 changes: 17 additions & 0 deletions src/Thycotic.SecretServer.Types.ps1xml
Expand Up @@ -321,6 +321,23 @@
</ScriptProperty>
</Members>
</Type>
<Type>
<Name>Thycotic.PowerShell.SecretExtensions.Secret</Name>
<Members>
<AliasProperty>
<Name>SecretTemplateId</Name>
<ReferencedMemberName>SecretTypeId</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>SecretId</Name>
<ReferencedMemberName>Id</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>SecretName</Name>
<ReferencedMemberName>Name</ReferencedMemberName>
</AliasProperty>
</Members>
</Type>

<Type>
<Name>Thycotic.PowerShell.Diagnostics.Diagnostic</Name>
Expand Down
25 changes: 25 additions & 0 deletions src/Thycotic.SecretServer/classes/secret-extensions/Secret.cs
@@ -0,0 +1,25 @@
using System;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using Thycotic.PowerShell.Enums;

namespace Thycotic.PowerShell.SecretExtensions
{
public class Secret
{
public bool HasOwnerOrEditAccess { get; set; }
public int Id { get; set; }
public bool IsButtonBound { get; set; }
public bool IsFavoriteSecret { get; set; }
public bool IsSystemFolder { get; set; }
public SecretMatchType MatchOrderType { get; set; }
public string Name { get; set; }
public string RedirectUrl { get; set; }
public bool RequireComment { get; set; }
public int ResultPriority { get; set; }
public int SecretTypeId { get; set; }
public string SecretUrl { get; set; }
public bool ShouldRedirect { get; set; }
}
}
@@ -0,0 +1,14 @@
using System;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;

namespace Thycotic.PowerShell.Enums
{
public enum SecretMatchType
{
Loose,
Partial,
Exact
}
}
69 changes: 69 additions & 0 deletions src/functions/secret-extensions/Search-TssSecretsByUrl.ps1
@@ -0,0 +1,69 @@
function Search-TssSecretsByUrl {
<#
.SYNOPSIS
Search for Secrets that match a URL for Web Password Filler
.DESCRIPTION
Search for Secrets that match a URL for Web Password Filler
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/secret-extensions/Search-TssSecretsByUrl
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-extensions/Search-TssSecretsByUrl.ps1
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Search-TssWpfSecretsByUrl -TssSession $session -Url 'https://citibank.com/login'
Return Secrets that match the URL provided
.NOTES
Requires TssSession object returned by New-TssSession
#>
[CmdletBinding()]
[OutputType('Thycotic.PowerShell.SecretExtensions.Secret')]
param (
# TssSession object created by New-TssSession for authentication
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[Thycotic.PowerShell.Authentication.Session]
$TssSession,

# URL to search against
[string]
$Url
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeApiParams $TssSession
}
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'secret-extensions', 'search-by-url' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'POST'
$invokeParams.Body = "`"$Url`""

Write-Verbose "Performing the operation $($invokeParams.Method) $($invokeParams.Uri) with $($invokeParams.Body)"
try {
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} 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 records found"
}
if ($restResponse.model) {
[Thycotic.PowerShell.SecretExtensions.Secret[]]$restResponse.model
}
} else {
Write-Warning "No valid session found"
}
}
}
24 changes: 24 additions & 0 deletions tests/secret-extensions/Search-TssSecretsByUrl.Tests.ps1
@@ -0,0 +1,24 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
[object[]]$knownParameters = 'TssSession', 'Url'
[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.SecretExtensions.Secret" -TestCases $commandDetails {
$_.OutputType.Name | Should -Be 'Thycotic.PowerShell.SecretExtensions.Secret'
}
}
}

0 comments on commit 20dc14c

Please sign in to comment.