You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fly adds quotes when inserting vars into part of a string #360
It will fail because it tries to upload a file with quotes:
error running command: no matches found for pattern: updated-bosh-init-state/"bosh-manifest-state-eu-west-1a.json"
+1 it is quite annoying.
In general we workaround this issue by:
Adding logic before uploading the pipeline in a shell script, doing the interpolation before and uploading different variables. In this case a variable called generated_bosh_manifest_state: --var generated_bosh_manifest_state=updated-bosh-init-state/${BOSH_MANIFEST_STATE}.
For cases where pure YAML is required, as @rmasand describes, we have to do string substitution in the pipeline before uploading. Other option is using spruce or spiff
If the variable is going to be consumed by tasks, we do interpolation using environment variables and shell script in the task.
In the case of S3 resource, use a wildcard which matches only that file: "updated-bosh-init-state/bosh-manifest-state-*.json", s3 recognises wildcards.
All of these solutions are suboptimal workarounds.
I'm hesitant to fix this as I'm not convinced text substitution is the correct layer to be doing anything more than passing raw values around. I also don't want to end up with another templating language on my hands. Especially since if you really need fancier parameterization, you could always just use any of those tools: there's no need to make Fly's any fancier.
Fly's templating system is intentionally braindead simple. It's not just that it wraps quotes around the strings - it JSON encodes it so it can be safely passed into the YAML unsullied - and from there it'll be passed along through wherever you put the value, explicitly handed to whatever needs it.
Raw text substitution at this layer is an easy way to quickly hack something together and introduce all kinds of implicit dependencies and subtle bugs. For example, if you were to interpolate it into an argument passed to an embedded task script, what happens when that argument starts to contain special characters that BASH interprets? ($, !, etc. - pretty likely if the param is e.g. a generated password). Passing along the value wholesale via params would then be the solution, which is the same thing you'd do today.
In most other cases, there's normally a better answer that removes the need for the param in the first place. For example, having abstract filenames, or a consistent pattern for them. Related to @keymon's point, I actually think the S3 wildcard pattern approach is better than using a parameter as it seems more self-documenting, and is a common pattern today already for matching filenames with version numbers in them.
Sometimes the right answer is to just move the whole string into the parameter and don't try to get too fancy with it. This tends to make the pipeline usable in more cases, e.g. when you don't want to put your files in the exact same folder structure as the other team using the template. Params are cheap: they're usually just kept in a file, and I don't think having to write a bit more around the param is a big deal.
So: rather than just +1'ing the issue, can you each give a specific example of when you needed this?
"Passing along the value wholesale via params would then be the solution, which is the same thing you'd do today."
Could you explain what you mean by this bit? Do you mean params in a task? If so I don't think this would apply to my three examples: s3 regexp, s3 private config boolean, empty worker tags list.
I explained my motivations and I wanted to avoid having to use a template engine like spiff/spruce, but if the position of the concourse development is not handling this, it is fine for me and it justifies introduce 3rd party templating solutions.
@vito My use cause is the externalizing the credentials for a URI. In one of our tests, we need to pass in the URI to use to access a private Cloud Foundry buildpack. That param is TEST_BUILDPACK: https://username:[email protected]/org/repo.git. At the moment, this now requires me to external the entirety of the URI, unlike everywhere else in our many pipelines that use URIs. Ideally I'd like to be able to write ``TEST_BUILDPACK: https://username:{{github-access-token}}@github.com/org/repo.git` instead.
I'm still not clear on what you meant by the bit I quoted above, but I get that anything more than quick and dirty templating should be done with a 3rd party tool. Which is fine because we like to put all of our fly set-pipeline calls in scripts anyway.
Ohhh, you were probably referring to the Using {{parameters}} section of the fly set-pipeline documentation. Yeah, for substituting parts of strings that makes sense. Doesn't address the boolean field problem, which is too bad but easily fixed pre-fly. And the dynamic workers sound cool :) I'm excited to see what that looks like.
(sid)alex@localhost:~$ curl http://foo:foo!@example.com
bash: !@example.com: event not found
However, if the value is propagated through params and into the task's env:
Having {{params}} behave as stupidly as they do now is a pretty OK way of preventing this kind of thing from happening. I'd sooner go farther though and have them only valid as the complete value of a YAML node.
That params usage is good for tasks, but in the case of resources does not work. Because that, you need to build a url like http://{{my-username}}:{{my-password}}@example.com using a shell script or a template engine before calling fly.
@nebhale Similar case there: it may make sense to just have separate username and password fields. Curl and most tools support explicit username and password handling. If your tooling doesn't support it you could always just add them to the URL in your task.
In my case, I'm templating a fairly extensive pipeline -- it's currently up to ~20 resources, similar number of jobs. And I see getting up to 200 copies of this pipeline in the relatively near term (we currently have 35).
I use a credentials file to populate git keys, etc that are all shared. Otherwise the pipeline varies by a single "Alias" for the specific project that I'm passing into it.
The alias is used to specify a bunch of different things: path inside S3 bucket, git repo name, pipeline name, various filenames.
So far what I've done is create a shell script for creating each pipeline -- the main purpose of which is purely to expand the alias into a bunch of variables to plug into the pipeline (because otherwise it gets quoted and breaks all kinds of things). For example, here's what I currently have in the shell script:
... And I'm nowhere near done yet. I'll probably need to add at least another 6 - 7 variables like this to the shell script, if the parameter expansion stays as is. This solution does work just fine for me, but it "feels" a bit ugly... I think in my case it would be far clearer to allow the parameters to be embedded in the Yaml strings without quotes -- as it is, it's quite unclear whether a parameter is comprised of something expanded from the site alias, or something coming from the shared credential file.
I'm beginning to think that once we get to implementing Vault support (#291) we should consider deprecating {{params}} usage entirely. It was added as a stopgap to get credentials safely split out of a pipeline. Vault support will mean switching to or adding a syntax that gets sent to the ATC to interpret, which is different from today's behavior (straight text substitution). Today's {{params}} syntax is also not valid YAML which would make that difficult, so we'd probably use a different syntax for Vault references.
With our intentionally dumb templating system out of the way people will more quickly lean on any of the dozens of more appropriate tools for the hopefully fewer cases (now that Vault is used for creds) where they need parameterization.
I tend to agree that parameterization should be external to fly. Partly because of single-responsibilities, and partly because this would pave the way for some better tooling to emerge - perhaps some first-class tooling around building pipelines from snippets?
Separately, as a developer of the concourse-pipeline-resource which consumes both the go-concourse library and needs to reimplement the templating logic from fly, not having to support templating would make my life much easier. I infer the same is true for developers of fly too.
Resolve some parameters client-side, and leave anything left over to the server to try to resolve via its credential service (i.e. Vault).
This would probably entail switching from the current raw substitution method, which means switching to (( these guys )) so that we can parse the YAML first and then interpret any embedded template values.
We would then special-case foo((bar))baz like so: expand it into something like (( "foo" bar "baz" )), load the bar value, require that it be a String, and then concatenate.
This would also fix the true/false case, as we'd be pulling in whatever the value was from the template files. However this would leave -v foo=true ambiguous, so maybe we'd start encouraging using a template file for those.
You could also do (( foo.bar.baz )), which would work if your vars file had something like foo: {bar: baz: 42}} in it. If not, we would leave it un-interpolated, and the ATC would look it up in the credential store (i.e. Vault) instead. Which would support the same interpolation rules, though I'm not sure Vault supports typed values, and I don't want to require that people store JSON.
Activity
concourse-bot commentedon Apr 8, 2016
Hi there!
We use Pivotal Tracker to provide visibility into what our team is working on. A story for this issue has been automatically created.
The current status is as follows:
This comment, as well as the labels on the issue, will be automatically updated as the status in Tracker changes.
nebhale commentedon Apr 8, 2016
@xtreme-gavin-enns For reference: https://concourseci.slack.com/archives/general/p1458065128000371
danger-ranger commentedon Apr 11, 2016
sadness
keymon commentedon Apr 27, 2016
+1 for fixing this
keymon commentedon Apr 29, 2016
Other place where this is annoying, if you are using the s3-resource:
It will fail because it tries to upload a file with quotes:
+1 it is quite annoying.
In general we workaround this issue by:
generated_bosh_manifest_state:--var generated_bosh_manifest_state=updated-bosh-init-state/${BOSH_MANIFEST_STATE}."updated-bosh-init-state/bosh-manifest-state-*.json", s3 recognises wildcards.All of these solutions are suboptimal workarounds.
mtekel commentedon Apr 29, 2016
+1 !
combor commentedon Jun 9, 2016
+1
christophe-f commentedon Jun 9, 2016
+1
vito commentedon Jul 13, 2016
I'm hesitant to fix this as I'm not convinced text substitution is the correct layer to be doing anything more than passing raw values around. I also don't want to end up with another templating language on my hands. Especially since if you really need fancier parameterization, you could always just use any of those tools: there's no need to make Fly's any fancier.
Fly's templating system is intentionally braindead simple. It's not just that it wraps quotes around the strings - it JSON encodes it so it can be safely passed into the YAML unsullied - and from there it'll be passed along through wherever you put the value, explicitly handed to whatever needs it.
Raw text substitution at this layer is an easy way to quickly hack something together and introduce all kinds of implicit dependencies and subtle bugs. For example, if you were to interpolate it into an argument passed to an embedded task script, what happens when that argument starts to contain special characters that BASH interprets? (
$,!, etc. - pretty likely if the param is e.g. a generated password). Passing along the value wholesale viaparamswould then be the solution, which is the same thing you'd do today.In most other cases, there's normally a better answer that removes the need for the param in the first place. For example, having abstract filenames, or a consistent pattern for them. Related to @keymon's point, I actually think the S3 wildcard pattern approach is better than using a parameter as it seems more self-documenting, and is a common pattern today already for matching filenames with version numbers in them.
Sometimes the right answer is to just move the whole string into the parameter and don't try to get too fancy with it. This tends to make the pipeline usable in more cases, e.g. when you don't want to put your files in the exact same folder structure as the other team using the template. Params are cheap: they're usually just kept in a file, and I don't think having to write a bit more around the param is a big deal.
So: rather than just +1'ing the issue, can you each give a specific example of when you needed this?
keymon commentedon Jul 13, 2016
+1
danger-ranger commentedon Jul 13, 2016
"Passing along the value wholesale via params would then be the solution, which is the same thing you'd do today."
Could you explain what you mean by this bit? Do you mean
paramsin a task? If so I don't think this would apply to my three examples: s3 regexp, s3 private config boolean, empty worker tags list.keymon commentedon Jul 13, 2016
😆 I'm joking about the +1.
I see your point of view.
I explained my motivations and I wanted to avoid having to use a template engine like spiff/spruce, but if the position of the concourse development is not handling this, it is fine for me and it justifies introduce 3rd party templating solutions.
1 remaining item
nebhale commentedon Jul 13, 2016
@vito My use cause is the externalizing the credentials for a URI. In one of our tests, we need to pass in the URI to use to access a private Cloud Foundry buildpack. That param is
TEST_BUILDPACK: https://username:[email protected]/org/repo.git. At the moment, this now requires me to external the entirety of the URI, unlike everywhere else in our many pipelines that use URIs. Ideally I'd like to be able to write ``TEST_BUILDPACK: https://username:{{github-access-token}}@github.com/org/repo.git` instead.danger-ranger commentedon Jul 13, 2016
I'm still not clear on what you meant by the bit I quoted above, but I get that anything more than quick and dirty templating should be done with a 3rd party tool. Which is fine because we like to put all of our
fly set-pipelinecalls in scripts anyway.Ohhh, you were probably referring to the
Using {{parameters}}section of thefly set-pipelinedocumentation. Yeah, for substituting parts of strings that makes sense. Doesn't address the boolean field problem, which is too bad but easily fixed pre-fly. And the dynamic workers sound cool :) I'm excited to see what that looks like.vito commentedon Jul 13, 2016
@xtreme-gavin-enns Ah sorry - I was just pointing out that raw text substitution can get pretty dangerous as it propagates through abstraction layers.
For example, from YAML to Bash embedded in the same document:
If
my-passwordis set tofoo!, this will blow up:However, if the value is propagated through
paramsand into the task's env:...that'll work fine:
Having
{{params}}behave as stupidly as they do now is a pretty OK way of preventing this kind of thing from happening. I'd sooner go farther though and have them only valid as the complete value of a YAML node.keymon commentedon Jul 13, 2016
That
paramsusage is good for tasks, but in the case of resources does not work. Because that, you need to build a url likehttp://{{my-username}}:{{my-password}}@example.comusing a shell script or a template engine before calling fly.vito commentedon Jul 13, 2016
@keymon In that case you should use explicit
usernameandpasswordfields, which thegit,semver, andpoolresources for example support.vito commentedon Jul 13, 2016
@nebhale Similar case there: it may make sense to just have separate username and password fields. Curl and most tools support explicit username and password handling. If your tooling doesn't support it you could always just add them to the URL in your task.
freelock commentedon Jul 13, 2016
Hi,
In my case, I'm templating a fairly extensive pipeline -- it's currently up to ~20 resources, similar number of jobs. And I see getting up to 200 copies of this pipeline in the relatively near term (we currently have 35).
I use a credentials file to populate git keys, etc that are all shared. Otherwise the pipeline varies by a single "Alias" for the specific project that I'm passing into it.
The alias is used to specify a bunch of different things: path inside S3 bucket, git repo name, pipeline name, various filenames.
So far what I've done is create a shell script for creating each pipeline -- the main purpose of which is purely to expand the alias into a bunch of variables to plug into the pipeline (because otherwise it gets quoted and breaks all kinds of things). For example, here's what I currently have in the shell script:
... And I'm nowhere near done yet. I'll probably need to add at least another 6 - 7 variables like this to the shell script, if the parameter expansion stays as is. This solution does work just fine for me, but it "feels" a bit ugly... I think in my case it would be far clearer to allow the parameters to be embedded in the Yaml strings without quotes -- as it is, it's quite unclear whether a parameter is comprised of something expanded from the site alias, or something coming from the shared credential file.
vito commentedon Jul 15, 2016
I'm beginning to think that once we get to implementing Vault support (#291) we should consider deprecating
{{params}}usage entirely. It was added as a stopgap to get credentials safely split out of a pipeline. Vault support will mean switching to or adding a syntax that gets sent to the ATC to interpret, which is different from today's behavior (straight text substitution). Today's{{params}}syntax is also not valid YAML which would make that difficult, so we'd probably use a different syntax for Vault references.With our intentionally dumb templating system out of the way people will more quickly lean on any of the dozens of more appropriate tools for the hopefully fewer cases (now that Vault is used for creds) where they need parameterization.
robdimsdale commentedon Jul 15, 2016
I tend to agree that parameterization should be external to fly. Partly because of single-responsibilities, and partly because this would pave the way for some better tooling to emerge - perhaps some first-class tooling around building pipelines from snippets?
Separately, as a developer of the concourse-pipeline-resource which consumes both the go-concourse library and needs to reimplement the templating logic from fly, not having to support templating would make my life much easier. I infer the same is true for developers of
flytoo.vito commentedon Jul 18, 2016
Another set of ideas after chatting with @cppforlife who has basically the same goals but with BOSH:
This would probably entail switching from the current raw substitution method, which means switching to
(( these guys ))so that we can parse the YAML first and then interpret any embedded template values.We would then special-case
foo((bar))bazlike so: expand it into something like(( "foo" bar "baz" )), load thebarvalue, require that it be a String, and then concatenate.This would also fix the
true/falsecase, as we'd be pulling in whatever the value was from the template files. However this would leave-v foo=trueambiguous, so maybe we'd start encouraging using a template file for those.You could also do
(( foo.bar.baz )), which would work if your vars file had something likefoo: {bar: baz: 42}}in it. If not, we would leave it un-interpolated, and the ATC would look it up in the credential store (i.e. Vault) instead. Which would support the same interpolation rules, though I'm not sure Vault supports typed values, and I don't want to require that people store JSON.nebhale commentedon Jul 18, 2016
@vito This certainly meets all of my requirements and I don't find the change from curly-braces to parenthesis to be onerous.
vito commentedon Jul 19, 2016
Consolidating this and all related issues into #545 so I can break this out into multiple stories for the one issue. Thanks for the feedback everyone!
bump a *bunch* of dependencies
concourse does not support expanding variables without quotes in pipe…