CIF3.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Get public and private function definition files.
$Public = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -Recurse -ErrorAction SilentlyContinue )
$Private = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -Recurse -ErrorAction SilentlyContinue )

# Dot source the files
foreach ($Import in @($Public + $Private)) {
    try {
        . $Import.FullName
    } 
    catch {
        Write-Error -Message "Failed to import function $($Import.FullName): $_"
    }
}

# Create / Read config
$Script:_CIF3YmlPath = Join-Path -Path $Home -ChildPath '.cif.yml'
if (-not (Test-Path -Path $Script:_CIF3YmlPath -ErrorAction SilentlyContinue)) {
    try {
        Write-Warning "Did not find config file $($Script:_CIF3YmlPath), attempting to create"
        @{ client = @{
                remote        = $null
                token         = $null
                no_verify_ssl = $true
                force_verbose = $false
                proxy         = $null
            } 
        } | ConvertTo-Yaml -OutFile $($Script:_CIF3YmlPath) -Force -ErrorAction Stop
    }
    catch {
        Write-Warning "Failed to create config file $($Script:_CIF3YmlPath): $_"
    }
}

#Initialize the config variable.
try {
    #Import the config
    $Script:CIF3 = $null
    $Script:CIF3 = Get-CIF3Config -Source YML -ErrorAction Stop
}
catch {
    Write-Warning "Error importing CIF3 config: $_"
}