From bcdecbdb45fb7c8311381206d05aa7cf19dcea1b Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Wed, 25 Jun 2025 00:09:17 -0400 Subject: [PATCH] Update StackMonkey.ps1 --- StackMonkey.ps1 | 52 +++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/StackMonkey.ps1 b/StackMonkey.ps1 index a01db9d..0134169 100644 --- a/StackMonkey.ps1 +++ b/StackMonkey.ps1 @@ -63,9 +63,15 @@ #> #region ScriptMonkey run silently Entrypoint - [CmdletBinding(DefaultParameterSetName='UI', - SupportsShouldProcess = $true, - ConfirmImpact = 'Medium' + + # ───────────────────────────────────────────────────────────────────────── + # 1) ENTRYPOINT + PARAMETER DECLARATION + # ───────────────────────────────────────────────────────────────────────── + + [CmdletBinding( + DefaultParameterSetName='UI', + SupportsShouldProcess=$true, + ConfirmImpact= 'Medium' )] param( # ───────────────────────────────────────────────────────── @@ -81,18 +87,21 @@ [Parameter(ParameterSetName='Datto')][switch] $SaveCopy ) - # Listening port for HTTP UI -$Port = 8082 + # ───────────────────────────────────────────────────────────────────────── + # 2) GLOBAL SETTINGS & HELPERS + # ───────────────────────────────────────────────────────────────────────── -# Configurable endpoints -$Global:DattoWebhookUrl = 'https://automate.svstools.ca/webhook/svsmspkit' + # Listening port for HTTP UI + $Port = 8082 + + # Configurable endpoints + $Global:DattoWebhookUrl = 'https://automate.svstools.ca/webhook/svsmspkit' #region Get-DattoApiCredentials function Get-DattoApiCredentials { [CmdletBinding()] param ( - [Parameter(Mandatory)] - [string]$Password + [Parameter(Mandatory)][string]$Password ) $headers = @{ "SVSMSPKit" = $Password } try { @@ -110,9 +119,9 @@ function Get-DattoApiCredentials { return $null } } - -#endregion - +# ───────────────────────────────────────────────────────────────────────── +# 3) MAIN LOGIC (Toolkit vs Datto vs UI) +# ───────────────────────────────────────────────────────────────────────── switch ($PSCmdlet.ParameterSetName) { 'Toolkit' { @@ -126,17 +135,16 @@ function Get-DattoApiCredentials { # ──────────────────────────────────────────── # 1) Fetch URL, Key & Secret from n8n webhook - # (this is your lines 415-424) # ──────────────────────────────────────────── # 1) Fetch creds - $resp = Get-DattoApiCredentials -Password $N8nPassword - if (-not $resp) { throw "Could not fetch creds" } + $creds = Get-DattoApiCredentials -Password $N8nPassword + if (-not $creds) { throw "Could not fetch creds" } # 2) Store in globals for everyone else - $Global:ApiUrl = $resp.ApiUrl - $Global:ApiKey = $resp.ApiKey - $Global:ApiSecretKey = $resp.ApiSecretKey + $Global:ApiUrl = $creds.ApiUrl + $Global:ApiKey = $creds.ApiKey + $Global:ApiSecretKey = $creds.ApiSecretKey Write-LogHelper "Fetched Datto API credentials from n8n" Success DattoAuth } @@ -149,7 +157,7 @@ function Get-DattoApiCredentials { # 2) Invoke the existing Install-DattoRMM cmdlet # ──────────────────────────────────────────── - + if ($PSCmdlet.ShouldProcess("Datto site '$SiteName'", "Headless install")) { Install-DattoRMM ` -ApiUrl $Global:ApiUrl ` @@ -160,14 +168,12 @@ function Get-DattoApiCredentials { -PushSiteVars:$PushSiteVars ` -InstallRMM:$InstallRMM ` -SaveCopy:$SaveCopy - - - + } return } - + #endregion ScriptMonkey run silently Entrypoint # STACK = Scripted Tooling for Automated Client Kickoff