| 41 | var timeRegex = regexp.MustCompile(`\$\{time:([^}]+)\}`) |
| 42 | |
| 43 | func expandFileConfig(cfg []byte) ([]byte, error) { |
| 44 | var expandErr error |
| 45 | cfg = fileRegex.ReplaceAllFunc(cfg, func(match []byte) []byte { |
| 46 | filename := fileRegex.FindSubmatch(match)[1] |
| 47 | content, err := os.ReadFile(string(filename)) |
| 48 | if err != nil { |
| 49 | expandErr = err |
| 50 | return nil |
| 51 | } |
| 52 | if shouldEscapeFileContent(content) { |
| 53 | // Values that should be treated as strings in YAML have leading and trailing quotes already |
| 54 | // so we remove the one added by strconv.Quote |
| 55 | quoted := strconv.Quote(string(content)) |
| 56 | return []byte(quoted[1 : len(quoted)-1]) |
| 57 | } |
| 58 | return content |
| 59 | }) |
| 60 | return cfg, expandErr |
| 61 | } |
| 62 | |
| 63 | // expand environment variables in the format ${ENV_VAR} |
| 64 | func expandEnv(cfg []byte) ([]byte, error) { |