Private/ApiKeyUtil.ps1

function Get-ApiPath {
    return "$env:ProgramData\$TenantPrefix\API\"
}

function Get-ApiFile {
    $baseDir = Get-ApiPath
    return $baseDir + "key"
}

function Get-ApiKey {
    $path = Get-ApiFile
    if (!(Test-Path $path)) {
        Write-Warning "No PlannerOne API key stored"
        Write-Warning "Store one with Set-P1ApiKey"
        Write-Warning "Contact PlannerOne team to get your private key"
        return ""
    }

    return Get-Content $path
}

function Set-ApiKey($key) {
    $baseDir = Get-ApiPath
    if (!(Test-Path $baseDir)) {
        mkdir $baseDir | Out-Null
    }

    $path = Get-ApiFile
    $key | Out-File $path
}

function Get-FeedURL {
    $ApiKey = Get-ApiKey
    if ($ApiKey -eq "") {
        return ""
    }

    $feedUrl = [string]::Format($SourceURL,$ApiKey)
    Write-Verbose "Feed URL is $feedUrl"
    return $feedUrl
}