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

[WIP] resolve !env in yaml#1519

Closed

Conversation

yannick
Copy link
Contributor

@yannick yannick commented Dec 5, 2017

No description provided.

@yannick yannick changed the title resolve !env in yaml [WIP] resolve !env in yaml Dec 5, 2017
Copy link
Member

@kazuho kazuho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR.

I think that this would be a nice new feature.

if ((env_var_content = getenv(env_var)) == NULL)
env_var_content = "";

yaml_parser_t parser;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming that we can agree that the environment value should be accepted as a scalar (rather than a YAML), what you need to do is:

  1. free(node->data.scalar)
  2. initialize node->data.scalar to a string that can be freed using free (e.g. h2o_strdup(NULL, s, SIZE_MAX).base)
  3. increment the refcount of the node
  4. return the node

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kazuho i just realised that only scalars might not be useful enough.
how about numbers? probably the most obvious thing you want to sed is e.g. num-threads.
also being able to use anchors would be neat, so you can "implement" simple switches.

i actually do not see any downside (except for the more complex code) to parsing it correctly.
what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yannick

i just realised that only scalars might not be useful enough.
how about numbers? probably the most obvious thing you want to sed is e.g. num-threads.

In YAML there is no distinction between strings and numbers. Both are scalars.

also being able to use anchors would be neat, so you can "implement" simple switches.

I would rather not take that into consideration when making the decision. I do not think having room to "hack" is bad, but having a straightforward design is more important.

i actually do not see any downside (except for the more complex code) to parsing it correctly.

Users would be required to encode the environment variable in YAML, which is not an easy task.

Consider the case where a script accepts some argument and convert that to a environment variable to be used for substitution in the configuration file. The script would be required to convert the argument to YAML, otherwise things could go wrong depending on the argument.

Not only implementing such escaping is difficult, it is very easy for the author of script to forget implementing it. That means that we could see issues in production...

My anticipation is that majority (if not most) of the use-case can be covered by just supporting scalars to be supplied with environment variables. So I think we should not require escaping for the use case, instead of making it difficult for all users.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for the clarifications, i think it makes sense. i'll change the implementation

@yannick
Copy link
Contributor Author

yannick commented Dec 7, 2017

replaced by #1524

@yannick yannick closed this Dec 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants