Skip to content

Commit

Permalink
Allow append properties and tags for all resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaydon committed Jan 13, 2023
1 parent 737899a commit 4ab6d8a
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 31 deletions.
1 change: 0 additions & 1 deletion functions/core.ps1
Original file line number Diff line number Diff line change
@@ -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 }

Expand Down
14 changes: 12 additions & 2 deletions functions/helper.ps1
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions resources/dataconnection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions resources/extension.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions resources/node.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions resources/proxy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 1 addition & 9 deletions resources/rule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ function New-QlikRule {
[int64]$actions,
[string]$comment,
[switch]$disabled,
[string[]]$customProperties,
[string[]]$tags
)

Expand All @@ -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())
Expand Down Expand Up @@ -152,7 +149,6 @@ function Update-QlikRule {
[string]$comment,
[switch]$disabled,

[string[]]$customProperties,
[string[]]$tags
)

Expand All @@ -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
Expand All @@ -191,7 +186,6 @@ function New-QlikLicenseRule {
[string]$Rule,
[string]$Comment,
[switch]$Disabled,
[string[]]$CustomProperties,
[string[]]$Tags
)
PROCESS {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions resources/stream.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions resources/task.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions resources/user.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions resources/userdirectory.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function New-QlikUserDirectory {
[string]$configuredError = "",
[string]$operationalError = "",
[System.Object[]]$settings = @(),
[string[]]$customProperties,
[string[]]$tags
)

Expand All @@ -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

Expand Down Expand Up @@ -101,7 +99,6 @@ function Update-QlikUserDirectory {
[string]$ldapFilter,
[int]$timeout,
[Int]$pageSize,
[string[]]$customProperties,
[string[]]$tags
)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4ab6d8a

Please sign in to comment.