Skip to content

Commit

Permalink
Find-Group - closes #57
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed May 29, 2021
1 parent 14ba703 commit 257a8d6
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/_data/navigation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ commands:

- title: "Groups"
children:
- title: "Find-TssGroup"
url: /commands/Find-TssGroup
- title: "Get-TssGroupMember"
url: /commands/Get-TssGroupMember
- title: "Search-TssUserGroup"
Expand Down Expand Up @@ -316,8 +318,12 @@ abouttopics:

- title: "Groups"
children:
- title: "TssGroupLookup"
url: /abouttopics/about_tssgrouplookup
- title: "TssGroupSummary"
url: /abouttopics/about_tssgroupsummary
- title: "TssGroupUserSummary"
url: /abouttopics/about_tssgroupusersummary

- title: "Reports"
children:
Expand Down
28 changes: 28 additions & 0 deletions docs/collections/_abouttopics/about_tssgrouplookup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
category: groups
title: "TssGroupLookup"
last_modified_at: 2021-05-26T00:00:00-00:00
---

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

# CLASS
TssGroupLookup

# INHERITANCE
None

# DESCRIPTION
The TssGroupLookup class represents the GroupLookup object returned by Secret Server endpoint GET /groups/lookup

# CONSTRUCTORS
new()

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

# METHODS

# RELATED LINKS:
Find-TssGroup
6 changes: 6 additions & 0 deletions docs/collections/_pages/abouttopics.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ About topics cover the [PowerShell classes](https://docs.microsoft.com/en-us/pow

**Class** | **Thycotic.SecretServer Command** |
--------------------------------- | -------------------------------------------------- |
[TssGroupLookup] | [Find-TssGroup]
[TssGroupSummary] | [Search-TssGroup]
[TssGroupUserSummary] | [Get-TssGroupMember]

## Reports

Expand Down Expand Up @@ -207,7 +209,11 @@ About topics cover the [PowerShell classes](https://docs.microsoft.com/en-us/pow
[Get-TssSecretDependency]:/thycotic.secretserver/commands/Get-TssSecretDependency
[Get-TssSecretDependencyRunStatus]:/thycotic.secretserver/commands/Get-TssSecretDependencyRunStatus
[Get-TssSecretDependencyTemplate]:/thycotic.secretserver/commands/Get-TssSecretDependencyTemplate
[Find-TssGroup]:/thycotic.secretserver/commands/Find-TssGroup
[Get-TssGroupMember]:/thycotic.secretserver/commands/Get-TssGroupMember

[TssGroupUserSummary]:/thycotic.secretserver/abouttopics/about_tssgroupusersummary
[TssGroupLookup]:/thycotic.secretserver/abouttopics/about_tssgrouplookup
[TssDependencyTemplate]:/thycotic.secretserver/abouttopics/about_tssdependencytemplate
[TssSecretDependencyTaskError]:/thycotic.secretserver/abouttopics/about_tsssecretdependencytaskerror
[TssSecretDependencyTaskProgress]:/thycotic.secretserver/abouttopics/about_tsssecretdependencytaskprogress
Expand Down
4 changes: 3 additions & 1 deletion docs/collections/_pages/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ The table below lists the API endpoints matched up to the function that directly

**Command** | **API Endpoint** |
---------------- | --------------------------------- |
[Find-TssGroup] | GET /groups/lookups
[Get-TssGroupMember] | GET /groups/{id}/users
[Search-TssGroup] | GET /groups

Expand Down Expand Up @@ -271,4 +272,5 @@ The table below lists the API endpoints matched up to the function that directly
[Remove-TssSecretDependency]:/thycotic.secretserver/commands/Remove-TssSecretDependency
[Start-TssSecretDependency]:/thycotic.secretserver/commands/Start-TssSecretDependency
[Get-TssSecretDependencyRunStatus]:/thycotic.secretserver/commands/Get-TssSecretDependencyRunStatus
[Get-TssSecretDependencyTemplate]:/thycotic.secretserver/commands/Get-TssSecretDependencyTemplate
[Get-TssSecretDependencyTemplate]:/thycotic.secretserver/commands/Get-TssSecretDependencyTemplate
[Find-TssGroup]:/thycotic.secretserver/commands/Find-TssGroup
28 changes: 28 additions & 0 deletions src/Thycotic.SecretServer.Format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -1626,5 +1626,33 @@
</TableControl>
</View>

<!-- Find-TssGroup -->
<View>
<Name>TssGroupLookup</Name>
<ViewSelectedBy>
<TypeName>TssGroupLookup</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
</TableColumnHeader>
<TableColumnHeader>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>GroupId</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>GroupName</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>

</ViewDefinitions>
</Configuration>
13 changes: 13 additions & 0 deletions src/Thycotic.SecretServer.Types.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,17 @@
</AliasProperty>
</Members>
</Type>
<Type>
<Name>TssGroupLookup</Name>
<Members>
<AliasProperty>
<Name>GroupId</Name>
<ReferencedMemberName>Id</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>GroupName</Name>
<ReferencedMemberName>Value</ReferencedMemberName>
</AliasProperty>
</Members>
</Type>
</Types>
7 changes: 7 additions & 0 deletions src/classes/groups/TssGroupLookup.class.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class TssGroupLookup {
[int]
$Id

[string]
$Value
}
22 changes: 22 additions & 0 deletions src/en-us/about_tssgrouplookup.help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
TOPIC
This help topic describes the TssGroupLookup class in the Thycotic.SecretServer module

CLASS
TssGroupLookup

INHERITANCE
None

DESCRIPTION
The TssGroupLookup class represents the GroupLookup object returned by Secret Server endpoint GET /groups/lookup

CONSTRUCTORS
new()

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

METHODS

RELATED LINKS:
Find-TssGroup
104 changes: 104 additions & 0 deletions src/functions/groups/Find-Group.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
function Find-Group {
<#
.SYNOPSIS
Find for a Secret Server Group
.DESCRIPTION
Find for a Secret Server Group (domain or local)
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/Find-TssGroup
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/groups/Find-Group.ps1
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Find-TssGroup -TssSession $session -DomainId 1
Return list of Groups found in Secret Server for Domain Directory 1
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha/SecretServer -Credential $ssCred
Find-TssGroup -TssSession $session -SearchText 'IT'
Return list of Groups found in Secret Server matching the characters IT
.NOTES
Requires TssSession object returned by New-TssSession
#>
[CmdletBinding()]
[OutputType('TssGroupLookup')]
param (
# TssSession object created by New-TssSession for auth
[Parameter(Mandatory, ValueFromPipeline, Position = 0)]
[TssSession]
$TssSession,

# Director Services Domain Id
[int]
$DomainId,

# Limit to groups the current user can view details
[switch]
$ViewableGroups,

# Search text
[string]
$SearchText,

# Include inactive Groups
[switch]
$IncludeInactive,

# Sort by specific property, default Name
[string]
$SortBy = 'Name'
)
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
$restResponse = $null
$uri = $TssSession.ApiUrl, 'groups', 'lookup' -join '/'
$uri = $uri, "sortBy[0].direction=asc&sortBy[0].name=$SortBy&take=$($TssSession.Take)" -join '?'
$invokeParams.Method = 'GET'

$filters = @()
switch ($tssParams.Keys) {
'DomainId' { $filters += "filter.domainId=$DomainId" }
'IncludeInactive' { $filters += "filter.includeInactive=$([boolean]$IncludeInactive)" }
'ViewableGroups' { $filters += "filter.limitToViewableGroups=$([boolean]$ViewableGroups)" }
'SearchText' { $filters += "filter.searchText=$SearchText" }
}
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 find request"
$err = $_
. $ErrorHandling $err
}

if ($restResponse.records.Count -le 0 -and $restResponse.records.Length -eq 0) {
Write-Warning "No Group found"
}
if ($restResponse.records) {
[TssGroupLookup[]]$restResponse.records
}
} else {
Write-Warning "No valid session found"
}
}
}
25 changes: 25 additions & 0 deletions tests/groups/Find-Group.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
. ([IO.Path]::Combine([string]$PSScriptRoot, '..', 'constants.ps1'))
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
[object[]]$knownParameters = 'TssSession', 'DomainId', 'IncludeInactive', 'SearchText', 'ViewableGroups'
[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 TssGroupLookup" -TestCases $commandDetails {
$_.OutputType.Name | Should -Be 'TssGroupLookup'
}
}
}

0 comments on commit 257a8d6

Please sign in to comment.