Skip to content

fix(multienv): allow commas and quoted values#3542

Merged
GenPage merged 6 commits intorunatlantis:mainfrom
inkel:inkel/multienv/proper-parsing-value-commas-quotes
Oct 6, 2023
Merged

fix(multienv): allow commas and quoted values#3542
GenPage merged 6 commits intorunatlantis:mainfrom
inkel:inkel/multienv/proper-parsing-value-commas-quotes

Conversation

@inkel
Copy link
Contributor

@inkel inkel commented Jun 21, 2023

what

As first stated by @acostaedg in #2765, the multienv step was failing if a value contained a comma (,). This PR adds the capability to quote values and thus having commas as part of the value.

why

Upon inspecting the previous multienv code I've found it was using a naive algorithm that was prone to errors. At Grafana Labs we are about to use multienv steps with lots of custom environment variables, many of which can contain characters like commas, equals (=), newlines (\n), or being a full JSON object.

By using a custom algorithm to parse the output of the multienv program we can now have a more thorough test suite and also provide advanced value for this feature.

tests

I've added a full test suite for the internal algorithm. See server/core/runtime/multienv_step_runner_internal_test.go for additional information.

I've also added a regression test for the original issue reported.

references

@inkel inkel requested a review from a team as a code owner June 21, 2023 21:44
@github-actions github-actions bot added the go Pull requests that update Go code label Jun 21, 2023
@inkel inkel force-pushed the inkel/multienv/proper-parsing-value-commas-quotes branch from 8a86a78 to afdadb7 Compare June 26, 2023 13:17
@jamengual jamengual added the waiting-on-review Waiting for a review from a maintainer label Sep 8, 2023
@jamengual
Copy link
Contributor

@inkel could you fix the conflict?

Thanks.

While at it makes it more readable.

Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>
This new function properly deals with quotes and commas in values.

Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>
See runatlantis#2765 for an issue report.

Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>
Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>
This new function properly deals with quotes and commas in values.

Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>
@inkel inkel force-pushed the inkel/multienv/proper-parsing-value-commas-quotes branch from afdadb7 to c6c31ca Compare September 8, 2023 19:41
@inkel
Copy link
Contributor Author

inkel commented Sep 8, 2023

@inkel could you fix the conflict?

Thanks.

Done!

@GenPage GenPage added the feature New functionality/enhancement label Oct 6, 2023
@GenPage GenPage removed the waiting-on-review Waiting for a review from a maintainer label Oct 6, 2023
@GenPage GenPage merged commit bb18da2 into runatlantis:main Oct 6, 2023
@inkel inkel deleted the inkel/multienv/proper-parsing-value-commas-quotes branch October 6, 2023 16:16
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
* Make code more Go-idiomatic

While at it makes it more readable.

Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>

* Add internal function to parse multienv step input

This new function properly deals with quotes and commas in values.

Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>

* Add regression test for multienv output with comma in values

See runatlantis#2765 for an issue report.

Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>

* Use parseMultienvLine for parsing multienv steps output

Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>

* Add internal function to parse multienv step input

This new function properly deals with quotes and commas in values.

Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>

---------

Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>
Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
* Make code more Go-idiomatic

While at it makes it more readable.

Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>

* Add internal function to parse multienv step input

This new function properly deals with quotes and commas in values.

Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>

* Add regression test for multienv output with comma in values

See runatlantis#2765 for an issue report.

Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>

* Use parseMultienvLine for parsing multienv steps output

Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>

* Add internal function to parse multienv step input

This new function properly deals with quotes and commas in values.

Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>

---------

Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>
Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New functionality/enhancement go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants