Skip to content

Commit

Permalink
Merge pull request #480 from TheJumpCloud/SA-3230_ReplaceIWRGroupFunc…
Browse files Browse the repository at this point in the history
…tions

SA-3230: Replace IWR Calls with SDK Functions
  • Loading branch information
gweinjc authored Mar 23, 2023
2 parents 99f6ef2 + 3c5ca23 commit 7cc301b
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 77 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
17 changes: 16 additions & 1 deletion PowerShell/JumpCloud Module/Docs/Get-JCEvent.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Query the API for Directory Insights events

### GetExpanded (Default)
```
Get-JCEvent -Service <String[]> -StartTime <DateTime> [-EndTime <DateTime>] [-Fields <String[]>]
Get-JCEvent -Service <String[]> -StartTime <DateTime> [-EndTime <DateTime>] [-Fields <String[]>] [-Q <String>]
[-SearchAfter <String[]>] [-SearchTermAnd <Hashtable>] [-SearchTermNot <Hashtable>]
[-SearchTermOr <Hashtable>] [-Sort <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
```
Expand Down Expand Up @@ -133,6 +133,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Q
optional string for specifying a full text query
```yaml
Type: System.String
Parameter Sets: GetExpanded
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -SearchAfter
Specific query to search after, see x-* response headers for next values
Expand Down
17 changes: 16 additions & 1 deletion PowerShell/JumpCloud Module/Docs/Get-JCEventCount.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Query the API for a count of matching events
### GetExpanded (Default)
```
Get-JCEventCount -Service <String[]> -StartTime <DateTime> [-EndTime <DateTime>] [-Fields <String[]>]
[-SearchAfter <String[]>] [-SearchTermAnd <Hashtable>] [-SearchTermNot <Hashtable>]
[-Q <String>] [-SearchAfter <String[]>] [-SearchTermAnd <Hashtable>] [-SearchTermNot <Hashtable>]
[-SearchTermOr <Hashtable>] [-Sort <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

Expand Down Expand Up @@ -105,6 +105,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Q
optional string for specifying a full text query
```yaml
Type: System.String
Parameter Sets: GetExpanded
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -SearchAfter
Specific query to search after, see x-* response headers for next values
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.2.0
Help Version: 2.3.0
Locale: en-US
---

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.2.0</version>
<version>2.3.0.8049-202303231610</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: 2/7/2023
# Generated on: 3/23/2023
#

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

# Version number of this module.
ModuleVersion = '2.2.0'
ModuleVersion = '2.3.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ BODY <IEventQuery>: EventQuery is the users' command to search our auth logs
[EndTime <DateTime?>]: optional query end time, UTC in RFC3339 format
[Fields <String[]>]: optional list of fields to return from query
[Limit <Int64?>]: Max number of rows to return
[Q <String>]: optional string for specifying a full text query
[SearchAfter <String[]>]: Specific query to search after, see x-* response headers for next values
[SearchTermAnd <ITermConjunction>]: TermConjunction represents a conjunction (and/or) NOTE: the validator limits what the operator can be, not the object for future-proof-ness and a list of sub-values
[(Any) <Object>]: This indicates any property can be added to this object.
Expand Down Expand Up @@ -99,6 +100,12 @@ Function Get-JCEvent
# optional list of fields to return from query
${Fields},

[Parameter(ParameterSetName='GetExpanded')]
[JumpCloud.SDK.DirectoryInsights.Category('Body')]
[System.String]
# optional string for specifying a full text query
${Q},

[Parameter(ParameterSetName='GetExpanded')]
[AllowEmptyCollection()]
[JumpCloud.SDK.DirectoryInsights.Category('Body')]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ BODY <IEventQuery>: EventQuery is the users' command to search our auth logs
[EndTime <DateTime?>]: optional query end time, UTC in RFC3339 format
[Fields <String[]>]: optional list of fields to return from query
[Limit <Int64?>]: Max number of rows to return
[Q <String>]: optional string for specifying a full text query
[SearchAfter <String[]>]: Specific query to search after, see x-* response headers for next values
[SearchTermAnd <ITermConjunction>]: TermConjunction represents a conjunction (and/or) NOTE: the validator limits what the operator can be, not the object for future-proof-ness and a list of sub-values
[(Any) <Object>]: This indicates any property can be added to this object.
Expand Down Expand Up @@ -83,6 +84,12 @@ Function Get-JCEventCount
# optional list of fields to return from query
${Fields},

[Parameter(ParameterSetName='GetExpanded')]
[JumpCloud.SDK.DirectoryInsights.Category('Body')]
[System.String]
# optional string for specifying a full text query
${Q},

[Parameter(ParameterSetName='GetExpanded')]
[AllowEmptyCollection()]
[JumpCloud.SDK.DirectoryInsights.Category('Body')]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ SystemID has an Alias of _id. This means you can leverage the PowerShell pipelin
begin {
Write-Debug 'Verifying JCAPI Key'
if ($JCAPIKEY.length -ne 40) {
Connect-JConline
Connect-JCOnline
}

Write-Debug 'Populating API headers'
Expand Down Expand Up @@ -103,14 +103,11 @@ SystemID has an Alias of _id. This means you can leverage the PowerShell pipelin
Write-Debug $jsonbody


$GroupsURL = "$JCUrlBasePath/api/v2/systemgroups/$GroupID/members"
Write-Debug $GroupsURL

try {
$GroupAdd = Invoke-RestMethod -Method POST -Body $jsonbody -Uri $GroupsURL -Headers $hdrs -UserAgent:(Get-JCUserAgent)
$GroupAdd = Set-JcSdkSystemGroupMember -GroupId $GroupID -Body $body -ErrorVariable addError -ErrorAction SilentlyContinue
if ($addError) {
$Status = $addError.ErrorDetails.Message
} else {
$Status = 'Added'
} catch {
$Status = $_.ErrorDetails
}

$FormattedResults = [PSCustomObject]@{
Expand Down Expand Up @@ -146,14 +143,11 @@ SystemID has an Alias of _id. This means you can leverage the PowerShell pipelin
Write-Debug $jsonbody


$GroupsURL = "$JCUrlBasePath/api/v2/systemgroups/$GroupID/members"
Write-Debug $GroupsURL

try {
$GroupAdd = Invoke-RestMethod -Method POST -Body $jsonbody -Uri $GroupsURL -Headers $hdrs -UserAgent:(Get-JCUserAgent)
$GroupAdd = Set-JcSdkSystemGroupMember -GroupId $GroupID -Body $body -ErrorVariable addError -ErrorAction SilentlyContinue
if ($addError) {
$Status = $addError.ErrorDetails.Message
} else {
$Status = 'Added'
} catch {
$Status = $_.ErrorDetails
}

$FormattedResults = [PSCustomObject]@{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The SystemID will be the 24 character string populated for the _id field. System
begin {
Write-Debug 'Verifying JCAPI Key'
if ($JCAPIKEY.length -ne 40) {
Connect-JConline
Connect-JCOnline
}

Write-Debug 'Populating API headers'
Expand Down Expand Up @@ -70,15 +70,11 @@ The SystemID will be the 24 character string populated for the _id field. System
$jsonbody = $body | ConvertTo-Json
Write-Debug $jsonbody


$GroupsURL = "$JCUrlBasePath/api/v2/systemgroups/$GroupID/members"
Write-Debug $GroupsURL

try {
$GroupRemove = Invoke-RestMethod -Method POST -Body $jsonbody -Uri $GroupsURL -Headers $hdrs -UserAgent:(Get-JCUserAgent)
$GroupRemove = Set-JcSdkSystemGroupMember -GroupId $GroupID -Body $body -ErrorVariable removeError -ErrorAction SilentlyContinue
if ($removeError) {
$Status = $removeError.ErrorDetails.Message
} else {
$Status = 'Removed'
} catch {
$Status = $_.ErrorDetails
}

$FormattedResults = [PSCustomObject]@{
Expand Down Expand Up @@ -114,14 +110,11 @@ The SystemID will be the 24 character string populated for the _id field. System
Write-Debug $jsonbody


$GroupsURL = "$JCUrlBasePath/api/v2/systemgroups/$GroupID/members"
Write-Debug $GroupsURL

try {
$GroupRemove = Invoke-RestMethod -Method POST -Body $jsonbody -Uri $GroupsURL -Headers $hdrs -UserAgent:(Get-JCUserAgent)
$GroupRemove = Set-JcSdkSystemGroupMember -GroupId $GroupID -Body $body -ErrorVariable removeError -ErrorAction SilentlyContinue
if ($removeError) {
$Status = $removeError.ErrorDetails.Message
} else {
$Status = 'Removed'
} catch {
$Status = $_.ErrorDetails
}

$FormattedResults = [PSCustomObject]@{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ UserID has an Alias of _id. This means you can leverage the PowerShell pipeline
begin {
Write-Debug 'Verifying JCAPI Key'
if ($JCAPIKEY.length -ne 40) {
Connect-JConline
Connect-JCOnline
}

Write-Debug 'Populating API headers'
Expand Down Expand Up @@ -100,14 +100,11 @@ UserID has an Alias of _id. This means you can leverage the PowerShell pipeline
Write-Debug $jsonbody


$GroupsURL = "$JCUrlBasePath/api/v2/usergroups/$GroupID/members"
Write-Debug $GroupsURL

try {
$GroupAdd = Invoke-RestMethod -Method POST -Body $jsonbody -Uri $GroupsURL -Headers $hdrs -UserAgent:(Get-JCUserAgent)
$GroupAdd = Set-JcSdkUserGroupMember -GroupId $GroupID -Body $body -ErrorVariable addError -ErrorAction SilentlyContinue
if ($addError) {
$Status = $addError.ErrorDetails.Message
} else {
$Status = 'Added'
} catch {
$Status = $_.ErrorDetails
}

$FormattedResults = [PSCustomObject]@{
Expand Down Expand Up @@ -162,14 +159,11 @@ UserID has an Alias of _id. This means you can leverage the PowerShell pipeline
Write-Debug $jsonbody


$GroupsURL = "$JCUrlBasePath/api/v2/usergroups/$GroupID/members"
Write-Debug $GroupsURL

try {
$GroupAdd = Invoke-RestMethod -Method POST -Body $jsonbody -Uri $GroupsURL -Headers $hdrs -UserAgent:(Get-JCUserAgent)
$GroupAdd = Set-JcSdkUserGroupMember -GroupId $GroupID -Body $body -ErrorVariable addError -ErrorAction SilentlyContinue
if ($addError) {
$Status = $addError.ErrorDetails.Message
} else {
$Status = 'Added'
} catch {
$Status = $_.ErrorDetails
}

$FormattedResults = [PSCustomObject]@{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The UserID will be the 24 character string populated for the _id field. UserID h
begin {
Write-Debug 'Verifying JCAPI Key'
if ($JCAPIKEY.length -ne 40) {
Connect-JConline
Connect-JCOnline
}

Write-Debug 'Populating API headers'
Expand Down Expand Up @@ -68,34 +68,26 @@ The UserID will be the 24 character string populated for the _id field. UserID h
$UserID = $UserNameHash.GetEnumerator().Where({ $_.Value.username -contains ($Username) }).Name

$body = @{

type = "user"
op = "remove"
id = $UserID

}

$jsonbody = $body | ConvertTo-Json
Write-Debug $jsonbody


$GroupsURL = "$JCUrlBasePath/api/v2/usergroups/$GroupID/members"
Write-Debug $GroupsURL

try {
$GroupAdd = Invoke-RestMethod -Method POST -Body $jsonbody -Uri $GroupsURL -Headers $hdrs -UserAgent:(Get-JCUserAgent)
$GroupRemove = Set-JcSdkUserGroupMember -GroupId $GroupID -Body $body -ErrorVariable removeError -ErrorAction SilentlyContinue
if ($removeError) {
$Status = $removeError.ErrorDetails.Message
} else {
$Status = 'Removed'
} catch {
$Status = $_.ErrorDetails
}

$FormattedResults = [PSCustomObject]@{

'GroupName' = $GroupName
'Username' = $Username
'UserID' = $UserID
'Status' = $Status

}

$resultsArray += $FormattedResults
Expand All @@ -109,29 +101,22 @@ The UserID will be the 24 character string populated for the _id field. UserID h
}

$body = @{

type = "user"
op = "remove"
id = $UserID

}

$jsonbody = $body | ConvertTo-Json
Write-Debug $jsonbody


$GroupsURL = "$JCUrlBasePath/api/v2/usergroups/$GroupID/members"
Write-Debug $GroupsURL

try {
$GroupRemove = $GroupAdd = Invoke-RestMethod -Method POST -Body $jsonbody -Uri $GroupsURL -Headers $hdrs -UserAgent:(Get-JCUserAgent)
$GroupRemove = Set-JcSdkUserGroupMember -GroupId $GroupID -Body $body -ErrorVariable removeError -ErrorAction SilentlyContinue
if ($removeError) {
$Status = $removeError.ErrorDetails.Message
} else {
$Status = 'Removed'
} catch {
$Status = $_.ErrorDetails
}

$FormattedResults = [PSCustomObject]@{

'GroupID' = $GroupID
'UserID' = $UserID
'Status' = $Status
Expand Down
Loading

0 comments on commit 7cc301b

Please sign in to comment.