Skip to content

Commit bc926c3

Browse files
committed
Added support for endpoint functions.
1 parent a1fe8d2 commit bc926c3

3 files changed

Lines changed: 69 additions & 6 deletions

File tree

Private/New-ZorusQuery.ps1

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,49 @@ function New-ZorusQuery {
2727
catch {
2828
$Errorcode=$_.Exception.Response.statuscode.Value__
2929
}
30+
$CurrentVerbose=$VerbosePreference
31+
$VerbosePreference='Continue'
3032
switch ($Errorcode) {
3133
200 {
3234
# Everything successful. Exit Loop.
3335
$retry=$false
3436
}
37+
202 {
38+
# Request was accepted. Exit Loop.
39+
$retry=$false
40+
}
3541
401 {
3642
throw "401 : Unauthorized. Check API key."
3743
}
44+
404 {
45+
# Not found
46+
throw "404 : Not Found."
47+
}
3848
406 {
3949
throw "406 : Invalid Query. Check request body."
4050
}
4151
409 {
42-
# This is a conflict status returned when creating deployment tokens with name already used.
43-
throw "409 : Conflict. An existing entry with that name already exists."
52+
# Minimize the impact of setting an endpoint to the same state it currently has.
53+
if ($URI -match "/api/endpoints/"){
54+
write-verbose "The endpoint is already in the selected state."
55+
}
56+
elseif ($URI -match "/api/deployment-token"){
57+
# This is a conflict status returned when creating deployment tokens with name already used.
58+
throw "409: A deployment token with that name already exists."
59+
}
60+
else {
61+
# Any other use case of the 409 error response that isn't otherwise known.
62+
throw "409 : Conflict."
63+
}
64+
4465
}
4566
default {
4667
write-host "StatusCode $Errorcode recieved. Waiting 5 seconds and retrying request." -ForegroundColor Yellow
4768
$retry=$true
4869
start-sleep 5
4970
}
5071
}
72+
$VerbosePreference=$CurrentVerbose
5173
if ($retry){
5274
$retrycount++
5375
}
@@ -57,5 +79,7 @@ function New-ZorusQuery {
5779
}
5880
}
5981
until ($retry -eq $false)
60-
$Response.content | ConvertFrom-Json
82+
# Moved this to a try/catch in order to work with the verbose only errors for endpoint state changes.
83+
try {$Response.content | ConvertFrom-Json -erroraction stop}
84+
catch {$response}
6185
}

Public/Set-ZorusEndpoint.ps1

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function Set-ZorusEndpoint {
2+
[CmdletBinding()]
3+
param (
4+
[Parameter(Mandatory=$true)]$Uuid,
5+
[Parameter(Mandatory=$false,ParameterSetName="Enable")][switch]$Enable,
6+
[Parameter(Mandatory=$false,ParameterSetName="Disable")][switch]$Disable,
7+
[Parameter(Mandatory=$false,ParameterSetName="RestartService")][switch]$RestartService,
8+
[Parameter(Mandatory=$false,ParameterSetName="Release")][switch]$Release,
9+
[Parameter(Mandatory=$false,ParameterSetName="Isolate")][switch]$Isolate,
10+
[Parameter(Mandatory=$true,ParameterSetName="Isolate")]$Reason,
11+
[Parameter(Mandatory=$true,ParameterSetName="Isolate")]$Passphrase
12+
)
13+
14+
$body=@{}
15+
if (!([string]::IsNullOrWhiteSpace($uuid))){
16+
$body.add('endpointUuid',$uuid)
17+
}
18+
if ($Enable){
19+
$URI="/api/endpoints/$uuid/actions/enable"
20+
}
21+
if ($Disable){
22+
$URI="/api/endpoints/$uuid/actions/disable"
23+
}
24+
if ($RestartService){
25+
$URI="/api/endpoints/$uuid/actions/restart-service"
26+
}
27+
if ($Release){
28+
$URI="/api/endpoints/$uuid/actions/release"
29+
}
30+
if ($Isolate){
31+
$URI="/api/endpoints/$uuid/actions/isolate"
32+
$body.add('reason',$Reason)
33+
$body.add('passphrase',$Passphrase)
34+
}
35+
$data=New-ZorusQuery -method POST -body $Body -uri $URI
36+
37+
$data
38+
}

ZorusAPI.psd1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
RootModule = 'ZorusAPI.psm1'
66

77
# Version number of this module.
8-
ModuleVersion = '0.6'
8+
ModuleVersion = '0.7'
99

1010
# Supported PSEditions
1111
# CompatiblePSEditions = @()
@@ -20,7 +20,7 @@
2020
CompanyName = 'Michael McCool'
2121

2222
# Copyright statement for this module
23-
Copyright = '(c)2024 Michael McCool'
23+
Copyright = '(c)2025 Michael McCool'
2424

2525
# Description of the functionality provided by this module
2626
Description = 'This module allows you to connect to the Zorus API via PowerShell.'
@@ -70,7 +70,8 @@
7070
'Get-ZorusPolicy',
7171
'Get-ZorusGroup',
7272
'Get-ZorusEndpoint',
73-
'New-ZorusDeploymentToken'
73+
'New-ZorusDeploymentToken',
74+
'Set-ZorusEndpoint'
7475
)
7576

7677
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.

0 commit comments

Comments
 (0)