Skip to content

Commit

Permalink
Testing for Get-QlikSession (#71)
Browse files Browse the repository at this point in the history
* Add Pester tests

* Add CI job to publish github release

* fix job dependencies

* fix output paths

* use workspace instead of artifact store

* publish only in master branch

* Convert test results to JUnit so CircleCI can process

* store test results as artifacts

* Added pre-release checks

* Update to function Get-QlikSession (#70)
  • Loading branch information
ahaydon authored Dec 6, 2018
1 parent 3686ad9 commit dd591dd
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 30 deletions.
53 changes: 53 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,53 @@ jobs:
paths:
- ./*

pre-release-checks:
docker:
- image: microsoft/powershell:ubuntu-16.04
command: pwsh
steps:
- checkout
- run:
name: Check module version is newer than latest published to PowerShell Gallery
command: |
pwsh -Command '
if ((Test-ModuleManifest -Path ./Qlik-Cli.psd1).Version -le (Find-Module -Name Qlik-Cli).Version) {
Write-Error "Module version already exists"
}'
- run:
name: Check module version is newer than latest published to GitHub releases
command: |
pwsh -Command '
$password = ConvertTo-SecureString -String $env:GITHUB_TOKEN -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential("ahaydon", $password)
$release = Invoke-RestMethod `
-Method Get `
-Uri "https://api.github.com/repos/ahaydon/qlik-cli/releases/latest" `
-Credential $credential
if ((Test-ModuleManifest -Path ./Qlik-Cli.psd1).Version -le [System.Version]$release.tag_name) {
Write-Error "Module version must be newer than last published version" -ErrorAction Stop
}
$version = (Test-ModuleManifest -Path ./Qlik-Cli.psd1).Version
$release = $null
$null = try {
$release = Invoke-RestMethod `
-Method Get `
-Uri "https://api.github.com/repos/ahaydon/qlik-cli/releases/tags/$version" `
-Credential $credential `
-ErrorAction SilentlyContinue
} catch [System.Net.Http.HttpRequestException] {
if ($_.Exception.Response.StatusCode -ne "NotFound") {
Throw $_
}
$Error | Out-Null #clear the error so we exit cleanly
}
if ($release) {
Write-Error "Module version already exists" -ErrorAction Stop
}'
publish-powershell-gallery:
docker:
- image: microsoft/powershell:ubuntu-16.04
Expand Down Expand Up @@ -115,6 +162,12 @@ workflows:
test-and-deploy:
jobs:
- test
- pre-release-checks:
requires:
- test
filters:
branches:
only: testing
- publish-powershell-gallery:
requires:
- test
Expand Down
2 changes: 1 addition & 1 deletion Qlik-Cli.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'Qlik-Cli.psm1'

# Version number of this module.
ModuleVersion = '1.13.3'
ModuleVersion = '1.13.4'

# ID used to uniquely identify this module
GUID = '730275fa-35db-42e2-9400-eac7e3043ea4'
Expand Down
105 changes: 76 additions & 29 deletions resources/session.ps1
Original file line number Diff line number Diff line change
@@ -1,31 +1,78 @@
function Get-QlikSession {
[CmdletBinding(DefaultParameterSetName="User")]
param (
[parameter(ParameterSetName="Id",Mandatory=$true,Position=0,ValueFromPipelinebyPropertyName=$true)]
[string]$id,
<#
.SYNOPSIS
Gets the current User Sessions on the specified Proxy
.DESCRIPTION
This returns a session object with the corresponding SessionId.
https://help.qlik.com/en-US/sense-developer/November2018/apis/ProxyAPI/OpenAPI_Main.generated.html
.PARAMETER id
This is to return the Session Object for a Specific Session ID
.PARAMETER userDirectory
The userDirecotry paramater is used as part of identitying the users sessions, must be used with userID
.PARAMETER userId
The userID paramater is used as part of identitying the users sessions, must be used with userDirecotry
.PARAMETER virtualProxyPrefix
Specifies the Virtual Proxy to get the sessions from
.EXAMPLE
PS C:\> Get-QlikSession
.EXAMPLE
PS C:\> Get-QlikSession -virtualProxyPrefix "/ProxyX1"
.EXAMPLE
PS C:\> Get-QlikSession -userDirectory Domain -userId Marc
.EXAMPLE
PS C:\> Get-QlikSession -virtualProxyPrefix "/ProxyX1" -userDirectory Domain -userId Marc
[parameter(ParameterSetName="User",Mandatory=$true,Position=0,ValueFromPipelinebyPropertyName=$true)]
[string]$userDirectory,
.NOTES
Additional information about the Session API can be found
https://help.qlik.com/en-US/sense-developer/November2018/apis/ProxyAPI/OpenAPI_Main.generated.html#19b1cf4a56294022A146C978a46f3a59
https://help.qlik.com/en-US/sense-developer/November2018/Subsystems/ProxyServiceAPI/Content/Sense_ProxyServiceAPI/ProxyServiceAPI-Session-Module-API-Session-Get.htm
[parameter(ParameterSetName="User",Mandatory=$true,Position=1,ValueFromPipelinebyPropertyName=$true)]
[string]$userId,

[alias("vp")]
[string]$virtualProxyPrefix,

[switch]$raw
)

PROCESS {
$proxy = Get-QlikProxy local
$prefix = "https://$($proxy.serverNodeConfiguration.hostName):$($proxy.settings.restListenPort)/qps"
if ($virtualProxyPrefix) { $prefix += "/$virtualProxyPrefix" }
if ($id) {
$path = "$prefix/session/$id"
} else {
$path = "$prefix/user/$userDirectory/$userId"
}
If( $raw ) { $rawOutput = $true }
return Invoke-QlikGet $path
}
}
#>
function Get-QlikSession
{
[CmdletBinding(DefaultParameterSetName = 'Default')]
param
(
[Parameter(ParameterSetName = 'Id',
Mandatory = $true,
ValueFromPipelineByPropertyName = $true,
Position = 0)]
[string]$id,
[Parameter(ParameterSetName = 'User',
Mandatory = $true,
ValueFromPipelineByPropertyName = $true,
Position = 0)]
[string]$userDirectory,
[Parameter(ParameterSetName = 'User',
Mandatory = $true,
ValueFromPipelineByPropertyName = $true,
Position = 1)]
[string]$userId,
[Alias('vp')]
[string]$virtualProxyPrefix
)

PROCESS
{
$proxy = Get-QlikProxy local
$prefix = "https://$($proxy.serverNodeConfiguration.hostName):$($proxy.settings.restListenPort)/qps"
if ($PSBoundParameters.ContainsKey("virtualProxyPrefix")) { $prefix = "$($prefix)/$virtualProxyPrefix" }
switch ($PSCmdlet.ParameterSetName)
{
USER{ $path = "$prefix/user/$userDirectory/$userId" }
ID{ $path = "$prefix/session/$id" }
Default { $path = "$prefix/session" }
}
try
{
$response = Invoke-QlikGet $path
}
catch { $response = $null }
return $response
}
}

0 comments on commit dd591dd

Please sign in to comment.