Skip to content

Commit

Permalink
Merge pull request #492 from TheJumpCloud/SA-3170_CommandResultSDKRep…
Browse files Browse the repository at this point in the history
…lace

SA-3170: Replace Get-JCCommandResults with Search-JCSdkCommandResult
  • Loading branch information
gweinjc authored May 24, 2023
2 parents d0792a8 + 553575a commit ad447b3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
14 changes: 14 additions & 0 deletions scripts/automation/Radius/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## 1.0.3

Release Date: May 24, 2023

#### RELEASE NOTES

```
Fixed an issue affecting permissions on certain MacOS devices when attempting to deploy certs
Improved performance when reviewing Command Results by changing fetch requests to Search-JCSDKCommandResult endpoint
```
#### FEATURES:

- Fixed an issue affecting permissions on certain MacOS devices when attempting to deploy certs
- Improved performance when reviewing Command Results by changing fetch requests to Search-JCSDKCommandResult endpoint
## 1.0.2

Release Date: May 2, 2023
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ Function Get-CommandObjectTable {
$CommandObjectTable = @()

# Clean up command results
$commandResults = Get-JCCommandResult | Where-Object name -Like "RadiusCert-Install*"
$SearchFilter = @{
searchTerm = 'RadiusCert-Install'
fields = @('name')
}
$commandResults = Search-JcSdkCommandResult -SearchFilter $SearchFilter
if ($commandResults) {
$groupedCommandResults = $commandResults | Group-Object name, system | Sort-Object -Property responseTime -Descending
$groupedCommandResults = $commandResults | Sort-Object -Property responseTime -Descending | Group-Object name, SystemId
$mostRecentCommandResults = $groupedCommandResults | ForEach-Object { $_.Group | Select-Object -First 1 }
$commandResults | ForEach-Object {
if ($_._id -in $mostRecentCommandResults._id) {
if ($_.id -in $mostRecentCommandResults.id) {
return
} else {
Remove-JCCommandResult -CommandResultID $_._id -force | Out-Null
Remove-JCCommandResult -CommandResultID $_.id -force | Out-Null
}
}
}
Expand All @@ -42,17 +46,17 @@ Function Get-CommandObjectTable {
if ($finishedCommands) {
# If there are finished command results, iterate through each and add to command object array
$finishedCommands | ForEach-Object {
if (($_.exitCode -ne 0)) {
if (($_.DataExitCode -ne 0)) {
$character = "$([char]0x1b)[91mFAILED"
$output = Get-JCCommandResult -id $_._id | Select-Object -ExpandProperty output
#$output = Get-JCCommandResult -id $_._id | Select-Object -ExpandProperty output
} else {
continue
}
$CommandTable = @{
commandName = $command.commandName
systemDisplayName = $_.system
systemDisplayName = $SystemHash | Where-Object _id -EQ $_.systemId | Select-Object -ExpandProperty displayName
status = $character
output = $output
output = $_.DataOutput
}
$CommandObjectTable += $CommandTable
}
Expand All @@ -73,15 +77,19 @@ Function Get-CommandObjectTable {
$CommandObjectTable = @()

# Clean up command results
$commandResults = Get-JCCommandResult | Where-Object name -Like "RadiusCert-Install*"
$SearchFilter = @{
searchTerm = 'RadiusCert-Install'
fields = @('name')
}
$commandResults = Search-JcSdkCommandResult -SearchFilter $SearchFilter
if ($commandResults) {
$groupedCommandResults = $commandResults | Group-Object name, system | Sort-Object -Property responseTime -Descending
$groupedCommandResults = $commandResults | Sort-Object -Property responseTime -Descending | Group-Object name, SystemId
$mostRecentCommandResults = $groupedCommandResults | ForEach-Object { $_.Group | Select-Object -First 1 }
$commandResults | ForEach-Object {
if ($_._id -in $mostRecentCommandResults._id) {
if ($_.id -in $mostRecentCommandResults.id) {
return
} else {
Remove-JCCommandResult -CommandResultID $_._id -force | Out-Null
Remove-JCCommandResult -CommandResultID $_.id -force | Out-Null
}
}
}
Expand Down Expand Up @@ -113,7 +121,7 @@ Function Get-CommandObjectTable {
if ($finishedCommands) {
# If there are finished command results, iterate through each and add to command object array
$finishedCommands | ForEach-Object {
if (($finishedCommands.exitCode -eq 0)) {
if (($_.DataExitCode -eq 0)) {
$character = "$([char]0x1b)[92mOK"
# Remove successful systems from command associations
Set-JcSdkCommandAssociation -CommandId:("$($command.commandId)") -Op 'remove' -Type:('system') -Id:("$($_.systemId)") -ErrorAction SilentlyContinue | Out-Null
Expand All @@ -122,7 +130,7 @@ Function Get-CommandObjectTable {
}
$CommandTable = @{
commandName = $command.commandName
systemDisplayName = $_.system
systemDisplayName = $SystemHash | Where-Object _id -EQ $_.systemId | Select-Object -ExpandProperty displayName
status = $character
}
$CommandObjectTable += $CommandTable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ Function Invoke-CommandsRetry {
$RetryCommands = @()
$commandsObject = Get-Content -Raw -Path $jsonFile | ConvertFrom-Json -Depth 6
$queuedCommands = Get-JCQueuedCommands
$commandResults = Get-JCCommandResult | Where-Object name -Like "RadiusCert-Install*"
$groupedCommandResults = $commandResults | Group-Object name, system | Sort-Object -Property responseTime -Descending
$SearchFilter = @{
searchTerm = 'RadiusCert-Install'
fields = @('name')
}
$commandResults = Search-JcSdkCommandResult -SearchFilter $SearchFilter
$groupedCommandResults = $commandResults | Sort-Object -Property responseTime -Descending | Group-Object name, SystemId
$mostRecentCommandResults = $groupedCommandResults | ForEach-Object { $_.Group | Select-Object -First 1 }
}
process {
# Prompt to rerun commands that have failed or expired
Foreach ($command in $commandsObject.commandAssociations) {
$failedCommands = $mostRecentCommandResults | Where-Object exitCode -NE 0
$failedCommands = $mostRecentCommandResults | Where-Object DataExitCode -NE 0

if ($queuedCommands.command -contains $command.commandId) {
Write-Host "[status] $($command.commandName) is currently $([char]0x1b)[93mPENDING"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ foreach ($user in $userArray) {
Command = @"
set -e
unzip -o /tmp/$($user.userName)-client-signed.zip -d /tmp
chmod 755 /tmp/$($user.userName)-client-signed.pfx
currentUser=`$(/usr/bin/stat -f%Su /dev/console)
currentUserUID=`$(id -u "`$currentUser")
currentCertSN="$($certHash.serial)"
Expand Down

0 comments on commit ad447b3

Please sign in to comment.