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

Try to improve code readability of var_kv #581

Merged
merged 6 commits into from
Dec 17, 2021

Conversation

beyhan
Copy link
Member

@beyhan beyhan commented Dec 8, 2021

This is a refactoring suggestion for #580. I had hard time to read the code and this is a small refactoring to improve that.

Copy link
Contributor

@klakin-pivotal klakin-pivotal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are a few changes. Otherwise, it looks fine.

director/template/var_kv.go Outdated Show resolved Hide resolved
director/template/var_kv.go Outdated Show resolved Hide resolved
director/template/var_kv.go Outdated Show resolved Hide resolved
if we skip YAML.unmarshal on the value we may end up with superfluos
quotes around the actual value. This is mostly for backwards compability
as it may break scripts/manifest that would currently render fine:

e.g.:

```
+ releases:
+ - name: bosh
+   version: "'271.17.0+dev.1638991106'"
```

vs

```
+ releases:
+ - name: bosh
+   version: 271.17.0+dev.1638885656
```

Signed-off-by: Brian Cunnie <[email protected]>
@nouseforaname
Copy link
Contributor

I added a commit to this PR because we found that the new code also changes rendering behaviour in specific situations

Expect(err).ToNot(HaveOccurred())
Expect(arg).To(Equal(VarKV{Name: "name", Value: "val"}))
})
It("Trim only removes wrapping quotes", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For completeness's sake, can we add in a test or three here that ensures that values with unbalanced quote characters are correctly handled? For example
"'some-data"' or '"some-data'" get transformed into 'some-data" and "some-data', respectively?

I expect this to work today, but it'd be good to ensure that it keeps working in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a syntax issue with the test which I fixed. I wanted to add the suggested cases here but they don't work at the moment. You get errors like:

  Unexpected error:
        <errors.ComplexError>: {
            Err: <*errors.errorString | 0xc00039ac80>{
                s: "Deserializing variables 'name='\"some-data'\"'",
            },
            Cause: <*errors.errorString | 0xc00039ac50>{
                s: "yaml: found unexpected end of stream",
            },
        }
        Deserializing variables 'name='"some-data'"': yaml: found unexpected end of stream
    occurred

Is this expected to work?

Copy link
Contributor

@nouseforaname nouseforaname Dec 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should since that could be a Passwort Value:

"'someString"' should be untouched and render to "'someString"'
"'someString" should be touched and render to 'someString

I added a "custom" trim instead of using strings.Trim for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, now all cases are supported. Ideally, this should be part of a different pr but let's keep it here.

beyhan and others added 3 commits December 14, 2021 08:35
@lnguyen lnguyen merged commit e04501b into main Dec 17, 2021
@lnguyen lnguyen deleted the refactor_allow_newlines_in_var branch December 17, 2021 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

7 participants