Skip to content

Commit

Permalink
Version 0.28
Browse files Browse the repository at this point in the history
New Features:

- Added pipe support for SLA Cmdlets
  [From PR 57](#57)

Fixes:

- Updated help texts
  [From PR 53](#53)
- Fixed build and tests for PowerShell 5.1
  • Loading branch information
guirava committed Mar 28, 2024
2 parents 4dec354 + d3e96f4 commit 11be216
Show file tree
Hide file tree
Showing 22 changed files with 410 additions and 180 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,5 @@ GraphQL Schme Downloader/schema/.env.json

# PowerShell module
Output/
Output.Release/
.vscode/
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## Version 0.28

New Features:

- Added pipe support for SLA Cmdlets
[From PR 57](https://github.com/rubrikinc/rubrik-powershell-sdk/pull/57)

Fixes:

- Updated help texts
[From PR 53](https://github.com/rubrikinc/rubrik-powershell-sdk/pull/53)
- Fixed build and tests for PowerShell 5.1

## Version 0.27

Fixes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,16 @@ internal void ProcessRecord_Query()
{
throw new ArgumentException("No GQL query provided");
}
var _asPathString = Path.GetFullPath(sQuery);
if (File.Exists(_asPathString))
{
sQuery = File.ReadAllText(_asPathString);

// if the content of sQuery is an existing file, read it
try {
var _asPathString = Path.GetFullPath(sQuery);
if (File.Exists(_asPathString))
{
sQuery = File.ReadAllText(_asPathString);
}
} catch (Exception) {
// ignore
}

GqlQuery = sQuery;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ protected void ProcessDomainOp(string domain, string op)

}


/// <summary>
/// Create a new RscMutation object.
/// </summary>
[CmdletBinding()]
[Cmdlet(
"New",
Expand Down Expand Up @@ -223,6 +225,9 @@ public New_RscMutation()
}
}

/// <summary>
/// Create a new RscQuery object.
/// </summary>
[CmdletBinding()]
[Cmdlet(
"New",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,94 +27,104 @@ function Get-RscHelp {
Param (
[Parameter(
ParameterSetName = 'Locations',
HelpMessage = 'Show File System locations the SDK uses.',
Position = 0
HelpMessage = 'Show File System locations the SDK uses.'
)]
[Switch]$Locations,

[Parameter(
ParameterSetName = 'Schema',
HelpMessage = 'Look up any symbol in the schema.',
Position = 0
HelpMessage = 'Look up any symbol in the schema.'
)]
[Switch]$Schema,

[Parameter(
ParameterSetName = 'Query',
HelpMessage = 'Look up a query by name.',
Position = 0
HelpMessage = 'Look up a query by name.'
)]
[Switch]$Query,

[Parameter(
ParameterSetName = 'Mutation',
HelpMessage = 'Look up a mutation by name.',
Position = 0
HelpMessage = 'Look up a mutation by name.'
)]
[Switch]$Mutation,

[Parameter(
ParameterSetName = 'Type',
HelpMessage = 'Look up a type by name.',
Position = 0
HelpMessage = 'Look up a type by name.'
)]
[Switch]$Type,

[Parameter(
ParameterSetName = 'Scalar',
HelpMessage = 'Look up a scalar by name.',
Position = 0
HelpMessage = 'Look up a scalar by name.'
)]
[Switch]$Scalar,

[Parameter(
ParameterSetName = 'Union',
HelpMessage = 'Look up a union by name.',
Position = 0
HelpMessage = 'Look up a union by name.'
)]
[Switch]$Union,

[Parameter(
ParameterSetName = 'Interface',
HelpMessage = 'Look up an interface by name.',
Position = 0
HelpMessage = 'Look up an interface by name.'
)]
[Switch]$Interface,

[Parameter(
ParameterSetName = 'Input',
HelpMessage = 'Look up an input by name.',
Position = 0
HelpMessage = 'Look up an input by name.'
)]
[Switch]$Inputs,

[Parameter(
ParameterSetName = 'Enum',
HelpMessage = 'Look up an enum by name.',
Position = 0
HelpMessage = 'Look up an enum by name.'
)]
[Switch]$Enum,

[Parameter(
ParameterSetName = 'Domain',
HelpMessage = 'Look up an API domain by name.',
Position = 0
HelpMessage = 'Look up an API domain by name.'
)]
[Switch]$Domain,

[Parameter(
ParameterSetName = 'Cmdlet',
HelpMessage = 'This is equivalent to Get-Help -Name <cmdlet> -Full'
)]
[Switch]$Cmdlet,

[Parameter(
HelpMessage = 'Regular expression to match',
Position = 1
Position = 0
)]
[string]$Match = ""

)
Begin {
Write-Debug "=> ParameterSetName: $($PSCmdlet.ParameterSetName) Match: $Match"
function GetLocationHelp {
Write-Debug "Getting locations"
Get-RscCmdlet -Locations
}

function GetCmdletHelp {
Write-Debug "Getting cmdlet help for '$Match'"
if ($Match -eq "") {
$Match = "New-Rsc"
}
Get-Help -Name $Match -Full
}

function LookupSchema {
Write-Debug "Looking up schema for '$Match'"
if ($Match -imatch "^new-") {
GetCmdletHelp
return
}
$tableData = @()
# Get all the enums within the SchemaMeta class
$enums = [RubrikSecurityCloud.Types.SchemaMeta].GetNestedTypes() | Where-Object { $_.IsEnum -and $_.Name -ne 'GqlRootFieldName' -and $_.Name -ne 'RootFieldKind' }
Expand Down Expand Up @@ -149,6 +159,7 @@ function Get-RscHelp {
}

function LookupQuery {
Write-Debug "Looking up query for '$Match'"
$enumValues = [Enum]::GetValues([RubrikSecurityCloud.Types.SchemaMeta+GqlQueryName]) | Where-Object { $_ -ine 'Unknown' }
foreach ($value in $enumValues) {
# if it's an exact match, print query info
Expand Down Expand Up @@ -387,6 +398,7 @@ function Get-RscHelp {
}
switch ($PSCmdlet.ParameterSetName) {
'Locations' { GetLocationHelp }
'Cmdlet' { GetCmdletHelp }
'Schema' { LookupSchema }
'Query' { LookupQuery }
'Mutation' { LookupMutation }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$psdFile = "$PSScriptRoot/RubrikSecurityCloud.psd1"
$psdContent = Get-Content -Path $psdFile -Raw

$toolkitDir = Join-Path (Get-Item $PSScriptRoot).Parent.Parent.FullName "Toolkit"
$toolkitDir = Join-Path -Path (Get-Item $PSScriptRoot).Parent.Parent.FullName -ChildPath "Toolkit"

# Update list of ps1xml format files to process:
$ps1xmlFiles = Get-ChildItem -Path "$toolkitDir/Format" -Filter "*.ps1xml"
Expand Down
8 changes: 6 additions & 2 deletions Samples/SampleUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ function Write-IndentedWrappedMessage {
[int] $Indent = 2,

[Parameter(Mandatory=$false)]
[int] $Width = ($Host.UI -and $Host.UI.RawUI) ? $Host.UI.RawUI.BufferSize.Width : 80
[int] $Width = 80
)

if ($Host.UI -and $Host.UI.RawUI) {
$Width = $Host.UI.RawUI.BufferSize.Width
}

$indentString = " " * $Indent
$width = $Width - $Indent
$lines = $Message -split "`n"
Expand Down Expand Up @@ -112,7 +116,7 @@ function Wait-ForKey {
[Console]::TreatControlCAsInput = $true
$key = [Console]::ReadKey($false)
Write-Host "`r$('-' * ($Continue.Length + 1))`r"
if ($key.Key -eq [System.ConsoleKey]::Escape || ($key.Key -eq [System.ConsoleKey]::C -and $key.Modifiers -eq [System.ConsoleModifiers]::Control)) {
if ($key.Key -eq [System.ConsoleKey]::Escape -or ($key.Key -eq [System.ConsoleKey]::C -and $key.Modifiers -eq [System.ConsoleModifiers]::Control)) {
exit
}
}
8 changes: 1 addition & 7 deletions Tests/connect.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
$ModuleName = 'RubrikSecurityCloud'
$DllName = $ModuleName + '.psd1'
$DllDir = '../Output/'
$DllPath = Join-Path $PSScriptRoot $DllDir $DllName

Remove-Module -Name $ModuleName -ErrorAction 'SilentlyContinue'
Import-Module $DllPath -Verbose
. "$PSScriptRoot/../Utils/Import-RscModuleFromLocalOutputDir.ps1" -Quiet
Connect-Rsc
2 changes: 1 addition & 1 deletion Tests/e2e/Get-RscFilesetTemplate.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Describe -Name 'Get-RscFilesetTemplate' -Tag 'Public' -Fixture{

It -Name 'Parameters Id and Name cannot be simultaneously used' -Test {
{ Get-RscFilesetTemplate -Id my-host-id-that-doesnot-exist -Name 'swagsanta' } |
Should -Throw "Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided."
Should -Throw -ErrorId 'AmbiguousParameterSet,RubrikSecurityCloud.PowerShell.Cmdlets.Get_RscFilesetTemplate'
}

It -Name 'Parameter OsType cannot be $null' -Test{
Expand Down
2 changes: 1 addition & 1 deletion Tests/e2e/Get-RscHost.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Describe -Name 'Get-RscHost' -Tag 'Public' -Fixture{

It -Name 'Parameters Id and Name cannot be simultaneously used' -Test {
{ Get-RscHost -Id my-host-id-that-doesnot-exist -Name 'swagsanta' } |
Should -Throw "Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided."
Should -Throw -ErrorId 'AmbiguousParameterSet,RubrikSecurityCloud.PowerShell.Cmdlets.Get_RscHost'
}

It -Name 'Parameter OsType cannot be $null' -Test{
Expand Down
2 changes: 1 addition & 1 deletion Tests/e2e/Get-RscVsphereVm.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Describe -Name 'Get-RscVSphereVM' -Tag 'Public' -Fixture{
}
It -Name 'Parameters Id and Name cannot be simultaneously used' -Test {
{ Get-RscVsphereVm -Id VirtualMachine:::1226ff04-6100-454f-905b-5df817b6981a-vm-1025 -Name 'swagsanta' } |
Should -Throw "Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided."
Should -Throw -ErrorId 'AmbiguousParameterSet,RubrikSecurityCloud.PowerShell.Cmdlets.Get_RscVsphereVm'
}
}
}
12 changes: 9 additions & 3 deletions Tests/e2e/Invoke-Rsc.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ Describe -Name "Send a generic GraphQL call" -Fixture {
$response.IsEulaAccepted | Should -Not -BeNullOrEmpty

# Query file with no variables
$gqlFile = "$PSScriptRoot\..\..\Samples\queryAccountOwners.gql"
$owners = Get-Content -Path $gqlFile -Raw | Invoke-Rsc
$gqlFileName = Join-Path -Path $PSScriptRoot -ChildPath "..\..\Samples\queryAccountOwners.gql" -Resolve
$gqlContent = Get-Content -Path $gqlFileName -Raw
$owners = $gqlContent | Invoke-Rsc
$owners[0].GetType().Name | Should -BeExactly 'User'

# Same but pass as parameter
$owners = Invoke-Rsc (Get-Item -Path $gqlFile).FullName
$owners = Invoke-Rsc "$gqlContent"
$owners[0].GetType().Name | Should -BeExactly 'User'

# Same but with a file name
$owners = Invoke-Rsc $gqlFileName
$owners[0].GetType().Name | Should -BeExactly 'User'

# Query file with variables embedded in top comment
Expand Down
47 changes: 43 additions & 4 deletions Tests/unit/Import.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,21 +1,60 @@
. "$PSScriptRoot\..\UnitTestInit.ps1"

Describe -Name 'Verify correct import' -Fixture {
It "should be version 6.0.0" {
It -Name "min version of PowerShell required by the module should be 5.0.0" {
$module = Get-Module -Name RubrikSecurityCloud
$expectedVersion = New-Object System.Version(5, 0, 0)
$module.PowerShellVersion | Should -Be $expectedVersion
}
# Connect-Rsc should always be available
It -Name 'Connect-Rsc exists' -Test {
(Get-Command -Name Connect-Rsc -ErrorAction SilentlyContinue) | Out-String |
Should -BeLikeExactly '*Connect-Rsc*'
Should -BeLikeExactly '*Connect-Rsc*'
}
# Disconnect-Rsc should always be available
It -Name 'Disconnect-Rsc exists' -Test {
(Get-Command -Name Disconnect-Rsc -ErrorAction SilentlyContinue) | Out-String |
Should -BeLikeExactly '*Disconnect-Rsc*'
Should -BeLikeExactly '*Disconnect-Rsc*'
}
# Arbitrary command that should always be available
It -Name 'Get-RscVsphereVm exists' -Test {
(Get-Command -Name Get-RscVsphereVm -ErrorAction SilentlyContinue) | Out-String |
Should -BeLikeExactly '*Get-RscVsphereVm*'
Should -BeLikeExactly '*Get-RscVsphereVm*'
}

# Make sure exported command list is the same on PowerShell 7 and PowerShell 5
It -Name 'Exported command list is the same on PowerShell 7 and PowerShell 5' -Test {
# Determine if running on Windows
$win = $false
if ($PSVersionTable.PSVersion.Major -ge 6) {
# PowerShell Core/7+
$win = $IsWindows
}
else {
# Windows PowerShell 5 ("Desktop PowerShell")
$win = [System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Win32NT
}

if (-not $win) {
# Skip this test on non-Windows platforms
Set-ItResult -Skipped -Because 'This test is only applicable on Windows'
return
}

$sdkDir = Join-Path -Path $PSScriptRoot -ChildPath '..\..' -Resolve
$psCommand = ". Utils/Import-RscModuleFromLocalOutputDir.ps1 -Quiet; Get-Command -Module RubrikSecurityCloud | Sort-Object Name | Select-Object -ExpandProperty Name"
# Run the command on PowerShell 7
$ps7OutFile = "get-command.powershell7.txt"
Start-Process -WorkingDirectory $sdkDir -FilePath "pwsh" -ArgumentList "-NoProfile", "-Command", $psCommand -Wait -NoNewWindow -PassThru -RedirectStandardOutput $ps7OutFile
# Run the command on PowerShell 5
$ps5OutFile = "get-command.powershell5.txt"
Start-Process -WorkingDirectory $sdkDir -FilePath "powershell" -ArgumentList "-NoProfile", "-Command", $psCommand -Wait -NoNewWindow -PassThru -RedirectStandardOutput $ps5OutFile
# Compare the output
$ps7Out = Get-Content -Path $ps7OutFile
$ps5Out = Get-Content -Path $ps5OutFile
$ps7Out | Should -Be $ps5Out
# Clean up
Remove-Item -Path $ps7OutFile
Remove-Item -Path $ps5OutFile
}
}
Loading

0 comments on commit 11be216

Please sign in to comment.