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

Authentication for HTTP/HTTPS datasources #113

Closed
abnerjacobsen opened this issue Apr 5, 2017 · 5 comments
Closed

Authentication for HTTP/HTTPS datasources #113

abnerjacobsen opened this issue Apr 5, 2017 · 5 comments
Assignees

Comments

@abnerjacobsen
Copy link

I'm using gomplate to generate the configurations of docker containers in a project I keep named Daspanel. So far I've used the datasource coming from a file with success, but now I need to get data from an API using authentication through a token that has to be passed using an HTTP header. An example of calling the API using curl is below:

curl -X GET --header 'Accept: application/json' --header 'Authorization: myauthtoken' 'http://api.daspanel.site/1.0/sites/httpconf/mydomain.com'

I looked in the documentation but found no example of how to pass a header when using the HTTP/HTTPS datasource. Is this possible ? If not, could you consider adding this feature to gomplate?

With this feature gomplate can directly consume json data from APIs that use token or JWT authentication.

@hairyhenderson
Copy link
Owner

@abnerjacobsen Hi, thanks for logging this - always good to meet new gomplate users!

I've started thinking about how to implement this months ago, and truth be told it fell by the wayside.

What would be the best interface for your use-case? Would something like an HTTP_AUTH_HEADER environment variable work? Or would it be better if it were a command-line option, maybe part of the --datasource option? Any ideas would be appreciated 🙂

@abnerjacobsen
Copy link
Author

Ideally, you can enter the required header as a command-line option. In case of my API has to be the following:

'Authorization: myapikey'

Other examples I found on the internet:

Http://jwt.io:
Authorization:Bearer <token>

Https://api.data.gov/docs/api-key:
'X-Api-Key: DEMO_KEY'

Http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-api-keys.html
X-api-key: hzYAVO9Sg98nsNh81M84O2kyXVy6K1xwHD8

Https://api.cloudflare.com/#getting-started-requests

"X-Auth-Key: 1234567893feefc5f0q5000bfo0c38d90bbeb"
"X-Auth-Email: example@example.com"

In the case of Cloudflare 2 HTTP headers are required to authenticate. For this reason it is ideal to be able to set one or more HTTP headers, as is done with the curl using the --header option.
A --header option would also allow other type of configurations, like Content-Type

@hairyhenderson
Copy link
Owner

Ok, thanks @abnerjacobsen, that helps. Since the headers should only be sent with one datasource (wouldn't want secret tokens being sent to the wrong URLs!), I'm thinking a command like this might work:

$ gomplate --datasource daspanel=http://api.daspanel.site/1.0/sites/httpconf/mydomain.com --datasource-header 'daspanel=Authorization: myauthtoken' --datasource-header 'daspanel=Accept: application/json' < foo.template

As a short-form to --datasource-header, maybe -H would work.

As an aside, gomplate will auto-detect what format the data is based on the Content-Type header, so if your API sends application/json by default, setting the Accept: application/json header may not be necessary.

Does this all sound 👍 to you? I'll try to find some time to get started implementing this soon.

@abnerjacobsen
Copy link
Author

@hairyhenderson This proposed implementation is fine for me. Thank you for your attention to this request.

@hairyhenderson
Copy link
Owner

@abnerjacobsen I've implemented this in #115 - it'll be released as part of v1.6.0

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

No branches or pull requests

2 participants