From 8d36cb3e966fe0754f7a1bddfb669715cc5b6571 Mon Sep 17 00:00:00 2001 From: Jared Holgate Date: Fri, 13 Oct 2023 11:39:39 +0100 Subject: [PATCH 1/2] Add YAML Support for override config --- src/ALZ/Private/Get-ALZConfig.ps1 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ALZ/Private/Get-ALZConfig.ps1 b/src/ALZ/Private/Get-ALZConfig.ps1 index 8ec6054e..68eee0e3 100644 --- a/src/ALZ/Private/Get-ALZConfig.ps1 +++ b/src/ALZ/Private/Get-ALZConfig.ps1 @@ -15,7 +15,19 @@ function Get-ALZConfig { # Import the config from the json file inside assets and transform it to a PowerShell object if ($configFilePath -ne "") { - $config = Get-Content -Path $configFilePath | ConvertFrom-Json + $extension = (Get-Item -Path $configFilePath).Extension.ToLower() + if($extension -eq ".yml" -or $extension -eq ".yaml") { + if (!(Get-Module -ListAvailable -Name powershell-Yaml)) { + Write-Host "Installing YAML module" + Install-Module powershell-Yaml -Force + } + $config = [PSCustomObject](Get-Content -Path $configFilePath | ConvertFrom-Yaml) + } elseif($extension -eq ".json") { + $config = Get-Content -Path $configFilePath | ConvertFrom-Json + } else { + throw "The config file must be a json or yaml file" + } + return $config } From b30dd5e8d7e4d600ff1f1be94ea278d0f343c071 Mon Sep 17 00:00:00 2001 From: Jared Holgate Date: Fri, 13 Oct 2023 14:39:31 +0100 Subject: [PATCH 2/2] Update error message to be more accurate Co-authored-by: Jack Tracey <41163455+jtracey93@users.noreply.github.com> --- src/ALZ/Private/Get-ALZConfig.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ALZ/Private/Get-ALZConfig.ps1 b/src/ALZ/Private/Get-ALZConfig.ps1 index 68eee0e3..2e75c0ae 100644 --- a/src/ALZ/Private/Get-ALZConfig.ps1 +++ b/src/ALZ/Private/Get-ALZConfig.ps1 @@ -25,7 +25,7 @@ function Get-ALZConfig { } elseif($extension -eq ".json") { $config = Get-Content -Path $configFilePath | ConvertFrom-Json } else { - throw "The config file must be a json or yaml file" + throw "The config file must be a json or yaml/yml file" } return $config