functions/Add-CheckmarxConnector.ps1

<#
.SYNOPSIS
  
Create a single Checkmarx connector
  
.DESCRIPTION
Adds a single Checkmarx connector using the tool connector config API endpoints
  
.EXAMPLE
Add-CheckmarxConnector "My Code Dx Project" "Checkmarx Connector 1" "My Checkmarx Project" https://cxprivatecloud.checkmarx.net/ username@email.com mypw1234 "15:00" $true
 
Output (entry ID)
 
  
#>


Function Add-CheckmarxConnector
{
    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true)]
        [string]$ProjectName,
        [Parameter(Mandatory=$true)]
        [string]$NewConnectorName,
        [Parameter(Mandatory=$true)]
        [string]$ToolProjectName,
        [Parameter(Mandatory=$true)]
        [string]$HostURL,
        [Parameter(Mandatory=$true)]
        [string]$UserName,
        [Parameter(Mandatory=$true)]
        [string]$Password,
        [Parameter(Mandatory=$false)]
        [string]$RefreshTime,
        [Parameter(Mandatory=$false)]
        [boolean]$IncludeOSA
    )

    If($IncludeOSA -eq $null) {
        $IncludeOSA = $false
    }
    
    # Get the Code Dx project ID from the name
    $projects = Get-Projects
    $ProjectHash = @{}
    $projects.projects | ForEach-Object {
        $ProjectHash[$_.name] = $_.id
    }
    $ProjectID = $ProjectHash.$ProjectName
    
    # Create a blank tool connector
    $ConnectorInfo = Add-BlankConnector $ProjectID Checkmarx $NewConnectorName
    $ConnectorID = $ConnectorInfo.id
    
    
    # Get the Checkmarx tool project ID
    $ToolProjectID = Get-ToolProject "selected_project" $ToolProjectName $ConnectorID $HostURL $UserName $Password

    # Update the blank tool connector with the proper configuration info
    $uri = $CDXSERVER + "/x/tool-connector-config/values/" + $ConnectorID

    If($RefreshTime -ne "") {
        $RefreshInterval = @{ daily = $RefreshTime }
    }else {
        $RefreshInterval = $false
    }
    
    $body = Convertto-Json @{
        include_osa_results = $IncludeOSA
        selected_project = $ToolProjectID
        "auto-refresh-interval" = $RefreshInterval
        host_url = $HostURL
        username = $UserName
        password = $Password
    }
    $CreateCheckmarx = Invoke-RestMethod -Uri $uri -Method Put -Body $body -Headers $headers -ContentType "application/json" 
    Write-Verbose ( $CreateCheckmarx | Format-Table | Out-String )

}