Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

[WIP] Hardening the interpolation of parameters containing special characters #587

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jcsirot
Copy link
Contributor

@jcsirot jcsirot commented Jul 31, 2019

- What I did
Fixes #574

- How I did it

- How to verify it

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

TBD

@@ -148,7 +148,8 @@ func initFromComposeFile(name string, composeFile string) error {
}
}
}
vars, err := compose.ExtractVariables(composeRaw, compose.ExtrapolationPattern)
vars, err := compose.ExtractVariables(composeRaw, compose.ComposeExtrapolationPattern)
fmt.Println(vars)
Copy link
Member

Choose a reason for hiding this comment

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

Oups

…. and -) not allowed by

the original compose file format more robust. Docker App is now using 2 different regexps when
parsing a .dockerapp file and processing a compose file to generate a .dockerapp

Signed-off-by: Jean-Christophe Sirot <jean-christophe.sirot@docker.com>
@jcsirot jcsirot force-pushed the fix-var-substitution-regex branch from 164e4d0 to 72b27fc Compare July 31, 2019 15:56
@codecov
Copy link

codecov bot commented Jul 31, 2019

Codecov Report

Merging #587 into master will increase coverage by 1.8%.
The diff coverage is 90.62%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #587     +/-   ##
=========================================
+ Coverage   70.74%   72.55%   +1.8%     
=========================================
  Files          55       54      -1     
  Lines        3247     2827    -420     
=========================================
- Hits         2297     2051    -246     
+ Misses        649      511    -138     
+ Partials      301      265     -36
Impacted Files Coverage Δ
internal/version.go 92.85% <ø> (-0.48%) ⬇️
internal/commands/inspect.go 81.81% <0%> (ø) ⬆️
internal/commands/render.go 81.25% <0%> (ø) ⬆️
internal/packager/extract.go 62.5% <0%> (ø) ⬆️
render/render.go 76.38% <100%> (+4.78%) ⬆️
internal/store/bundle.go 68.88% <100%> (ø) ⬆️
internal/commands/status.go 83.33% <100%> (+1.7%) ⬆️
internal/log/log.go 100% <100%> (ø)
internal/commands/uninstall.go 51.02% <100%> (+2%) ⬆️
internal/packager/packing.go 57.44% <100%> (+29.48%) ⬆️
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8d52f6d...72b27fc. Read the comment docs.

substitution = "[_a-z][._a-z0-9]*(?::?[-?][^}]*)?"
delimiter = "\\$"
substitution = "[_a-z][._a-z0-9-]*"
composeSubstitution = "[_a-z][._a-z0-9]*(?::?[-?][^}]*)?"
Copy link
Member

Choose a reason for hiding this comment

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

Shoud we add the . here? The cli doesn't have it, I'm not sure we really need it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a true question. I added the . to make this test pass

func TestInitFromComposeFileWithFlattenedParams(t *testing.T) {

But I'm not sure if the tested usecase is legit

Copy link
Member

Choose a reason for hiding this comment

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

I think the test is bogus since env variables can only be alphanumeric and _.

Copy link
Contributor

Choose a reason for hiding this comment

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

Dots are necessary for the indentation levels in the parameters yaml file.
As in:

const expectedParameters = `ports:
service1: 9001
service2: 9002
`

Copy link
Member

Choose a reason for hiding this comment

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

Yeah but here we are talking about variable substitution that the cli does, it can substitute an environment variable inside a compose file (using ${VARIABLE:-default_value} notation. And an environment variable can only have [a-zA-Z_]+. No dots.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test here is verifying the conversion of the valid compose file into a dockerapp file. But the compose file syntax does not support the dot notation.

Copy link
Member

Choose a reason for hiding this comment

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

So one could say that it’s not a valid compose file :)

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

Successfully merging this pull request may close these issues.

Render error of a variable with the dash symbol and surrounded with the double-quotes
4 participants