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

Add format option for env command #253

Open
Na3blis opened this issue Jan 8, 2021 · 1 comment
Open

Add format option for env command #253

Na3blis opened this issue Jan 8, 2021 · 1 comment
Labels

Comments

@Na3blis
Copy link

Na3blis commented Jan 8, 2021

Expected behavior

I would like to be able to format the output of envconsul env. Currently it outputs the following:

MY_SERVICE_URL=http://my-service-v2:8080/
SVC_KEY_P12=MIIQYQIBAzCCECcGCSqGSIb3DQEHAaCCEBgEghAUMIIQEDCCBkcGCSqGSIb3DQEHBqCCBjgwggY0
AgEAMIIGLQYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQYwDgQIn5LPw/Y+X3YCAggAgIIGAC0mH42g
qRZFopAvv/zNu8Pyn8K7kGBTO2kolHhOI6IjondOiNOCGLbZDxgicAO2cVbA0YfLdopB78GKRSeI
6k1o7cb2H7a4I/ncEjVLcZOoOWYzi1hfY7CfjIPjpjRAp6b0eqL7krO6U+By340vbPjUHL4hQY2t
MY_SERVICE_PORT=8080

Actual behavior

I would like to print in JSON or some other easily parsable format, ie:

{
   "MY_SERVICE_URL": "http://my-service-v2:8080/",
   "SVC_KEY_P12": "MIIQYQIBAzCCECcGCSqGSIb3DQEHAaCCEBgEghAUMIIQEDCCBkcGCSqGSIb3DQEHBqCCBjgwggY0
   AgEAMIIGLQYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQYwDgQIn5LPw/Y+X3YCAggAgIIGAC0mH42g
qRZFopAvv/zNu8Pyn8K7kGBTO2kolHhOI6IjondOiNOCGLbZDxgicAO2cVbA0YfLdopB78GKRSeI
6k1o7cb2H7a4I/ncEjVLcZOoOWYzi1hfY7CfjIPjpjRAp6b0eqL7krO6U+By340vbPjUHL4hQY2t",
   "MY_SERVICE_PORT": 8080
}

The issue is I cannot easily parse multi-line values. As you can see the SVC_KEY_P12 comes across 4 separate lines (though really a P12 would be many more than 4 lines), but there's not really a way to tell that that all of that is a single variable since every each variable is on it's own new line, making it looks like it's a separate variable.

@eikenb eikenb added the question label Jan 8, 2021
@eikenb
Copy link
Contributor

eikenb commented Jan 8, 2021

Envconsul is designed to export string values into the environment. You could shove a whole JSON object into it with some work (escaping quoting might be an issue... not sure), but ideally it would be better to have those JSON values pre-split into separate fields in consul so you could load them into separate environment variables (eg. MY_SERVICE_URL, SVC_KEY_P12 would be separate entries).

If you really want to work with something in a JSON format it sounds like you might be more interested in using consul-template for this as it has features to let you output data in a JSON format.

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

No branches or pull requests

2 participants