Skip to content

Commit

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

- Toolkit: Operations (patch files) are now part of Toolkit
- AutoFieldSpec: patch file for `QueryCdmMssqlLogShippingTargets`
- AutoFieldSpec: patch file for `QueryMssqlDatabaseLiveMounts`
- [README](https://github.com/rubrikinc/rubrik-powershell-sdk/blob/devel/Toolkit/Operations/README.md)
  on how to write patch files.

Fixes:

- Fix for queries that return a single interface object.
  See `Tests/unit/Sla.Tests.ps1`.
  (implemented with _type composition_ in the C# core)
  • Loading branch information
guirava committed Apr 1, 2024
2 parents 14233e0 + f4cbded commit 034c6d5
Show file tree
Hide file tree
Showing 22 changed files with 612 additions and 92 deletions.
18 changes: 16 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## Version 0.29

New Features:

- Toolkit: Operations (patch files) are now part of Toolkit
- AutoFieldSpec: patch file for `QueryCdmMssqlLogShippingTargets`
- AutoFieldSpec: patch file for `QueryMssqlDatabaseLiveMounts`
- [README](https://github.com/rubrikinc/rubrik-powershell-sdk/blob/devel/Toolkit/Operations/README.md)
on how to write patch files.

Fixes:

- Fix for queries that return a single interface object.
See `Tests/unit/Sla.Tests.ps1`.
(implemented with _type composition_ in the C# core)

## Version 0.28

New Features:
Expand Down Expand Up @@ -395,5 +411,3 @@ Fixes:
Breaking changes:

- `-InputProfile DETAILS` is now `-InputProfile DETAIL`


22 changes: 19 additions & 3 deletions RubrikSecurityCloud/RubrikSecurityCloud.Common/BaseType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,25 @@ namespace RubrikSecurityCloud.Types
{
public abstract class BaseType : IFieldSpec
{
// pointer to next object in chain.
// Composite field spec support:
// _next is the pointer to next object in chain.
// Used for building up a chain of objects
// to represent a "composite field spec".
internal BaseType? _next = null;
public BaseType? Next() => _next;
public void SetNext(BaseType? next) => _next = next;
public bool IsComposite() => _next != null;
public int CompositeLength()
{
int len = 1;
BaseType? next = _next;
while (next != null)
{
len++;
next = next._next;
}
return len;
}

// IFieldSpec interface:
public abstract string AsFieldSpec(FieldSpecConfig? conf = null);
Expand Down Expand Up @@ -61,13 +76,14 @@ public static string AsFieldSpec(this List<BaseType> list,
StringBuilder sb = new StringBuilder();
foreach (BaseType item in list)
{
string fs = item.AsFieldSpec(conf.Child(ignoreComposition:true));
if (conf.Flat)
{
sb.Append(item.AsFieldSpec(conf.Child()));
sb.Append(fs);
}
else
{
sb.Append(ind + " ... on " + item.GetType().Name + " {\n" + item.AsFieldSpec(conf.Child()) + ind + "}\n");
sb.Append(ind + " ... on " + item.GetType().Name + " {\n" + fs + ind + "}\n");
}
}
return sb.ToString();
Expand Down
2 changes: 1 addition & 1 deletion RubrikSecurityCloud/RubrikSecurityCloud.Common/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static class Config
{"^version$" , null },
// prefix matches
{"^has", null },
{"^is", null },
{"^is", new List<string>{ "isTprEnabled" } },
// partial matches
{"status", new List<string>{ "cdmRbacMigrationStatus", "eosStatus" } },
{"state", null },
Expand Down
3 changes: 2 additions & 1 deletion RubrikSecurityCloud/RubrikSecurityCloud.Common/Files.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public static string GetAssemblyDir()
public static string GetSdkOperationsDir(string InputProfileName)
{
string assemblyDir = GetAssemblyDir();
return Path.Combine(assemblyDir, "..", "Operations", InputProfileName);
return Path.Combine(assemblyDir, "..", "Toolkit", "Operations",
InputProfileName);
}

// return empty string if file doesn't exist
Expand Down
22 changes: 20 additions & 2 deletions RubrikSecurityCloud/RubrikSecurityCloud.Common/IFieldSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ public class FieldSpecConfig

public string Node { get; set; } = "";

public FieldSpecConfig Child(string thisNode = "", string childNode = "")
// IgnoreComposition does not automatically get passed down
// to child/copy FieldSpecConfigs. It must be set explicitly.
public bool IgnoreComposition { get; set; } = false;

public FieldSpecConfig Child(string thisNode = "", string childNode = "",
bool ignoreComposition = false)
{
thisNode = string.IsNullOrEmpty(thisNode) ? this.Node : thisNode;
return new FieldSpecConfig
Expand All @@ -23,7 +28,20 @@ public FieldSpecConfig Child(string thisNode = "", string childNode = "")
Indent = this.Indent + 1,
Prefix = this.Prefix +
(string.IsNullOrEmpty(thisNode) ? "" : thisNode + "."),
Node = childNode
Node = childNode,
IgnoreComposition = ignoreComposition
};
}

public FieldSpecConfig Copy(bool ignoreComposition = false)
{
return new FieldSpecConfig
{
Flat = this.Flat,
Indent = this.Indent,
Prefix = this.Prefix,
Node = this.Node,
IgnoreComposition = ignoreComposition
};
}

Expand Down
16 changes: 12 additions & 4 deletions RubrikSecurityCloud/RubrikSecurityCloud.Common/InterfaceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ public static BaseType MakeCompositeFromList(IEnumerable<object> list)
current = baseTypeItem;
} else
{
current._next = baseTypeItem;
current = current._next;
current.SetNext(baseTypeItem);
// move to next item
current = current.Next();
}
}
current?.SetNext(null);
}
else
{
throw new ArgumentException("List item is not of BaseType or derived from BaseType", nameof(list));
Expand All @@ -149,10 +151,16 @@ public static List<BaseType> MakeListFromComposite(BaseType composite)
while (current != null)
{
list.Add(current);
current = current._next as BaseType;
current = current.Next();
}

return list;
}

public static string CompositeAsFieldSpec(BaseType composite, FieldSpecConfig conf)
{
var list = MakeListFromComposite(composite);
return list.AsFieldSpec(conf.Copy(ignoreComposition: true));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
debugconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ param(
[switch] $VerboseLogging=$false,
[string] $EnvName
)

Set-Location $PSScriptRoot\..
$psd1_path = ".\bin\Debug\RubrikSecurityCloud.psd1"

try{
Expand Down Expand Up @@ -76,7 +76,7 @@ try{
try{
#Check if the encrypted SA file exists and if not, create it.
if (-Not (Test-Path $sa_enc_file_full_path)){
Set-RscServiceAccountFile -InputFilePath $sa_file_full_path -OutputFilePath $sa_enc_file_full_path
Set-RscServiceAccountFile -InputFilePath $sa_file_full_path -OutputFilePath $sa_enc_file_full_path -KeepOriginalClearTextFile
}
}
catch{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ function Get-RscHelp {
)]
[Switch]$Interface,

[Parameter(
ParameterSetName = 'Interface',
HelpMessage = 'Only show the implementing types.'
)]
[Switch]$ImplementingTypes,

[Parameter(
ParameterSetName = 'Input',
HelpMessage = 'Look up an input by name.'
Expand Down Expand Up @@ -311,6 +317,10 @@ function Get-RscHelp {
foreach ($value in $enumValues) {
# if it's an exact match, print interface info
if ( $value -eq $Match ) {
if ($ImplementingTypes) {
Get-RscType -Interface $value
return
}
try {
Write-Output "# Types that implement interface ${value}:"
$info = Get-RscType -Interface $value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

<Target Name="CopyToolkitFormatFiles" AfterTargets="Build" Condition="'$(TargetFramework)' == 'net6.0'">
<ItemGroup>
<ToolkitFormatFiles Include="$(ProjectDir)/../../Toolkit/Format/*.ps*" />
<ToolkitFormatFiles Include="$(ProjectDir)/../../Toolkit/Format/*" />
</ItemGroup>
<Copy SourceFiles="@(ToolkitFormatFiles)" DestinationFolder="$(TargetDir)/../Toolkit/Format" />
</Target>
Expand All @@ -113,15 +113,15 @@

<!-- Copy all files from Operations/DEFAULT -->
<ItemGroup>
<DefaultOperationFiles Include="$(ProjectDir)../../Operations/DEFAULT/*.*" />
<DefaultOperationFiles Include="$(ProjectDir)../../Toolkit/Operations/DEFAULT/*" />
</ItemGroup>
<Copy SourceFiles="@(DefaultOperationFiles)" DestinationFolder="$(TargetDir)/../Operations/DEFAULT" />
<Copy SourceFiles="@(DefaultOperationFiles)" DestinationFolder="$(TargetDir)/../Toolkit/Operations/DEFAULT" />

<!-- Copy all files from Operations/DETAIL -->
<ItemGroup>
<DetailOperationFiles Include="$(ProjectDir)/../../Operations/DETAIL/*.*" />
<DetailOperationFiles Include="$(ProjectDir)/../../Toolkit/Operations/DETAIL/*" />
</ItemGroup>
<Copy SourceFiles="@(DetailOperationFiles)" DestinationFolder="$(TargetDir)/../Operations/DETAIL" />
<Copy SourceFiles="@(DetailOperationFiles)" DestinationFolder="$(TargetDir)/../Toolkit/Operations/DETAIL" />
</Target>

<Target Name="GeneratePSDocs" AfterTargets="Build" Condition="'$(TargetFramework)' == 'net6.0' AND '$(GeneratePSDocs)'=='true'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Copyright = '(c) Rubrik. All rights reserved.'

# Description of the functionality provided by this module
# NOTE: This entry is generated.
Description = 'PowerShell Module for Rubrik Security Cloud. GraphQL schema version: v20240304-17 .'
Description = 'PowerShell Module for Rubrik Security Cloud. GraphQL schema version: v20240325-21 .'

# Minimum version of the PowerShell engine required by this module
PowerShellVersion = '5.0.0'
Expand Down
56 changes: 56 additions & 0 deletions Tests/e2e/Sla.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<#
.SYNOPSIS
Run tests around SLAs
.DESCRIPTION
This file is the companion to the Sla.Tests.ps1 file in the unit folder.
This file tests if the query runs correctly.
It does not test the integrity of the query.
See Tests/unit/Sla.Tests.ps1 for testing the integrity of the query.
#>
BeforeAll {
. "$PSScriptRoot\..\E2eTestInit.ps1"
}

Describe -Name 'SLAs' -Fixture {
It -Name 'SLA Domains' -Test {

# ----------------------------------------------------------
#
# 1. Retrieve the list of SLAs
#
# (list of 1 but still a list, not a single object)
# ----------------------------------------------------------

$q1 = New-RscQuery -GqlQuery slaDomains -Var @{first = 1 }

$r1 = $q1 | Invoke-Rsc
$totalSlaCount = $r1.count
$retrievedSlaCount = $r1.nodes.count
$totalSlaCount | Should -BeGreaterOrEqual $retreivedSlaCount
if ($retrievedSlaCount -ne 1) {
Set-ItResult -Skipped -Because "This test needs at least 1 SLA to run"
return
}
# The returned SLA object should be a SlaDomain-implementing object
$implementingTypes = Get-RscHelp -Interface SlaDomain -ImplementingTypes
$r1.Nodes | ForEach-Object {
$implementingTypes | Should -Contain $_.GetType().Name
}

# ----------------------------------------------------------
#
# 2. Retrieve a single SLA
#
# ----------------------------------------------------------

$slaId = $r1.nodes[0].id
$q2 = New-RscQuery -GqlQuery slaDomain -Var @{id = $slaId }
$r2 = $q2 | Invoke-Rsc
$r2.Count | Should -Be 1
$implementingTypes | Should -Contain $r2.GetType().Name
$r2.id | Should -Be $slaId
}
}
57 changes: 57 additions & 0 deletions Tests/unit/Patching.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,61 @@ Describe -Name "Test patching" -Fixture {
$qe2 = New-RscQueryCluster -Op List -RemoveField Nodes, PageInfo
$qe1.Field.AsFieldSpec() | Should -Be $qe2.Field.AsFieldSpec()
}

It -Name "With New-RscQueryMSsql -Operation Databases" -Test {

# Patching with -AddField
$qobj1 = New-RscQueryMSsql -Op Databases -AddField Nodes.PhysicalPath
$q1 = $qobj1.GqlRequest().Query

# Patching after copy
$qobj = New-RscQueryMSsql -Op Databases
$qobj2 = New-RscQuery -Copy $qobj -AddField Nodes.PhysicalPath
$q2 = $qobj2.GqlRequest().Query

# Post-patching with Get-RscType -InitialProperties
$qobj3 = New-RscQueryMSsql -Operation Databases
$qobj3.Field.Nodes[0].PhysicalPath = Get-RscType -Name PathNode -InitialProperties @("Fid", "Name", "ObjectType")
$q3 = $qobj3.GqlRequest().Query

# Post-patching with SelectForRetrieval
$qobj4 = New-RscQueryMSsql -Op Databases
$qobj4.Field.Nodes[0].PhysicalPath = New-Object RubrikSecurityCloud.Types.PathNode
$qobj4.Field.Nodes[0].PhysicalPath[0].SelectForRetrieval()
$q4 = $qobj4.GqlRequest().Query

$q1 | Should -Be $q2
$q1 | Should -Be $q3
$q1 | Should -Be $q4

#
# Same as above, but with domain-less cmdlets
#

$rootField = $qobj1.OpInfo().GqlRootFieldName

# Patching with -AddField
$qobj5 = New-RscQuery -GqlQuery $rootField -AddField Nodes.PhysicalPath
$q5 = $qobj5.GqlRequest().Query

# Patching after copy
$qobj6 = New-RscQuery -Copy $qobj -AddField Nodes.PhysicalPath
$q6 = $qobj6.GqlRequest().Query

# Post-patching with Get-RscType -InitialProperties
$qobj7 = New-RscQuery -GqlQuery $rootField
$qobj7.Field.Nodes[0].PhysicalPath = Get-RscType -Name PathNode -InitialProperties @("Fid", "Name", "ObjectType")
$q7 = $qobj7.GqlRequest().Query

# Post-patching with SelectForRetrieval
$qobj8 = New-RscQuery -GqlQuery $rootField
$qobj8.Field.Nodes[0].PhysicalPath = New-Object RubrikSecurityCloud.Types.PathNode
$qobj8.Field.Nodes[0].PhysicalPath[0].SelectForRetrieval()
$q8 = $qobj8.GqlRequest().Query

$q5 | Should -Be $q1
$q6 | Should -Be $q1
$q7 | Should -Be $q1
$q8 | Should -Be $q1
}
}
Loading

0 comments on commit 034c6d5

Please sign in to comment.