Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5ec2034
fix for config/yaml files
jworkmanjc Sep 26, 2025
0b0084c
manually define v1/v2
jworkmanjc Sep 26, 2025
d420e3b
user group model
jworkmanjc Sep 26, 2025
21df2c7
set default parameter host
jworkmanjc Sep 29, 2025
b1a8c12
scope envHost to jcsdk module functions
jworkmanjc Sep 29, 2025
393060f
Applied changes for hostEnv parameter + det default hostEnv
jworkmanjc Sep 29, 2025
2c8b304
user group fix for SearchFilters
jworkmanjc Oct 1, 2025
50df4bb
v1 with systemAttributesPut
jworkmanjc Oct 1, 2025
398ef17
customDefinitions & ApiTransform
jworkmanjc Oct 1, 2025
fb5c785
fix for override definition matching
jworkmanjc Oct 1, 2025
22b271b
hide autorest output
jworkmanjc Nov 10, 2025
5cbd2bc
bump autorest versions
jworkmanjc Nov 10, 2025
1e98cb5
module changes
jworkmanjc Nov 10, 2025
2db86f8
ordered x-ms-parameterized-host property
jworkmanjc Nov 10, 2025
f9f7e3c
version bump + build module changes
jworkmanjc Nov 10, 2025
d28f52c
custom defs for user/system Group filters
jworkmanjc Nov 10, 2025
dc0432f
v1 config
jworkmanjc Nov 10, 2025
dfb17ce
module nameSpace
jworkmanjc Nov 10, 2025
979fae5
autospell
jworkmanjc Nov 10, 2025
840a580
spec gen
jworkmanjc Nov 10, 2025
a0c7c5d
module gen
jworkmanjc Nov 10, 2025
2b01310
member query override
jworkmanjc Nov 10, 2025
2c8e24a
clean up overrides
jworkmanjc Nov 10, 2025
4cf2048
static and filter type group definitions
jworkmanjc Nov 11, 2025
c8c9cb8
directory insights changelog
jworkmanjc Nov 11, 2025
05b6f94
date
jworkmanjc Nov 11, 2025
dec596a
Pester configuration
jworkmanjc Nov 11, 2025
de7971d
directory insights EU support
jworkmanjc Nov 11, 2025
22f886c
write-host host env
jworkmanjc Nov 11, 2025
d244be5
set env
jworkmanjc Nov 11, 2025
8b5b438
set env in test
jworkmanjc Nov 11, 2025
3f2cb6d
set loadEnv
jworkmanjc Nov 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
97 changes: 73 additions & 24 deletions ApiTransform.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ $TransformConfig = [Ordered]@{
};
OverrideDefinitions = @(
'definitions.application.properties.config'
'definitions.systemput.properties'
)
OperationIdMapping = [Ordered]@{
'admin_totpreset_begin' = 'AdministratorUserTotp_Reset';
Expand Down Expand Up @@ -161,6 +162,8 @@ $TransformConfig = [Ordered]@{
OverrideDefinitions = @(
'definitions.bulk-user-create.properties'
'definitions.bulk-user-update.properties'
'definitions.MemberQuery'
'definitions.jumpcloud.search.searchRequest.properties'
)
OperationIdMapping = [Ordered]@{
'activedirectories_agentsDelete' = 'ActiveDirectoryAgent_Delete';
Expand Down Expand Up @@ -510,6 +513,67 @@ $TransformConfig = [Ordered]@{
)
}
}
#region HelperFunctions
function Add-ParameterizedHost {
param (
[Parameter(Mandatory = $true)]
[object]$SwaggerObject
)

# Check if property already exists (works for both hashtable and OrderedDictionary)
if ($SwaggerObject.Contains('x-ms-parameterized-host')) {
return $SwaggerObject
}

# Determine host prefix and enum values based on existing host
$hostPrefix = 'console'
$enumValues = @('console', 'console.eu')

if ($SwaggerObject.Contains('host')) {
$currentHost = $SwaggerObject['host']
if ($currentHost -like 'api.jumpcloud.com*') {
$hostPrefix = 'api'
$enumValues = @('api', 'api.eu')
} elseif ($currentHost -like 'console.jumpcloud.com*') {
$hostPrefix = 'console'
$enumValues = @('console', 'console.eu')
}
}

# Define the x-ms-parameterized-host property
$parameterizedHost = [ordered]@{
hostTemplate = '{hostEnv}.jumpcloud.com'
useSchemePrefix = $true
parameters = @(
[ordered]@{
name = 'hostEnv'
description = "Region for JumpCloud API host. Use '$hostPrefix' for US or '$hostPrefix.eu' for EU."
required = $true
type = 'string'
in = 'client'
enum = $enumValues
'x-ms-parameter-location' = 'client'
}
)
}

# Create a new ordered hashtable to preserve alphabetical order
$newSwagger = [ordered]@{}

# Get all keys and sort alphabetically
$allKeys = @($SwaggerObject.Keys) + @('x-ms-parameterized-host') | Sort-Object

# Add properties in alphabetical order
foreach ($key in $allKeys) {
if ($key -eq 'x-ms-parameterized-host') {
$newSwagger[$key] = $parameterizedHost
} elseif ($SwaggerObject.Contains($key)) {
$newSwagger[$key] = $SwaggerObject[$key]
}
}

return $newSwagger
}
function Remove-ParamsByOperationId {
param (
[Parameter(Mandatory = $true)]
Expand Down Expand Up @@ -986,8 +1050,9 @@ function Fix-SearchEndpointsPagination {

return $Swagger
}
#endRegion HelperFunctions


#region ApiTransform
# Start script
$SDKName | ForEach-Object {
$SDKNameItem = $_
Expand Down Expand Up @@ -1031,7 +1096,8 @@ $SDKName | ForEach-Object {
$SwaggerObject = Remove-ParamsByOperationId -Swagger $SwaggerObjectContent -OperationIds $operationIdsToClean -Params @('fields', 'filter', 'X-Eventually-Consistent')
# Run the inlining on the whole Swagger object
$SwaggerObject = Replace-InvalidPropertyRefs -Swagger $SwaggerObject

# ensure the swagger object has an "x-ms-parameterized-host" entry
$SwaggerObject = Add-ParameterizedHost -SwaggerObject $SwaggerObject
# Find and replace on file
$SwaggerObject = $SwaggerObject | ConvertTo-Json -Depth:(100) -Compress
# Perform find and replace
Expand All @@ -1048,35 +1114,17 @@ $SDKName | ForEach-Object {
}
}
}

# replace override definitions
if ($config.OverrideDefinitions) {
foreach ($overrideDef in $config.OverrideDefinitions) {
write-warning "$overrideDef"
$SwaggerObject = $SwaggerObject | ConvertFrom-Json -depth 100
# check that a coresponding def exists in /Custom directory
if (Test-Path -Path "$PSScriptRoot/CustomDefinitions/$($overrideDef).json") {
$configContent = Get-Content -Path ("$PSScriptRoot/CustomDefinitions/$($overrideDef).json")
$configOverride = ($configContent | ConvertFrom-Json)
# test for special chars in property string:
if ($overrideDef -match "-") {
$splitDef = $overRideDef.Split(".")
$newOverrideDef = ""
for ($i = 0; $i -lt $splitDef.Count; $i++) {
if ($splitDef[$i] -match "-") {
$splitDef[$i] = "'" + $splitDef[$i] + "'"
}

if ($i -eq ($splitDef.Count - 1)) {
$newOverrideDef += "$($splitDef[$i])"
} else {
$newOverrideDef += "$($splitDef[$i])."

}
}
$overrideDef = $newOverrideDef

}
$overrideDef = $overrideDef -replace "^(definitions)\.(.+)\.(properties.*)$", "`$1.'`$2'.`$3"
write-warning "Writing custom override for: $overrideDef"
Invoke-Expression -Command ('$SwaggerObject.' + "$($overrideDef)" + '=' + '$configOverride' )
$SwaggerObject = $SwaggerObject | Convertto-Json -depth 100
} else {
Expand All @@ -1087,10 +1135,10 @@ $SDKName | ForEach-Object {
} else {
$SwaggerObject = $SwaggerObject | ConvertFrom-Json -Depth:(100)
}

# Remove limit/skip parameters from Search endpoints
# Remove limit/skip parameters from Search endpoints
$SwaggerObject = Remove-SearchEndpointLimitSkipParams -Swagger $SwaggerObject
$SwaggerObject = Fix-SearchEndpointsPagination -Swagger $SwaggerObject

#######################################################################
# # Resolve the swagger references ($ref)/flatten
# $SwaggerObjectRefMatches = $SwaggerObject | ConvertFrom-Json -Depth:(100)
Expand Down Expand Up @@ -1202,3 +1250,4 @@ $SDKName | ForEach-Object {
Write-Error ("Config 'TransformConfig' does not contain an SDK called '$($SDKNameItem)'.")
}
}
#endregion ApiTransform
53 changes: 51 additions & 2 deletions BuildAutoRest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ ForEach ($SDK In $SDKName)
$Config = $ConfigContent | ConvertFrom-Yaml
# Write current branch back to config file
$Config.branch = $CurrentBranch
$Config | Set-Content -Path:($ConfigFileFullName)
$Config | ConvertTo-Yaml -OutFile:($ConfigFileFullName) -force
$OutputFullPath = '{0}/{1}' -f $BaseFolder, [System.String]$Config.'output-folder'
$ToolsFolderPath = '{0}/Tools' -f $BaseFolder
$RunPesterTestsFilePath = '{0}/RunPesterTests.ps1' -f $ToolsFolderPath
Expand Down Expand Up @@ -133,7 +133,7 @@ ForEach ($SDK In $SDKName)
bash $CleanScript $PSScriptRoot $OutputFullPath
}
Write-Host ('[RUN COMMAND] autorest ' + $ConfigFileFullName + ' --force --verbose --debug') -BackgroundColor:('Black') -ForegroundColor:('Magenta')
npx autorest $ConfigFileFullName --force --version:$($npmDependencies.dependencies.'@autorest/core') --use:@autorest/powershell@$($npmDependencies.dependencies.'@autorest/powershell') | Tee-Object -FilePath:($LogFilePath) -Append
npx autorest $ConfigFileFullName --force --version:$($npmDependencies.dependencies.'@autorest/core') --use:@autorest/powershell@$($npmDependencies.dependencies.'@autorest/powershell') | Out-Null
}
###########################################################################
If ($CopyCustomFiles)
Expand Down Expand Up @@ -169,6 +169,29 @@ ForEach ($SDK In $SDKName)
$PsProxyTypes = (Get-Content $CustomHelpProxyType -Raw)
$OnlineVersionPsProxyTypes = [Regex]::Replace($PsProxyTypes, ('\$\@\"{HelpLinkPrefix}.*'), '$@"{HelpLinkPrefix}{variantGroup.ModuleName}/docs/exports/{variantGroup.CmdletName}.md";', [System.Text.RegularExpressions.RegexOptions]::IgnoreCase);
Set-Content -Path:($CustomHelpProxyType) -Value:($OnlineVersionPsProxyTypes)
# before building the module, remove the generate-portal-ux.ps1 from the module directory, we don't need it and will not be building for Azure Portal UX at this time.
If (Test-Path $OutputFullPath/generate-portal-ux.ps1) {
write-Host ('[REMOVING] generate-portal-ux.ps1 from module directory.') -BackgroundColor:('Black') -ForegroundColor:('Magenta')
Remove-Item -Path $OutputFullPath/generate-portal-ux.ps1 -Force
}
# After AutoRest generation, create a ModuleIdentifier.cs file for each SDK
$moduleIdentifierPath = "$OutputFullPath/custom/ModuleIdentifier.cs"
$sdkIdentifier = switch ($SDKNameItem) {
'JumpCloud.SDK.DirectoryInsights' { 'DirectoryInsights' }
'JumpCloud.SDK.V1' { 'V1' }
'JumpCloud.SDK.V2' { 'V2' }
}

$moduleIdentifierContent = @"
namespace ModuleNameSpace
{
public static class ModuleIdentifier
{
public const string SDKName = "$sdkIdentifier";
}
}
"@
Set-Content -Path $moduleIdentifierPath -Value $moduleIdentifierContent -Force
# build the module
$BuildModuleCommandJob = Start-Job -ArgumentList:($BuildModuleCommand) -ScriptBlock:( { param ($BuildModuleCommand);
Invoke-Expression -Command:($BuildModuleCommand)
Expand Down Expand Up @@ -293,6 +316,32 @@ ForEach ($SDK In $SDKName)
$testModuleContent = $testModuleContent.Replace($InvokePesterLine.Matches.Value, $PesterTestsContent)
$testModuleContent = $testModuleContent.Replace('Import-Module -Name Az.Accounts', '# Import-Module -Name Az.Accounts')
$testModuleContent | Set-Content -Path:($testModulePath)
# update the loadEnv.ps1 file for each SDK to set the default hostEnv while testing:
$loadEnvContent = Get-Content -Path:("$TestFolderPath/loadEnv.ps1") -Raw
$loadContentToAdd = @"

# Determine which SDK this is and set the appropriate default HostEnv
`$sdkName = Split-Path (Split-Path `$PSScriptRoot -Parent) -Leaf
# Write-Host "SDK Name detected: `$sdkName"
`$defaultHostEnv = switch (`$sdkName) {
'JumpCloud.SDK.DirectoryInsights' { 'api' }
'JumpCloud.SDK.V1' { 'console' }
'JumpCloud.SDK.V2' { 'console' }
default { 'console' }
}

# Check if user has set JCEnvironment to EU
if (`$env:JCEnvironment -eq 'EU') {
`$defaultHostEnv = "`$defaultHostEnv.eu"
}

# Set the default parameter value for this test session
`$PSDefaultParameterValues['*-JcSdk*:HostEnv'] = `$defaultHostEnv
# Write-Host "Test environment loaded. Default HostEnv set to: `$defaultHostEnv"
"@
# append to the end of the loadEnv.ps1 file
$loadEnvContent += $loadContentToAdd
$loadEnvContent | Set-Content -Path:("$TestFolderPath/loadEnv.ps1")
}
###########################################################################
# Remove auto generated .gitignore files
Expand Down
61 changes: 25 additions & 36 deletions Configs/JumpCloud.SDK.DirectoryInsights.yaml
Original file line number Diff line number Diff line change
@@ -1,44 +1,33 @@
debug: true
sample-generation: true
directive:
- hide: true
where:
prefix: JcSdk
input-file:
- SwaggerSpecs/JumpCloud.SDK.DirectoryInsights.json
module-version: 0.1.0
output-folder: SDKs/PowerShell/JumpCloud.SDK.DirectoryInsights
clear-output-folder: true
base-folder: ..
branch: CUT-4908_userGroupDeviceGroupFilters
dll-name: JumpCloud.SDK.DirectoryInsights.private
namespace: JumpCloud.SDK.DirectoryInsights
help-link-prefix: https://github.com/TheJumpCloud/jcapi-powershell/tree/$(branch)/SDKs/PowerShell/
verbose: true
# Values
# azure: false
powershell: true
branch: master
debug: true
metadata:
authors: JumpCloud
owners: JumpCloud
description: The JumpCloud DirectoryInsights PowerShell SDK
copyright: (c) JumpCloud. All rights reserved.
companyName: JumpCloud
requireLicenseAcceptance: false
companyName: JumpCloud
tags: JumpCloud, DaaS, Jump, Cloud, Directory
copyright: (c) JumpCloud. All rights reserved.
iconUri: https://console.jumpcloud.com/img/login-viewport-logo.png
licenseUri: https://github.com/TheJumpCloud/jcapi-powershell/tree/$(branch)/LICENSE
description: The JumpCloud DirectoryInsights PowerShell SDK
projectUri: https://github.com/TheJumpCloud/jcapi-powershell/tree/$(branch)/SDKs/PowerShell/JumpCloud.SDK.DirectoryInsights/
iconUri: https://console.jumpcloud.com/img/login-viewport-logo.png
tags: JumpCloud, DaaS, Jump, Cloud, Directory
owners: JumpCloud
formatsToProcess: []

# Names
authors: JumpCloud
module-name: JumpCloud.SDK.DirectoryInsights
prefix: JcSdkInternal
customFunctionPrefix: JcSdk
help-link-prefix: https://github.com/TheJumpCloud/jcapi-powershell/tree/$(branch)/SDKs/PowerShell/

# Folders
clear-output-folder: true
output-folder: SDKs/PowerShell/JumpCloud.SDK.DirectoryInsights
base-folder: '..'

input-file:
- SwaggerSpecs/JumpCloud.SDK.DirectoryInsights.json
# title: JumpCloud.SDK.DirectoryInsights
module-name: JumpCloud.SDK.DirectoryInsights
namespace: JumpCloud.SDK.DirectoryInsights
sample-generation: true
module-version: 0.0.34
dll-name: JumpCloud.SDK.DirectoryInsights.private

directive:
- where:
prefix: JcSdk
hide: true
# Prevent response flattening: https://github.com/Azure/autorest.powershell/issues/743
# inlining-threshold: 0
powershell: true
75 changes: 30 additions & 45 deletions Configs/JumpCloud.SDK.V1.yaml
Original file line number Diff line number Diff line change
@@ -1,55 +1,40 @@
debug: true
verbose: true
# Values
# azure: false
base-folder: ..
help-link-prefix: https://github.com/TheJumpCloud/jcapi-powershell/tree/$(branch)/SDKs/PowerShell/
dll-name: JumpCloud.SDK.V1.private
debug: true
output-folder: SDKs/PowerShell/JumpCloud.SDK.V1
module-version: 0.1.0
powershell: true
branch: master
input-file:
- SwaggerSpecs/JumpCloud.SDK.V1.json
module-name: JumpCloud.SDK.V1
prefix: JcSdkInternal
clear-output-folder: true
metadata:
authors: JumpCloud
owners: JumpCloud
description: The JumpCloud V1 PowerShell SDK
copyright: (c) JumpCloud. All rights reserved.
companyName: JumpCloud
requireLicenseAcceptance: false
licenseUri: https://github.com/TheJumpCloud/jcapi-powershell/tree/$(branch)/LICENSE
description: The JumpCloud V1 PowerShell SDK
projectUri: https://github.com/TheJumpCloud/jcapi-powershell/tree/$(branch)/SDKs/PowerShell/JumpCloud.SDK.V1/
iconUri: https://console.jumpcloud.com/img/login-viewport-logo.png
requireLicenseAcceptance: false
tags: JumpCloud, DaaS, Jump, Cloud, Directory
owners: JumpCloud
formatsToProcess: []

# Names
prefix: JcSdkInternal
customFunctionPrefix: JcSdk
help-link-prefix: https://github.com/TheJumpCloud/jcapi-powershell/tree/$(branch)/SDKs/PowerShell/

# Folders
clear-output-folder: true
output-folder: SDKs/PowerShell/JumpCloud.SDK.V1
base-folder: '..'

input-file:
- SwaggerSpecs/JumpCloud.SDK.V1.json
# title: JumpCloud.SDK.V1
module-name: JumpCloud.SDK.V1
companyName: JumpCloud
copyright: (c) JumpCloud. All rights reserved.
authors: JumpCloud
directive:
- where: $.definitions.commandresultssearchlist.properties.results.items.properties.system
from: swagger-document
transform: $["x-ms-client-name"] = "systemId";
- where: $.definitions.commandresultbycommandid.properties.system
from: swagger-document
transform: $["x-ms-client-name"] = "systemId";
- hide: true
where:
prefix: JcSdk
from: swagger-document
namespace: JumpCloud.SDK.V1
branch: CUT-4908_userGroupDeviceGroupFilters
sample-generation: true
module-version: 0.0.47
dll-name: JumpCloud.SDK.V1.private

directive:
# update search command results system property to be systemID
- from: swagger-document
where: "$.definitions.commandresultssearchlist.properties.results.items.properties.system"
transform: >-
$["x-ms-client-name"] = "systemId";
# update get command {id} results system property to be systemID
- from: swagger-document
where: "$.definitions.commandresultbycommandid.properties.system"
transform: >-
$["x-ms-client-name"] = "systemId";
- from: swagger-document
where:
prefix: JcSdk
hide: true
# Prevent response flattening: https://github.com/Azure/autorest.powershell/issues/743
# inlining-threshold: 0
customFunctionPrefix: JcSdk
Loading
Loading