Skip to content

Commit

Permalink
Merge pull request #382 from TheJumpCloud/SA-2592_BackupJCOrgReadOnly…
Browse files Browse the repository at this point in the history
…BugFix

Backup-JCOrg Read Only Support
  • Loading branch information
jworkmanjc authored May 19, 2022
2 parents 5740020 + e2b9c00 commit 3dd164f
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .circleci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ parameters:
description: 'Release Type. Accepted values [ Major, Minor, Patch ]'
type: enum
enum: ["Major", "Minor", "Patch"]
default: "Minor"
default: "Patch"
RequiredModulesRepo:
description: 'PowerShell Repository for JumpCloud SDKs'
type: enum
Expand All @@ -45,7 +45,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: 1.22.0
Help Version: 1.22.1
Locale: en-US
---

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: 5/17/2022
# Generated on: 5/19/2022
#

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

# Version number of this module.
ModuleVersion = '1.22.0'
ModuleVersion = '1.22.1'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ Function Backup-JCOrganization
# Build Command based upon source and target combinations
# *Group commands take "GroupId" as a parameter vs "{Type}Id"
# User associations is called Get-JcSdkUserAssociation and Get-JcSdkUserMember
# Print the Source & Target for debugging
# If ($PSBoundParameters.Debug) { Write-Host ("Source: $($SourceTypeMap.Value.Name) | Target: $($TargetTypeMap.Value.Name)") -ForegroundColor:('Yellow') }
If (($SourceTypeMap.Value.Name -eq 'system' -and $TargetTypeMap.Value.Name -eq 'system_group') -or ($SourceTypeMap.Value.Name -eq 'user' -and $TargetTypeMap.Value.Name -eq 'user_group'))
{
$Command = 'Get-JcSdk{0}Member -{1}Id:("{2}")' -f $SourceTypeMap.Key, $SourceTypeMap.Key.Replace('UserGroup', 'Group').Replace('SystemGroup', 'Group'), $BackupRecord.id
Expand Down Expand Up @@ -291,73 +293,98 @@ Function Backup-JCOrganization
ElseIf (($SourceTypeMap.Value.Name -eq 'command' -and $TargetTypeMap.Value.Name -eq 'system' -and $Settings.ROLE -eq 'Read Only') -or ($SourceTypeMap.Value.Name -eq 'command' -and $TargetTypeMap.Value.Name -eq 'system_group' -and $Settings.ROLE -eq 'Read Only'))
{
# Note on SA-2014 read only cases, this is temporary and should be addressed in the API but this is proving difficult, these cases are only necessary since the association endpoints on systems->commands/softwareapps is disabled for readonly users
$Command = 'Get-JcSdk{0}Traverse{2} -{0}Id:("{1}")' -f $SourceTypeMap.Key, $BackupRecord.id, (Get-Culture).TextInfo.ToTitleCase($TargetTypeMap.Value.Name)
$Command = 'Get-JcSdk{0}Traverse{2} -{0}Id:("{1}")' -f $SourceTypeMap.Key, $BackupRecord.id, ($TargetTypeMap.Value.Name).Replace('system_group', 'SystemGroup')
If ($PSBoundParameters.Debug) { Write-Host ("DEBUG: Running: $Command") -ForegroundColor:('Yellow') }
$AssociationResult = Invoke-Expression -Command:($Command)
If (-not [System.String]::IsNullOrEmpty($AssociationResult))
{
# The direct association/"Get-JcSdk*Membership" endpoints return null for FromId. So manually populate them here.
$AssociationResult.Paths | ForEach-Object {
$_ | ForEach-Object {
if ($_.FromType -eq $SourceTypeMap.Value.Name -and $_.ToType -eq $TargetTypeMap.Value.Name){
$AssociationResults += $_
If ([System.String]::IsNullOrEmpty($_.FromId))
{
$_.FromId = $BackupRecord.id
}
# The direct association/"Get-JcSdk*Membership" endpoints return null for FromType. So manually populate them here.
If ([System.String]::IsNullOrEmpty($_.FromType))
{
$_.FromType = $SourceTypeMap.Value.Name
}
}
}
$AssociationResults += $AssociationResult
}
}
ElseIf (($SourceTypeMap.Value.Name -eq 'system' -and $TargetTypeMap.Value.Name -eq 'command' -and $Global:JCSettings.ROLE -eq 'Read Only') -or ($SourceTypeMap.Value.Name -eq 'system_group' -and $TargetTypeMap.Value.Name -eq 'command' -and $Global:JCSettings.ROLE -eq 'Read Only'))
ElseIf (($SourceTypeMap.Value.Name -eq 'system' -and $TargetTypeMap.Value.Name -eq 'command' -and $Settings.ROLE -eq 'Read Only') -or ($SourceTypeMap.Value.Name -eq 'system_group' -and $TargetTypeMap.Value.Name -eq 'command' -and $Settings.ROLE -eq 'Read Only'))
{
$Command = 'Get-JcSdk{0}Traverse{2} -{0}Id:("{1}")' -f $SourceTypeMap.Key, $BackupRecord.id, (Get-Culture).TextInfo.ToTitleCase($TargetTypeMap.Value.Name)
$Command = 'Get-JcSdk{2}Traverse{0} -{2}Id:("{1}")' -f $SourceTypeMap.Key, $BackupRecord.id, ($TargetTypeMap.Value.Name).Replace('system_group', 'SystemGroup')
If ($PSBoundParameters.Debug) { Write-Host ("DEBUG: Running: $Command") -ForegroundColor:('Yellow') }
$AssociationResult = Invoke-Expression -Command:($Command)
If (-not [System.String]::IsNullOrEmpty($AssociationResult))
{
# The direct association/"Get-JcSdk*Membership" endpoints return null for FromId. So manually populate them here.
$AssociationResult.Paths | ForEach-Object {
$_ | ForEach-Object {
if ($_.FromType -eq $SourceTypeMap.Value.Name -and $_.ToType -eq $TargetTypeMap.Value.Name)
If ([System.String]::IsNullOrEmpty($_.FromId))
{
$_.FromId = $BackupRecord.id
}
# The direct association/"Get-JcSdk*Membership" endpoints return null for FromType. So manually populate them here.
If ([System.String]::IsNullOrEmpty($_.FromType))
{
$AssociationResults += $_
$_.FromType = $SourceTypeMap.Value.Name
}
}
}
$AssociationResults += $AssociationResult
}
}
ElseIf (($SourceTypeMap.Value.Name -eq 'SoftwareApp' -and $TargetTypeMap.Value.Name -eq 'system' -and $Global:JCSettings.ROLE -eq 'Read Only') -or ($SourceTypeMap.Value.Name -eq 'SoftwareApp' -and $TargetTypeMap.Value.Name -eq 'system_group' -and $Global:JCSettings.ROLE -eq 'Read Only'))
ElseIf (($SourceTypeMap.Value.Name -eq 'Software_App' -and $TargetTypeMap.Value.Name -eq 'system' -and $Settings.ROLE -eq 'Read Only') -or ($SourceTypeMap.Value.Name -eq 'Software_App' -and $TargetTypeMap.Value.Name -eq 'system_group' -and $Settings.ROLE -eq 'Read Only'))
{
$Command = 'Get-JcSdk{0}Traverse{2} -{0}Id:("{1}")' -f $SourceTypeMap.Key, $BackupRecord.id, (Get-Culture).TextInfo.ToTitleCase($TargetTypeMap.Value.Name)
$Command = 'Get-JcSdk{0}Traverse{2} -{0}Id:("{1}")' -f $SourceTypeMap.Key, $BackupRecord.id, ($TargetTypeMap.Value.Name).Replace('system_group', 'SystemGroup')
If ($PSBoundParameters.Debug) { Write-Host ("DEBUG: Running: $Command") -ForegroundColor:('Yellow') }
$AssociationResult = Invoke-Expression -Command:($Command)
If (-not [System.String]::IsNullOrEmpty($AssociationResult))
{
# The direct association/"Get-JcSdk*Membership" endpoints return null for FromId. So manually populate them here.
$AssociationResult.Paths | ForEach-Object {
$_ | ForEach-Object {
if ($_.FromType -eq $SourceTypeMap.Value.Name -and $_.ToType -eq $TargetTypeMap.Value.Name)
If ([System.String]::IsNullOrEmpty($_.FromId))
{
$_.FromId = $BackupRecord.id
}
# The direct association/"Get-JcSdk*Membership" endpoints return null for FromType. So manually populate them here.
If ([System.String]::IsNullOrEmpty($_.FromType))
{
$AssociationResults += $_
$_.FromType = $SourceTypeMap.Value.Name
}
}
}
$AssociationResults += $AssociationResult
}
}
ElseIf (($SourceTypeMap.Value.Name -eq 'system' -and $TargetTypeMap.Value.Name -eq 'SoftwareApp' -and $Global:JCSettings.ROLE -eq 'Read Only') -or ($SourceTypeMap.Value.Name -eq 'system_group' -and $TargetTypeMap.Value.Name -eq 'SoftwareApp' -and $Global:JCSettings.ROLE -eq 'Read Only'))
ElseIf (($SourceTypeMap.Value.Name -eq 'system' -and $TargetTypeMap.Value.Name -eq 'Software_App' -and $Settings.ROLE -eq 'Read Only') -or ($SourceTypeMap.Value.Name -eq 'system_group' -and $TargetTypeMap.Value.Name -eq 'Software_App' -and $Settings.ROLE -eq 'Read Only'))
{
$Command = 'Get-JcSdk{0}Traverse{2} -{0}Id:("{1}")' -f $SourceTypeMap.Key, $BackupRecord.id, (Get-Culture).TextInfo.ToTitleCase($TargetTypeMap.Value.Name)
$Command = 'Get-JcSdk{0}Traverse{2} -{0}Id:("{1}")' -f $SourceTypeMap.Key, $BackupRecord.id, ($TargetTypeMap.Value.Name).Replace('system_group', 'SystemGroup')
If ($PSBoundParameters.Debug) { Write-Host ("DEBUG: Running: $Command") -ForegroundColor:('Yellow') }
$AssociationResult = Invoke-Expression -Command:($Command)
If (-not [System.String]::IsNullOrEmpty($AssociationResult))
{
# The direct association/"Get-JcSdk*Membership" endpoints return null for FromId. So manually populate them here.
$AssociationResult.Paths | ForEach-Object {
$_ | ForEach-Object {
if ($_.FromType -eq $SourceTypeMap.Value.Name -and $_.ToType -eq $TargetTypeMap.Value.Name)
If ([System.String]::IsNullOrEmpty($_.FromId))
{
$_.FromId = $BackupRecord.id
}
# The direct association/"Get-JcSdk*Membership" endpoints return null for FromType. So manually populate them here.
If ([System.String]::IsNullOrEmpty($_.FromType))
{
$AssociationResults += $_
$_.FromType = $SourceTypeMap.Value.Name
}
}
}
$AssociationResults += $AssociationResult
}
}
Else
Expand Down
2 changes: 1 addition & 1 deletion PowerShell/ModuleBanner.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#### Latest Version

```
1.22.0
1.22.1
```

#### Banner Current
Expand Down
12 changes: 12 additions & 0 deletions PowerShell/ModuleChangelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 1.22.1

Release Date: May 19, 2022

#### RELEASE NOTES

This release includes a bug-fix for read only API Keys and running Backup-JCOrganization

#### BUG FIXES:

* Backup-JCOrganization no longer throws a forbidden error message when run with a read-only API Key. In the previous release, we solved for only a subset of Backup-JCOrganizations' Read-Only error messages, these should now be resolved.

## 1.22.0

Release Date: May 16, 2022
Expand Down

0 comments on commit 3dd164f

Please sign in to comment.