Code Monkey home page Code Monkey logo

Comments (5)

hairyhenderson avatar hairyhenderson commented on August 15, 2024 1

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.

from gomplate.

hairyhenderson avatar hairyhenderson commented on August 15, 2024

@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 🙂

from gomplate.

abnerjacobsen avatar abnerjacobsen commented on August 15, 2024

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: [email protected]"

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

from gomplate.

abnerjacobsen avatar abnerjacobsen commented on August 15, 2024

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

from gomplate.

hairyhenderson avatar hairyhenderson commented on August 15, 2024

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

from gomplate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.