Public/Settings/Get-EdenSettings.ps1

function Get-EdenSettings
{
    <#
    .SYNOPSIS
        Gets Eden settings from json files.
    .DESCRIPTION
        Gets the Eden settings from files that match the name specified in either
        the ./Eden/Settings/.local folder or the ./Eden/Settings/ folder.

    .EXAMPLE
        PS> Get-EdenSettings
        or
        PS> e-stg
        Gets the eden settings from one of the following places in order:
        './Eden/Settings/.local/Default.json'
        './Eden/Settings/Default.json'
        or if the above files do not exist it will generate a settings object
        with 'SolutionName' and 'ServiceName' properties whose values match
        the parent folder ('ServiceName') or the folder above that 'SolutionName'.
    .EXAMPLE
        PS> Get-EdenSettings -Name MySettings
        or
        PS> e-stg -n MySettings
        Gets the eden settings from one of the following places in order:
        './Eden/Settings/.local/MySettings.json'
        './Eden/Settings/MySettings.json'
        or if the above files do not exist it will generate a settings object
        with 'SolutionName' and 'ServiceName' properties whose values match
        the parent folder ('ServiceName') or the folder above that 'SolutionName'.
    .INPUTS
        None
    .OUTPUTS
        A Custom PS Object that is deserialized from the json file.
    .NOTES
        If a matching settings file is not found in the ./Eden/Settings/.local folder
        then the Eden Framework will use a matching file in the ./Eden/Settings folder
        if that file does not have any settings marked with any local values (contain
        values of "Prompt" or "PromptSecure").
    #>

    [CmdletBinding()]
    param(
        # The name of the settings file to load.
        [Alias("n")]
        [String] $Name = "Default"
    )

    try {

        if ($Name -eq "" -or $null -eq $Name) {
            $Name = "Default"
        }

        $settingsPath = "./Eden/Settings/.local/$Name.json"

        $globalSettingsPath = "./Eden/Settings/$Name.json"

        if (!(Test-Path $settingsPath)) {
            if(!(Test-Path $globalSettingsPath)) {
                if ($Name -eq "Default") {
                    $defaultSettings = [PSCustomObject]@{
                        Name = "Default"
                        SolutionName = Get-SolutionName
                        ServiceName = Get-ServiceName
                    }
                    return $defaultSettings
                }
                Write-EdenError "Unable to load the settings file at location: '$settingsPath'" $loggingPrefix
                Write-EdenError "Also unable to load a global settings file at location: '$globalSettingsPath'." $loggingPrefix
                Write-EdenError "Please do the following:" $loggingPrefix
                Write-EdenError "Create a single level json file to define all settings for the service: '$globalSettingsPath'" $loggingPrefix
                Write-EdenError "Include 'Prompt' as the value for the setting if the setting needs to be provided specifically for the local environment." $loggingPrefix
                Write-EdenError "Include 'SecurePrompt' for settings that need to be provided for the local environment and should be encrypted." $loggingPrefix
                Write-EdenError "After the global settings file has been created, run the following command to create a local version of the settings file:" $loggingPrefix
                Write-EdenError "New-EdenSettings -Name '$Name'" $loggingPrefix
                Write-EdenError "You may also use:" $loggingPrefix
                Write-EdenError "e-stn '$Name'" $loggingPrefix
                throw "Missing local and global settings file '$Name'."
            } else {
                $globalSettingsContent = Get-Content "./Eden/Settings/$Name.json"
                $globalSettings = ConvertFrom-Json "$globalSettingsContent"
                $globalSettings | Add-Member -Name 'Name' -Type NoteProperty -Value $Name
                $requiresPrompt = ($globalSettings.PSObject.Properties | Where-Object { $_.Value.Contains("Prompt") } | Measure-Object).Count -gt 0
                if (!$requiresPrompt) {
                    return $globalSettings
                } else {
                    Write-EdenError "Unable to load the settings file at location: '$settingsPath'" $loggingPrefix
                    Write-EdenError "Unable to load the global settings file at location: '$globalSettingsPath'" $loggingPrefix
                    Write-EdenError "The global settings file requires a local settings file to store local specific settings values." $loggingPrefix
                    Write-EdenError "You need to create the local file by running the following command:" $loggingPrefix
                    Write-EdenError "New-EdenSettings -Name '$Name'" $loggingPrefix
                    Write-EdenError "You may also use:" $loggingPrefix
                    Write-EdenError "e-stn '$Name'" $loggingPrefix
                    throw "Missing local settings file '$Name'."
                    return
                }
            }
        }

        [String]$json = Get-Content "./Eden/Settings/.local/$Name.json"
        $jsonObject = ConvertFrom-Json "$json"
        $jsonObject | Add-Member -Name 'Name' -Type NoteProperty -Value $Name
        return $jsonObject
    }
    catch {
        Write-EdenError "There was an error importing the Eden service settings: $($_.Exception.Message)" $loggingPrefix
        throw $_
    }
}
New-Alias `
    -Name e-stg `
    -Value Get-EdenSettings `
    -Force