codedx.psm1

#CodeDX Integration module

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

Write-Host "Loading CodeDX 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 "CodeDX 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)
}