Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CUT-4228: Get-JCAdmin Function #593

Merged
merged 24 commits into from
Aug 8, 2024
Merged

CUT-4228: Get-JCAdmin Function #593

merged 24 commits into from
Aug 8, 2024

Conversation

gweinjc
Copy link
Contributor

@gweinjc gweinjc commented Aug 8, 2024

Issues

What does this solve?

This new function allows for administrators to query the administrators in their organization. MTP/MSP tenants will have the ability to query all of their organizations or individually.

Is there anything particularly tricky?

Since the endpoint used to query admins does not have a searchFilter option, we had to manually create a filter using a foreach loop on the inputted params.

# Create a FilterScript scriptblock for use in Where-Object to filter the results based on the params used
$filterScriptArray = @()
foreach ($param in $PSBoundParameters.GetEnumerator()) {
    if ([System.Management.Automation.PSCmdlet]::CommonParameters -contains $param.key) {
        continue
    }
    if ($param.value -is [Boolean]) {
        $filterScriptArray += "`$_.$($param.key) -eq `$$($param.value)"
        continue
    }
    if ($param.value -is [String]) {
        $filterScriptArray += "`$_.$($param.key) -like '$($param.value)'"
        continue
    }
}
$filterScriptString = $filterScriptArray -join " -and "
$filterScript = [Scriptblock]::Create($filterScriptString)

The $filterScript is then used in a Where-Object -FilterScript $FilterScript to perform the actual filtering

How should this be tested?

  • Pester test suites have been created for both MTP/MSP tenants as well as regular tenants.

Non-MTP/MSP Tenant

# Get all admins
$Admins = Get-JCAdmin
$Admins | Should -Not -BeNullOrEmpty

# Get a specific administrator by email address'
$Admins = Get-JCAdmin -email 'solutions-architecture+pestermtp@jumpcloud.com'
$Admins | Should -Not -BeNullOrEmpty

# Get a specific administrator by email address with wildcard
$Admins = Get-JCAdmin -email 'solutions-architecture*'
$Admins | Should -Not -BeNullOrEmpty

# Get administrators by enableMultifactor
$Admins = Get-JCAdmin -enableMultifactor $true
$Admins | Should -Not -BeNullOrEmpty

# Get administrators by totpEnrolled
$Admins = Get-JCAdmin -totpEnrolled $true
$Admins | Should -Not -BeNullOrEmpty

# Get administrators by roleName
$Admins = Get-JCAdmin -roleName 'Administrator With Billing'
$Admins | Should -Not -BeNullOrEmpty

# Get administrators by email, enableMultifactor, totpEnrolled, roleName
$Admins = Get-JCAdmin -email 'solutions-architecture*' -enableMultifactor $true -totpEnrolled $true -roleName 'Administrator With Billing'
$Admins | Should -Not -BeNullOrEmpty

MTP/MSP Tenants

  • Same as above, however you can filter by a specific organization ID
# Get all organizations
$orgs = Get-JCOrganization

# Get all admins
$Admins = Get-JCAdmin
$Admins | Should -Not -BeNullOrEmpty

# Get administrators by email, enableMultifactor, totpEnrolled, roleName and organization
$Admins = Get-JCAdmin -email 'solutions-architecture*' -enableMultifactor $true -totpEnrolled $true -roleName 'Administrator With Billing' -organization $orgs[0].OrgID
$Admins | Should -Not -BeNullOrEmpty

@gweinjc gweinjc added minor minor version release PowerShell Module Release for JumpCloud PowerShell Module labels Aug 8, 2024
@gweinjc gweinjc requested a review from a team as a code owner August 8, 2024 16:56
Copy link
Contributor

@jworkmanjc jworkmanjc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really great, two items I believe we should change but otherwise perfect execution here.

There's no way to get around the filtering, that's okay.

Let me know what you think about those two comments on the params?

Copy link
Contributor

@kmaranionjc kmaranionjc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Tests worked on my end and code looks good.

@gweinjc gweinjc merged commit 0687bb7 into master Aug 8, 2024
10 checks passed
@gweinjc gweinjc temporarily deployed to PublishToPSGallery August 8, 2024 22:01 — with GitHub Actions Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor minor version release PowerShell Module Release for JumpCloud PowerShell Module
Development

Successfully merging this pull request may close these issues.

3 participants