Skip to content

Commit

Permalink
docs: auto generate authorization header in api doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Qingping Hou authored and jrgp committed May 9, 2017
1 parent e517c55 commit 4f4b080
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ test:
make unit
make e2e

docs:
make -C docs html

e2e:
py.test -vv ./test/e2etest.py

Expand All @@ -36,4 +39,4 @@ combined-cov:
coverage combine
coverage report -m

.PHONY: test
.PHONY: test docs
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
web: make serve
sender: make sender
doc: cd docs/build/html && python -m SimpleHTTPServer 16647
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXBUILD = sphinx-build -E
PAPER =
BUILDDIR = build

Expand Down
13 changes: 8 additions & 5 deletions docs/source/rest_api.rst
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
REST API
========

.. _hmac-auth-label:

HMAC Auth
---------

API requests which require auth will have an extra :code:`AUTHORIZATION` HTTP header. It looks like
this:
API requests which require API key auth will have an extra
:code:`AUTHORIZATION` HTTP header. It looks like this:

.. code-block:: none
AUTHORIZATION: hmac $application:$payload
:code:`$payload` is a base64 encoded hmac sha512 digest of the following string. In the resulting base64 string, instances of :code:`+` are replaced with :code:`-`
and :code:`/` are replaced with :code:`_`.
:code:`$payload` is a base64 encoded hmac sha512 digest of the following string
with the app's API key. In the resulting base64 string, instances of :code:`+`
are replaced with :code:`-` and :code:`/` are replaced with :code:`_`.

.. code-block:: none
$window $httpMethod $path $body
HMAC($api_key, "$window $httpMethod $path $body")
:code:`$window` is the current unix timestamp in seconds, divided by 5, floor'd.

Expand Down
3 changes: 3 additions & 0 deletions src/iris/sphinx_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def make_rst(self, section_title_set):
continue
if not docstring:
continue
if not (handler.__self__.allow_read_no_auth and method == 'GET'):
docstring += '\n:reqheader Authorization: see :ref:`hmac-auth-label`.\n'

docstring = prepare_docstring(docstring)

# generate section title if needed
Expand Down

0 comments on commit 4f4b080

Please sign in to comment.