Skip to content

Commit

Permalink
Merge pull request #395 from TheJumpCloud/SA-2697_Validate_state_para…
Browse files Browse the repository at this point in the history
…meter

Sa 2697 validate state parameter
  • Loading branch information
jworkmanjc authored Jul 7, 2022
2 parents b9fea59 + 61744a2 commit 2daf6d7
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 18 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
8 changes: 2 additions & 6 deletions PowerShell/JumpCloud Module/Docs/Get-JCCommand.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ Note that when running this command the time for the output to display will be d
PS C:\> Get-JCCommand -name '*BitLocker*' | Get-JCCommand -ByID
```

Returns all information describing all JumpCloud commands with a name of '*trigger*' by passing the -CommandID Parameter to the -ByID Parameter using the pipeline and Parameter Binding. Note, search parameters on Get-JCCommand support wildcard characters. In this example commands with the name BitLocker somewhere in the name would be returned.

Note that when running this command the time for the output to display will be directly proportionate to how many JumpCloud commands you have with a launchType of 'trigger'. The command 'Get-JCCommand -ByID' runs once for every JumpCloud command within your tenant with a launchType of 'trigger'.
Returns all information describing all JumpCloud commands with a name of '*BitLocker*' by passing the -CommandID Parameter to the -ByID Parameter using the pipeline and Parameter Binding. Note, search parameters on Get-JCCommand support wildcard characters. In this example commands with the string "BitLocker" somewhere in the name would be returned.

### Example 5
```powershell
Expand All @@ -74,9 +72,7 @@ Note that when running this command the time for the output to display will be d
PS C:\> Get-JCCommand -command '*fdesetup*' | Get-JCCommand -ByID
```

Returns all information describing all JumpCloud commands with a command string and the search term "fdesetup", by passing the -CommandID Parameter to the -ByID Parameter using the pipeline and Parameter Binding. Note, search parameters on Get-JCCommand support wildcard characters. In this example commands with the string "fdesetup" somewhere in the command body would be returned.

Note that when running this command the time for the output to display will be directly proportionate to how many JumpCloud commands you have with a launchType of 'trigger'. The command 'Get-JCCommand -ByID' runs once for every JumpCloud command within your tenant with a launchType of 'trigger'.
Returns all information describing all JumpCloud commands with a command string and the search term "*fdesetup*", by passing the -CommandID Parameter to the -ByID Parameter using the pipeline and Parameter Binding. Note, search parameters on Get-JCCommand support wildcard characters. In this example commands with the string "fdesetup" somewhere in the command body would be returned.

## PARAMETERS

Expand Down
1 change: 1 addition & 0 deletions PowerShell/JumpCloud Module/Docs/Get-JCUser.md
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ A search filter to return users that are in an ACTIVATED or SUSPENDED state
Type: System.String
Parameter Sets: SearchFilter
Aliases:
Accepted values: ACTIVATED, SUSPENDED, STAGED

Required: False
Position: Named
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.23.0
Help Version: 1.23.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: 6/22/2022
# Generated on: 7/7/2022
#

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

# Version number of this module.
ModuleVersion = '1.23.0'
ModuleVersion = '1.23.1'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
20 changes: 20 additions & 0 deletions PowerShell/JumpCloud Module/Public/Users/Get-JCUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Function Get-JCUser ()
[String]$manager,

[Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'SearchFilter', HelpMessage = 'A search filter to return users that are in an ACTIVATED, STAGED or SUSPENDED state')]
[ValidateSet('ACTIVATED','SUSPENDED','STAGED')]
[String]$state,

[Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'SearchFilter', HelpMessage = 'The recovery email of the JumpCloud user you wish to search for.')]
Expand Down Expand Up @@ -384,6 +385,19 @@ Function Get-JCUser ()
}
}

# case insensitve state param
if ("state" -eq $param.Key)
{
if ($param.Value -cin @('ACTIVATED', 'SUSPENDED', 'STAGED'))
{
$stateValue = $param.Value
}
else {
$stateValue = ($param.Value).ToUpper()
}
continue
}

$Value = ($param.value).replace('*', '')

if (($param.Value -match '.+?\*$') -and ($param.Value -match '^\*.+?'))
Expand Down Expand Up @@ -416,9 +430,15 @@ Function Get-JCUser ()
{
(($Search.filter).GetEnumerator()).add('recoveryEmail.address', $recoveryEmail )
}
if ($stateValue)
{
(($Search.filter).GetEnumerator()).add('state', $stateValue )
}

$SearchJSON = $Search | ConvertTo-Json -Compress -Depth 4

Write-Debug $SearchJSON

$URL = "$JCUrlBasePath/api/search/systemusers"

$Results = Invoke-RestMethod -Method POST -Uri $Url -Header $hdrs -Body $SearchJSON -UserAgent:(Get-JCUserAgent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,31 @@ Describe -Tag:('JCUser') 'Get-JCUser 1.1' {
It "Searches a JumpCloud user by state SUSPENDED" {
$NewUser = New-RandomUser -Domain DeleteMe | New-JcUser -state "SUSPENDED"
$SearchUser = Get-JCUser -state "SUSPENDED" | Select-Object -First 1
$SearchUserLower = Get-JCUser -state "suspended" | Select-Object -First 1
$SearchUserMixed = Get-JCUser -state "Suspended" | Select-Object -First 1
$SearchUser.state | Should -Be "SUSPENDED"
$SearchUserLower.state | Should -Be "SUSPENDED"
$SearchUserMixed.state | Should -Be "SUSPENDED"
Remove-JCUser -UserId $NewUser._id -force
}
It "Searches a JumpCloud user by state STAGED" {
$NewUser = New-RandomUser -Domain DeleteMe | New-JcUser -state "STAGED"
$SearchUser = Get-JCUser -state "STAGED" | Select-Object -First 1
$SearchUserLower = Get-JCUser -state "staged" | Select-Object -First 1
$SearchUserMixed = Get-JCUser -state "Staged" | Select-Object -First 1
$SearchUser.state | Should -Be "STAGED"
$SearchUserLower.state | Should -Be "STAGED"
$SearchUserMixed.state | Should -Be "STAGED"
Remove-JCUser -UserId $NewUser._id -force
}
It "Searches a JumpCloud user by state ACTIVATED" {
$NewUser = New-RandomUser -Domain DeleteMe | New-JcUser -state "ACTIVATED"
$SearchUser = Get-JCUser -state "ACTIVATED" | Select-Object -First 1
$SearchUserLower = Get-JCUser -state "activated" | Select-Object -First 1
$SearchUserMixed = Get-JCUser -state "Activated" | Select-Object -First 1
$SearchUser.state | Should -Be "ACTIVATED"
$SearchUserLower.state | Should -Be "ACTIVATED"
$SearchUserMixed.state | Should -Be "ACTIVATED"
Remove-JCUser -UserId $NewUser._id -force
}

Expand Down
11 changes: 7 additions & 4 deletions PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3769,8 +3769,7 @@ PS C:\&gt; $BackupJcOrganizationResults.User</dev:code>
<maml:title>-------------------------- Example 4 --------------------------</maml:title>
<dev:code>PS C:\&gt; Get-JCCommand -name '*BitLocker*' | Get-JCCommand -ByID</dev:code>
<dev:remarks>
<maml:para>Returns all information describing all JumpCloud commands with a name of ' trigger ' by passing the -CommandID Parameter to the -ByID Parameter using the pipeline and Parameter Binding. Note, search parameters on Get-JCCommand support wildcard characters. In this example commands with the name BitLocker somewhere in the name would be returned.</maml:para>
<maml:para>Note that when running this command the time for the output to display will be directly proportionate to how many JumpCloud commands you have with a launchType of 'trigger'. The command 'Get-JCCommand -ByID' runs once for every JumpCloud command within your tenant with a launchType of 'trigger'.</maml:para>
<maml:para>Returns all information describing all JumpCloud commands with a name of ' BitLocker ' by passing the -CommandID Parameter to the -ByID Parameter using the pipeline and Parameter Binding. Note, search parameters on Get-JCCommand support wildcard characters. In this example commands with the string "BitLocker" somewhere in the name would be returned.</maml:para>
</dev:remarks>
</command:example>
<command:example>
Expand All @@ -3785,8 +3784,7 @@ PS C:\&gt; $BackupJcOrganizationResults.User</dev:code>
<maml:title>-------------------------- Example 6 --------------------------</maml:title>
<dev:code>PS C:\&gt; Get-JCCommand -command '*fdesetup*' | Get-JCCommand -ByID</dev:code>
<dev:remarks>
<maml:para>Returns all information describing all JumpCloud commands with a command string and the search term "fdesetup", by passing the -CommandID Parameter to the -ByID Parameter using the pipeline and Parameter Binding. Note, search parameters on Get-JCCommand support wildcard characters. In this example commands with the string "fdesetup" somewhere in the command body would be returned.</maml:para>
<maml:para>Note that when running this command the time for the output to display will be directly proportionate to how many JumpCloud commands you have with a launchType of 'trigger'. The command 'Get-JCCommand -ByID' runs once for every JumpCloud command within your tenant with a launchType of 'trigger'.</maml:para>
<maml:para>Returns all information describing all JumpCloud commands with a command string and the search term " fdesetup ", by passing the -CommandID Parameter to the -ByID Parameter using the pipeline and Parameter Binding. Note, search parameters on Get-JCCommand support wildcard characters. In this example commands with the string "fdesetup" somewhere in the command body would be returned.</maml:para>
</dev:remarks>
</command:example>
</command:examples>
Expand Down Expand Up @@ -7855,6 +7853,11 @@ PS C:\&gt; $BackupJcOrganizationResults.User</dev:code>
<maml:description>
<maml:para>A search filter to return users that are in an ACTIVATED or SUSPENDED state</maml:para>
</maml:description>
<command:parameterValueGroup>
<command:parameterValue required="false" command:variableLength="false">ACTIVATED</command:parameterValue>
<command:parameterValue required="false" command:variableLength="false">SUSPENDED</command:parameterValue>
<command:parameterValue required="false" command:variableLength="false">STAGED</command:parameterValue>
</command:parameterValueGroup>
<command:parameterValue required="true" variableLength="false">System.String</command:parameterValue>
<dev:type>
<maml:name>System.String</maml:name>
Expand Down
6 changes: 3 additions & 3 deletions PowerShell/ModuleBanner.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#### Latest Version

```
1.23.0
1.23.1
```

#### Banner Current

```
* Added search endpoint functionality and parameters to Get-jCCommand
* Get-JCUser -State should accept case insensitive values such as "suspended" "activated" "staged" and validate input
```

#### Banner Old

```
* Added functionality for Set, Get, New-JCUser to Search by Email to Manager Field
* Added search endpoint functionality and parameters to Get-jCCommand
```
9 changes: 9 additions & 0 deletions PowerShell/ModuleChangelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 1.23.1

Release Date: June 21, 2022

#### RELEASE NOTES

This release adds validate to the Get-JCUser -State parameter set. It should now validate supplied acceptable values.
Documentation for Get-JCCommand updated thanks to JumpCloud Community member: Ryan Bailey @rybai

## 1.23.0

Release Date: June 21, 2022
Expand Down

0 comments on commit 2daf6d7

Please sign in to comment.