-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
280 additions
and
0 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
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,22 @@ | ||
class TssGroupSummary { | ||
# Created date | ||
[datetime]$Created | ||
# Domain Directory Group GUID | ||
[string]$DomainGuid | ||
# Directory Domain ID | ||
[int]$DomainId | ||
# Directory Domain Name | ||
[string]$DomainName | ||
# Group is Active | ||
[boolean]$Enabled | ||
# Group ID | ||
[int]$Id | ||
# Number of members | ||
[int]$MemberCount | ||
# Group Name | ||
[string]$Name | ||
# Group is synchronized with Active Directory | ||
[boolean]$Synchronized | ||
# Active Directory Sync will pull members for domain groups | ||
[boolean]$SynchronizeNow | ||
} |
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,103 @@ | ||
function Search-UserGroup { | ||
<# | ||
.SYNOPSIS | ||
Search for user management groups | ||
.DESCRIPTION | ||
Search for user management groups | ||
.EXAMPLE | ||
PS C:\> $session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
PS C:\> Search-UserGroup -TssSession $session | ||
Return list of all groups found in Secret Server that account has access to manage | ||
.NOTES | ||
Requires TssSession object returned by New-TssSession | ||
#> | ||
[CmdletBinding()] | ||
[OutputType('TssGroupSummary')] | ||
param ( | ||
# TssSession object created by New-TssSession for auth | ||
[Parameter(Mandatory, | ||
ValueFromPipeline, | ||
Position = 0)] | ||
[TssSession]$TssSession, | ||
|
||
# Active Directory Domain Id | ||
[int] | ||
$DomainId, | ||
|
||
# Include inactive groups in results | ||
[switch] | ||
$IncludeInactive, | ||
|
||
# Text to search for group name | ||
[string] | ||
$SearchText, | ||
|
||
# Sort by specific property, default Name | ||
[string] | ||
$SortBy = 'Name', | ||
|
||
# Output the raw response from the API endpoint | ||
[switch] | ||
$Raw | ||
) | ||
begin { | ||
$tssParams = . $SearchUserGroupParams $PSBoundParameters | ||
$invokeParams = @{ } | ||
|
||
$groupParams = . $SearchUserGroupParams $PSBoundParameters | ||
$groupParams.Remove('TssSession') | ||
$groupParams.Remove('Raw') | ||
} | ||
|
||
process { | ||
Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)" | ||
if ($tssParams.Contains('TssSession') -and $TssSession.IsValidSession()) { | ||
$uri = $TssSession.ApiUrl, 'groups' -join '/' | ||
$uri += "?sortBy[0].direction=asc&sortBy[0].name=$SortBy&take=$($TssSession.Take)" | ||
|
||
$filters = @() | ||
if ($groupParams.Contains('DomainId')) { | ||
$filters += "filter.domainId=$DomainId" | ||
} | ||
if ($groupParams.Contains('IncludeInactive')) { | ||
$filters += "filter.includeInactive=$IncludeInactive" | ||
} | ||
if ($groupParams.Contains('SearchText')) { | ||
$filters += "filter.searchText=$SearchText" | ||
} | ||
if ($filters) { | ||
$uriFilter = $filters -join '&' | ||
Write-Verbose "Filters: $uriFilter" | ||
$uri = $uri, $uriFilter -join '&' | ||
} | ||
|
||
$invokeParams.Uri = $uri | ||
$invokeParams.PersonalAccessToken = $TssSession.AccessToken | ||
$invokeParams.Method = 'GET' | ||
Write-Verbose "$($invokeParams.Method) $uri" | ||
try { | ||
$restReponse = Invoke-TssRestApi @invokeParams | ||
} catch { | ||
Write-Warning "Issue on search request" | ||
$err = $_.ErrorDetails.Message | ||
Write-Error $err | ||
} | ||
|
||
if ($tssParams['Raw']) { | ||
return $restReponse | ||
} | ||
if ($restReponse.records.Count -le 0 -and $restReponse.records.Length -eq 0) { | ||
Write-Warning "No groups found" | ||
} | ||
if ($restReponse.records) { | ||
. $TssGroupSummaryObject $restReponse.records | ||
} | ||
} else { | ||
Write-Warning "No valid session found" | ||
} | ||
} | ||
} |
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,35 @@ | ||
<# | ||
.Synopsis | ||
Gets Search-TssUserGroup's parameters | ||
.Description | ||
Gets the parameters for Search-TssUserGroup from a collection of parameters | ||
#> | ||
param( | ||
# A collection of parameters. Parameters not used in Search-TssUserGroup will be removed | ||
[Parameter(ValueFromPipeline,Position = 0,Mandatory,ParameterSetName = 'GetParameterValues')] | ||
[Alias('Parameters')] | ||
[Collections.IDictionary] | ||
$Parameter | ||
) | ||
|
||
begin { | ||
if (-not ${script:Search-TssUserGroup}) { | ||
# If we haven't cached a reference to Search-TssUserGroup, | ||
${script:Search-TssUserGroup} = # make it so. | ||
[Management.Automation.CommandMetaData]$ExecutionContext.SessionState.InvokeCommand.GetCommand('Search-TssUserGroup', 'Function') | ||
} | ||
} | ||
|
||
process { | ||
if ($PSCmdlet.ParameterSetName -eq 'GetParameterValues') { | ||
$searchReportSched = [Ordered]@{ } + $Parameter # Then we copy our parameters | ||
foreach ($k in @($searchReportSched.Keys)) { | ||
# and walk thru each parameter name. | ||
# If a parameter isn't found in Search-TssUserGroup | ||
if (-not ${script:Search-TssUserGroup}.Parameters.ContainsKey($k)) { | ||
$searchReportSched.Remove($k) # we remove it. | ||
} | ||
} | ||
return $searchReportSched | ||
} | ||
} |
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,29 @@ | ||
<# | ||
.Synopsis | ||
Creates a TssGroupSummary class in the Thycotic.SecretServer module. | ||
.Description | ||
Creates an instance of the TssGroupSummary class to output the GroupSummary object | ||
#> | ||
param( | ||
[pscustomobject]$Object | ||
) | ||
|
||
begin { | ||
$Properties = $Object[0].PSObject.Properties.Name | ||
} | ||
|
||
process { | ||
$outObject = @() | ||
foreach ($g in $Object) { | ||
$outGroupSummary = [TssGroupSummary]::new() | ||
foreach ($rsProp in $Properties) { | ||
if ($rsProp -in $outGroupSummary.PSObject.Properties.Name) { | ||
$outGroupSummary.$rsProp = $g.$rsProp | ||
} else { | ||
Write-Warning "Property $rsProp does not exist in the TssGroupSummary class. Please create a bug report at https://github.com/thycotic-ps/thycotic.secretserver/issues/new/choose" | ||
} | ||
} | ||
$outObject += $outGroupSummary | ||
} | ||
return $outObject | ||
} |
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,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', 'Raw', 'DomainId', 'IncludeInactive', 'SearchText', '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 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 TssGroupSummary" -TestCases $commandDetails { | ||
$_.OutputType.Name | Should -Be 'TssGroupSummary' | ||
} | ||
} | ||
} |