From 8a2787b81980e43d2837a2c339c0b90550125878 Mon Sep 17 00:00:00 2001 From: Ceej - The MSP Automator <68078971+cscaminaci@users.noreply.github.com> Date: Wed, 10 May 2023 09:44:08 -0400 Subject: [PATCH 1/2] Add Keyvault Support The Connect-HaloAPI function in this PowerShell module is used to establish a connection to a Halo instance. This function can use either client credentials (ClientId and ClientSecret) or Managed Identity or Service Principal (when using Azure Key Vault) for authentication. The function can also save the credentials to Azure Key Vault for future use. Parameters URL: The URL of the Halo instance to connect to. ClientID: The Client ID for the application configured in Halo. ClientSecret: The Client Secret for the application configured in Halo. Scopes: The API scopes to request. If this isn't passed, the scope is assumed to be "all". Pass a string or array of strings. Limited by the scopes granted to the application in Halo. Tenant: The tenant name required for hosted Halo instances. AdditionalHeaders: Hashtable containing additional parameters to be sent with each request. UseKeyVault: If $true, retrieve parameters from Azure Key Vault. If $false, use parameters passed to function. SecretName: The name of the secret in the Azure Key Vault. VaultName: The name of the Azure Key Vault. SaveToKeyVault: If $true, save parameters to Azure Key Vault. If $false or not specified, do not save parameters. Identity: The object ID of the Managed Identity or Service Principal. Usage To establish a connection to a Halo instance, call the Connect-HaloAPI function with the required parameters. For example: Connect-HaloAPI -URL "https://example.halopsa.com" -ClientId "c9534241-dde9-4d04-9d45-32b1fbff22ed" -ClientSecret "14c0c9af-2db1-48ab-b29c-51975df4afa2-739e4ef2-9aad-4fe9-b486-794feca48ea8" -Scopes "all" -Tenant "demo" -VaultName "MyVault" -SaveToKeyVault $true To use the Azure Key Vault for storing and retrieving secrets, you should use the UseKeyVault and SaveToKeyVault parameters. Additionally, you can use a Managed Identity or Service Principal for authentication with the Identity parameter. For example: Connect-HaloAPI -URL "https://example.halopsa.com" -VaultName "MyVault" -UseKeyVault $true -Identity "your_managed_identity_or_service_principal_id" Note: Replace "your_managed_identity_or_service_principal_id" with your actual Managed Identity or Service Principal ID. In this case, the function will connect to the Azure Key Vault with the provided Managed Identity or Service Principal and retrieve the ClientId, ClientSecret, and URL. If SaveToKeyVault is $true, the function will also save these parameters to the Azure Key Vault for future use. --- Public/Connect-HaloAPI.ps1 | 307 ++++++++++++++++++++++++++++++++++++- 1 file changed, 300 insertions(+), 7 deletions(-) diff --git a/Public/Connect-HaloAPI.ps1 b/Public/Connect-HaloAPI.ps1 index dea8844..9c08d99 100644 --- a/Public/Connect-HaloAPI.ps1 +++ b/Public/Connect-HaloAPI.ps1 @@ -1,7 +1,8 @@ -using module ..\Classes\HaloLookup.psm1 +using module ..\Classes\HaloLookup.psm1 using module ..\Classes\Completers\HaloAuthScopesCompleter.psm1 using module ..\Classes\Validators\HaloAuthScopesValidator.psm1 #Requires -Version 7 + function Connect-HaloAPI { <# .SYNOPSIS @@ -9,10 +10,8 @@ function Connect-HaloAPI { .DESCRIPTION Creates a new connection to a Halo instance and stores this in a PowerShell Session. .EXAMPLE - PS C:\> Connect-HaloAPI -URL "https://example.halopsa.com" -ClientId "c9534241-dde9-4d04-9d45-32b1fbff22ed" -ClientSecret "14c0c9af-2db1-48ab-b29c-51975df4afa2-739e4ef2-9aad-4fe9-b486-794feca48ea8" -Scopes "all" -Tenant "demo" - This logs into Halo using the Client Credentials authorisation flow. - .OUTPUTS - Sets two script-scoped variables to hold connection and authentication information. + PS C:\> Connect-HaloAPI -URL "https://example.halopsa.com" -ClientId "c9534241-dde9-4d04-9d45-32b1fbff22ed" -ClientSecret "14c0c9af-2db1-48ab-b29c-51975df4afa2-739e4ef2-9aad-4fe9-b486-794feca48ea8" -Scopes "all" -Tenant "demo" -VaultName "MyVault" -SaveToKeyVault $true + This logs into Halo using the Client Credentials authorisation flow and saves the secrets to the specified Azure Key Vault for future use. #> [CmdletBinding( DefaultParameterSetName = 'Client Credentials' @@ -48,9 +47,70 @@ function Connect-HaloAPI { )] [String]$Tenant, # Hashtable containing additional parameters to be sent with each request. - [Hashtable]$AdditionalHeaders + [Hashtable]$AdditionalHeaders, + # If $true, retrieve parameters from Azure Key Vault. If $false, use parameters passed to function. + [Parameter( + ParameterSetName = 'Client Credentials' + )] + [bool]$UseKeyVault = $False, + # The name of the secret in the Azure Key Vault. + [Parameter( + ParameterSetName = 'Client Credentials', + Mandatory = $False + )] + [String]$SecretName, + # The name of the Azure Key Vault. + [Parameter( + ParameterSetName = 'Client Credentials', + Mandatory = $False + )] + [String]$VaultName, + # If $true, save parameters to Azure Key Vault. If $false or not specified, do not save parameters. + [Parameter( + ParameterSetName = 'Client Credentials' + )] + [bool]$SaveToKeyVault = $False, + # The object ID of the Managed Identity or Service Principal. + [Parameter( + ParameterSetName = 'Client Credentials', + Mandatory = $False + )] + [String]$Identity ) - # Convert scopes to space separated string if it's an array. + + + if ($UseKeyVault) { + # If the Identity parameter is specified, use it to connect. + # Otherwise, fall back to interactive login. + if ($Identity) { + Connect-AzAccount -Identity + } + else { + Connect-AzAccount + } + $URL = (Get-AzKeyVaultSecret -VaultName $VaultName -Name "${SecretName}_URL").SecretValueText + $ClientID = (Get-AzKeyVaultSecret -VaultName $VaultName -Name "${SecretName}_ClientID").SecretValueText + $ClientSecret = (Get-AzKeyVaultSecret -VaultName $VaultName -Name "${SecretName}_ClientSecret").SecretValueText + } elseif ($SaveToKeyVault) { + # Save the URL, ClientID, and ClientSecret to the Azure Key Vault. + if ($Identity) { + Connect-AzAccount -Identity + } + else { + Connect-AzAccount + } + $URL_Secret = ConvertTo-SecureString -String $URL -AsPlainText -Force + Set-AzKeyVaultSecret -VaultName $VaultName -Name "${SecretName}_URL" -SecretValue $URL_Secret + + $ClientID_Secret = ConvertTo-SecureString -String $ClientID -AsPlainText -Force + Set-AzKeyVaultSecret -VaultName $VaultName -Name "${SecretName}_ClientID" -SecretValue $ClientID_Secret + + $ClientSecret_Secret = ConvertTo-SecureString -String $ClientSecret -AsPlainText -Force + Set-AzKeyVaultSecret -VaultName $VaultName -Name "${SecretName}_ClientSecret" -SecretValue $ClientSecret_Secret + } + + + # Convert scopes to space separated string if it's an array. if ($Scopes -is [system.array]) { $AuthScopes = $Scopes -Join ' ' } else { @@ -191,3 +251,236 @@ function Connect-HaloAPI { New-HaloError -ModuleMessage ('Retried auth request {0} times, request unsuccessful.' -f $Retries) } } +# SIG # Begin signature block +# MIIrMAYJKoZIhvcNAQcCoIIrITCCKx0CAQExDzANBglghkgBZQMEAgEFADB5Bgor +# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG +# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCCPERVs3c7cE1JR +# LxUPY7YsZmYFTUImrqAa/mKf2sEScKCCJFUwggQyMIIDGqADAgECAgEBMA0GCSqG +# SIb3DQEBBQUAMHsxCzAJBgNVBAYTAkdCMRswGQYDVQQIDBJHcmVhdGVyIE1hbmNo +# ZXN0ZXIxEDAOBgNVBAcMB1NhbGZvcmQxGjAYBgNVBAoMEUNvbW9kbyBDQSBMaW1p +# dGVkMSEwHwYDVQQDDBhBQUEgQ2VydGlmaWNhdGUgU2VydmljZXMwHhcNMDQwMTAx +# MDAwMDAwWhcNMjgxMjMxMjM1OTU5WjB7MQswCQYDVQQGEwJHQjEbMBkGA1UECAwS +# R3JlYXRlciBNYW5jaGVzdGVyMRAwDgYDVQQHDAdTYWxmb3JkMRowGAYDVQQKDBFD +# b21vZG8gQ0EgTGltaXRlZDEhMB8GA1UEAwwYQUFBIENlcnRpZmljYXRlIFNlcnZp +# Y2VzMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvkCd9G7h6naHHE1F +# RI6+RsiDBp3BKv4YH47kAvrzq11QihYxC5oG0MVwIs1JLVRjzLZuaEYLU+rLTCTA +# vHJO6vEVrvRUmhIKw3qyM2Di2olV8yJY897cz++DhqKMlE+faPKYkEaEJ8d2v+PM +# NSyLXgdkZYLASLCokflhn3YgUKiRx2a163hiA1bwihoT6jGjHqCZ/Tj29icyWG8H +# 9Wu4+xQrr7eqzNZjX3OM2gWZqDioyxd4NlGs6Z70eDqNzw/ZQuKYDKsvnw4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vxHfW+1D7VzMwTKuMGV/pnxNU5hBT2r8tkOvsEMzRgTA8ZH +# 6XFg58rAhrM+Omzi37HUTFO2UJnRuGYgNzCwo+n+Q9geI/ErKK+QZB0aiXdB3NG1 +# 5uHkmYscUTd1145O59N/mG9umGFhcnxE4eqzDRBm1rlVsOTQ9HBIg0MNX1KIsHKj +# iN3t5wPaGAiAA7IVffZdjC5CQ4t0hZ2ITVOFuRNSPVV9rQ+IJrRDatz9/tBijSuV +# I85mmtmoHUwXizdwxUJD+aCd1GanCkXGPl1xDtHyN8igygo39Qwt1JaIh98YtAle +# Gf5BAxXgBQWQvd9hp9YHC+rx+n9NRDARYbGz8UIdvIGMau9fqABvqIxLbcZ40NV2 +# pN+CeZuR5iEp+3AEe2Wu2r+QO1M= +# SIG # End signature block From 54c87d4a3d3575147d6cfb9da798ce4d5919825f Mon Sep 17 00:00:00 2001 From: Christopher Scaminaci Date: Fri, 7 Jul 2023 22:41:00 -0400 Subject: [PATCH 2/2] Outcome Support New-HaloOutcome and Get-HaloOutcome support the ticket actions /Outcome (TOutcome) endpoint to retrieve and create ticket actions. --- HaloAPI.psd1 | 6 ++-- Public/Get/Get-HaloOutcome.ps1 | 63 ++++++++++++++++++++++++++++++++++ Public/New/New-HaloOutcome.ps1 | 17 +++++++++ 3 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 Public/Get/Get-HaloOutcome.ps1 create mode 100644 Public/New/New-HaloOutcome.ps1 diff --git a/HaloAPI.psd1 b/HaloAPI.psd1 index cc55123..a666494 100644 --- a/HaloAPI.psd1 +++ b/HaloAPI.psd1 @@ -12,7 +12,7 @@ RootModule = '.\HaloAPI.psm1' # Version number of this module. - ModuleVersion = '1.14.0' + ModuleVersion = '1.14.1' # Supported PSEditions # CompatiblePSEditions = @() @@ -226,7 +226,9 @@ 'Set-HaloUser', 'Set-HaloWorkday', 'New-HaloTab', - 'Get-HaloTabs' + 'Get-HaloTabs', + 'Get-HaloOutcome', + 'New-HaloOutcome' ) diff --git a/Public/Get/Get-HaloOutcome.ps1 b/Public/Get/Get-HaloOutcome.ps1 new file mode 100644 index 0000000..5140572 --- /dev/null +++ b/Public/Get/Get-HaloOutcome.ps1 @@ -0,0 +1,63 @@ +# Get-HaloOutcome.ps1 +function Get-HaloOutcome { + [CmdletBinding( DefaultParameterSetName = 'Multi' )] + [OutputType([Object])] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '', Justification = 'Uses dynamic parameter parsing.')] + Param( + [Parameter( ParameterSetName = 'Single', Mandatory = $True )] + [int64]$OutcomeID, + [Parameter( ParameterSetName = 'Multi' )] + [int64]$Count, + [Parameter( ParameterSetName = 'Multi' )] + [Alias('pageinate')] + [switch]$Paginate, + [Parameter( ParameterSetName = 'Multi' )] + [Alias('page_size')] + [int32]$PageSize, + [Parameter( ParameterSetName = 'Multi' )] + [Alias('page_no')] + [int32]$PageNo, + [Parameter( ParameterSetName = 'Multi' )] + [string]$Order, + [Parameter( ParameterSetName = 'Multi' )] + [switch]$OrderDesc, + [Parameter( ParameterSetName = 'Single' )] + [switch]$IncludeDetails + ) + Invoke-HaloPreFlightCheck + $CommandName = $MyInvocation.MyCommand.Name + $Parameters = (Get-Command -Name $CommandName).Parameters + + if ($OutcomeID) { + $Parameters.Remove('OutcomeID') | Out-Null + } + try { + if ($OutcomeID) { + Write-Verbose "Running in single-item mode because '-OutcomeID' was provided." + $QSCollection = New-HaloQuery -CommandName $CommandName -Parameters $Parameters + $Resource = "api/Outcome/$($OutcomeID)" + $RequestParams = @{ + Method = 'GET' + Resource = $Resource + AutoPaginateOff = $True + QSCollection = $QSCollection + ResourceType = 'Outcome' + } + } else { + Write-Verbose 'Running in multi-item mode.' + $QSCollection = New-HaloQuery -CommandName $CommandName -Parameters $Parameters -IsMulti + $Resource = 'api/Outcome' + $RequestParams = @{ + Method = 'GET' + Resource = $Resource + AutoPaginateOff = $Paginate + QSCollection = $QSCollection + ResourceType = 'Outcome' + } + } + $OutcomeResults = New-HaloGETRequest @RequestParams + Return $OutcomeResults + } catch { + New-HaloError -ErrorRecord $_ + } +} diff --git a/Public/New/New-HaloOutcome.ps1 b/Public/New/New-HaloOutcome.ps1 new file mode 100644 index 0000000..3df3768 --- /dev/null +++ b/Public/New/New-HaloOutcome.ps1 @@ -0,0 +1,17 @@ +# New-HaloOutcome.ps1 +Function New-HaloOutcome { + [CmdletBinding( SupportsShouldProcess = $True )] + [OutputType([Object[]])] + Param ( + [Parameter( Mandatory = $True )] + [Object[]]$Outcome + ) + Invoke-HaloPreFlightCheck + try { + if ($PSCmdlet.ShouldProcess($Outcome -is [Array] ? 'Outcomes' : 'Outcome', 'Create')) { + New-HaloPOSTRequest -Object $Outcome -Endpoint 'Outcome' + } + } catch { + New-HaloError -ErrorRecord $_ + } +}