Commit Graph

46 Commits

Author SHA1 Message Date
David Timm 20c3b18735 test: update references to use ginkgo/v2
Ginkgo 2.0 introduced [new features](https://onsi.github.io/ginkgo/MIGRATING_TO_V2#major-additions-and-improvement)
that substatially improve developer experience. It is also now the only
actively developed and supported version of Ginkgo.

Co-authored-by: Rui Yang <ruiya@vmware.com>
Signed-off-by: David Timm <dtimm@vmware.com>
2023-03-10 17:33:13 -05:00
Aidan Oldershaw ec6fd962f5 B: unmarshal using json.Number rather than float64
by default, "encoding/json" (and hence "sigs.k8s.io/yaml") decode any
number as float64 (if you try to decode into a generic type like
interface{})

vars/template.go does not allow interpolating float64 into a string,
presumably because you could end up interpolating the number 123.0 as
e.g. 122.99999999999999 due to limitations with float precision.

this means that if you ever load_var on a file containing a number
(even an integer), then you can never interpolate that number into a
string, which can be pretty annoying.

json.Number, on the other hand, stores the number as a string, so there
is no issue with precision - and it means ints will stay as "ints".
since we never use these values directly (they are just
serialized/deserialized), this *shouldn't* cause issues.

Signed-off-by: Aidan Oldershaw <aoldershaw@pivotal.io>
2021-07-07 16:46:52 -04:00
Esteban Foronda Sierra 5c311157aa
Merge pull request #6830 from concourse/issue/6617
Re ordering instanced pipelines
2021-05-03 11:09:31 -05:00
Tom Godkin 3c5e57c540 Use counterfeiter directive
Signed-off-by: Tom Godkin <tomgodkin@pm.me>
2021-04-19 22:18:05 +01:00
Aidan Oldershaw bc87962455 B: quote / in var reference
we quoted / when it appeared in an instance var's value, but not when it
appeared in the key. while we still parse var references properly if
they contain a / without quoting, when we generate the string, we should
quote it for consistency

Signed-off-by: Aidan Oldershaw <aoldershaw@pivotal.io>
Co-authored-by: Esteban Foronda <eforonda@vmware.com>
2021-04-08 13:53:50 -04:00
Rui Yang c1012fb8b8 B: static vars should only resolve on "" sources
Signed-off-by: Rui Yang <ruiya@vmware.com>
Co-authored-by: Bohan Chen <bochen@pivotal.io>
2021-03-01 12:15:41 -05:00
Chao Li 050e2a7e9d update fake files generated by latest version of counterfeiter.
Signed-off-by: Chao Li <chaol@vmware.com>
2021-02-23 09:23:47 +08:00
Aidan Oldershaw 8a692c37b7 atc: behaviour: begin to consolidate web/api query params
Apologies for this unfocused commit - it does several things:

* Rename WebQueryParams and InstanceVarsFromWebQueryParams by removing
  the Web specification
* Remove the old instance_vars implementation of API query params
  * Note that this breaks a ton of code/tests - going to hold this off
    for subsequent commits
* Change the query param prefix from var to vars, which felt more
  natural
  * This will of course require a change in #6105 as well
* Allow specifying the root-level vars in full. This makes certain APIs
  more convenient, and this ends up making the query param API a
  generalization of the old instance_vars one
* Make parsing query params strict (i.e. don't ignore errors)

Signed-off-by: Aidan Oldershaw <aoldershaw@pivotal.io>
2020-11-10 10:58:16 -05:00
Aidan Oldershaw c9c95afc62 atc: behaviour: fix instance vars serialization
A few issues:

- We didn't quote special characters (e.g. comma), which would result in
  the flag not working if you copy/paste it directly into fly
- We marshaled everything as YAML, which has unpleasant results for
  lists
- We weren't quoting fields with spaces in them

This switches to JSON marshaling, but explicitly unquotes values that
don't require quoting (i.e. don't have special characters and don't
change type when unmarshaled as YAML unquoted).

Signed-off-by: Aidan Oldershaw <aoldershaw@pivotal.io>
2020-10-22 19:48:18 -04:00
Aidan Oldershaw 9f4807d7aa fly: behaviour: parse var flags as references
concourse/concourse#6041

...and use the references to properly construct a StaticVariables.

This also changes the YAMLVariableFlag slightly - rather than using
"gopkg.in/yaml.v2" to parse the YAML value, it uses "sigs.k8s.io/yaml",
which converts YAML to JSON first, and then unmarshals the JSON. This is
the package we use in most of Concourse. The reason for the change is
that parsing the YAML directly results in YAML objects being unmarshaled
as `map[interface{}]interface{}`, which is less than ideal. However, it
also means that numbers will be interpolated as `float64`, which is also
less than ideal - so, instead, we unmarshal numbers as `json.Number`,
which is just the string value of the number that's passed in.

We could possibly get rid of the map[interface{}]interface{} handling in
the vars package now, but I'm a bit worried about the implications of
that, so I'll hold off for now.

Signed-off-by: Aidan Oldershaw <aoldershaw@pivotal.io>
2020-10-17 00:32:28 -04:00
Aidan Oldershaw aaefbc252f vars: behaviour: fix parsing var with : and no var source
I noticed a subtle bug in var parsing:

* ((vault:"my:var")) parses correctly, but
* (("my:var")) does not (the Source is set as `"my`, and the path as
`var`)

This commit fixes that bug by manually parsing the reference rather than
using a regular expression. It's easier to have fine control over the
parsing this way IMO.

I also made vars.ParseReference public - I was planning on doing so,
anyway, as I intend to use it outside of vars.Template (specifically,
for parsing variable flags)

Signed-off-by: Aidan Oldershaw <aoldershaw@pivotal.io>
2020-10-15 15:39:51 -04:00
Aidan Oldershaw ea9a1bc414 vars: structure: allow converting KV pairs to/from static vars
concourse/concourse#6041

Adds a new KVPairs type that is a list of key-value pairs. KVPairs can
be Expanded into a StaticVariables (which supports the usual Get/List
methods of a Variables impl), and StaticVariables can be Flattened into
a KVPairs.

The intention of Expand is to go from a list of var flags to a
StaticVariables for interpolating the pipeline template. The intention
of Flatten is to convert a pipeline's instance vars to a flat string
form using dot notation.

Note that we already have an implementation of both methods in
atc/pipeline.go for instance vars - however, I intend to use this
simplified implementation that does not traverse lists since the
notation for doing so is ambiguous (if a field name is an integer, it
assumes that it's an index in a list). Instead of using dot notation for
lists, we'll just display the list as '[a, b, c]'

Signed-off-by: Aidan Oldershaw <aoldershaw@pivotal.io>
2020-10-14 22:30:43 -04:00
Aidan Oldershaw 17b835b32d vars: structure: derive Reference name
...rather than tracking the raw name that's passed into the template. It
felt a bit odd to me that we tracked this name, given that we never
really used it (practically only for error messages). It was also a bit
worrisome that we only sometimes set the Name, which felt like a
potential bug waiting to happen if we ever decided to use the Name for
something.

Signed-off-by: Aidan Oldershaw <aoldershaw@pivotal.io>
2020-10-14 00:25:28 -04:00
Aidan Oldershaw da028aba22 vars: structure: Variable impls traverse fields
Previously, vars.Variable implementations only considered the `Path`
(and occasionally, `Source`) fields, and completely ignored the `Fields`
of the passed in `vars.Reference` - it was up to `vars.Template` to
actually traverse the fields.

This is certainly odd - I would expect as a caller of a `vars.Variables`
that the Fields would be traversed given that I'm passing in a full
Reference.

Signed-off-by: Aidan Oldershaw <aoldershaw@pivotal.io>
2020-10-13 21:50:53 -04:00
Aidan Oldershaw 2561420f90 vars: structure: remove VariableDefinition
I'm not sure if the Type/Option fields were ever used, but they aren't
anymore - so, let's just get rid of the wrapper type and use
vars.Reference instead

Signed-off-by: Aidan Oldershaw <aoldershaw@pivotal.io>
2020-10-13 17:53:32 -04:00
Aidan Oldershaw 5f29d0875f vars: structure: rename VariableReference to Reference
It's already namespaced to the `vars` package, so adding `Variable` is
redundant. Note that I didn't do this for `VariableDefinition`, since
it's getting the boot

Signed-off-by: Aidan Oldershaw <aoldershaw@pivotal.io>
2020-10-13 14:40:36 -04:00
Taylor Silva 11e614d791
Merge pull request #6082 from concourse/refactor-vars
Refactor RunState to have ownership over build vars
2020-10-08 14:02:23 -04:00
Alex Suraci 95f7540e0e
Merge pull request #6129 from concourse/bug/at-sign-in-var
allow @ sign in var
2020-10-07 09:37:48 -04:00
Aidan Oldershaw 538dc68b5f Merge branch 'master' into refactor-vars
Signed-off-by: Aidan Oldershaw <aoldershaw@pivotal.io>
2020-10-06 22:14:05 -04:00
Rui Yang 0126ff79b4 atc:var: allow @ in a var path
Signed-off-by: Rui Yang <ruiya@vmware.com>
2020-10-06 12:18:08 -04:00
Anshul Sirur ea527224a9
vars: fix quoting for subkeys
JSON-escaped quotes were not being removed from subkeys and secret
fields that are quoted because they contain special characters.

Signed-off-by: Anshul Sirur <vixus0@gmail.com>
2020-10-05 13:14:46 +02:00
Aidan Oldershaw e38d12e7ad atc: structure: move vars.BuildVariables to exec pkg
Something specific to Builds didn't belong outside of the atc package.
Given that it's only consumed directly by the exec.RunState, it made
sense to go there.

I considered just inlining all of the logic in RunState, but decided
it's better to keep RunState lean, since it already has a few
responsibilities.

Signed-off-by: Aidan Oldershaw <aoldershaw@pivotal.io>
2020-09-21 09:14:32 -04:00
Aidan Oldershaw 41c606daa6 vars: behaviour: properly handle local scope
I realized that local scope wasn't being handled properly before. We
created a clone of the local vars when we called `NewLocalScope`, but
local vars are typically populated at runtime - not in the
`engine/builder`. So, the clone was always empty. Instead, form a linked
list of `BuildVariables` that point to its parent scope.

This commit also renames `CredVarsTracker` to `BuildVariables`, and
exposes the struct directly rather than an interface. This commit is
incomplete in the sense that it doesn't perform that renaming
everywhere, but the diff got pretty huge and I wanted to separate out
just the behaviour aspect of this change.

Signed-off-by: Aidan Oldershaw <aoldershaw@pivotal.io>
2020-08-16 11:22:16 -04:00
Aidan Oldershaw 4d4c3f8baf atc: behaviour: allow creating var subscopes
In order for the across step to function properly, each instance of a
step run `across` multiple values must have its own local scope. This
way, the each step will have its own version of the value its iterating
over, and any `get_var` or `load_var` steps run in an `across` step
won't pollute the others (since `across` steps can run multiple things
in parallel).

Signed-off-by: Aidan Oldershaw <aoldershaw@pivotal.io>
2020-08-14 14:54:39 -04:00
Rui Yang 03306f7d26 vars: use unique var name for missing error
use source+path as unique identifier for visited all error

Signed-off-by: Rui Yang <ruiya@vmware.com>
2020-07-28 22:13:39 -04:00
Rui Yang 390db17a4b creds: ref.Path instead of red.Name to fetch secret
Signed-off-by: Rui Yang <ruiya@vmware.com>
2020-07-23 11:38:52 -04:00
Zoe Tian c02c41102f chagne var name to var reference in creds package
put back fields look up logic from static_vars to tempalte

Signed-off-by: Rui Yang <ruiya@vmware.com>
2020-07-23 11:38:52 -04:00
Rui Yang 1a6e35143a vars: allow special char in var lookup path
* extract source, path and fields from secrect name instead of treating it
as black box
* move nested variables lookup out of template into static_vars
* refactor trackers error handling

Signed-off-by: Rui Yang <ryang@pivotal.io>
Co-authored-by: Bohan Chen <bochen@pivotal.io>
2020-07-23 11:38:52 -04:00
Bishoy Youssef 6c31eb8626 update notice and concourse email
Signed-off-by: Bishoy Youssef <byoussef@pivotal.io>
2020-07-09 12:24:23 -04:00
Ciro S. Costa bea76f65e0 vars: use go std err wrapping
as we standardize on wrapping errors using `errors` (rather than
`github.com/pkg/errors), we can also make our testing standard (using
`errors.Is()` to check if we got a specific err in the chain).

Signed-off-by: Ciro S. Costa <cscosta@pivotal.io>
2020-03-04 10:18:05 -05:00
Chao Li 817bcb9afe Change "insensitive" to "reveal". And make unit tests and test flights pass.
Signed-off-by: Chao Li <chaol@vmware.com>
2020-01-29 16:08:45 +08:00
Chao Li d08381cdf6 Rename var step to load_var step.
Signed-off-by: Chao Li <chaol@vmware.com>
2020-01-29 16:08:45 +08:00
Chao Li d9c24f1e85 atc(feat): initial code of input_vars
Signed-off-by: Chao Li <chaol@vmware.com>
2020-01-29 15:47:26 +08:00
Chao Li 34caec908a Addressed the review comment of "unknow var source error".
Signed-off-by: Chao Li <chaol@vmware.com>
2019-12-12 14:47:17 +08:00
Chao Li 8636b9f239 Addressed review comments and fixed the testflight failure. Dec. 12 2019
Signed-off-by: Chao Li <chaol@vmware.com>
2019-12-12 09:53:17 +08:00
Chao Li 6cc09c2800 Addressed review comments. Dec. 11, 2019
Signed-off-by: Chao Li <chaol@vmware.com>
2019-12-11 10:22:26 +08:00
Chao Li d11896e8ac Order var_sources by dependency and enhanced error message.
Signed-off-by: Chao Li <chaol@vmware.com>
2019-12-11 07:16:20 +08:00
Chao Li 6ea4b10312 feat(atc): support named var.
Signed-off-by: Chao Li <chaol@vmware.com>
2019-12-11 07:16:20 +08:00
Chao Li 738d0a0cd2 fix(atc): fixed a crash from credVarsTracker.
Signed-off-by: Chao Li <chaol@vmware.com>
2019-12-02 15:25:59 +08:00
Chao Li 17eb00662e fix(atc): when secret redaiction is not enabled, should not buffer build log lines.
Fixes #4799

Signed-off-by: Chao Li <chaol@vmware.com>
2019-11-25 22:40:16 +08:00
Jamie Klassen 98446dc88d ginkgo blur
Signed-off-by: Jamie Klassen <cklassen@pivotal.io>
2019-09-16 17:09:56 -04:00
Chao Li ebc23a7fa5 feat: redacting secrets in build logs.
With this change, for all secrets fetched from credential manager, if they appear
in build logs, then they will be automatically redacted as "[**redacted**]]".

As this is currently an exprimental feature, a "concourse web" command option
"--enable-redact-secrets" has been added to turn on this feature.

Close #4311

Signed-off-by: Chao Li <chaol@vmware.com>
2019-09-09 13:34:30 +08:00
Alex Suraci 9f09c18404 switch to sigs.k8s.io/yaml
this is the fork of github.com/ghodss/yaml maintained by the k8s project

bumped a few dependencies necessary to get github.com/ghodss/yaml out of
the dependency graph; notably k8s and etcd (which is a transitive
dependency of the vault cred manager)

Signed-off-by: Alex Suraci <suraci.alex@gmail.com>
2019-09-04 10:13:24 -04:00
Alex Suraci 299abbca81 atc: refactor all vars errors
Define '*Error' types instead of generating an error string each time,
and update the wording to be more consistent with the rest of the errors
(mainly, lowercase them)

side note: I noticed a few places where these error strings were faked
out in a HTTP response for tests, but those tests don't actually care
about the error message, so I changed them to just use a filler message.
Those tests should probably be refactored to assert on the only actual
change in behavior: that the ?check_creds query param is set.

Signed-off-by: Alex Suraci <suraci.alex@gmail.com>
2019-08-13 15:17:15 -04:00
Alex Suraci 46271aaf47 atc: use higher-level constructs for k8s tests
Signed-off-by: Alex Suraci <suraci.alex@gmail.com>
2019-08-12 13:56:46 -04:00
Alex Suraci b1683c58c4 rename atc/template package to vars
this fixes auto-import conflicts with text/template and moves it
somewhere central so fly doesn't have to import it from the atc

Signed-off-by: Alex Suraci <suraci.alex@gmail.com>
2019-07-23 11:06:11 -04:00