-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathKNClasses.ps1
26 lines (25 loc) · 924 Bytes
/
KNClasses.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
<#
This script is called from Keenetic.psm1 as `ScriptsToProcess = @('KNClasses.ps1')`
That's the way to expose public classes from module.
KNSession class:
- Stores session parameters,
- Can validate session.
#>
class KNSession {
# Uri to connect, like http://192.168.0.1 or https://my.keentic.pro
[System.Uri]$Target
# Username and password. User must have 'http' tag.
[pscredential]$Credential
# Session variable to store session cookies.
[Microsoft.PowerShell.Commands.WebRequestSession]$WebSession
# Can probe session for expiration.
[bool]IsValid() {
try {
Write-Verbose "KNSession.IsValid(): probe $($this.Target)auth to find out session status."
Invoke-WebRequest -Uri "$($this.Target)auth" -WebSession $this.WebSession -ContentType 'application/json' | Out-Null
return $true
} catch {
return $false
}
}
}