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
    }
Advertisements
This entry was posted in Powershell and tagged , , . Bookmark the permalink.

One Response to Using the Tufin path analysis API with Powershell

  1. David says:

    Wow… I was brainstorming on this but you were thinking ahead of me.
    Thanks for making my task easy..

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s