From 4ab6d8a347eaafa3ecb3e727c436e5e7bd374fe0 Mon Sep 17 00:00:00 2001 From: Adam Haydon Date: Fri, 13 Jan 2023 11:44:35 +0000 Subject: [PATCH] Allow append properties and tags for all resources --- functions/core.ps1 | 1 - functions/helper.ps1 | 14 ++++++++++++-- resources/dataconnection.ps1 | 4 ++-- resources/extension.ps1 | 4 ++-- resources/node.ps1 | 4 ++-- resources/proxy.ps1 | 4 ++-- resources/rule.ps1 | 10 +--------- resources/stream.ps1 | 4 ++-- resources/task.ps1 | 4 ++-- resources/user.ps1 | 4 ++-- resources/userdirectory.ps1 | 6 +----- 11 files changed, 28 insertions(+), 31 deletions(-) diff --git a/functions/core.ps1 b/functions/core.ps1 index 0b8faad..4da9f0b 100644 --- a/functions/core.ps1 +++ b/functions/core.ps1 @@ -1,5 +1,4 @@ $script:guid = "^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$" -$script:isDate = "^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$" $script:webSessionContainer = $null if ($qlik_output_raw) { $rawOutput = $true } diff --git a/functions/helper.ps1 b/functions/helper.ps1 index 270a3ad..364b7a9 100644 --- a/functions/helper.ps1 +++ b/functions/helper.ps1 @@ -1,4 +1,6 @@ function FormatOutput($objects, $schemaPath) { + $isDate = "^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$" + Write-Debug "Resolving enums" If ( !$Script:enums ) { $rawOutput = $true @@ -49,7 +51,7 @@ function GetCustomProperties($customProperties, $existing) { } elseif ($_ -is [System.Collections.Hashtable]) { foreach ($key in $_.Keys) { - $p = Get-QlikCustomProperty -filter "name eq '$key'" + $p = Get-QlikCustomProperty -filter "name eq '$key'" -raw if (! $p) { Write-Warning "Property with name '$key' not found" continue @@ -65,7 +67,15 @@ function GetCustomProperties($customProperties, $existing) { } elseif ($_ -is [System.String]) { $val = $_.Split("=", 2) - $p = Get-QlikCustomProperty -filter "name eq '$($val[0])'" + $p = Get-QlikCustomProperty -filter "name eq '$($val[0])'" -raw + if (! $p) { + Write-Warning "Property with name '$($val[0])' not found" + return + } + if ($p.choiceValues -notcontains $val[1]) { + Write-Warning "Value '$($val[1])' not valid for property '$($val[0])'" + return + } @{ value = ($p.choiceValues -eq $val[1])[0] definition = $p diff --git a/resources/dataconnection.ps1 b/resources/dataconnection.ps1 index b8bb07b..7a30533 100644 --- a/resources/dataconnection.ps1 +++ b/resources/dataconnection.ps1 @@ -144,8 +144,8 @@ function Update-QlikDataConnection { $qdc | Add-Member -MemberType NoteProperty -Name "password" -Value $($Credential.GetNetworkCredential().Password) } } - if ($PSBoundParameters.ContainsKey("customProperties")) { $qdc.customProperties = @(GetCustomProperties $customProperties) } - if ($PSBoundParameters.ContainsKey("tags")) { $qdc.tags = @(GetTags $tags) } + if ($PSBoundParameters.ContainsKey("customProperties")) { $qdc.customProperties = @(GetCustomProperties $customProperties $qdc.customProperties) } + if ($PSBoundParameters.ContainsKey("tags")) { $qdc.tags = @(GetTags $tags $qdc.tags) } if ($PSBoundParameters.ContainsKey("owner")) { $qdc.owner = GetUser $owner } $json = $qdc | ConvertTo-Json -Compress -Depth 10 diff --git a/resources/extension.ps1 b/resources/extension.ps1 index ba7005a..ac5ff16 100644 --- a/resources/extension.ps1 +++ b/resources/extension.ps1 @@ -67,8 +67,8 @@ function Update-QlikExtension { PROCESS { $ext = Get-QlikExtension -raw -Id $id - if ($PSBoundParameters.ContainsKey("customProperties")) { $ext.customProperties = @(GetCustomProperties $customProperties) } - if ($PSBoundParameters.ContainsKey("tags")) { $ext.tags = @(GetTags $tags) } + if ($PSBoundParameters.ContainsKey("customProperties")) { $ext.customProperties = @(GetCustomProperties $customProperties $ext.customProperties) } + if ($PSBoundParameters.ContainsKey("tags")) { $ext.tags = @(GetTags $tags $ext.tags) } if ($PSBoundParameters.ContainsKey("owner")) { $ext.owner = GetUser $owner } $json = $ext | ConvertTo-Json -Compress -Depth 10 diff --git a/resources/node.ps1 b/resources/node.ps1 index eabda4c..1e01b69 100644 --- a/resources/node.ps1 +++ b/resources/node.ps1 @@ -160,8 +160,8 @@ function Update-QlikNode { Both { $node.nodePurpose = 2 } } } - if ($PSBoundParameters.ContainsKey("customProperties")) { $node.customProperties = @(GetCustomProperties $customProperties) } - if ($PSBoundParameters.ContainsKey("tags")) { $node.tags = @(GetTags $tags) } + if ($PSBoundParameters.ContainsKey("customProperties")) { $node.customProperties = @(GetCustomProperties $customProperties $node.customProperties) } + if ($PSBoundParameters.ContainsKey("tags")) { $node.tags = @(GetTags $tags $node.tags) } If ( $psBoundParameters.ContainsKey("failoverCandidate") ) { $node.failoverCandidate = $failoverCandidate.IsPresent if ($failoverCandidate.IsPresent) { diff --git a/resources/proxy.ps1 b/resources/proxy.ps1 index 4dfea24..2ec75e2 100644 --- a/resources/proxy.ps1 +++ b/resources/proxy.ps1 @@ -459,8 +459,8 @@ function Update-QlikVirtualProxy { If ( $psBoundParameters.ContainsKey("jwtAttributeUserDirectory") ) { $proxy.jwtAttributeUserDirectory = $jwtAttributeUserDirectory } If ( $psBoundParameters.ContainsKey("jwtAttributeMap") ) { $proxy.jwtAttributeMap = $jwtAttributeMap } If ( $psBoundParameters.ContainsKey("sessionInactivityTimeout") ) { $proxy.sessionInactivityTimeout = $sessionInactivityTimeout } - if ($PSBoundParameters.ContainsKey("customProperties")) { $proxy.customProperties = @(GetCustomProperties $customProperties) } - if ($PSBoundParameters.ContainsKey("tags")) { $proxy.tags = @(GetTags $tags) } + if ($PSBoundParameters.ContainsKey("customProperties")) { $proxy.customProperties = @(GetCustomProperties $customProperties $proxy.customProperties) } + if ($PSBoundParameters.ContainsKey("tags")) { $proxy.tags = @(GetTags $tags $proxy.tags) } $json = $proxy | ConvertTo-Json -Compress -Depth 10 return Invoke-QlikPut "/qrs/virtualproxyconfig/$id" $json diff --git a/resources/rule.ps1 b/resources/rule.ps1 index 5f44480..f2820a0 100644 --- a/resources/rule.ps1 +++ b/resources/rule.ps1 @@ -76,7 +76,6 @@ function New-QlikRule { [int64]$actions, [string]$comment, [switch]$disabled, - [string[]]$customProperties, [string[]]$tags ) @@ -94,11 +93,9 @@ function New-QlikRule { comment = $comment; disabled = $disabled.IsPresent; ruleContext = $context; - customProperties = @(); schemaPath = "SystemRule" } - if ($PSBoundParameters.ContainsKey("customProperties")) { $systemrule.customProperties = @(GetCustomProperties $customProperties) } if ($PSBoundParameters.ContainsKey("tags")) { $systemrule.tags = @(GetTags $tags) } # category is case-sensitive so convert to Title Case $systemrule.category = (Get-Culture).TextInfo.ToTitleCase($category.ToLower()) @@ -152,7 +149,6 @@ function Update-QlikRule { [string]$comment, [switch]$disabled, - [string[]]$customProperties, [string[]]$tags ) @@ -172,8 +168,7 @@ function Update-QlikRule { If ( $actions ) { $systemrule.actions = $actions } If ( $comment ) { $systemrule.comment = $comment } If ( $psBoundParameters.ContainsKey("disabled") ) { $systemrule.disabled = $disabled.IsPresent } - if ($PSBoundParameters.ContainsKey("customProperties")) { $systemrule.customProperties = @(GetCustomProperties $customProperties) } - if ($PSBoundParameters.ContainsKey("tags")) { $systemrule.tags = @(GetTags $tags) } + if ($PSBoundParameters.ContainsKey("tags")) { $systemrule.tags = @(GetTags $tags $systemrule.tags) } $json = $systemrule | ConvertTo-Json -Compress -Depth 10 return Invoke-QlikPut "/qrs/systemrule/$id" $json @@ -191,7 +186,6 @@ function New-QlikLicenseRule { [string]$Rule, [string]$Comment, [switch]$Disabled, - [string[]]$CustomProperties, [string[]]$Tags ) PROCESS { @@ -204,11 +198,9 @@ function New-QlikLicenseRule { comment = $Comment; disabled = $Disabled.IsPresent; ruleContext = 1; - customProperties = @(); schemaPath = "SystemRule" category = "License" } - if ($PSBoundParameters.ContainsKey("customProperties")) { $systemrule.customProperties = @(GetCustomProperties $customProperties) } if ($PSBoundParameters.ContainsKey("tags")) { $systemrule.tags = @(GetTags $tags) } $AccessGroup = @{ name = $Name diff --git a/resources/stream.ps1 b/resources/stream.ps1 index b910f6a..2bad64c 100644 --- a/resources/stream.ps1 +++ b/resources/stream.ps1 @@ -70,8 +70,8 @@ function Update-QlikStream { $stream = Get-QlikStream $id -raw if ($PSBoundParameters.ContainsKey("name")) { $stream.name = $name } - if ($PSBoundParameters.ContainsKey("customProperties")) { $stream.customProperties = @(GetCustomProperties $customProperties) } - if ($PSBoundParameters.ContainsKey("tags")) { $stream.tags = @(GetTags $tags) } + if ($PSBoundParameters.ContainsKey("customProperties")) { $stream.customProperties = @(GetCustomProperties $customProperties $stream.customProperties) } + if ($PSBoundParameters.ContainsKey("tags")) { $stream.tags = @(GetTags $tags $stream.tags) } if ($PSBoundParameters.ContainsKey("owner")) { $stream.owner = GetUser $owner } $json = $stream | ConvertTo-Json -Compress -Depth 10 diff --git a/resources/task.ps1 b/resources/task.ps1 index d0061bc..a5db380 100644 --- a/resources/task.ps1 +++ b/resources/task.ps1 @@ -242,8 +242,8 @@ function Update-QlikReloadTask { If ( $psBoundParameters.ContainsKey("Enabled") ) { $task.enabled = $Enabled } If ( $psBoundParameters.ContainsKey("TaskSessionTimeout") ) { $task.taskSessionTimeout = $TaskSessionTimeout } If ( $psBoundParameters.ContainsKey("MaxRetries") ) { $task.maxRetries = $MaxRetries } - if ($PSBoundParameters.ContainsKey("customProperties")) { $task.customProperties = @(GetCustomProperties $customProperties) } - if ($PSBoundParameters.ContainsKey("tags")) { $task.tags = @(GetTags $tags) } + if ($PSBoundParameters.ContainsKey("customProperties")) { $task.customProperties = @(GetCustomProperties $customProperties $task.customProperties) } + if ($PSBoundParameters.ContainsKey("tags")) { $task.tags = @(GetTags $tags $task.tags) } $json = $task | ConvertTo-Json -Compress -Depth 10 return Invoke-QlikPut -path "/qrs/reloadtask/$id" -body $json diff --git a/resources/user.ps1 b/resources/user.ps1 index 6b431f0..29da492 100644 --- a/resources/user.ps1 +++ b/resources/user.ps1 @@ -91,8 +91,8 @@ function Update-QlikUser { $user = Get-QlikUser $id -raw If ( $roles ) { $user.roles = $roles } If ( $name ) { $user.name = $name } - if ($PSBoundParameters.ContainsKey("customProperties")) { $user.customProperties = @(GetCustomProperties $customProperties) } - if ($PSBoundParameters.ContainsKey("tags")) { $user.tags = @(GetTags $tags) } + if ($PSBoundParameters.ContainsKey("customProperties")) { $user.customProperties = @(GetCustomProperties $customProperties $user.customProperties) } + if ($PSBoundParameters.ContainsKey("tags")) { $user.tags = @(GetTags $tags $user.tags) } $json = $user | ConvertTo-Json -Compress -Depth 10 return Invoke-QlikPut "/qrs/user/$id" $json diff --git a/resources/userdirectory.ps1 b/resources/userdirectory.ps1 index 721049c..25d0505 100644 --- a/resources/userdirectory.ps1 +++ b/resources/userdirectory.ps1 @@ -34,7 +34,6 @@ function New-QlikUserDirectory { [string]$configuredError = "", [string]$operationalError = "", [System.Object[]]$settings = @(), - [string[]]$customProperties, [string[]]$tags ) @@ -52,7 +51,6 @@ function New-QlikUserDirectory { operationalError = $operationalError; settings = $settings } - if ($PSBoundParameters.ContainsKey("customProperties")) { $ud.customProperties = @(GetCustomProperties $customProperties) } if ($PSBoundParameters.ContainsKey("tags")) { $ud.tags = @(GetTags $tags) } $json = $ud | ConvertTo-Json -Compress -Depth 10 @@ -101,7 +99,6 @@ function Update-QlikUserDirectory { [string]$ldapFilter, [int]$timeout, [Int]$pageSize, - [string[]]$customProperties, [string[]]$tags ) @@ -136,8 +133,7 @@ function Update-QlikUserDirectory { if ($pageSize) { ($ud.settings | Where-Object name -EQ 'Page size').value = $pageSize } - if ($PSBoundParameters.ContainsKey("customProperties")) { $ud.customProperties = @(GetCustomProperties $customProperties) } - if ($PSBoundParameters.ContainsKey("tags")) { $ud.tags = @(GetTags $tags) } + if ($PSBoundParameters.ContainsKey("tags")) { $ud.tags = @(GetTags $tags $ud.tags) } $json = $ud | ConvertTo-Json -Compress -Depth 10 return Invoke-QlikPut -path "/qrs/userdirectory/$id" -body $json