using_webhooks.rst 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. Using web-hooks
  2. ===============
  3. Web-hooks are a notification system that could be compared to a callback.
  4. Basically, pagure will make a HTTP POST request to one or more third party
  5. server/application with information about what is or just happened.
  6. To set-up a web-hook, simply go to the settings page of your project and
  7. enter the URL to the server/endpoint that will receive the notifications.
  8. There is, in the settings page, a web-hook key which is used by the
  9. server (here pagure) to sign the message sent and which you can use to
  10. ensure the notifications received are coming from the right source.
  11. Each POST request made contains two specific headers:
  12. ::
  13. X-Pagure-Topic
  14. X-Pagure-Signature
  15. ``X-Pagure-Topic`` is a global header giving a clue about the type of action
  16. that just occured. For example ``issue.edit``.
  17. ``X-Pagure-Signature`` contains the signature of the message allowing to
  18. check that the message comes from pagure.
  19. .. warning:: These headers are present for convenience only, they are not
  20. signed and therefore should not be trusted. Rely on the payload
  21. after checking the signature to make any decision.
  22. Pagure relies on ``hmac`` to sign the content of its messages. If you want
  23. to validate the message, in python, you can do something like the following:
  24. ::
  25. import hmac
  26. import hashlib
  27. payload = # content you received in the POST request
  28. headers = # headers of the POST request
  29. project_web_hook_key = # private web-hook key of the project
  30. hashhex = hmac.new(
  31. str(project_web_hook_key), payload, hashlib.sha1).hexdigest()
  32. if hashhex != headers.get('X-Pagure-Signature'):
  33. raise Exception('Message received with an invalid signature')
  34. The notifications sent via web-hooks have the same payload as what is sent
  35. via `fedmsg <http://www.fedmsg.com/en/latest/>`_. Therefore, the list of
  36. pagure topics as well as example messages can be found in the
  37. `fedmsg documentation about pagure
  38. <https://fedora-fedmsg.readthedocs.org/en/latest/topics.html#id532>`_