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

Allow passing a prefix format along with prefix path #161

Closed
wants to merge 1 commit into from
Closed

Allow passing a prefix format along with prefix path #161

wants to merge 1 commit into from

Conversation

franckverrot
Copy link

This commit makes it possible to pass a prefix format to the CLI, along
with a prefix path, also enabling one format per path.

The delimiter that has been chosen is "@", as this character is not
allowed in the naming scheme of environment variables [1].

This type of command is now possible:

envconsul -prefix my_prefix_1@pref1_{{key}} -prefix my_prefix_2@some_other_prefix_{{key}}

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html

This commit makes it possible to pass a prefix format to the CLI, along
with a prefix path, also enabling one format per path.

The delimiter that has been chosen is "@", as this character is not
allowed in the naming scheme of environment variables [1].

This type of command is now possible:

    envconsul -prefix my_prefix_1@pref1_{{key}} -prefix my_prefix_2@some_other_prefix_{{key}}

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html
@eikenb
Copy link
Contributor

eikenb commented May 14, 2019

Hi @franckverrot, thanks for the submission and sorry for the delayed response.

If possible would you be able to provide a use case for this feature. There are several prefix related PRs and I'm trying to get a handle on why they are wanted to see if I can figure out the best way forward. Thanks.

@franckverrot
Copy link
Author

Hey @eikenb,

It's been a while and I changed a bit my naming scheme to get going and avoid the issue, but for a k/v structure that would look like:

+ /
+-- project1
   |- foo: bar
+-- project2
   |- foo: baz
   |- bat: qux

A configuration like:

envconsul -prefix project1@project1_{{key}} -prefix project2@project2_{{key}}

would allow importing the keys without conflicts, resulting in the following environment variables:

project1_foo: bar
project2_foo: baz
project2_bat: qux

It's useful to:

  1. Split keys based by apps
  2. Have common prefixes for values that are shared between apps
  3. Know, from just reading the key, where it was coming from (eg. is it my app's configuration or some other app/a shared infrastructure configuration that I am looking at?)

Does it help?

Thanks!

@eikenb
Copy link
Contributor

eikenb commented May 16, 2019

@franckverrot Thanks for the detailed response.

Sounds like you might be happy if you were able to have the prefixes prepended to your keys. Up until a couple days ago the consul keys returned from the requested -prefix always just returned the final key name. Now with #204 merged, there is a no_prefix option for consul which, somewhat confusingly, means you now have the option for all consul keys to be returned with the prefixes as part of the key name. So using your example, if you configure envconsul with no_prefix=false...

Right now you need to use a config file (see #205 is about adding the cli argument)..

prefix {               
    no_prefix = false
    path = "project1"
}
prefix {
    no_prefix = false
    path = "project2"
}

Then assuming the same data..

$ envconsul -config=example.hcl -pristine env
project2_bat=qux
project2_foo=baz
project1_foo=bar

Once some version of #205 lands, you'll be able to get the same results with..
envconsul -prefix project1 -prefix project2 -no-prefix=false -pristine env

Does that seem like it'd meet your needs?

@franckverrot
Copy link
Author

@eikenb A little bit confusing on the naming but exactly what I was looking for. I'm closing this PR then. Thanks a bunch!

@franckverrot franckverrot deleted the add-prefix-format branch May 16, 2019 20:32
@eikenb
Copy link
Contributor

eikenb commented May 16, 2019

Yeah. The naming is unfortunate and not breaking the old behavior complicated things (ie. we had to keep the default of no_profix=true for consul for backwards compatibility).

We'll probably change the default to make more sense at some point when we can afford to make more backwards incompatibilities. But we want to keep it as is for now.

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.

None yet

2 participants