Public/Set-IAMCoreConnector.ps1

function Set-IAMCoreConnector {
    [CmdletBinding(SupportsShouldProcess = $true)]
    param (
        [Parameter(Mandatory = $true)]
        [ValidatePattern("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")] # Is a guid connector object id
        [string]$Id,

        [Parameter(Mandatory = $false)]
        [string]$Description,

        [Parameter(Mandatory = $false)]
        [System.Collections.Hashtable] $Configuration = @{},

        [Parameter(Mandatory = $false)]
        [System.Collections.Hashtable] $Secrets = @{}
    )

    $Existing = Get-IAMCoreConnector -Id $Id

    if(!$Existing.Id) {
        throw "IAM Core Connector $Id not found"
    }

    $Existing = $Existing | ConvertTo-Json -Depth 10 | ConvertFrom-Json -Depth 10 -AsHashtable

    if($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("Description")) {
        $Existing.Description = $Description
    }

    if($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("Configuration")) {
        $Existing.Configuration = $Configuration
    }

    if($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("Secrets")) {
        $Existing.Configuration = $Secrets
    }

    if ($PSCmdlet.ShouldProcess("Updating IAM Core connector $Id")) {
        $Body = $Existing | ConvertTo-Json -Depth 10
        $Result = Invoke-RestMethod -Uri "$Script:APIRoot/sync/connectors/$Id" -Headers (Get-IAMCoreHeader) -Method Put -Body $Body -ContentType "application/json"

        if ($Result.IsSuccess) {
            # return $Result.Data
        }
        else {
            throw "Failed to create IAM Core connector: $($Result.ErrorMessage)"
        }
    }
}