diff --git a/CHANGELOG.md b/CHANGELOG.md index f9b73b1..0d6bd21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,35 @@ # Change Log All notable changes to this project will be documented in this file. +## [unreleased] - 2023-08-30 + +### Added +- N/A + +### Changed +- N/A + +### Fixed +- N/A + +## [0.1 - Update 1] - 2023-08-30 + +Additional Functions + +### Added +- `Get-IDUserRole` - Get a list of roles for a user +- `Get-IDAnalyticsDataset` - Get all datasets accessible by a user +- `Get-IDTenantCname` - Get Tenant Cnames +- `Get-IDDownloadUrl` - Get download Urls +- `Get-IDUserIdentifier` - Get the configuration of the user attributes +- `Invoke-IDSqlcmd` - Query the database tables + +### Changed +- N/A + +### Fixed +- N/A + ## [0.1] - 2023-08-21 Initial module development prior to main release diff --git a/IdentityCommand/IdentityCommand.psd1 b/IdentityCommand/IdentityCommand.psd1 index a404c52..04f2399 100644 --- a/IdentityCommand/IdentityCommand.psd1 +++ b/IdentityCommand/IdentityCommand.psd1 @@ -86,7 +86,13 @@ 'Get-IDTenant', 'Get-IDTenantConfiguration', 'Get-IDConnector', - 'New-IDPlatformToken' + 'New-IDPlatformToken', + 'Get-IDUserRole', + 'Get-IDAnalyticsDataset', + 'Get-IDTenantCname', + 'Get-IDDownloadUrl', + 'Get-IDUserIdentifier', + 'Invoke-IDSqlcmd' ) # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. @@ -122,7 +128,7 @@ ProjectUri = 'https://github.com/pspete/IdentityCommand/' # A URL to an icon representing this module. - IconUri = 'https://github.com/pspete/IdentityCommand/blob/main/docs/media/images/IdentityCommand-Logo.png' + IconUri = 'https://raw.githubusercontent.com/pspete/IdentityCommand/main/docs/media/images/IdentityCommand-Logo.png' # ReleaseNotes of this module ReleaseNotes = 'https://github.com/pspete/IdentityCommand/blob/main/CHANGELOG.md' diff --git a/IdentityCommand/Private/Get-Parameter.ps1 b/IdentityCommand/Private/Get-Parameter.ps1 index a9af146..8a14f69 100644 --- a/IdentityCommand/Private/Get-Parameter.ps1 +++ b/IdentityCommand/Private/Get-Parameter.ps1 @@ -19,6 +19,10 @@ object. Specifying additional parameter names/keys here means that the default value assigned to the BaseParameters parameter will remain unchanged. + .PARAMETER ParametersToKeep + Accepts an array of any additional parameter keys which should be selected from the passed input + object. + .EXAMPLE $PSBoundParameters | Get-Parameter diff --git a/IdentityCommand/Public/Get-IDAnalyticsDataset.ps1 b/IdentityCommand/Public/Get-IDAnalyticsDataset.ps1 new file mode 100644 index 0000000..cd1d22b --- /dev/null +++ b/IdentityCommand/Public/Get-IDAnalyticsDataset.ps1 @@ -0,0 +1,21 @@ +# .ExternalHelp IdentityCommand-help.xml +function Get-IDAnalyticsDataset { + [CmdletBinding()] + param( ) + + BEGIN { + + $URI = "$Script:tenant_url/analytics/services/v1.0/dataset" + + }#begin + + PROCESS { + + #Send Request + Invoke-IDRestMethod -Uri $URI -Method GET + + }#process + + END {}#end + +} \ No newline at end of file diff --git a/IdentityCommand/Public/Get-IDDownloadUrl.ps1 b/IdentityCommand/Public/Get-IDDownloadUrl.ps1 new file mode 100644 index 0000000..7502ed7 --- /dev/null +++ b/IdentityCommand/Public/Get-IDDownloadUrl.ps1 @@ -0,0 +1,21 @@ +# .ExternalHelp IdentityCommand-help.xml +function Get-IDDownloadUrl { + [CmdletBinding()] + param( ) + + BEGIN { + + $URI = "$Script:tenant_url/Core/GetDownloadUrls" + + }#begin + + PROCESS { + + #Send Request + Invoke-IDRestMethod -Uri $URI -Method POST + + }#process + + END {}#end + +} \ No newline at end of file diff --git a/IdentityCommand/Public/Get-IDTenantCname.ps1 b/IdentityCommand/Public/Get-IDTenantCname.ps1 new file mode 100644 index 0000000..d8b8370 --- /dev/null +++ b/IdentityCommand/Public/Get-IDTenantCname.ps1 @@ -0,0 +1,21 @@ +# .ExternalHelp IdentityCommand-help.xml +function Get-IDTenantCname { + [CmdletBinding()] + param( ) + + BEGIN { + + $URI = "$Script:tenant_url/TenantCnames/UiGet" + + }#begin + + PROCESS { + + #Send Request + Invoke-IDRestMethod -Uri $URI -Method POST + + }#process + + END {}#end + +} \ No newline at end of file diff --git a/IdentityCommand/Public/Get-IDUserIdentifier.ps1 b/IdentityCommand/Public/Get-IDUserIdentifier.ps1 new file mode 100644 index 0000000..ef46544 --- /dev/null +++ b/IdentityCommand/Public/Get-IDUserIdentifier.ps1 @@ -0,0 +1,21 @@ +# .ExternalHelp IdentityCommand-help.xml +function Get-IDUserIdentifier { + [CmdletBinding()] + param( ) + + BEGIN { + + $URI = "$Script:tenant_url/UserIdentifiers/Get" + + }#begin + + PROCESS { + + #Send Request + Invoke-IDRestMethod -Uri $URI -Method POST + + }#process + + END {}#end + +} \ No newline at end of file diff --git a/IdentityCommand/Public/Get-IDUserRole.ps1 b/IdentityCommand/Public/Get-IDUserRole.ps1 new file mode 100644 index 0000000..a5985ef --- /dev/null +++ b/IdentityCommand/Public/Get-IDUserRole.ps1 @@ -0,0 +1,72 @@ +# .ExternalHelp IdentityCommand-help.xml +function Get-IDUserRole { + [CmdletBinding()] + param( + [parameter( + Mandatory = $true, + ValueFromPipelinebyPropertyName = $true + )] + [ValidateNotNullOrEmpty()] + [Alias('Uuid')] + [String]$ID, + + [parameter( + Mandatory = $false, + ValueFromPipelinebyPropertyName = $true + )] + [ValidateNotNullOrEmpty()] + [int]$Limit, + + [parameter( + Mandatory = $false, + ValueFromPipelinebyPropertyName = $true + )] + [ValidateNotNullOrEmpty()] + [int]$PageNumber, + + [parameter( + Mandatory = $false, + ValueFromPipelinebyPropertyName = $true + )] + [ValidateNotNullOrEmpty()] + [int]$PageSize, + + [parameter( + Mandatory = $false, + ValueFromPipelinebyPropertyName = $true + )] + [ValidateRange(-1, 0)] + [int]$Caching, + + [parameter( + Mandatory = $false, + ValueFromPipelinebyPropertyName = $true + )] + [string]$SortBy + ) + + BEGIN { + + }#begin + + PROCESS { + + $URLParameters = $PSBoundParameters | Get-Parameter -ParametersToKeep ID + $BoundParameters = $PSBoundParameters | Get-Parameter -ParametersToRemove ID + + $URI = "$Script:tenant_url/UserMgmt/GetUsersRolesAndAdministrativeRights?$($URLParameters | ConvertTo-QueryString)" + + $Body = @{'Args' = $BoundParameters } | ConvertTo-Json + + #Send Request + $result = Invoke-IDRestMethod -Uri $URI -Method POST -Body $Body + + if ($null -ne $result) { + $result + } + + }#process + + END { }#end + +} \ No newline at end of file diff --git a/IdentityCommand/Public/Invoke-IDSqlcmd.ps1 b/IdentityCommand/Public/Invoke-IDSqlcmd.ps1 new file mode 100644 index 0000000..a181d65 --- /dev/null +++ b/IdentityCommand/Public/Invoke-IDSqlcmd.ps1 @@ -0,0 +1,76 @@ +function Invoke-IDSqlcmd { + [CmdletBinding()] + param( + [parameter( + Mandatory = $true, + ValueFromPipelinebyPropertyName = $true + )] + [ValidateNotNullOrEmpty()] + [String]$Script, + + [parameter( + Mandatory = $false, + ValueFromPipelinebyPropertyName = $true + )] + [ValidateNotNullOrEmpty()] + [int]$Limit, + + [parameter( + Mandatory = $false, + ValueFromPipelinebyPropertyName = $true + )] + [ValidateNotNullOrEmpty()] + [int]$PageNumber, + + [parameter( + Mandatory = $false, + ValueFromPipelinebyPropertyName = $true + )] + [ValidateNotNullOrEmpty()] + [int]$PageSize, + + [parameter( + Mandatory = $false, + ValueFromPipelinebyPropertyName = $true + )] + [ValidateRange(-1, 0)] + [int]$Caching, + + [parameter( + Mandatory = $false, + ValueFromPipelinebyPropertyName = $true + )] + [bool]$Direction, + + [parameter( + Mandatory = $false, + ValueFromPipelinebyPropertyName = $true + )] + [string]$SortBy + ) + + BEGIN { + + }#begin + + PROCESS { + + $URI = "$Script:tenant_url/Redrock/query" + + #Create request body with Script & args properties + $Cmd = $PSBoundParameters | Get-Parameter -ParametersToKeep Script + $Cmd.Add('args', $($PSBoundParameters | Get-Parameter -ParametersToRemove Script)) + $Body = $Cmd | ConvertTo-Json + + #Send Request + $result = Invoke-IDRestMethod -Uri $URI -Method POST -Body $Body + + if ($null -ne $result) { + $result.Results.Row + } + + }#process + + END { }#end + +} diff --git a/IdentityCommand/about_IdentityCommand.help.txt b/IdentityCommand/about_IdentityCommand.help.txt index 7baf0b2..e1bdf35 100644 --- a/IdentityCommand/about_IdentityCommand.help.txt +++ b/IdentityCommand/about_IdentityCommand.help.txt @@ -21,14 +21,14 @@ EXAMPLES Once successfully authenticated, all IdentityCommand module commands which require an authenticated session can be used from within the same PowerShell session. - #### GetBearerToken Method + #### GetToken Method You may have a scenario where you want to use APIs for which we have not yet developed, built or published module commands. - The GetBearerToken method of the object returned on successful authentication can be invoked to obtain a bearer token to be used for further requests. + The GetToken method of the object returned on successful authentication can be invoked to obtain a bearer token to be used for further requests. PS C:\> $Session = New-IDSession -tenant_url https://some.tenant.cyberark.cloud -Credential $Credential - PS C:\> $Session.GetBearerToken() + PS C:\> $Session.GetToken() Name Value ---- ----- @@ -36,7 +36,7 @@ EXAMPLES GetWebSession Method - The GetWebSession method can be used in a similar way to GetBearerToken, but the websession object for the authenticated session is returned instead of a Bearer token. + The GetWebSession method can be used in a similar way to GetToken, but the websession object for the authenticated session is returned instead of a Bearer token. PS C:\> $Session = New-IDSession -tenant_url https://some.tenant.cyberark.cloud -Credential $Credential PS C:\> $session.GetWebSession() diff --git a/IdentityCommand/en-US/IdentityCommand-help.xml b/IdentityCommand/en-US/IdentityCommand-help.xml index c76a200..194017a 100644 --- a/IdentityCommand/en-US/IdentityCommand-help.xml +++ b/IdentityCommand/en-US/IdentityCommand-help.xml @@ -115,6 +115,43 @@ + + + Get-IDAnalyticsDataset + Get + IDAnalyticsDataset + + Get all datasets accessible to user + + + + Lists the following: + All custom datasets created by one user All default datasets available to all users in the tenant for CyberArk User Behaviour Analytics Service. + + + + Get-IDAnalyticsDataset + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Get-IDAnalyticsDataset + + Returns any accessible datasets + + + + + Get-IDConnector @@ -183,6 +220,42 @@ + + + Get-IDDownloadUrl + Get + IDDownloadUrl + + Get download URLs + + + + Get download URLs + + + + Get-IDDownloadUrl + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Get-IDDownloadUrl + + Get download Urls + + + + + Get-IDSession @@ -255,6 +328,42 @@ + + + Get-IDTenantCname + Get + IDTenantCname + + Get Tenant Cnames + + + + Get Tenant Cnames + + + + Get-IDTenantCname + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Get-IDTenantCname + + Get tenant Cnames + + + + + Get-IDTenantConfiguration @@ -460,6 +569,467 @@ + + + Get-IDUserIdentifier + Get + IDUserIdentifier + + Get user identifiers + + + + Get the configuration of the user attributes + + + + Get-IDUserIdentifier + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Get-IDUserIdentifier + + Get user identifiers + + + + + + + + Get-IDUserRole + Get + IDUserRole + + List roles user is a member of. + + + + Get a list of roles for a user. Returns user roles and administrative rights associated with the roles. + + + + Get-IDUserRole + + ID + + The ID of the user + + String + + String + + + None + + + Limit + + The maximum number of results to return for the specified page. + + Int32 + + Int32 + + + 0 + + + PageNumber + + The number of pages of results to return. + + Int32 + + Int32 + + + 0 + + + PageSize + + The number of entities to return per page. + + Int32 + + Int32 + + + 0 + + + Caching + + Can be set to the following values: -1: returns live data but writes to the cache for query results. <-1: don't read from or write to the cache for query results. 0: use the cache for both read/write with 'caching in minutes' as TTL of the results. + + Int32 + + Int32 + + + 0 + + + SortBy + + Comma-separated list of column names to sort by. + + String + + String + + + None + + + + + + ID + + The ID of the user + + String + + String + + + None + + + Limit + + The maximum number of results to return for the specified page. + + Int32 + + Int32 + + + 0 + + + PageNumber + + The number of pages of results to return. + + Int32 + + Int32 + + + 0 + + + PageSize + + The number of entities to return per page. + + Int32 + + Int32 + + + 0 + + + Caching + + Can be set to the following values: -1: returns live data but writes to the cache for query results. <-1: don't read from or write to the cache for query results. 0: use the cache for both read/write with 'caching in minutes' as TTL of the results. + + Int32 + + Int32 + + + 0 + + + SortBy + + Comma-separated list of column names to sort by. + + String + + String + + + None + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Get-IDUserRole -ID SomeID + + Return a list of roles for a matching user. + + + + + + + + Invoke-IDSqlcmd + Invoke + IDSqlcmd + + Query the database tables + + + + The SQL query interface allows you to read database tables for the Identity Solution. It does not allow you to modify or create data in these tables. + This function requires a script with the SQL code to execute as a query and optional parameters to control the output. + + + + Invoke-IDSqlcmd + + Script + + The SQL code to execute + + String + + String + + + None + + + Limit + + The maximum number of results to return for the specified page. + + Int32 + + Int32 + + + None + + + PageNumber + + The specific page number of results to be returned. + + Int32 + + Int32 + + + None + + + PageSize + + The number of entities to return per page. + + Int32 + + Int32 + + + None + + + Caching + + How the results should be cached. + + Int32 + + Int32 + + + None + + + Direction + + Whether the results are sorted in ascending or descending order. + - True: The results are sorted in ascending order. + - False: The results are sorted in descending order. + + Boolean + + Boolean + + + None + + + SortBy + + An optional, comma-separated list of column names to sort by. + + String + + String + + + None + + + + + + Caching + + How the results should be cached. + + Int32 + + Int32 + + + None + + + Direction + + Whether the results are sorted in ascending or descending order. + - True: The results are sorted in ascending order. + - False: The results are sorted in descending order. + + Boolean + + Boolean + + + None + + + Limit + + The maximum number of results to return for the specified page. + + Int32 + + Int32 + + + None + + + PageNumber + + The specific page number of results to be returned. + + Int32 + + Int32 + + + None + + + PageSize + + The number of entities to return per page. + + Int32 + + Int32 + + + None + + + Script + + The SQL code to execute + + String + + String + + + None + + + SortBy + + An optional, comma-separated list of column names to sort by. + + String + + String + + + None + + + + + + System.String + + + + + + + + System.Int32 + + + + + + + + System.Boolean + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Invoke-IDSqlcmd -Script 'Select ID, Username from User ORDER BY Username COLLATE NOCASE' + + Invoke query on the User table, returning the ID and name for each user who has accessed the cloud service + + + + + Lock-IDUser @@ -560,6 +1130,28 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + @@ -587,6 +1179,30 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + diff --git a/README.md b/README.md index 9ac2843..5706107 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,12 @@ The commands currently available in the _IdentityCommand_ module are listed here | `Get-IDTenantConfiguration` | Get tenant configuration data | | `Get-IDConnector` | Get connector health | | `New-IDPlatformToken` | Request OIDC token based on grant type | +| `Get-IDUserRole` | Get a list of roles for a user | +| `Get-IDAnalyticsDataset` | Get all datasets accessible by a user | +| `Get-IDTenantCname` | Get Tenant Cnames | +| `Get-IDDownloadUrl` | Get download Urls | +| `Get-IDUserIdentifier` | Get the configuration of the user attributes | +| `Invoke-IDSqlcmd` | Query the database tables | ## Installation diff --git a/Tests/Get-IDAnalyticsDataset.Tests.ps1 b/Tests/Get-IDAnalyticsDataset.Tests.ps1 new file mode 100644 index 0000000..35f9fb5 --- /dev/null +++ b/Tests/Get-IDAnalyticsDataset.Tests.ps1 @@ -0,0 +1,79 @@ +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 ) { + + BeforeEach { + Mock Invoke-IDRestMethod -MockWith { + [pscustomobject]@{'property' = 'value' } + } + + $response = Get-IDAnalyticsDataset + + } + + Context 'Input' { + + It 'sends request' { + + Assert-MockCalled Invoke-IDRestMethod -Times 1 -Exactly -Scope It + + } + + It 'sends request to expected endpoint' { + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { + + $URI -eq 'https://somedomain.id.cyberark.cloud/analytics/services/v1.0/dataset' + + } -Times 1 -Exactly -Scope It + + } + + It 'uses expected method' { + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { $Method -match 'GET' } -Times 1 -Exactly -Scope It + + } + + It 'sends request with no body' { + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { $Body -eq $null } -Times 1 -Exactly -Scope It + + } + + } + + Context 'Output' { + + It 'provides output' { + + $response | Should -Not -BeNullOrEmpty + + } + + } + + } + +} \ No newline at end of file diff --git a/Tests/Get-IDDownloadUrl.Tests.ps1 b/Tests/Get-IDDownloadUrl.Tests.ps1 new file mode 100644 index 0000000..b381773 --- /dev/null +++ b/Tests/Get-IDDownloadUrl.Tests.ps1 @@ -0,0 +1,79 @@ +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 ) { + + BeforeEach { + Mock Invoke-IDRestMethod -MockWith { + [pscustomobject]@{'property' = 'value' } + } + + $response = Get-IDDownloadUrl + + } + + Context 'Input' { + + It 'sends request' { + + Assert-MockCalled Invoke-IDRestMethod -Times 1 -Exactly -Scope It + + } + + It 'sends request to expected endpoint' { + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { + + $URI -eq 'https://somedomain.id.cyberark.cloud/Core/GetDownloadUrls' + + } -Times 1 -Exactly -Scope It + + } + + It 'uses expected method' { + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { $Method -match 'POST' } -Times 1 -Exactly -Scope It + + } + + It 'sends request with no body' { + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { $Body -eq $null } -Times 1 -Exactly -Scope It + + } + + } + + Context 'Output' { + + It 'provides output' { + + $response | Should -Not -BeNullOrEmpty + + } + + } + + } + +} \ No newline at end of file diff --git a/Tests/Get-IDTenantCname.Tests.ps1 b/Tests/Get-IDTenantCname.Tests.ps1 new file mode 100644 index 0000000..95e9724 --- /dev/null +++ b/Tests/Get-IDTenantCname.Tests.ps1 @@ -0,0 +1,79 @@ +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 ) { + + BeforeEach { + Mock Invoke-IDRestMethod -MockWith { + [pscustomobject]@{'property' = 'value' } + } + + $response = Get-IDTenantCname + + } + + Context 'Input' { + + It 'sends request' { + + Assert-MockCalled Invoke-IDRestMethod -Times 1 -Exactly -Scope It + + } + + It 'sends request to expected endpoint' { + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { + + $URI -eq 'https://somedomain.id.cyberark.cloud/TenantCnames/UiGet' + + } -Times 1 -Exactly -Scope It + + } + + It 'uses expected method' { + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { $Method -match 'POST' } -Times 1 -Exactly -Scope It + + } + + It 'sends request with no body' { + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { $Body -eq $null } -Times 1 -Exactly -Scope It + + } + + } + + Context 'Output' { + + It 'provides output' { + + $response | Should -Not -BeNullOrEmpty + + } + + } + + } + +} \ No newline at end of file diff --git a/Tests/Get-IDUserIdentifier.Tests.ps1 b/Tests/Get-IDUserIdentifier.Tests.ps1 new file mode 100644 index 0000000..88be5f3 --- /dev/null +++ b/Tests/Get-IDUserIdentifier.Tests.ps1 @@ -0,0 +1,82 @@ +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 ) { + + BeforeEach { + + $Script:tenant_url = 'https://somedomain.id.cyberark.cloud' + + Mock Invoke-IDRestMethod -MockWith { + [pscustomobject]@{'property' = 'value' } + } + + $response = Get-IDUserIdentifier + + } + + Context 'Input' { + + It 'sends request' { + + Assert-MockCalled Invoke-IDRestMethod -Times 1 -Exactly -Scope It + + } + + It 'sends request to expected endpoint' { + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { + + $URI -eq 'https://somedomain.id.cyberark.cloud/UserIdentifiers/Get' + + } -Times 1 -Exactly -Scope It + + } + + It 'uses expected method' { + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { $Method -match 'POST' } -Times 1 -Exactly -Scope It + + } + + It 'sends request with no body' { + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { $Body -eq $null } -Times 1 -Exactly -Scope It + + } + + } + + Context 'Output' { + + It 'provides output' { + + $response | Should -Not -BeNullOrEmpty + + } + + } + + } + +} \ No newline at end of file diff --git a/Tests/Get-IDUserRole.Tests.ps1 b/Tests/Get-IDUserRole.Tests.ps1 new file mode 100644 index 0000000..f6a5466 --- /dev/null +++ b/Tests/Get-IDUserRole.Tests.ps1 @@ -0,0 +1,93 @@ +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 'Input' { + + BeforeEach { + Mock Invoke-IDRestMethod -MockWith { @{SomeProperty = 'SomeValue' } } + $Script:tenant_url = 'https://somedomain.id.cyberark.cloud' + $response = Get-IDUserRole -ID 1234 -Limit 1 -SortBy String + + } + + It 'sends request' { + + Assert-MockCalled Invoke-IDRestMethod -Times 1 -Exactly -Scope It + + } + + It 'sends request to expected endpoint' { + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { + + $URI -eq 'https://somedomain.id.cyberark.cloud/UserMgmt/GetUsersRolesAndAdministrativeRights?ID=1234' + + } -Times 1 -Exactly -Scope It + + } + + It 'sends request to expected endpoint when object with UUID is provided via pipe' { + + [pscustomobject]@{'Uuid' = 5678 } | Get-IDUserRole + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { + + $URI -eq 'https://somedomain.id.cyberark.cloud/UserMgmt/GetUsersRolesAndAdministrativeRights?ID=5678' + + } -Times 1 -Exactly -Scope It + + } + + It 'uses expected method' { + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { $Method -match 'POST' } -Times 1 -Exactly -Scope It + + } + + It 'sends request with expected body' { + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { $Body -ne $null } -Times 1 -Exactly -Scope It + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { + ($Body | ConvertFrom-Json | Select-Object -ExpandProperty Args | Select-Object -ExpandProperty Limit) -eq 1 + } -Times 1 -Exactly -Scope It + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { + ($Body | ConvertFrom-Json | Select-Object -ExpandProperty Args | Select-Object -ExpandProperty SortBy) -eq 'String' + } -Times 1 -Exactly -Scope It + + } + + It 'provides expected output' { + + $response | Should -Not -BeNullOrEmpty + + } + + } + + } + +} \ No newline at end of file diff --git a/Tests/Invoke-IDSqlcmd.Tests.ps1 b/Tests/Invoke-IDSqlcmd.Tests.ps1 new file mode 100644 index 0000000..2fea4c2 --- /dev/null +++ b/Tests/Invoke-IDSqlcmd.Tests.ps1 @@ -0,0 +1,123 @@ +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 ) { + + BeforeEach { + $Script:tenant_url = 'https://somedomain.id.cyberark.cloud' + } + + Context 'GetUsers' { + + BeforeEach { + Mock Invoke-IDRestMethod -MockWith { + [pscustomobject]@{'Results' = @( + [pscustomobject]@{ + 'Row' = [pscustomobject]@{ + 'property' = 'value' + 'test' = 'result' + } + }, + [pscustomobject]@{ + 'Row' = [pscustomobject]@{ + 'property' = 'value' + 'test' = 'result' + } + }, + [pscustomobject]@{ + 'Row' = [pscustomobject]@{ + 'property' = 'value' + 'test' = 'result' + } + } + ) + } + } + $response = Invoke-IDSqlcmd -Script 'Some SQL Query' -Limit 3 + } + + It 'sends request' { + + Assert-MockCalled Invoke-IDRestMethod -Times 1 -Exactly -Scope It + + } + + It 'sends request to expected endpoint' { + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { + + $URI -eq 'https://somedomain.id.cyberark.cloud/Redrock/query' + + } -Times 1 -Exactly -Scope It + + } + + It 'uses expected method' { + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { $Method -match 'POST' } -Times 1 -Exactly -Scope It + + } + + It 'sends request with expected script' { + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { + + ($Body | ConvertFrom-Json | Select-Object -ExpandProperty Script) -eq 'Some SQL Query' + + } -Times 1 -Exactly -Scope It + + } + + It 'sends request with expected args' { + + Assert-MockCalled Invoke-IDRestMethod -ParameterFilter { + + ($Body | ConvertFrom-Json | Select-Object -ExpandProperty args).Limit -eq 3 + + } -Times 1 -Exactly -Scope It + + } + + It 'provides output' { + + $response | Should -Not -BeNullOrEmpty + + } + + It 'outputs expected number of results' { + + $response.length | Should -Be 3 + + } + + It 'outputs expected result' { + + $response | Select-Object -First 1 -ExpandProperty property | Should -Be 'value' + + } + + } + + } + +} \ No newline at end of file diff --git a/docs/collections/_commands/Get-IDAnalyticsDataset.md b/docs/collections/_commands/Get-IDAnalyticsDataset.md new file mode 100644 index 0000000..68b5ee3 --- /dev/null +++ b/docs/collections/_commands/Get-IDAnalyticsDataset.md @@ -0,0 +1,44 @@ +--- +external help file: IdentityCommand-help.xml +Module Name: IdentityCommand +online version: +schema: 2.0.0 +--- + +# Get-IDAnalyticsDataset + +## SYNOPSIS +Get all datasets accessible to user + +## SYNTAX + +``` +Get-IDAnalyticsDataset [] +``` + +## DESCRIPTION +Lists the following: + +All custom datasets created by one user All default datasets available to all users in the tenant for CyberArk User Behaviour Analytics Service. + +## EXAMPLES + +### Example 1 +``` +PS C:\> Get-IDAnalyticsDataset +``` + +Returns any accessible datasets + +## PARAMETERS + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/docs/collections/_commands/Get-IDDownloadUrl.md b/docs/collections/_commands/Get-IDDownloadUrl.md new file mode 100644 index 0000000..028cca2 --- /dev/null +++ b/docs/collections/_commands/Get-IDDownloadUrl.md @@ -0,0 +1,42 @@ +--- +external help file: IdentityCommand-help.xml +Module Name: IdentityCommand +online version: +schema: 2.0.0 +--- + +# Get-IDDownloadUrl + +## SYNOPSIS +Get download URLs + +## SYNTAX + +``` +Get-IDDownloadUrl [] +``` + +## DESCRIPTION +Get download URLs + +## EXAMPLES + +### Example 1 +``` +PS C:\> Get-IDDownloadUrl +``` + +Get download Urls + +## PARAMETERS + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/docs/collections/_commands/Get-IDTenantCname.md b/docs/collections/_commands/Get-IDTenantCname.md new file mode 100644 index 0000000..80000cd --- /dev/null +++ b/docs/collections/_commands/Get-IDTenantCname.md @@ -0,0 +1,42 @@ +--- +external help file: IdentityCommand-help.xml +Module Name: IdentityCommand +online version: +schema: 2.0.0 +--- + +# Get-IDTenantCname + +## SYNOPSIS +Get Tenant Cnames + +## SYNTAX + +``` +Get-IDTenantCname [] +``` + +## DESCRIPTION +Get Tenant Cnames + +## EXAMPLES + +### Example 1 +``` +PS C:\> Get-IDTenantCname +``` + +Get tenant Cnames + +## PARAMETERS + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/docs/collections/_commands/Get-IDUserIdentifier.md b/docs/collections/_commands/Get-IDUserIdentifier.md new file mode 100644 index 0000000..bdf9ca7 --- /dev/null +++ b/docs/collections/_commands/Get-IDUserIdentifier.md @@ -0,0 +1,42 @@ +--- +external help file: IdentityCommand-help.xml +Module Name: IdentityCommand +online version: +schema: 2.0.0 +--- + +# Get-IDUserIdentifier + +## SYNOPSIS +Get user identifiers + +## SYNTAX + +``` +Get-IDUserIdentifier [] +``` + +## DESCRIPTION +Get the configuration of the user attributes + +## EXAMPLES + +### Example 1 +``` +PS C:\> Get-IDUserIdentifier +``` + +Get user identifiers + +## PARAMETERS + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/docs/collections/_commands/Get-IDUserRole.md b/docs/collections/_commands/Get-IDUserRole.md new file mode 100644 index 0000000..03c959c --- /dev/null +++ b/docs/collections/_commands/Get-IDUserRole.md @@ -0,0 +1,136 @@ +--- +external help file: IdentityCommand-help.xml +Module Name: IdentityCommand +online version: +schema: 2.0.0 +--- + +# Get-IDUserRole + +## SYNOPSIS +List roles user is a member of. + +## SYNTAX + +``` +Get-IDUserRole [-ID] [[-Limit] ] [[-PageNumber] ] [[-PageSize] ] + [[-Caching] ] [[-SortBy] ] [] +``` + +## DESCRIPTION +Get a list of roles for a user. +Returns user roles and administrative rights associated with the roles. + +## EXAMPLES + +### Example 1 +``` +PS C:\> Get-IDUserRole -ID SomeID +``` + +Return a list of roles for a matching user. + +## PARAMETERS + +### -ID +The ID of the user + +```yaml +Type: String +Parameter Sets: (All) +Aliases: Uuid + +Required: True +Position: 1 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Limit +The maximum number of results to return for the specified page. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: 0 +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -PageNumber +The number of pages of results to return. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 3 +Default value: 0 +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -PageSize +The number of entities to return per page. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 4 +Default value: 0 +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Caching +Can be set to the following values: -1: returns live data but writes to the cache for query results. +\<-1: don't read from or write to the cache for query results. +0: use the cache for both read/write with 'caching in minutes' as TTL of the results. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 5 +Default value: 0 +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -SortBy +Comma-separated list of column names to sort by. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 6 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/docs/collections/_commands/Invoke-IDSqlcmd.md b/docs/collections/_commands/Invoke-IDSqlcmd.md new file mode 100644 index 0000000..f5af09d --- /dev/null +++ b/docs/collections/_commands/Invoke-IDSqlcmd.md @@ -0,0 +1,158 @@ +--- +external help file: IdentityCommand-help.xml +Module Name: IdentityCommand +online version: +schema: 2.0.0 +--- + +# Invoke-IDSqlcmd + +## SYNOPSIS +Query the database tables + +## SYNTAX + +``` +Invoke-IDSqlcmd [-Script] [[-Limit] ] [[-PageNumber] ] [[-PageSize] ] + [[-Caching] ] [[-Direction] ] [[-SortBy] ] [] +``` + +## DESCRIPTION +The SQL query interface allows you to read database tables for the Identity Solution. +It does not allow you to modify or create data in these tables. + +This function requires a script with the SQL code to execute as a query and optional parameters to control the output. + +## EXAMPLES + +### Example 1 +``` +PS C:\> Invoke-IDSqlcmd -Script 'Select ID, Username from User ORDER BY Username COLLATE NOCASE' +``` + +Invoke query on the User table, returning the ID and name for each user who has accessed the cloud service + +## PARAMETERS + +### -Caching +How the results should be cached. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 4 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Direction +Whether the results are sorted in ascending or descending order. + +- True: The results are sorted in ascending order. +- False: The results are sorted in descending order. + +```yaml +Type: Boolean +Parameter Sets: (All) +Aliases: + +Required: False +Position: 5 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Limit +The maximum number of results to return for the specified page. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -PageNumber +The specific page number of results to be returned. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -PageSize +The number of entities to return per page. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 3 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Script +The SQL code to execute + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -SortBy +An optional, comma-separated list of column names to sort by. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 6 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.String +### System.Int32 +### System.Boolean +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/docs/collections/_commands/New-IDPlatformToken.md b/docs/collections/_commands/New-IDPlatformToken.md index 2403039..bd03390 100644 --- a/docs/collections/_commands/New-IDPlatformToken.md +++ b/docs/collections/_commands/New-IDPlatformToken.md @@ -13,7 +13,8 @@ Request authentication token using OAuth ## SYNTAX ``` -New-IDPlatformToken [-tenant_url] [-Credential] [] +New-IDPlatformToken [-tenant_url] [-Credential] [-WhatIf] [-Confirm] + [] ``` ## DESCRIPTION @@ -22,7 +23,7 @@ Gets a CyberArk Identity Security Platform OIDC token based on grant type. ## EXAMPLES ### Example 1 -```powershell +``` PS C:\> New-IDPlatformToken -tenant_url https://sometenant.id.cyberark.cloud -Credential $Cred ``` @@ -60,6 +61,37 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).