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

: inserted as list separator if list is >= 4 items long #85

Open
gabbifish opened this issue Nov 16, 2020 · 3 comments
Open

: inserted as list separator if list is >= 4 items long #85

gabbifish opened this issue Nov 16, 2020 · 3 comments

Comments

@gabbifish
Copy link

Hello! We are on hiera version v0.2.0.
We are parsing a fact into a JSON output format and noticed a parsing error.

When parsing a yaml list like

myList:
  - typeA: a
  - typeB: b
  - typeC: c
  - tupeD: d

hiera will parse it as

[{"typeA":"a"},{"typeB":"b"},{"typeC":"c"}:{"tupeD":"d"}]

Note that what should have been a comma delimiter is now a :!

We have the go code to parse from the yaml file:

	var variables []string
	for _, fact := range facts {
		variables = append(variables, fact.String())
	}

	cmdOpts.Merge = "deep"
	cmdOpts.Variables = variables
	cmdOpts.RenderAs = formatToFormatString(format)

	configOptions := map[string]px.Value{
		provider.LookupKeyFunctions: types.WrapRuntime([]hieraapi.LookupKey{provider.ConfigLookupKey, provider.Environment})}
	configOptions[hieraapi.HieraConfig] = types.WrapString(path.Join(directory, "hierav5.yaml"))

	dest := bytes.NewBuffer(nil)
	err := hiera.TryWithParent(context.TODO(), provider.MuxLookupKey, configOptions, func(c px.Context) error {
		hiera.LookupAndRender(c, &cmdOpts, []string{key}, dest)
		return nil
	})
@thallgren
Copy link
Contributor

Would it be possible for you to try the tip of the v1.0.x branch and check if the problem is still there?

@thallgren
Copy link
Contributor

I added the following test to v1.0.x:

func TestLookup_fourElementSlice(t *testing.T) {
	inTestdata(func() {
		result, err := cli.ExecuteLookup(`--config`, `hiera.yaml`, `--render-as`, `json`, `myList`)
		require.NoError(t, err)
		require.Equal(t, `[{"typeA":"a"},{"typeB":"b"},{"typeC":"c"},{"tupeD":"d"}]`, strings.TrimSpace(string(result)))
	})
}

with this data in hiera/common.yaml

myList:
  - typeA: a
  - typeB: b
  - typeC: c
  - tupeD: d

and the test passes.

thallgren added a commit that referenced this issue Nov 22, 2020
@gabbifish
Copy link
Author

gabbifish commented Dec 1, 2020

Heh, after some grappling with the breaking changes between v0.2.0 and v1.0.x (there were quite a few!) it looks like this fix is present in v1.0.x! Thank you for adding a test to verify this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants