envconsul icon indicating copy to clipboard operation
envconsul copied to clipboard

Add format option for env command

Open Na3blis opened this issue 5 years ago • 1 comments

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.

Na3blis avatar Jan 08 '21 19:01 Na3blis

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.

eikenb avatar Jan 08 '21 21:01 eikenb