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
5 changed files
with
202 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class TssDomainSummary { | ||
[boolean] | ||
$Active | ||
|
||
[int] | ||
$DomainId | ||
|
||
[string] | ||
$DomainName | ||
|
||
[ValidateSet('ActiveDirectory','OpenLdap','AzureActiveDirectory')] | ||
[string] | ||
$DomainType | ||
|
||
[string] | ||
$FriendlyName | ||
|
||
[boolean] | ||
$RequireRadiusAuthentication | ||
|
||
[boolean] | ||
$UseSecureLdap | ||
} |
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,41 @@ | ||
TOPIC | ||
This help topic describes the TssDomainSummary class in the Thycotic.SecretServer module | ||
|
||
CLASS | ||
TssDomainSummary | ||
|
||
INHERITANCE | ||
None | ||
|
||
DESCRIPTION | ||
The TssDomainSummary class represents the DomainSummary object returned by Secret Server endpoint GET /directory-services/domains | ||
|
||
CONSTRUCTORS | ||
new() | ||
|
||
PROPERTIES | ||
Active | ||
Directory Serivce Domain is active | ||
|
||
DomainId | ||
Directory Service Domain ID | ||
|
||
DomainName | ||
Directory Service Domain Name | ||
|
||
DomainType | ||
Directory Service Domain Type (ActiveDirectory, OpenLdap,AzureActiveDirectory) | ||
|
||
FriendlyName | ||
Directory Service Domain friendly name | ||
|
||
RequireRadiusAuthentication | ||
Requires RADIUS Authentication | ||
|
||
UseSecureLdap | ||
Using Secure LDAP | ||
|
||
METHODS | ||
|
||
RELATED LINKS: | ||
Search-TssDirectoryServiceDomain |
86 changes: 86 additions & 0 deletions
86
src/functions/directory-services/Search-DirectoryServiceDomain.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,86 @@ | ||
function Search-DirectoryServiceDomain { | ||
<# | ||
.SYNOPSIS | ||
Search Directory Services domains | ||
.DESCRIPTION | ||
Search Directory Services domains | ||
.EXAMPLE | ||
PS> $session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
PS> Search-TssDirectoryServiceDomain -TssSession $session -DomainName lab.local | ||
Return the domain lab.local information | ||
.NOTES | ||
Requires TssSession object returned by New-TssSession | ||
#> | ||
[CmdletBinding()] | ||
[OutputType('TssDomainSummary')] | ||
param ( | ||
# TssSession object created by New-TssSession for auth | ||
[Parameter(Mandatory,ValueFromPipeline,Position = 0)] | ||
[TssSession] | ||
$TssSession, | ||
|
||
# Domain Name | ||
[Alias("Domain")] | ||
[int] | ||
$DomainName, | ||
|
||
# Include inactive domains | ||
[switch] | ||
$IncludeInactive, | ||
|
||
# Sort by specific property, default DomainName | ||
[string] | ||
$SortBy = 'DomainName' | ||
) | ||
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, 'directory-services', 'domains' -join '/' | ||
$uri = $uri, "sortBy[0].direction=asc&sortBy[0].name=$SortBy&take=$($TssSession.Take)" -join '?' | ||
|
||
$filters = @() | ||
if ($tssParams.ContainsKey('DomainName')) { | ||
$filters += "filter.DomainName=$DomainName" | ||
} | ||
if ($tssParams.ContainsKey('IncludeInactive')) { | ||
$filters += "filter.includeInactive=$([boolean]$IncludeInactive)" | ||
} | ||
if ($filters) { | ||
$uriFilter = $filters -join '&' | ||
Write-Verbose "Filters: $uriFilter" | ||
$uri = $uri, $uriFilter -join '&' | ||
} | ||
|
||
$invokeParams.Uri = $uri | ||
$invokeParams.Method = 'GET' | ||
|
||
Write-Verbose "Performing the operation $($invokeParams.Method) $uri" | ||
try { | ||
$restResponse = Invoke-TssRestApi @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 Directory Domain found" | ||
} | ||
if ($restResponse.records) { | ||
. $TssDomainSummaryObject $restResponse.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,27 @@ | ||
<# | ||
.Synopsis | ||
Creates a TssDomainSummary object to output the DomainSummary object | ||
#> | ||
param( | ||
[pscustomobject]$Object | ||
) | ||
|
||
begin { | ||
$Properties = $Object[0].PSObject.Properties.Name | ||
} | ||
|
||
process { | ||
$outObject = @() | ||
foreach ($p in $Object) { | ||
$currentObject = [TssDomainSummary]::new() | ||
foreach ($pProp in $Properties) { | ||
if ($pProp -in $currentObject.PSObject.Properties.Name) { | ||
$currentObject.$pProp = $p.$pProp | ||
} else { | ||
Write-Warning "Property $pProp does not exist in the TssDomainSummary class. Please create a bug report at https://github.com/thycotic-ps/thycotic.secretserver/issues/new/choose" | ||
} | ||
} | ||
$outObject += $currentObject | ||
} | ||
return $outObject | ||
} |
25 changes: 25 additions & 0 deletions
25
tests/directory-services/Search-TssDirectoryServiceDomain.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,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', 'DomainName', '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 TssDomainSummary" -TestCases $commandDetails { | ||
$_.OutputType.Name | Should -Be 'TssDomainSummary' | ||
} | ||
} | ||
} |