From 17faa8ddee20a181427803afde91f1540fa1935d Mon Sep 17 00:00:00 2001 From: Jaap Brasser Date: Sun, 14 Jul 2019 13:59:14 +0200 Subject: [PATCH 1/7] Added array wrapping for pwsh 5 support --- Rubrik/Public/Get-RubrikAPIToken.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rubrik/Public/Get-RubrikAPIToken.ps1 b/Rubrik/Public/Get-RubrikAPIToken.ps1 index f7f740805..b9737eaa3 100644 --- a/Rubrik/Public/Get-RubrikAPIToken.ps1 +++ b/Rubrik/Public/Get-RubrikAPIToken.ps1 @@ -77,7 +77,7 @@ function Get-RubrikAPIToken # Remove any api tokens generated for usage with web $result = $result | Where-Object {$_.sessionType -ne 'Web'} - $result.ForEach{$_.PSObject.TypeNames.Insert(0,'Rubrik.APIToken')} + @($result).ForEach{$_.PSObject.TypeNames.Insert(0,'Rubrik.APIToken')} return $result } # End of process From caffca3099e92c02a1f02fbf1f952b8acec684f4 Mon Sep 17 00:00:00 2001 From: Jaap Brasser Date: Sun, 14 Jul 2019 14:21:05 +0200 Subject: [PATCH 2/7] Added token validation --- Rubrik/Public/Connect-Rubrik.ps1 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Rubrik/Public/Connect-Rubrik.ps1 b/Rubrik/Public/Connect-Rubrik.ps1 index 4cb0b17f7..da1ecf5e2 100644 --- a/Rubrik/Public/Connect-Rubrik.ps1 +++ b/Rubrik/Public/Connect-Rubrik.ps1 @@ -99,8 +99,7 @@ function Connect-Rubrik { $UserAgent = "Rubrik-Powershell-SDK/$($MyInvocation.MyCommand.ScriptBlock.Module.Version.ToString())" Write-Verbose -Message "Using User Agent $($UserAgent)" - if($Token) - { + if($Token) { $head = @{'Authorization' = "Bearer $($Token)";'User-Agent' = $UserAgent} Write-Verbose -Message 'Storing all connection details into $global:rubrikConnection' $global:rubrikConnection = @{ @@ -114,6 +113,13 @@ function Connect-Rubrik { version = Get-RubrikSoftwareVersion -Server $Server authType = 'Token' } + + try { + $null = Get-RubrikVersion -ErrorAction Stop + } catch { + Disconnect-Rubrik + throw 'Invalid API Token provided, please provide correct token' + } } else { From 77329dd511d1c4f191fef3370745792061927e15 Mon Sep 17 00:00:00 2001 From: Jaap Brasser Date: Sun, 14 Jul 2019 14:25:06 +0200 Subject: [PATCH 3/7] Added null empty validation for token --- Rubrik/Public/Connect-Rubrik.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/Rubrik/Public/Connect-Rubrik.ps1 b/Rubrik/Public/Connect-Rubrik.ps1 index da1ecf5e2..4c5eb5ed9 100644 --- a/Rubrik/Public/Connect-Rubrik.ps1 +++ b/Rubrik/Public/Connect-Rubrik.ps1 @@ -55,6 +55,7 @@ function Connect-Rubrik { [Parameter(ParameterSetName='Credential',Mandatory=$true, Position = 1)] [System.Management.Automation.CredentialAttribute()]$Credential, [Parameter(ParameterSetName='Token',Mandatory=$true, Position = 1)] + [ValidateNotNullOrEmpty()] [String]$Token, #Organization to connect with, assuming the user has multiple organizations [Alias('organization_id')] From 2157462e5984b532339f62524186be9da0963a09 Mon Sep 17 00:00:00 2001 From: Jaap Brasser Date: Sun, 14 Jul 2019 14:26:03 +0200 Subject: [PATCH 4/7] Added parameter help description --- Rubrik/Public/Connect-Rubrik.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/Rubrik/Public/Connect-Rubrik.ps1 b/Rubrik/Public/Connect-Rubrik.ps1 index 4c5eb5ed9..3831806a7 100644 --- a/Rubrik/Public/Connect-Rubrik.ps1 +++ b/Rubrik/Public/Connect-Rubrik.ps1 @@ -54,6 +54,7 @@ function Connect-Rubrik { # Optionally, use the Username and Password parameters [Parameter(ParameterSetName='Credential',Mandatory=$true, Position = 1)] [System.Management.Automation.CredentialAttribute()]$Credential, + # Provide the Rubrik API Token instead, these are specificially created API token for authentication. [Parameter(ParameterSetName='Token',Mandatory=$true, Position = 1)] [ValidateNotNullOrEmpty()] [String]$Token, From b06c43cc919d35a5b67d88370eb2e543cdce8f3c Mon Sep 17 00:00:00 2001 From: Jaap Brasser Date: Sun, 14 Jul 2019 14:28:58 +0200 Subject: [PATCH 5/7] Updated changelog.md --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0626afe30..4af906011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +## 2019-07-14 + +### Changed [Connect-Rubrik] - Will validate if token is correct + +* Added validation step for token, a query is executed against the cluster endpoint to validate the token +* Get-RubrikAPIToken pwsh 5 bug fixed + ## 2019-07-13 ### Changed [Submit-Request] private function From f0d2744a01967c468b4c384d09cfde5599710601 Mon Sep 17 00:00:00 2001 From: Jaap Brasser Date: Sun, 14 Jul 2019 14:36:23 +0200 Subject: [PATCH 6/7] Added verbose message incorrect token --- Rubrik/Public/Connect-Rubrik.ps1 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Rubrik/Public/Connect-Rubrik.ps1 b/Rubrik/Public/Connect-Rubrik.ps1 index 3831806a7..45d764a2a 100644 --- a/Rubrik/Public/Connect-Rubrik.ps1 +++ b/Rubrik/Public/Connect-Rubrik.ps1 @@ -119,12 +119,11 @@ function Connect-Rubrik { try { $null = Get-RubrikVersion -ErrorAction Stop } catch { + Write-Verbose -Message 'Removing API token from $RubrikConnection using Disconnect-Rubrik' Disconnect-Rubrik throw 'Invalid API Token provided, please provide correct token' } - } - else - { + } else { $Credential = Test-RubrikCredential -Username $Username -Password $Password -Credential $Credential $uri = New-URIString -server $Server -endpoint ($resources.URI) -id $id From 54bdf1ea064aa1ea98429d700bae9a8e707cef9d Mon Sep 17 00:00:00 2001 From: Jaap Brasser Date: Sun, 14 Jul 2019 15:14:55 +0200 Subject: [PATCH 7/7] Only add typename if there is a result --- Rubrik/Public/Get-RubrikAPIToken.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Rubrik/Public/Get-RubrikAPIToken.ps1 b/Rubrik/Public/Get-RubrikAPIToken.ps1 index b9737eaa3..064255a13 100644 --- a/Rubrik/Public/Get-RubrikAPIToken.ps1 +++ b/Rubrik/Public/Get-RubrikAPIToken.ps1 @@ -77,7 +77,9 @@ function Get-RubrikAPIToken # Remove any api tokens generated for usage with web $result = $result | Where-Object {$_.sessionType -ne 'Web'} - @($result).ForEach{$_.PSObject.TypeNames.Insert(0,'Rubrik.APIToken')} + if ($null -ne $result) { + @($result).ForEach{$_.PSObject.TypeNames.Insert(0,'Rubrik.APIToken')} + } return $result } # End of process