Skip to content

Commit

Permalink
0.2 - Update 3
Browse files Browse the repository at this point in the history
* 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
pspete authored Mar 3, 2024
1 parent ba48066 commit 212c228
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 1 deletion.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ All notable changes to this project will be documented in this file.
### Fixed
- N/A

## [0.2 - Update 3] - 2024-03-03

### Added
- `Find-SharedServicesURL`
- New helper function that can be used to find URLs for ISPSS services under a tenant

### Changed
- `ConvertTo-QueryString`
- Updates helper function to implement functionality required in `Get-DPAStrongAccount` function of the `IdentityCommand.DPA` module.
- If multiple values are accepted and provided for a value, return all values joined, delimited by a comma.

### Fixed
- N/A

## [0.2 - Update 2] - 2024-02-19

### Added
Expand Down
2 changes: 1 addition & 1 deletion IdentityCommand/Private/ConvertTo-QueryString.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Formats input as: "Key=Value&Key=Value"
} Else {

#Return Key=Value string, escaped.
$Value = "$PSItem=$($Parameters[$PSItem] | Get-EscapedString)"
$Value = "$PSItem=$($Parameters[$PSItem] -join ','| Get-EscapedString)"

}

Expand Down
116 changes: 116 additions & 0 deletions IdentityCommand/Private/Find-SharedServicesURL.ps1
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 {}

}
80 changes: 80 additions & 0 deletions Tests/Find-SharedServicesURL.Tests.ps1
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'
}

}

}

}

0 comments on commit 212c228

Please sign in to comment.