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

Single-Value arrays passed through Remove-Null command get converted to Objects #50

Open
TriggerAu opened this issue Sep 27, 2024 · 0 comments

Comments

@TriggerAu
Copy link
Contributor

Revisiting #35 Issue as that code works with raw JSON, but not when you feedin objects created via the Okta PS Modules

This is the test case in the Module today and works correctly when we convert back to objects as happens at the API end

#Test case form Github
$RawNewGroupRule = [PSObject]@{
    name = "Assign users to the Sales Team"
    type = "group_rule"
    actions = [PSObject]@{ 
        assignUserToGroups = [PSObject]@{
            groupIds = [array]@('foo')
        }
    } 
}

$RawCleanedRule = Remove-NullProperties $RawNewGroupRule

$rawNewGroupRuleJSON = $RawNewGroupRule | ConvertTo-Json -Depth 10
$RawCleanedRuleJSON = $RawCleanedRule | ConvertTo-Json -Depth 10

Write-Host "Test case with raw json input"
Write-Host "-----------------------------"
Write-Host "OG:    $(($rawNewGroupRuleJSON | ConvertFrom-Json).actions.assignUserToGroups)"
Write-Host "Clean: $(($rawCleanedRuleJSON | ConvertFrom-Json).actions.assignUserToGroups)"

This is the same test case when the object is created using the API and does not maintain the integrity of the array object

$GroupRuleGroupAssignment = Initialize-OktaGroupRuleGroupAssignment -GroupIds ([array]@("foo"))
$GroupRuleAction = Initialize-OktaGroupRuleAction -AssignUserToGroups $GroupRuleGroupAssignment

$GroupRuleExpression = Initialize-OktaGroupRuleExpression -Type "urn:okta:expression:1.0" -Value "user.title=='Sales Representative'"

$GroupRuleConditions = Initialize-OktaGroupRuleConditions -Expression $GroupRuleExpression

$NewGroupRule = Initialize-OktaGroupRule -Actions $GroupRuleAction -Conditions $GroupRuleConditions -Name "TEST_OktaAPI" -Type "group_rule"

$CleanedRule = Remove-NullProperties $NewGroupRule

$groupRuleJSON = $NewGroupRule | ConvertTo-Json -Depth 10
$cleanedRuleJSON = $CleanedRule | ConvertTo-Json -Depth 10

Write-Host "Test case with Okta method creation"
Write-Host "-----------------------------"
Write-Host "OG:    $(($groupRuleJSON | ConvertFrom-Json).actions.assignUserToGroups)"
Write-Host "Clean: $(($cleanedRuleJSON | ConvertFrom-Json).actions.assignUserToGroups)"

This is caused by some piping in the 1Remove-NullProperties` Ill post a PR in a few minutes

TriggerAu added a commit to TriggerAu/okta-powershell-cli that referenced this issue Sep 27, 2024
This adds a forced cast inside the method that prevents Powershell from
converting a single valued array to an object.

This pr does not include changes to the test methods as Im not sure how
the team would intend the use case to be tested

Its a revisit on okta#35
laura-rodriguez pushed a commit that referenced this issue Oct 30, 2024
This adds a forced cast inside the method that prevents Powershell from
converting a single valued array to an object.

This pr does not include changes to the test methods as Im not sure how
the team would intend the use case to be tested

Its a revisit on #35

Signed-off-by: Laura Rodriguez <[email protected]>
laura-rodriguez pushed a commit that referenced this issue Oct 30, 2024
This adds a forced cast inside the method that prevents Powershell from
converting a single valued array to an object.

This pr does not include changes to the test methods as Im not sure how
the team would intend the use case to be tested

Its a revisit on #35

Signed-off-by: Laura Rodriguez <[email protected]>
laura-rodriguez pushed a commit that referenced this issue Oct 30, 2024
This adds a forced cast inside the method that prevents Powershell from
converting a single valued array to an object.

This pr does not include changes to the test methods as Im not sure how
the team would intend the use case to be tested

Its a revisit on #35

Signed-off-by: Laura Rodriguez <[email protected]>
TriggerAu added a commit to TriggerAu/okta-powershell-cli that referenced this issue Nov 1, 2024
TriggerAu added a commit to TriggerAu/okta-powershell-cli that referenced this issue Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant