Skip to content

Commit

Permalink
Merge pull request #447 from TheJumpCloud/SA-3036_SetJCSystemPipeline
Browse files Browse the repository at this point in the history
identify pipeline position/ functions
  • Loading branch information
jworkmanjc authored Nov 30, 2022
2 parents 76d4bb8 + edf1bf6 commit 8cfe069
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .circleci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ parameters:
PublishToPSGallery:
description: "When `true` and when run against Master branch, this workflow will publish the latest code to PSGallery"
type: boolean
default: false
default: true
ManualModuleVersion:
description: "When `true` the pipeline will use the Module Version specified in JumpCloud Module JumpCloud.psd1 file"
type: boolean
Expand Down
2 changes: 1 addition & 1 deletion PowerShell/JumpCloud Module/Docs/JumpCloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Module Name: JumpCloud
Module Guid: 31c023d1-a901-48c4-90a3-082f91b31646
Download Help Link: https://github.com/TheJumpCloud/support/wiki
Help Version: 2.1.1
Help Version: 2.1.2
Locale: en-US
---

Expand Down
2 changes: 1 addition & 1 deletion PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Updates the JumpCloud Module Settings File
## SYNTAX

```
Set-JCSettingsFile [-moduleBannerMessageCount <PSObject>] [-parallelOverride <PSObject>] [<CommonParameters>]
Set-JCSettingsFile [-parallelOverride <PSObject>] [-moduleBannerMessageCount <PSObject>] [<CommonParameters>]
```

## DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion PowerShell/JumpCloud Module/JumpCloud.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>JumpCloud</id>
<version>2.1.1</version>
<version>2.1.2.7154-202211300042</version>
<description>PowerShell functions to manage a JumpCloud Directory-as-a-Service</description>
<authors>JumpCloud Solutions Architect Team</authors>
<owners>JumpCloud</owners>
Expand Down
4 changes: 2 additions & 2 deletions PowerShell/JumpCloud Module/JumpCloud.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: JumpCloud Solutions Architect Team
#
# Generated on: 11/22/2022
# Generated on: 11/30/2022
#

@{
Expand All @@ -12,7 +12,7 @@
RootModule = 'JumpCloud.psm1'

# Version number of this module.
ModuleVersion = '2.1.1'
ModuleVersion = '2.1.2'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Function Get-PipelineDetails {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, HelpMessage = 'Pipeline String to test ($myInvocation.line)')]
[System.String]
$line
)
Begin {
$funcArray = @()
# split line by | opperator
$pipelines = $line.split('|')
$pipelineCount = $pipelines.count
}
Process {
foreach ($pipe in $pipelines) {
# trim whitespace
$function = $pipe.replace('{', '').replace('}', '')
$function = $function.TrimStart(" ")
$functionName = $function -match '^([\S]+)'
if ($matches) {
# add functionName $matches[0] and position
$funcArray += [PSCustomObject]@{
Function = $matches[0];
Position = $pipelines.IndexOf($pipe)
}
}
}
}
End {
# Return num of piped functions, and the array list of functions & positions
return $pipelineCount, $funcArray
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Function Get-PipelinePositionBefore {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, HelpMessage = 'Function name to test pipeline position is directly before function defined in the "after" param')]
[System.String]
$before,
[Parameter(Mandatory = $true, HelpMessage = 'Function name to test pipeline position is directly after function defined in the "before" param')]
[System.String]
$after,
[Parameter(Mandatory = $true, HelpMessage = 'Objects from Get-PipelineDetails')]
[System.object]
$functionArray
)
begin {
$occursBefore = $false
}
process {
# If function in pipeline (n) occurs before n+1, return $true
for ($i = 0; $i -le $functionArray.count; $i++) {
if (($functionArray[$i].Function -match $before) -and ($functionArray[$i + 1].Function -match $after)) {
$occursBefore = $true
}
}
}
end {
return $occursBefore
}
}
19 changes: 19 additions & 0 deletions PowerShell/JumpCloud Module/Public/Systems/Get-JCSystem.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,25 @@ Function Get-JCSystem () {
} # End process

end {
# finally determine pipeline info
$pipelineLength, $functions = Get-PipelineDetails -line $MyInvocation.Line
$setAfterGet = Get-PipelinePositionBefore -before "Get-JCSystem" -after "Set-JCSystem" -functionArray $functions
if ($pipelineLength -gt 1) {
if (($resultsArrayList.Count -ne 0) -And ($setAfterGet -eq $true)) {
foreach ($item in $resultsArrayList) {
$itemSysInsightsState = switch ($item.systemInsights.state) {
'enabled' {
$true
}
'deferred' {
$false
}
}
$item.systemInsights = $itemSysInsightsState
}
}
}

switch ($PSCmdlet.ParameterSetName) {
SearchFilter {
return $resultsArrayList | Select-Object -ExcludeProperty associatedTagCount, id, sshRootEnabled
Expand Down
21 changes: 15 additions & 6 deletions PowerShell/JumpCloud Module/Public/Systems/Set-JCSystem.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ Function Set-JCSystem () {
begin {

Write-Debug 'Verifying JCAPI Key'
if ($JCAPIKEY.length -ne 40) { Connect-JConline }
if ($JCAPIKEY.length -ne 40) {
Connect-JConline
}

$hdrs = @{

Expand All @@ -62,17 +64,24 @@ Function Set-JCSystem () {

foreach ($param in $PSBoundParameters.GetEnumerator()) {

if ([System.Management.Automation.PSCmdlet]::CommonParameters -contains $param.key) { continue }
if ([System.Management.Automation.PSCmdlet]::CommonParameters -contains $param.key) {
continue
}

if ($param.key -eq 'SystemID', 'JCAPIKey') { continue }
if ($param.key -eq 'SystemID', 'JCAPIKey') {
continue
}

if ($param.key -eq 'systemInsights') {
$state = switch ($systemInsights) {
true { 'enabled' }
false { 'deferred' }
true {
'enabled'
}
false {
'deferred'
}
}
$body.add('systemInsights', @{'state' = $state })

continue
}

Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Describe -Tag:('JCSystem') 'Set-JCSystem 1.0' {
$Update.systemInsights.state | Should -Be "enabled"
}
}
Describe -Tag:('JCSystem') "Get-JCSystem 2.1.0" {
Describe -Tag:('JCSystem') "Get-JCSystem 2.1.0 & 2.1.2" {
BeforeAll {
# Reset Description
$systems = Get-JCSystem | Where-Object { $_.description -ne "" }
Expand All @@ -69,7 +69,14 @@ Describe -Tag:('JCSystem') "Get-JCSystem 2.1.0" {
$systemBfore = Set-JCSystem -SystemID $($PesterParams_SystemWindows._id) -description $descriptionText
$FoundSystem = Get-JCSystem -description $descriptionText
$FoundSystem._id | Should -Be $($PesterParams_SystemWindows._id)
# Return system to
# Return system to orig state
Set-JCSystem -SystemId $($PesterParams_SystemWindows._id) -description $systemBfore.description
}
It "Sets a System using a pipeline without throwing" {
$descriptionText = "Pester"
$systemBfore = Set-JCSystem -SystemID $($PesterParams_SystemWindows._id) -description $descriptionText
{ Get-JCSystem -description $descriptionText | Set-JCSystem -description "Modified" } | Should -Not -Throw
# Return system to orig state
Set-JCSystem -SystemId $($PesterParams_SystemWindows._id) -description $systemBfore.description
}
}
14 changes: 14 additions & 0 deletions PowerShell/ModuleChangelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## 2.1.2

Release Date: November 22, 2022

#### RELEASE NOTES

```
- Fixed an issue with passing pipeline data from Get-JCSystem to Set-JCsystem
```

#### BUG FIXES:

- Set-JCSystem would throw error regarding systemInsights when using data passed via Get-JCSystem pipeline

## 2.1.1

Release Date: November 22, 2022
Expand Down

0 comments on commit 8cfe069

Please sign in to comment.