Skip to content

Commit

Permalink
Merge pull request #724 from rubrikinc/mwp-userissue
Browse files Browse the repository at this point in the history
Updating Get-RubrikUser for 5.3
  • Loading branch information
jaapbrasser authored Jan 28, 2021
2 parents 37dd75a + d63b072 commit ca3a1f7
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

* Added support to `Get-RubrikUser` to work around all of the API endpoint changes in CDM 5.3 as per [Issue 723](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/723)
* Added new parameter, `SLAPrimaryClusterId`, to `Protect-RubrikFileset` & `New-RubrikSnapshot`, fixing [Issue 720](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/720)
* Added additional parameters: `-DoNotProtect` & `-Inherit` to `Set-RubrikSQLInstance` as requested in [Issue 717](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/717)
* Added `Request` parameter to allow `Get-RubrikRequest` to work directly from the pipeline as request in [Issue 715](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/715)
Expand Down Expand Up @@ -67,7 +68,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

* The `DynamicDNS` parameter of `New-RubrikLDAP` is no longer a mandatory parameter [Issue 662](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/662)
* Fixed `Test-RubrikSLA` internal function behaviour to no longer enforce `local` cluster ID when not supplied [Issue 659](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/659)
* Fixed `Test-RubrikSLA` internal function behaviour to no longer enforce `local` cluster ID when not supplied [Issue 659](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/659)
* WhatIf/Verbose messages for `Remove-RubrikSLA` will display SLA name and ID for additional clarification [Issue 653](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/653)
* Invoke-RubrikRestCall no longer takes Body object for Get Method [Issue 652](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/652)
* Created entries for 5.2 endpoints in `Get-RubrikAPIData` private function for `Get-RubrikEvent` & `Get-RubrikEventSeries` which caused these cmdlets to no longer work on Rubrik CDM 5.2 [Issue 626](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/626)
Expand Down
15 changes: 15 additions & 0 deletions Rubrik/Private/Get-RubrikAPIData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,21 @@ function Get-RubrikAPIData {
Success = '200'
ObjectTName = 'Rubrik.User'
}
'5.3' = @{
Description = 'Retrieves settings related to a given user within the Rubrik cluster'
URI = '/api/v1/principal'
Method = 'Get'
Body = ''
Query = @{
name = 'name'
auth_domain_id = 'auth_domain_id'
principal_type = 'principal_type'
}
Result = 'data'
Filter = ''
Success = '200'
ObjectTName = 'Rubrik.User'
}
}
'Get-RubrikUserRole' = @{
'1.0' = @{
Expand Down
22 changes: 21 additions & 1 deletion Rubrik/Public/Get-RubrikUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,18 @@ function Get-RubrikUser
[Parameter(
ParameterSetName='Query',
Position = 0)]
[Alias('name')]
[String] $Username,
# AuthDomainId to filter on
[Parameter(ParameterSetName='Query')]
[Alias('auth_domain_id')]
[String]$AuthDomainId,
# PrincipalType - For 5.3 and above
[Parameter(ParameterSetName='Query')]
[Parameter(ParameterSetName='ID')]
[Parameter(DontShow)]
[Alias('principal_type')]
[String]$PrincipalType="User",
# User ID
[Parameter(
ParameterSetName='ID',
Expand Down Expand Up @@ -103,13 +110,26 @@ function Get-RubrikUser
if ($AuthDomainId -eq 'local') {
$AuthDomainId = (Get-RubrikLDAP | Where-Object {$_.domainType -eq 'LOCAL'}).id
}
$uri = New-URIString -server $Server -endpoint ($resources.URI) -id $id

# if 5.3 or higher and calling with either ID we need to use the older internal endpoint...
if (($rubrikConnection.version.substring(0,5) -as [version]) -ge [version]5.3 -and $PSBoundParameters.containskey('id') ) {
Write-Verbose -Message "Detected 5.3 or above with ID parameter, explicitly setting endpoint"
$uri = New-URIString -server $Server -endpoint "/api/internal/user" -id $id
} else {
$uri = New-URIString -server $Server -endpoint ($resources.URI) -id $id
}

$uri = Test-QueryParam -querykeys ($resources.Query.Keys) -parameters ((Get-Command $function).Parameters.Values) -uri $uri
$body = New-BodyString -bodykeys ($resources.Body.Keys) -parameters ((Get-Command $function).Parameters.Values)
$result = Submit-Request -uri $uri -header $Header -method $($resources.Method) -body $body
$result = Test-ReturnFormat -api $api -result $result -location $resources.Result
$result = Test-FilterObject -filter ($resources.Filter) -result $result

# if 5.3 or higher, add username property as api has changed....
if (($rubrikConnection.version.substring(0,5) -as [version]) -ge [version]5.3 -and ($result) -and (-not $PSBoundParameters.containskey('id')) ) {
$result = $result | Select-Object *,@{Name="Username"; Expression={$_.name}}
}

if (($DetailedObject) -and (-not $PSBoundParameters.containskey('id'))) {
for ($i = 0; $i -lt @($result).Count; $i++) {
$Percentage = [int]($i/@($result).count*100)
Expand Down
21 changes: 18 additions & 3 deletions Tests/Get-RubrikUser.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,26 @@ Describe -Name 'Public/Get-RubrikUser' -Tag 'Public', 'Get-RubrikUser' -Fixture
( Get-RubrikUser -authDomainId 'local').Count |
Should -BeExactly 3
}

It -Name 'Verify 5.3 fallback block uri block - Should not trigger before 5.3' -Test {
$Output = & {
Get-RubrikUser -id User:111113 -Verbose 4>&1
}
(-join $Output) | Should -Not -BeLike '*Detected 5.3 or above with ID parameter, explicitly setting endpoint*'
}

It -Name 'Verify 5.3 fallback block uri block - Should Trigger on 5.3' -Test {
$rubrikconnection.version = '5.3.5'
$Output = & {
Get-RubrikUser -id User:111113 -Verbose 4>&1
}
(-join $Output) | Should -BeLike '*Detected 5.3 or above with ID parameter, explicitly setting endpoint*'
}

Assert-VerifiableMock
Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Times 1
Assert-MockCalled -CommandName Get-RubrikLDAP -ModuleName 'Rubrik' -Times 1
Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Times 2
Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 4
Assert-MockCalled -CommandName Get-RubrikLDAP -ModuleName 'Rubrik' -Exactly 1
Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 4
}
Context -Name 'Parameter Validation' {
It -Name 'ID Missing' -Test {
Expand Down

0 comments on commit ca3a1f7

Please sign in to comment.