Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support exclude key on interpolation for himl #16

Closed
ecojan opened this issue Apr 30, 2020 · 12 comments
Closed

Support exclude key on interpolation for himl #16

ecojan opened this issue Apr 30, 2020 · 12 comments
Labels
enhancement New feature or request

Comments

@ecojan
Copy link
Collaborator

ecojan commented Apr 30, 2020

Himl goes through each value and checks for "{{ interpolation.key }}".
If we want to pass the following value "{{ template custom.value }}" that can be used by an end application, interpolation will fail as custom.value is not found.

It would be nice to have a flag or way to explicitly say a value should not be interpolated.

The only workaround for this is be setting "skip_interpolation_validation=True".

@danielcoman
Copy link
Contributor

I can see this as a valid use case resolved right now by the flag you mentioned 'skip_interpolation_validation=True'.
Also, excluse will completely remove the key before any interpolation. I'm thinking you want something that will not do validation on specified keys. This has the potential to be missused or get cumbersome with more than a few keys that you need to keep track of.

Can you elaborate more on your use case and why just disabling validation doesn't work?

@ecojan
Copy link
Collaborator Author

ecojan commented Apr 30, 2020

Can you elaborate more on your use case and why just disabling validation doesn't work?

I see the validation as a safety net, something that must be interpolated but doesn't get interpolated due to an error should come up when running himl. On the other hand if there are some keys that you specifically don't want to interpolate (leave them as they are), here is where I would see the advantage of having an option to exclude the aforementioned key from the interpolation process.

WDYT?

@danielcoman
Copy link
Contributor

Yes, validation good.
Still interested in your use case, if you can elaborate on that.
At first glance seems you are trying to use hiera as a template engine to template a template and I don't think this is a good use case.

@ecojan
Copy link
Collaborator Author

ecojan commented Apr 30, 2020

Yes, validation good.
Still interested in your use case, if you can elaborate on that.
At first glance seems you are trying to use hiera as a template engine to template a template and I don't think this is a good use case.

I'm not sure what you are referring to or how hiera is tied in here.
My use case is as follow:

I have the following yaml file in one of the subdirectories traversed by himl

slack_configs:
- channel: my-channel
   text: '{{ template "__slack_text" . }}'

I'm just trying to ignore the text key during interpolation here as it would crash the himl processing without disabling validation. The value for the text key ( '{{ template "__slack_text" . }}' ) is gonna be used later in the obtained output by something independent of himl (again just trying to ignore a key).

@ecojan
Copy link
Collaborator Author

ecojan commented Apr 30, 2020

The issue is when using himl on a configuration that needs to be passed to a different application that is using the same format "{{"and "}}"

@danielcoman
Copy link
Contributor

danielcoman commented Apr 30, 2020

Seems that what you need is to escape the key value. For example, using double quotes in key: "{{ val }}" resolves the interpolation, but using single quotes key: '{{ val }}' results in the literal {{ val }} string. I think instead of manually ignoring some keys it would be better to support escaping interpolation on values. Would this fit your use case?

@amuraru
Copy link
Contributor

amuraru commented Apr 30, 2020

Escaping interpolation is the keyword here, yes.

Double quote vs single quote seems weak though.
The himl user should be able to explicitly turn off interpolation within a value.
And it may not be possible to implement, when parsing value in https://github.com/adobe/himl/blob/master/himl/interpolation.py#L17

key: "value", key: 'value' and key: value are equivalent in yaml parser. you get the value string

@danielcoman
Copy link
Contributor

danielcoman commented May 1, 2020

I've only used quotes as an example on escaping values. Wanted to use something else but thought quotation would be more familiar and easy to visualize.

@amuraru
Copy link
Contributor

amuraru commented May 1, 2020

Cool - makes sense

@amuraru
Copy link
Contributor

amuraru commented May 1, 2020

I think we can use a similar escape sequence as in go templates:

{{`this is a {{value}} that should not be interpolated`}}

/cc @costimuraru

@ecojan
Copy link
Collaborator Author

ecojan commented May 5, 2020

@danielcoman I tried escaping via single quotes vs double quotes.
None of them have worked, they both are equivalent as @amuraru said.
One option that can actually make it work is "--skip-interpolation-resolving" but this is not actual escaping and is turning off other features.

@danielcoman danielcoman added the enhancement New feature or request label May 5, 2020
@danielcoman
Copy link
Contributor

@ecojan Well... it's not implemented. Quotation is only used as an example.

I've only used quotes as an example on escaping values. Wanted to use something else but thought quotation would be more familiar and easy to visualize.

Conclusions from this thread is that the feature needed is not a flag or a list of keys to ignore in interpolation validation, but proper escaping for values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants