codedx.psm1

#CodeDX Integration module

<#
.SYNOPSIS
Used to interact with Code Dx vulnerability management and remediation platform.
  
.DESCRIPTION
  
Used to interact with Code Dx vulnerability management and remediation platform.
This is done by exporting the REST API calls to powershell functions.
#>


#Set verbose preference
$VerbosePreference = "silentlycontinue"
#$VerbosePreference = "continue"

Write-Host "Loading Code Dx Powershell Module..." -ForegroundColor Green

#obtain CDX API Key from env vars. Create at runtime if not present.
#
# Add the following Environmental vars to your system for ease of use:
# CDXAPI = yourapikey
# CDXURL = http://yourhost/codedx
#

Write-Host "Checking for API Key..." -ForegroundColor Green
if (-not (Test-Path env:CDXAPI)) { 

        Write-Host "Code Dx API key not found!!" -ForegroundColor Red
        $key = Read-Host 'Please input your API Key '
        $env:CDXAPI = $key
}

$APIKEY = Get-Childitem env:CDXAPI
$APIKEY = $APIKEY.value;

Write-Verbose "API Key set to: $($APIKEY)"

#Set web request header value
$headers = @{
    'API-Key' = $APIKEY
}

#obtain CDX server info from environmental variables. Create at runtime if not there.
Write-Host "Checking for Code Dx Server" -ForegroundColor Green
if (-not (Test-Path env:CDXURL)) { 

        Write-Host "CodeDX Host URL not found!!" -ForegroundColor Red
        $host = Read-Host 'Please input your host (e.g. http://myserver.com/codedx) '
        $env:CDXURL = $host
}

$CDXSERVER = Get-Childitem env:CDXURL
$CDXSERVER = $CDXSERVER.value;

Write-Verbose "Server set to: $($CDXSERVER)"

#Get Functions from sub directory .\functions
#This simplifies addition and removal of functions from the module.

$functionPath = $PSScriptRoot + "\functions\"
$functionlist = Get-ChildItem -Path $functionPath -Name
foreach ($function in $functionlist)
{
    . ($functionPath + $function)
}