MCPcopy Index your code
hub / github.com/cloudquery/cloudquery / expandFileConfig

Function expandFileConfig

cli/internal/specs/v0/spec_reader.go:43–61  ·  view source on GitHub ↗
(cfg []byte)

Source from the content-addressed store, hash-verified

41var timeRegex = regexp.MustCompile(`\$\{time:([^}]+)\}`)
42
43func 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}
64func expandEnv(cfg []byte) ([]byte, error) {

Callers 2

TestExpandFileFunction · 0.85
loadSpecsFromFileMethod · 0.85

Calls 1

shouldEscapeFileContentFunction · 0.85

Tested by 1

TestExpandFileFunction · 0.68