delfick / bespin

Opinionated wrapper around boto that reads yaml
MIT License
6 stars 8 forks source link

Using formatted environment values breaks non-environment commands #74

Closed atward closed 7 years ago

atward commented 7 years ago

Probably best described by example:

$ cat bespin.yml
environments:
  example:
    tags:
      env: "{environment}"

stacks:
  example: {}
$ bespin
15:06:55 INFO    option_merge.collector Adding configuration from /Users/adamward/tmp/test/bespin.yml
15:06:55 INFO    bespin.collector Converting bespin
15:06:55 INFO    bespin.collector Converting environments

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Something went wrong! -- BadSpecValue
    "Bad value" meta={source=['./bespin.yml'], path=environments}
errors:
=======

    "Bad value" meta={source=['./bespin.yml'], path=environments.example}
    errors:
    =======

        "Bad value. Expected a value but got none"  meta={path=environments.example.account_id}
    -------
        "Bad value" meta={source=['./bespin.yml'], path=environments.example.tags}
        errors:
        =======

            "Something wrong with this specification. Spec doesn't know how to deal with this value"    meta={source=['./bespin.yml'], path=environments.example.tags.env}  spec=<input_algorithms.spec_base.formatted object at 0x1106ee310>   val={environment}
        -------
    -------
-------
$ bespin show
#also affected, same output

Also using {region} produces similar results.

delfick commented 7 years ago

try changing tags_spec to be

@memoized_property
def tags_spec(self):
    # http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html#tag-restrictions
    # Keys = 127 UTF-8 '^aws:' reserved. Values = 255 UTF-8
    return dictof(
          valid_string_spec(validators.regexed("^.{0,127}$"))
        , formatted(string_spec(), after_format=valid_string_spec(validators.regexed("^(?!aws:).{0,255}$")), formatter=MergedOptionStringFormatter)
        )

The difference is formatted taking in the after_format variable so it validates after the string has been formatted.

Though I'm confused at the error that is been risen.

It's complaining because the formatted doesn't know how to format the value (https://github.com/delfick/input_algorithms/blob/master/input_algorithms/spec_base.py#L158) but formatted has normalise_either and I don't see how it'd return NotSpecified.

What I expect is that the valid_string_spec raises an error saying {formatted} doesn't match your regex.....

atward commented 7 years ago

This does fix the issue. Though I don't think it's related to the regex. Regex of '.' should match everything

delfick commented 7 years ago

oh yeah, I didn't read the regex properly before... interesting....

atward commented 7 years ago

Closed in #75