Skip to content

Commit

Permalink
Merge pull request #396 from TheJumpCloud/SA-2733_SearchFilter_mangae…
Browse files Browse the repository at this point in the history
…rField

Sa 2733 search filter mangaer field
  • Loading branch information
jworkmanjc authored Jul 13, 2022
2 parents addd44c + 6ad3476 commit 1417eea
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 95 deletions.
7 changes: 1 addition & 6 deletions .circleci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 Expand Up @@ -85,7 +85,6 @@ workflows:
requires:
- Initial Setup
- Build Modules
- Build Help and Test Files
context: aws-credentials
- Module Validation Tests:
requires:
Expand All @@ -104,31 +103,27 @@ workflows:
- Initial Setup
- Build Help and Test Files
- Build Nuspec
- Module Validation Tests
- Invoke Git Commit
context: aws-credentials
- Pester Tests Mac:
requires:
- Initial Setup
- Build Help and Test Files
- Build Nuspec
- Module Validation Tests
- Invoke Git Commit
context: aws-credentials
- Pester Tests Linux:
requires:
- Initial Setup
- Build Help and Test Files
- Build Nuspec
- Module Validation Tests
- Invoke Git Commit
context: aws-credentials
- Publish Module Validation:
requires:
- Initial Setup
- Build Help and Test Files
- Build Nuspec
- Module Validation Tests
- Invoke Git Commit
release:
when:
Expand Down
43 changes: 21 additions & 22 deletions PowerShell/Deploy/Setup-Dependencies.ps1
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
Param(
[Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, Position = 0)][System.String[]]$DependentModules = ('PowerShellGet', 'PackageManagement', 'PSScriptAnalyzer', 'PlatyPS', 'Pester', 'AWS.Tools.Common', 'AWS.Tools.CodeArtifact')
, [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, Position = 1)][System.String]$RequiredModulesRepo = 'PSGallery'
[Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, Position = 0)][System.String]$RequiredModulesRepo = 'PSGallery'
)
# Install NuGet
If (!(Get-PackageProvider -Name:('NuGet') -ListAvailable -ErrorAction:('SilentlyContinue')))
{
Write-Host ('[status]Installing package provider NuGet');
Install-PackageProvider -Name:('NuGet') -Scope:('CurrentUser') -Force
}
# Install dependent modules
ForEach ($DependentModule In $DependentModules)

$PSDependencies = @{
'PowerShellGet' = @{Repository = 'PSGallery'; RequiredVersion = '3.0.12-beta' }
'PackageManagement' = @{Repository = 'PSGallery'; RequiredVersion = '1.4.8.1' }
'PSScriptAnalyzer' = @{Repository = 'PSGallery'; RequiredVersion = '1.19.1' }
'PlatyPS' = @{Repository = 'PSGallery'; RequiredVersion = '0.14.2' }
'Pester' = @{Repository = 'PSGallery'; RequiredVersion = '5.3.3' }
'AWS.Tools.Common' = @{Repository = 'PSGallery'; RequiredVersion = '4.1.122' }
'AWS.Tools.CodeArtifact' = @{Repository = 'PSGallery'; RequiredVersion = '4.1.122' }
}

foreach ($RequiredModule in $PSDependencies.Keys)
{
# Check to see if the module is installed
If ([System.String]::IsNullOrEmpty((Get-InstalledModule | Where-Object { $_.Name -eq $DependentModule })))
{
Write-Host("[status]Installing module: '$DependentModule' from 'PSGallery'")
if ($DependentModule -eq 'PowerShellGet'){
Install-Module -Name $DependentModule -Repository:('PSGallery') -RequiredVersion '3.0.12-beta' -AllowPrerelease -Force
}
elseif ($DependentModule -eq 'PSScriptAnalyzer') {
Install-Module -Name $DependentModule -Repository:('PSGallery') -RequiredVersion '1.19.1' -Force
}
else{
Install-Module -Repository:('PSGallery') -Force -Name:($DependentModule) -Scope:('CurrentUser') -AllowClobber
If ([System.String]::IsNullOrEmpty((Get-InstalledModule | Where-Object { $_.Name -eq $RequiredModule })))
{
Write-Host("[status]Installing module: '$RequiredModule'; version: $($PSDependencies[$RequiredModule].RequiredVersion) from $($PSDependencies[$RequiredModule].Repository)")
Install-Module -Name $RequiredModule -Repository:($($PSDependencies[$RequiredModule].Repository)) -RequiredVersion:($($PSDependencies[$RequiredModule].RequiredVersion)) -AllowPrerelease -Force
}
}
# Get-Module -Refresh -ListAvailable
If ([System.String]::IsNullOrEmpty((Get-Module | Where-Object { $_.Name -eq $DependentModule })))
If ([System.String]::IsNullOrEmpty((Get-Module | Where-Object { $_.Name -eq $RequiredModule })))
{
Write-Host("[status]Importing module: '$DependentModule'")
Import-Module -Name:($DependentModule) -Force -Global
Write-Host("[status]Importing module: '$RequiredModule'")
Import-Module -Name:($RequiredModule) -Force -Global
}
}
### TODO: Switch to CodeArtifact
Expand Down Expand Up @@ -86,7 +85,7 @@ If (-not [System.String]::IsNullOrEmpty($Psd1))
}
elseif ($PowerShellModulesPaths -match 'documents')
{
# Windows Ststems
# Windows Systems
$LocalPSModulePath = $env:PSModulePath.split(';') | Where-Object { $_ -like '*documents*' }
Write-Host "Module Installation Path: $LocalPSModulePath"
}
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.1
Help Version: 1.23.2
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: 7/7/2022
# Generated on: 7/11/2022
#

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

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

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
42 changes: 26 additions & 16 deletions PowerShell/JumpCloud Module/Public/Users/Get-JCUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -315,21 +315,25 @@ Function Get-JCUser ()
if (((Select-String -InputObject $param.Value -Pattern $regexPattern).Matches.value)::IsNullOrEmpty){
# if we have a 24 characterid, try to match the id using the search endpoint
$managerSearch = @{
searchFilter = @{
searchTerm = @($param.Value)
fields = @('id')
filter = @{
'and' = @(
@{'id' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } }
)
}
fields = 'id'
}
$managerResults = Search-JcSdkUser -Body:($managerSearch)
# Set managerValue; this is a validated user id
$managerValue = $managerResults.id
# if no value was returned, then assume the case this is actually a username and search
if (!$managerValue){
$managerSearch = @{
searchFilter = @{
searchTerm = @($param.Value)
fields = @('username')
filter = @{
'and' = @(
@{'username' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } }
)
}
fields = 'username'
}
$managerResults = Search-JcSdkUser -Body:($managerSearch)
# Set managerValue from the matched username
Expand All @@ -341,20 +345,24 @@ Function Get-JCUser ()
$null = [mailaddress]$EmailAddress
# Search manager using email
$managerSearch = @{
searchFilter = @{
searchTerm = @($param.Value)
fields = @('email')
filter = @{
'and' = @(
@{'email' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } }
)
}
fields = 'email'
}
$managerResults = Search-JcSdkUser -Body:($managerSearch)
# Set managerValue; this is a validated user id
$managerValue = $managerResults.id
if (!$managerValue){
$managerSearch = @{
searchFilter = @{
searchTerm = @($param.Value)
fields = @('username')
filter = @{
'and' = @(
@{'username' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } }
)
}
fields = 'username'
}
$managerResults = Search-JcSdkUser -Body:($managerSearch)
# Set managerValue from the matched username
Expand All @@ -364,10 +372,12 @@ Function Get-JCUser ()
catch {
# search the username in the search endpoint
$managerSearch = @{
searchFilter = @{
searchTerm = @($param.Value)
fields = @('username')
filter = @{
'and' = @(
@{'username' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } }
)
}
fields = 'username'
}
$managerResults = Search-JcSdkUser -Body:($managerSearch)
# Set managerValue from the matched username
Expand All @@ -385,7 +395,7 @@ Function Get-JCUser ()
}
}

# case insensitve state param
# case insensitive state param
if ("state" -eq $param.Key)
{
if ($param.Value -cin @('ACTIVATED', 'SUSPENDED', 'STAGED'))
Expand Down
44 changes: 27 additions & 17 deletions PowerShell/JumpCloud Module/Public/Users/New-JCUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -326,21 +326,25 @@ Function New-JCUser ()
if (((Select-String -InputObject $param.Value -Pattern $regexPattern).Matches.value)::IsNullOrEmpty){
# if we have a 24 characterid, try to match the id using the search endpoint
$managerSearch = @{
searchFilter = @{
searchTerm = @($param.Value)
fields = @('id')
filter = @{
'and' = @(
@{'id' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } }
)
}
fields = 'id'
}
$managerResults = Search-JcSdkUser -Body:($managerSearch)
# Set managerValue; this is a validated user id
$managerValue = $managerResults.id
# if no value was returned, then assume the case this is actuallty a username and search
# if no value was returned, then assume the case this is actually a username and search
if (!$managerValue){
$managerSearch = @{
searchFilter = @{
searchTerm = @($param.Value)
fields = @('username')
filter = @{
'and' = @(
@{'username' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } }
)
}
fields = 'username'
}
$managerResults = Search-JcSdkUser -Body:($managerSearch)
# Set managerValue from the matched username
Expand All @@ -351,21 +355,25 @@ Function New-JCUser ()
try {
$null = [mailaddress]$EmailAddress
$managerSearch = @{
searchFilter = @{
searchTerm = @($param.Value)
fields = @('email')
filter = @{
'and' = @(
@{'email' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } }
)
}
fields = 'email'
}
$managerResults = Search-JcSdkUser -Body:($managerSearch)
# Set managerValue; this is a validated user id
$managerValue = $managerResults.id
# if no value was returned, then assume the case this is actuallty a username and search
# if no value was returned, then assume the case this is actually a username and search
if (!$managerValue){
$managerSearch = @{
searchFilter = @{
searchTerm = @($param.Value)
fields = @('username')
filter = @{
'and' = @(
@{'username' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } }
)
}
fields = 'username'
}
$managerResults = Search-JcSdkUser -Body:($managerSearch)
# Set managerValue from the matched username
Expand All @@ -375,10 +383,12 @@ Function New-JCUser ()
catch {
# search the username in the search endpoint
$managerSearch = @{
searchFilter = @{
searchTerm = @($param.Value)
fields = @('username')
filter = @{
'and' = @(
@{'username' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } }
)
}
fields = 'username'
}
$managerResults = Search-JcSdkUser -Body:($managerSearch)
# Set managerValue from the matched username
Expand Down
Loading

0 comments on commit 1417eea

Please sign in to comment.