Using the Tufin path analysis API with Powershell

Here’s the powershell code.

#Parameters must be declared at the start of the script.
Param(
    [Parameter(Mandatory=$true)][string]$usr,
    [Parameter(Mandatory=$true)][string]$pwd,
    [Parameter(Mandatory=$true)][ipaddress]$src,
    [Parameter(Mandatory=$true)][ipaddress]$dst,
    [Parameter(Mandatory=$false)][string]$svc = 'any'
    )

add-type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    public class TrustAllCertsPolicy : ICertificatePolicy {
        public bool CheckValidationResult(
            ServicePoint srvPoint, X509Certificate certificate,
            WebRequest request, int certificateProblem) {
            return true;
        }
    }
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

$cred = "${usr}:${pwd}"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($cred)

#header has to be base64 encoding
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
$headers = @{ Authorization = $basicAuthValue }
$date = Get-Date

try {
    Invoke-RestMethod -Uri "https://tufin_hostname/securetrack/api/topology/path_image?src=$($src)&dst=$($dst)&service=$($svc)" -Method Get -ContentType 'application/xml' -Headers $headers -OutFile "$env:USERPROFILE\path_image_$($date.ToString('ddMMyy-HHmm')).png"
} catch {
    $Error[0].ErrorDetails.Message
    }
Advertisement

2 thoughts on “Using the Tufin path analysis API with Powershell

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s