diff --git a/CHANGELOG.md b/CHANGELOG.md index 43c181c..a58c391 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/IdentityCommand/Private/ConvertTo-QueryString.ps1 b/IdentityCommand/Private/ConvertTo-QueryString.ps1 index af63d72..ad5c6da 100644 --- a/IdentityCommand/Private/ConvertTo-QueryString.ps1 +++ b/IdentityCommand/Private/ConvertTo-QueryString.ps1 @@ -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)" } diff --git a/IdentityCommand/Private/Find-SharedServicesURL.ps1 b/IdentityCommand/Private/Find-SharedServicesURL.ps1 new file mode 100644 index 0000000..6c05e2a --- /dev/null +++ b/IdentityCommand/Private/Find-SharedServicesURL.ps1 @@ -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 {} + +} \ No newline at end of file diff --git a/Tests/Find-SharedServicesURL.Tests.ps1 b/Tests/Find-SharedServicesURL.Tests.ps1 new file mode 100644 index 0000000..fa6f71c --- /dev/null +++ b/Tests/Find-SharedServicesURL.Tests.ps1 @@ -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' + } + + } + + } + +} \ No newline at end of file