-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ADD Find-SharedServicesURL Helper function to find URLs for different ISPSS shared services based on tenant subdomain * UPDATE ConvertTo-QueryString If multiple values are accepted and provided for a value, return all values joined, delimited by a comma. Implemented for functionality required in the `IdentityCommand.DPA` module and the `Get-DPAStrongAccount` function. * Update CHANGELOG.md
- Loading branch information
Showing
4 changed files
with
211 additions
and
1 deletion.
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,116 @@ | ||
function Find-SharedServicesURL { | ||
<# | ||
.SYNOPSIS | ||
Find URL details for ISPSS shared services | ||
.DESCRIPTION | ||
Given a shared services subdomain or URL value, returns details of URLs for available Shared Services. | ||
.PARAMETER subdomain | ||
The Shared Services subdomain to return service URL values of. | ||
.PARAMETER url | ||
The Shared Services URL to return service URL values of. | ||
.PARAMETER service | ||
Specify to return the API URL of a particular service. | ||
.EXAMPLE | ||
Find-SharedServicesURL -subdomain somedomain | ||
.EXAMPLE | ||
Find-SharedServicesURL -url https://someotherdomain.cyberark.cloud | ||
.EXAMPLE | ||
Find-SharedServicesURL -subdomain somedomain -service pcloud | ||
.NOTES | ||
Pete Maan 2023 | ||
#> | ||
[CmdletBinding()] | ||
Param( | ||
[Parameter( | ||
Mandatory = $true, | ||
ValueFromPipeline = $true, | ||
ParameterSetName = 'Subdomain' | ||
)] | ||
[string]$subdomain, | ||
|
||
[Parameter( | ||
Mandatory = $true, | ||
ValueFromPipeline = $true, | ||
ParameterSetName = 'URL' | ||
)] | ||
[string]$url, | ||
|
||
[Parameter( | ||
Mandatory = $false, | ||
ValueFromPipeline = $true | ||
)] | ||
[ValidateSet( | ||
'analytics', | ||
'audit', | ||
'cem', | ||
'cloud_onboarding', | ||
'component_manager', | ||
'flows', | ||
'idaptive_risk_analytics', | ||
'identity_administration', | ||
'identity_compliance', | ||
'identity_user_portal', | ||
'jit', | ||
'pcloud', | ||
'sca', | ||
'secrets_hub', | ||
'secrets_manager', | ||
'session_monitoring' | ||
)] | ||
[string]$service | ||
) | ||
|
||
Begin { | ||
$PlatformDiscoveryURL = 'https://platform-discovery.cyberark.cloud/api/v2/services/subdomain/' | ||
} | ||
|
||
Process { | ||
|
||
if ($PSCmdlet.ParameterSetName -eq 'URL') { | ||
$URIObject = [System.UriBuilder]::new($url) | ||
$subdomain = $URIObject.host.Split('.') | Select-Object -First 1 | ||
} | ||
|
||
$PlatformDiscoveryURL = $PlatformDiscoveryURL + $subdomain | ||
|
||
$Result = Invoke-IDRestMethod -URI $PlatformDiscoveryURL -Method GET | ||
|
||
If ($null -ne $Result) { | ||
|
||
If ($PSBoundParameters.ContainsKey('service')) { | ||
|
||
$Services = $Result | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name | ||
|
||
If ($Services -notcontains $Service) { | ||
|
||
throw "URL for $service API not found" | ||
|
||
} | ||
|
||
Else { | ||
|
||
$Result | Select-Object -ExpandProperty $service | ||
|
||
} | ||
|
||
} Else { | ||
|
||
$Result | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
End {} | ||
|
||
} |
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,80 @@ | ||
Describe $($PSCommandPath -Replace '.Tests.ps1') { | ||
|
||
BeforeAll { | ||
#Get Current Directory | ||
$Here = Split-Path -Parent $PSCommandPath | ||
|
||
#Assume ModuleName from Repository Root folder | ||
$ModuleName = Split-Path (Split-Path $Here -Parent) -Leaf | ||
|
||
#Resolve Path to Module Directory | ||
$ModulePath = Resolve-Path "$Here\..\$ModuleName" | ||
|
||
#Define Path to Module Manifest | ||
$ManifestPath = Join-Path "$ModulePath" "$ModuleName.psd1" | ||
|
||
if ( -not (Get-Module -Name $ModuleName -All)) { | ||
|
||
Import-Module -Name "$ManifestPath" -ArgumentList $true -Force -ErrorAction Stop | ||
|
||
} | ||
|
||
} | ||
|
||
InModuleScope $(Split-Path (Split-Path (Split-Path -Parent $PSCommandPath) -Parent) -Leaf ) { | ||
|
||
Context 'General Operations' { | ||
|
||
BeforeEach { | ||
|
||
Mock Invoke-IDRestMethod -MockWith { | ||
|
||
[pscustomobject]@{ | ||
identity_user_portal = [pscustomobject]@{api = 'https://SubDomainABC.id.cyberark.cloud' } | ||
pcloud = [pscustomobject]@{api = 'https://SomeSubDomain.privilegecloud.cyberark.cloud' } | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
It 'sends request to expected endpoint when subdomain provided' { | ||
Find-SharedServicesURL -subdomain somedomain | ||
Assert-MockCalled -CommandName Invoke-IDRestMethod -Times 1 -ParameterFilter { | ||
$URI -eq 'https://platform-discovery.cyberark.cloud/api/v2/services/subdomain/somedomain' | ||
} -Scope It -Exactly | ||
} | ||
|
||
It 'sends request to expected endpoint when url provided' { | ||
Find-SharedServicesURL -url https://someotherdomain.cyberark.cloud | ||
Assert-MockCalled -CommandName Invoke-IDRestMethod -Times 1 -ParameterFilter { | ||
$URI -eq 'https://platform-discovery.cyberark.cloud/api/v2/services/subdomain/someotherdomain' | ||
} -Scope It -Exactly | ||
} | ||
|
||
It 'uses expected method' { | ||
Find-SharedServicesURL -url https://someotherdomain.cyberark.cloud | ||
Assert-MockCalled -CommandName Invoke-IDRestMethod -Times 1 -ParameterFilter { | ||
$Method -eq 'GET' | ||
} -Scope It -Exactly | ||
} | ||
|
||
It 'outputs expected results' { | ||
$results = Find-SharedServicesURL -url https://someotherdomain.cyberark.cloud | ||
$results.pcloud.api | Should -Be 'https://SomeSubDomain.privilegecloud.cyberark.cloud' | ||
$results.identity_user_portal.api | Should -Be 'https://SubDomainABC.id.cyberark.cloud' | ||
} | ||
|
||
It 'outputs filtered results when service is specified' { | ||
Find-SharedServicesURL -subdomain somedomain -service pcloud | Select-Object -ExpandProperty api | Should -Be 'https://SomeSubDomain.privilegecloud.cyberark.cloud' | ||
} | ||
|
||
It 'throws if specifed service detail is not included in results' { | ||
{ Find-SharedServicesURL -subdomain somedomain -service flows } | Should -Throw -ExpectedMessage 'URL for flows API not found' | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} |