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 headers to the POST notifications #117

Closed
panda87 opened this issue Dec 22, 2015 · 7 comments
Closed

Add headers to the POST notifications #117

panda87 opened this issue Dec 22, 2015 · 7 comments

Comments

@panda87
Copy link

panda87 commented Dec 22, 2015

It would be great if we will be able to add headers to the POST alert handler call, since we can add auth and other tokens to the request and make it more generic for many 3rd party services.

Thanks
D.

@nathanielc
Copy link
Contributor

Something like this:

.alert()
   .post('http://example.com/path/to/something')
      .header('Authorization', 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==')

This creates a new problem in that you probably don't want to expose the auth in plain text in the TICKscript. As a result we probably need a method for grabbing values from the config or environment:

Maybe?

.alert()
   .post('http://example.com/path/to/something')
      .header('Authorization', config('example.com-password'))

with corresponding config:

[tickscript]
   example.com-password = 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='

Or env based without config:

.alert()
   .post('http://example.com/path/to/something')
      .header('Authorization', env('EXAMPLE_COM_PASSWORD'))

Follow up question: Would being able to set header as static strings (independent of whether they are directly in the TICKscript, or come from config/env) be enough flexibility to do what you need? Or would you need to be able to specify the header value as a function of the data?

@panda87
Copy link
Author

panda87 commented Dec 22, 2015

I personally prefer the ENV option since it's allow me to work closely with Vault, and grab the secrets from there directly to the ENV var of the system.

@fcastello
Copy link

Is this already implemented?

@nathanielc
Copy link
Contributor

@fcastello nope

@nhaugo
Copy link

nhaugo commented Mar 6, 2017

Lets support both the env and config options.

@desa
Copy link
Contributor

desa commented Mar 6, 2017

After discussion, the option that we've decided on going with the following

|alert()
  .post()
    .endpoint('example')

Which requires the configuration

[[post]]
endpoint = "example"
url = "http://example.com"
headers = { Authorization = "...", others = "..." }

This way values may be set through the configuration file, environment variables (via the config), and the API.

@desa
Copy link
Contributor

desa commented May 8, 2017

@panda87 @fcastello We just recently implemented this feature. It would be great if you could give it a try. We've added a section to the configuration file like so

 [[httppost]]
    endpoint = "example"
    url = "http://example.com"
    headers = { Example = "result" }
    basic-auth = { username = "my-user", password = "my-pass" }

Then to use it in a tickscript you simply

...
|alert()
 ...
 .post()
  .endpoint('example')

You can also set headers that are not the authorization header directly in tickscript

|alert()
 ...
 .post('http://example.com')
  .header('my', 'header')
  .header('heres', 'another')

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

6 participants