DSCClassResources/QlikProxy.psm1

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
$ProjectRoot = Split-Path $PSScriptRoot -Parent
Import-Module (Join-Path $ProjectRoot -ChildPath 'Private' | Join-Path -ChildPath 'Common.psm1') -Force

[DscResource()]
class QlikProxy {

    [DscProperty(Key)]
    [string]$Node

    [DscProperty()]
    [ValidateRange(1, 65535)]
    [Int]$ListenPort

    [DscProperty()]
    [Bool]$AllowHttp

    [DscProperty()]
    [ValidateRange(1, 65535)]
    [Int]$UnencryptedListenPort

    [DscProperty()]
    [ValidateRange(1, 65535)]
    [Int]$AuthenticationListenPort

    [DscProperty()]
    [Bool]$KerberosAuthentication

    [DscProperty()]
    [ValidateRange(1, 65535)]
    [Int]$UnencryptedAuthenticationListenPort

    [DscProperty()]
    [String]$SslBrowserCertificateThumbprint

    [DscProperty()]
    [ValidateRange(1, 300)]
    [Int]$KeepAliveTimeoutSeconds

    [DscProperty()]
    [ValidateRange(512, 131072)]
    [Int]$MaxHeaderSizeBytes

    [DscProperty()]
    [ValidateRange(20, 1000)]
    [Int]$MaxHeaderLines

    [DscProperty()]
    [ValidateRange(1, 65535)]
    [Int]$RestListenPort

    [DscProperty()]
    [hashtable]$CustomProperties

    hidden [string]
    $SchemaPath = 'ProxyService'

    [Void] Set () {
        Write-Verbose "Get Qlik Proxy: $($this.Node)"
        $item = Get-QlikProxy -Full -Filter "serverNodeConfiguration.hostName eq '$($this.Node)'"
        if($item.id) {
            $engparams = @{
                id = $item.id
                AllowHTTP = $this.AllowHttp
                KerberosAuthentication = $this.KerberosAuthentication
            }
            if($this.ListenPort) { $engparams.Add("listenPort", $this.ListenPort) }
            if($this.UnencryptedListenPort) { $engparams.Add("unencryptedListenPort", $this.UnencryptedListenPort) }
            if($this.AuthenticationListenPort) { $engparams.Add("authenticationListenPort", $this.AuthenticationListenPort) }
            if($this.UnencryptedAuthenticationListenPort) { $engparams.Add("unencryptedAuthenticationListenPort", $this.UnencryptedAuthenticationListenPort) }
            if($this.SslBrowserCertificateThumbprint) { $engparams.Add("sslBrowserCertificateThumbprint", $this.SslBrowserCertificateThumbprint) }
            if($this.KeepAliveTimeoutSeconds) { $engparams.Add("KeepAliveTimeoutSeconds", $this.KeepAliveTimeoutSeconds) }
            if($this.MaxHeaderSizeBytes) { $engparams.Add("MaxHeaderSizeBytes", $this.MaxHeaderSizeBytes) }
            if($this.MaxHeaderLines) { $engparams.Add("MaxHeaderLines", $this.MaxHeaderLines) }
            if($this.RestListenPort) { $engparams.Add("RestListenPort", $this.RestListenPort) }
            $props = ConfigurePropertiesAndTags($this)
            if ($props.CustomProperties) { $engparams.Add("CustomProperties", $props.CustomProperties)}
            if ($props.Tags) { $engparams.Add("Tags", $props.Tags)}
            Write-Verbose "Update Qlik Proxy: $($this.Node)"
            Update-QlikProxy @engparams
        } else {
            Write-Verbose "Qlik Proxy '$($this.Node)' not found!"
        }
    }

    [Bool] Test () {
        Write-Verbose "Get Qlik Proxy: $($this.Node)"
        $item = Get-QlikProxy -Full -Filter "serverNodeConfiguration.hostName eq '$($this.Node)'"
        if($null -ne $item) {
            if($this.hasProperties($item)) {
                Write-Verbose "Qlik Proxy '$($this.Node)' is in desired state"
                return $true
            } else {
                Write-Verbose "Qlik Proxy '$($this.Node)' is not in desired state"
                return $false
            }
        } else {
            Write-Verbose "Qlik Proxy '$($this.Node)' not found!"
            return $false
        }
    }

    [QlikProxy] Get () {
        Write-Verbose "Get Qlik Proxy: $($this.Node)"
        $item = Get-QlikProxy -Full -Filter "serverNodeConfiguration.hostName eq '$($this.Node)'"
        if($null -ne $item) {
            $this.ListenPort = $item.settings.listenPort
            $this.AllowHttp = $item.settings.allowHttp
            $this.UnencryptedListenPort = $item.settings.unencryptedListenPort
            $this.AuthenticationListenPort = $item.settings.authenticationListenPort
            $this.KerberosAuthentication = $item.settings.kerberosAuthentication
            $this.UnencryptedAuthenticationListenPort = $item.settings.unencryptedAuthenticationListenPort
            $this.SslBrowserCertificateThumbprint = $item.settings.sslBrowserCertificateThumbprint
            $this.KeepAliveTimeoutSeconds = $item.settings.KeepAliveTimeoutSeconds
            $this.MaxHeaderSizeBytes = $item.settings.MaxHeaderSizeBytes
            $this.MaxHeaderLines = $item.settings.MaxHeaderLines
            $this.RestListenPort = $item.settings.RestListenPort
            $cp = @{}
            foreach ($property in $item.customProperties) {
                $cp.Add($property.definition.name, $property.Value)
            }
            $this.CustomProperties = $cp
        }
        return $this
    }

    [bool] hasProperties($item) {
        $props = @(
            'ListenPort',
            'AllowHttp',
            'UnencryptedListenPort',
            'AuthenticationListenPort',
            'KerberosAuthentication',
            'UnencryptedAuthenticationListenPort',
            'SslBrowserCertificateThumbprint',
            'KeepAliveTimeoutSeconds',
            'MaxHeaderSizeBytes',
            'MaxHeaderLines',
            'RestListenPort'
        )
        if( !(CompareProperties $this $item.settings $props ) ) {
            return $false
        }
        if( !(CompareProperties $this $item 'CustomProperties' ) ) {
            return $false
        }
        return $true
    }
}