Skip to content

Commit

Permalink
Merge pull request #32 from CxTyler/patch-1
Browse files Browse the repository at this point in the history
Update cxInsight_9_0.ps1
  • Loading branch information
kmcdon83 authored Mar 10, 2021
2 parents 8d8cdc5 + fb9de10 commit 5edfdd7
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions engineering-health-check/cxInsight_9_0.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ This script will collect Scan Information that includes data about: Projects, Pr
.NOTES
Author: Checkmarx
Date: April 13, 2020
Updated: March 9, 2021
#>

param(
[Parameter(Mandatory=$true)]
[String]$cx_sast_server,
[int]$day_span = 90,
[String]$start_date = ((Get-Date).AddDays(-$day_span).ToString("yyyy-MM-dd")),
[String]$end_date = (Get-Date -format "yyyy-MM-dd")
[String]$end_date = (Get-Date -format "yyyy-MM-dd"),
[Parameter(Mandatory=$False)]
[switch]
$bypassProxy
)

###### Do Not Change The Following Configs ######
Expand All @@ -38,7 +42,6 @@ $clientSecret = "014DF517-39D1-4453-B7B3-9930C563627C"

$cred = Get-Credential -Credential $null
$cxUsername = $cred.UserName
$pscred = $cred.GetNetworkCredential()
$cxPassword = $cred.GetNetworkCredential().password

$serverRestEndpoint = $cx_sast_server + "/cxrestapi/"
Expand All @@ -51,24 +54,27 @@ function getOAuth2Token() {
client_id = $clientId
client_secret = $clientSecret
}
Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription

try {
$response = Invoke-RestMethod -uri "${serverRestEndpoint}auth/identity/connect/token" -method post -body $body -contenttype 'application/x-www-form-urlencoded'
if ($bypassProxy) {
$response = Invoke-RestMethod -noProxy -uri "${serverRestEndpoint}auth/identity/connect/token" -method post -body $body -contenttype 'application/x-www-form-urlencoded'
}
else {
$response = Invoke-RestMethod -uri "${serverRestEndpoint}auth/identity/connect/token" -method post -body $body -contenttype 'application/x-www-form-urlencoded'
}
}
catch {
Write-Host "Exception:" $_
Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
$Url = "${cx_sast_server}/cxwebinterface/odata/v1/Scans?`$select=Id,ProjectName,OwningTeamId,TeamName,ProductVersion,EngineServerId,Origin,PresetName,ScanRequestedOn,QueuedOn,EngineStartedOn,EngineFinishedOn,ScanCompletedOn,ScanDuration,FileCount,LOC,FailedLOC,TotalVulnerabilities,High,Medium,Low,Info,IsIncremental,IsLocked,IsPublic&`$expand=ScannedLanguages(`$select=LanguageName)&`$filter=ScanRequestedOn%20gt%20${start_date}Z%20and%20ScanRequestedOn%20lt%20${end_date}z"
Write-Host $Url
Read-Host -Prompt "An Error has prevented this script from being successful. Press paste the above Odata query in your browser..."

throw "Could not authenticate"
Write-Host "Unable to retrieve Checkmarx AC Token"
exit(-1)
}

return $response.token_type + " " + $response.access_token
}

Write-Host "Running Script on Version " (get-host).Version
$token = getOAuth2Token

function getOdata() {
Expand All @@ -77,15 +83,21 @@ function getOdata() {
Authorization = $token
}
try {
$response = Invoke-RestMethod -uri "$Url" -method get -headers $headers -OutFile "data.txt"
if ($bypassProxy) {
$response = Invoke-RestMethod -noProxy -uri "$Url" -method get -headers $headers -OutFile "data.txt"
}
else {
$response = Invoke-RestMethod -uri "$Url" -method get -headers $headers -OutFile "data.txt"
}
return $response
}
catch {
Write-Host "Exception:" $_
Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
Write-Host $Url
Read-Host -Prompt "An Error has prevented this script from being successful. Press paste the above Odata query in your browser..."
throw "Cannot Get OData"
Write-Host "An Error has prevented this script from collecting Odata."
exit(-1)
}
}

Expand All @@ -96,6 +108,7 @@ try
}
catch
{
Write-Host "Exception:" $_
Write-Error $_.Exception.ToString()
Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
Expand Down

0 comments on commit 5edfdd7

Please sign in to comment.