Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhacement: add better error handling and masking for inputs #101

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/ALZ/Private/Get-ALZConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,28 @@ function Get-ALZConfig {

# Import the config and transform it to a PowerShell object
$extension = (Get-Item -Path $configFilePath).Extension.ToLower()
$config = $null
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)
try {
$config = [PSCustomObject](Get-Content -Path $configFilePath | ConvertFrom-Yaml)
} catch {
$errorMessage = "Failed to parse YAML inputs. Please check the YAML file for errors and try again. $_"
Write-Error $errorMessage
throw $errorMessage
}

} elseif($extension -eq ".json") {
$config = Get-Content -Path $configFilePath | ConvertFrom-Json
try {
$config = [PSCustomObject](Get-Content -Path $configFilePath | ConvertFrom-Json)
} catch {
$errorMessage = "Failed to parse JSON inputs. Please check the JSON file for errors and try again. $_"
Write-Error $errorMessage
throw $errorMessage
}
} else {
throw "The config file must be a json or yaml/yml file"
}
Expand Down
3 changes: 3 additions & 0 deletions src/ALZ/Private/Request-ConfigurationValue.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ function Request-ConfigurationValue {
Write-InformationColored "$($configName) " -ForegroundColor Yellow -NoNewline -InformationAction Continue
if ($hasDefaultValue) {
$displayDefaultValue = $defaultValue -eq "" ? "''" : $defaultValue
if($configValue.Sensitive -and $defaultValue -ne "") {
$displayDefaultValue = "<sensitive>"
}
Write-InformationColored "(default: ${displayDefaultValue}): " -ForegroundColor Yellow -NoNewline -InformationAction Continue
} else {
Write-InformationColored ": " -NoNewline -InformationAction Continue
Expand Down
Loading