fix(config): Support $$ in config for literal $ (#427)

This commit is contained in:
TwiN
2023-02-11 22:43:13 -05:00
committed by GitHub
parent 542da61215
commit 7d6923730e
2 changed files with 34 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import (
"log"
"os"
"path/filepath"
"strings"
"time"
"github.com/TwiN/deepmerge"
@ -214,8 +215,13 @@ func walkConfigDir(path string, fn fs.WalkDirFunc) error {
// parseAndValidateConfigBytes parses a Gatus configuration file into a Config struct and validates its parameters
func parseAndValidateConfigBytes(yamlBytes []byte) (config *Config, err error) {
// Replace $$ with __GATUS_LITERAL_DOLLAR_SIGN__ to prevent os.ExpandEnv from treating "$$" as if it was an
// environment variable. This allows Gatus to support literal "$" in the configuration file.
yamlBytes = []byte(strings.ReplaceAll(string(yamlBytes), "$$", "__GATUS_LITERAL_DOLLAR_SIGN__"))
// Expand environment variables
yamlBytes = []byte(os.ExpandEnv(string(yamlBytes)))
// Replace __GATUS_LITERAL_DOLLAR_SIGN__ with "$" to restore the literal "$" in the configuration file
yamlBytes = []byte(strings.ReplaceAll(string(yamlBytes), "__GATUS_LITERAL_DOLLAR_SIGN__", "$"))
// Parse configuration file
if err = yaml.Unmarshal(yamlBytes, &config); err != nil {
return