Public/new-AllegisIDNIdentityProfileAttributeTransform.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
function new-AllegisIDNIdentityProfileAttributeTransform { param( [cmdletbinding( DefaultParameterSetName='AccountAttribute' )] [string]$orgname, [Parameter(Position = 0,Mandatory=$true)]$identityAttributeName, [Parameter(ParameterSetName='AccountAttribute',Mandatory=$false)]$sourcename, [Parameter(ParameterSetName='AccountAttribute',Mandatory=$false)]$sourceattribute, [string]$accesstoken, [string]$rule, [string]$transform, [switch]$PurgeAndRefreshReferenceInfo ) if ($PurgeAndRefreshReferenceInfo -eq $true -or $Global:idn_identityAttributes -eq $null -or $Global:idn_rule -eq $null -or $Global:idn_transformnames -eq $null -or $Global:idn_sourcesWithImportSchema -eq $null -or $Global:idn_orgname -ne $orgname) {#populate data Set-Variable -Scope 'Global' -Name 'idn_orgname' -Value $orgname Set-Variable -Scope 'Global' -Name 'idn_rule' -Value (get-AllegisIDNrule -orgName $sourceOrg -accessToken $accesstoken) Set-Variable -Scope 'Global' -Name 'idn_transformnames' -Value ((get-AllegisIDNtransform -orgName $sourceOrg -accessToken $accesstoken).items.id) Set-Variable -Scope 'Global' -Name 'idn_sourcesWithImportSchema' -Value (get-AllegisIDNsource -orgName $sourceOrg -accessToken $accesstoken -importschema) Set-Variable -Scope 'Global' -Name 'idn_identityAttributes' -Value (get-AllegisIDNIdentityAttribute -orgName $sourceOrg -accessToken $accesstoken) } $rules=$Global:idn_rule $transformnames=$Global:idn_transformnames $sourcesWithImportSchema=$Global:idn_sourcesWithImportSchema $identityAttributes=$Global:idn_identityAttributes if ($identityAttributeName -cnotin $identityattributes.name){write-warning "identity attribute name does not exactly match an existing identity attribute";return} if ($rule.length -gt 0){ $type='rule' }elseif($transform.Length -gt 0){ $type='reference' }else{ $type='accountAttribute' } $source=$sourcesWithImportSchema.where{$_.name -eq $sourcename}[0] if ($source.importschema.attributes.where{$_.name -eq $sourceattribute} -eq $null){write-warning -Message "unable to find $sourcename : $sourceattribute in `sourcesWithImportSchema";return} if (($transform.length -gt 0 -and $transform -notin $transformnames)){write-warning -Message "provided transform name did not appear to be valid $transform";return} if ($accountattribute.length -eq 0){ $accountattribute=$sourcesWithImportSchema.where{$_.name -eq $sourcename}.importschema.identityAttribute[0] }else{ $accountattribute=$sourcesWithImportSchema.where{$_.name -eq $sourcename}.importschema.attributes.name.where{$_ -eq $sourceattribute}[0] } switch ($type){ rule{ $validrules=$rules.items.where{$_.type -eq 'IdentityAttribute'} $ruleObj=$validrules.where{$_.name -eq $rule}[0] $accountattribute=[pscustomobject]@{ id=$ruleObj.id name=$ruleObj.name } $attributeTransform=[pscustomobject]@{ attributename=$identityattributename attributes=$accountattribute type=$type } } reference{ $accountattribute=[pscustomobject]@{ applicationId=$source.externalid applicationName="$($source.health.name)" attributeName=$accountattribute sourceName=$sourcename } $input=[pscustomobject]@{ attributes=$accountattribute type='accountAttribute' } $attributes=[pscustomobject]@{ id=$transform input=$input } $attributeTransform=[pscustomobject]@{ attributename=$identityattributename attributes=$attributes type=$type } } accountAttribute{ $accountattribute=[pscustomobject]@{ applicationId=$source.externalid applicationName="$($source.health.name)" attributeName=$accountattribute sourceName=$sourcename } $attributeTransform=[pscustomobject]@{ attributename=$identityattributename attributes=$accountattribute type=$type } } } return $attributeTransform } |