Private/Utils/Import-AwsToolboxConfiguration.ps1

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
function Import-AwsToolboxConfiguration
{
    $configPath = [IO.Path]::Combine([Environment]::GetFolderPath('ApplicationData'), 'aws-toolbox', 'aws-toolbox.config.json')

    $config = New-Object PSObject -Property @{ }

    if (Test-Path -Path $configPath -PathType Leaf)
    {
        try
        {
            $config = Get-Content -Raw -Path $configPath | ConvertFrom-Json
        }
        catch
        {
            Write-Warning "Config at '$configPath' is corrupt. Please recreate with Set-ATConfigurationItem"
        }
    }

    $config |
    Add-Member -PassThru -MemberType ScriptMethod -Name HasItem -Value {
        param
        (
            [string]$ItemName
        )

        $null -ne (
            $this.PSObject.Properties |
            Where-Object {
                $_.MemberType -ne 'ScriptMethod' -and $_.Name -ieq $ItemName
            }
        )
    }
}