Public/Get-ConnectorConfiguration.ps1

<#
.SYNOPSIS
    Retrieves the connector configuration from the Fortytwo IAM Core Connector API.

.DESCRIPTION
    Fetches the connector's configuration data from the API and caches it in the module session.
    Subsequent calls return the cached value unless the -Update switch is specified.
    Requires an active connection established by Connect-Connector.

.PARAMETER Update
    If set, bypasses the cache and fetches a fresh configuration from the API.

.OUTPUTS
    System.Collections.Hashtable

.EXAMPLE
    $config = Get-ConnectorConfiguration

.EXAMPLE
    $config = Get-ConnectorConfiguration -Update
#>

function Get-ConnectorConfiguration {
    [CmdletBinding()]
    [OutputType([System.Collections.Hashtable])]
    param (
        [Switch] $Update
    )

    if (-not $Script:APIRoot -or -not $Script:AccessTokenProfile) {
        throw "Connector not connected. Please run Connect-Connector first."
    }

    if ($Script:ConnectorConfiguration -and -not $Update) {
        Write-Verbose "Using cached connector configuration"
        return $Script:ConnectorConfiguration
    }

    Write-Verbose "Fetching connector configuration from API"
    $result = Invoke-RestMethod -Uri "$($Script:APIRoot)data/configuration" -Headers (Get-EntraIDAccessTokenHeader -Profile $Script:AccessTokenProfile) -Method Get -SkipHttpErrorCheck -StatusCodeVariable StatusCode
    
    if (-not $result.IsSuccess) {
        throw "Failed to retrieve connector configuration. Status code: $StatusCode. Response: $($result)"
    }

    $Script:ConnectorConfiguration = $result.Data
    return $Script:ConnectorConfiguration
}