Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
aknysh committed Jan 18, 2025
1 parent 1935d5a commit 77b8202
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 11 deletions.
3 changes: 2 additions & 1 deletion examples/quick-start-advanced/b c.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
HELLO
- HELLO
- WORLD
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ components:
test6: !include stacks/catalog/vpc/ue2.yaml .components.terraform.vpc.vars.availability_zones
test7: !include 'stacks/catalog/vpc/ue2.yaml .components.terraform.vpc.vars.availability_zones[2]'
test8: !include a.txt
test9: !env USER
test9: !include '"b c.txt" ".[1]"'
test10: !env USER

Check failure on line 59 in examples/quick-start-advanced/stacks/catalog/vpc/defaults.yaml

View workflow job for this annotation

GitHub Actions / [validate] quick-start-advanced

Unresolved tag: !env YAML.

Unresolved tag: !env
8 changes: 7 additions & 1 deletion internal/exec/yaml_func_include.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ func processTagInclude(
// while also ignoring leading and trailing whitespace
var f string
q := ""
parts := strings.Fields(str)

parts, err := u.SplitStringByDelimiter(str, ' ')
if err != nil {
e := fmt.Errorf("error evaluating the YAML function: %s\n%v", input, err)
u.LogErrorAndExit(atmosConfig, e)
}

partsLen := len(parts)

if partsLen == 2 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/describe/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# are independent settings (supporting both absolute and relative paths).
# If 'base_path' is provided, 'components.terraform.base_path', 'components.helmfile.base_path', 'stacks.base_path' and 'workflows.base_path'
# are considered paths relative to 'base_path'.
base_path: "../../tests/fixtures/scenarios/complete"
base_path: "../../examples/quick-start-advanced"

components:
terraform:
Expand Down
12 changes: 12 additions & 0 deletions pkg/describe/describe_component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,15 @@ func TestDescribeComponent7(t *testing.T) {
assert.Nil(t, err)
t.Log(componentSectionYaml)
}

func TestDescribeComponent8(t *testing.T) {
component := "vpc"
stack := "plat-ue2-dev"

componentSection, err := ExecuteDescribeComponent(component, stack, true)
assert.Nil(t, err)

componentSectionYaml, err := u.ConvertToYAML(componentSection)
assert.Nil(t, err)
t.Log(componentSectionYaml)
}
18 changes: 18 additions & 0 deletions pkg/utils/string_utils.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package utils

import (
"encoding/csv"
"strings"
)

// UniqueStrings returns a unique subset of the string slice provided
func UniqueStrings(input []string) []string {
u := make([]string, 0, len(input))
Expand All @@ -14,3 +19,16 @@ func UniqueStrings(input []string) []string {

return u
}

// SplitStringByDelimiter splits a string by the delimiter, not splitting inside quotes
func SplitStringByDelimiter(str string, delimiter rune) ([]string, error) {
r := csv.NewReader(strings.NewReader(str))
r.Comma = delimiter

parts, err := r.Read()
if err != nil {
return nil, err
}

return parts, nil
}
16 changes: 9 additions & 7 deletions pkg/utils/yaml_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ func getValueWithTag(atmosConfig *schema.AtmosConfiguration, n *yaml.Node, file
var f string
q := ""

// Split the value into slices based on any whitespace (one or more spaces, tabs, or newlines),
// while also ignoring leading and trailing whitespace
parts := strings.Fields(val)
parts, err := SplitStringByDelimiter(val, ' ')
if err != nil {
return "", err
}

partsLen := len(parts)

if partsLen == 2 {
Expand All @@ -133,7 +135,7 @@ func getValueWithTag(atmosConfig *schema.AtmosConfiguration, n *yaml.Node, file
if !FileExists(f) {
return "", fmt.Errorf("the function '%s %s' points to a file that does not exist", tag, val)
}
return strings.TrimSpace(tag + " " + f + " " + q), nil
return strings.TrimSpace(tag + " \"" + f + "\" " + q), nil
}

// Detect relative paths (relative to the manifest file) and convert to absolute paths
Expand All @@ -142,7 +144,7 @@ func getValueWithTag(atmosConfig *schema.AtmosConfiguration, n *yaml.Node, file
if !FileExists(resolved) {
return "", fmt.Errorf("the function '%s %s' points to a file that does not exist", tag, val)
}
return strings.TrimSpace(tag + " " + resolved + " " + q), nil
return strings.TrimSpace(tag + " \"" + resolved + " \" " + q), nil
}

// Check if the `!include` function points to an Atmos stack manifest relative to the `base_path` defined in `atmos.yaml`
Expand All @@ -152,10 +154,10 @@ func getValueWithTag(atmosConfig *schema.AtmosConfiguration, n *yaml.Node, file
if err != nil {
return "", fmt.Errorf("error converting the file path to an ansolute path in the function '%s %s': %v", tag, val, err)
}
return strings.TrimSpace(tag + " " + atmosManifestAbsolutePath + " " + q), nil
return strings.TrimSpace(tag + " \"" + atmosManifestAbsolutePath + " \" " + q), nil
}

return strings.TrimSpace(tag + " " + f + " " + q), nil
return strings.TrimSpace(tag + " \"" + f + " \" " + q), nil
}

return strings.TrimSpace(tag + " " + val), nil
Expand Down

0 comments on commit 77b8202

Please sign in to comment.