[powershell]Get the verifier topology from Tufin SecureChange

There is a href in /securechangeworkflow/api/securechange/tickets/$ticket_id/steps for calling the topology map.

Consider this script, supposed the previous script has passed the request successfully, that script passed the ticket id to this script.

Param([string]$ticketID)
#ignore certificate validation
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
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$TUFIN_SC_USERNAME = "admin"
$i=0

$usr = $TUFIN_SC_USERNAME
$pwd = Obfuscate_Password($usr)
$cred = "${usr}:${pwd}"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($cred)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
$headers = @{ Authorization = $basicAuthValue }

try {
  [xml]$response_verifier = Invoke-RestMethod -Uri "https://tufin_address/securechangeworkflow/api/securechange/tickets/$ticketID/steps" -Method Get -Headers $headers

}
catch {
    $err=$_.Exception
    $err.Message
}
$verifier_maps = $response_verifier.steps.step.tasks.task.fields.field.access_request.verifier_result.result.href
foreach($verifier_map in $verifier_maps)
{
    
    Invoke-RestMethod -Uri "$verifier_map/topology_map" -Method Get -Headers $headers -OutFile "map$i.png"
    $i += 1
}
Advertisements
This entry was posted in Powershell, Scripting and tagged , , . Bookmark the permalink.

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 )

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s