canonical / hotsos

Software analysis toolkit. Define checks in high-level language and leverage library to perform analysis of common Cloud applications.
Apache License 2.0
30 stars 37 forks source link

YDefsLoader: add variable interpolation support #858

Open mustafakemalgilor opened 2 months ago

mustafakemalgilor commented 2 months ago

the default YAML format does not support variable interpolation e.g. referring to another key's value, but it's possible to add it with the help of 'add_constructorandadd_implicit_resolver`.

Example usage:

c: cool
x:
  y: abcdefg
  z: hijklmno
  t: ${c}

foo: ${x.y}${x.z} ${x.t}
# foo's value would be `abcdefghijklmno cool`
dosaboy commented 2 months ago

This is interesting. one bit of initial feedback i'd have is that it is providing an alternate way to define variables that doesn't behave in the same way e.g. with the existing vars: you can set a variable to a literal, property, factory etc. If we could somehow meld the two that would be cool but I think having two independent ways of doing this might not be a benefit. Thoughts?

mustafakemalgilor commented 2 months ago

This is interesting. one bit of initial feedback i'd have is that it is providing an alternate way to define variables that doesn't behave in the same way e.g. with the existing vars: you can set a variable to a literal, property, factory etc. If we could somehow meld the two that would be cool but I think having two independent ways of doing this might not be a benefit. Thoughts?

I feel the same way as well. The proposition value of this patch is not to provide an alternate way to bring properties or replace any other run-time interpreted values, on the contrary, it aims to complement it. I'll experiment with the existing scenarios and see how these two will behave together.