Commit 70b206a4 authored by Ilias Tsitsimpis's avatar Ilias Tsitsimpis
Browse files

Add documentation for snf-astakos-client package

parent e23e093f
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " texinfo to make Texinfo files"
@echo " info to make Texinfo files and run them through makeinfo"
@echo " gettext to make PO message catalogs"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
clean:
-rm -rf $(BUILDDIR)/*
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/synnefo.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/synnefo.qhc"
devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/synnefo"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/synnefo"
@echo "# devhelp"
epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."
latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."
man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
texinfo:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."
info:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
gettext:
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
@echo
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."
import sys
import os
sys.path.insert(0, os.path.abspath('..'))
from astakosclient.version import __version__
project = u'nnefo'
copyright = u'2012-2013, GRNET'
version = __version__
release = __version__
html_title = 'synnefo ' + version
templates_path = ['_templates']
source_suffix = '.rst'
master_doc = 'index'
exclude_patterns = ['_build']
pygments_style = 'sphinx'
html_theme = 'default'
html_theme_options = {
'collapsiblesidebar': 'true',
'footerbgcolor': '#55b577',
'footertextcolor': '#000000',
'sidebarbgcolor': '#ffffff',
'sidebarbtncolor': '#f2f2f2',
'sidebartextcolor': '#000000',
'sidebarlinkcolor': '#328e4a',
'relbarbgcolor': '#55b577',
'relbartextcolor': '#ffffff',
'relbarlinkcolor': '#ffffff',
'bgcolor': '#ffffff',
'textcolor': '#000000',
'headbgcolor': '#ffffff',
'headtextcolor': '#000000',
'headlinkcolor': '#c60f0f',
'linkcolor': '#328e4a',
'visitedlinkcolor': '#63409b',
'codebgcolor': '#eeffcc',
'codetextcolor': '#333333'
}
html_static_path = ['_static']
htmlhelp_basename = 'synnefodoc'
intersphinx_mapping = {
'pithon': ('http://docs.python.org/', None),
'django': ('https://docs.djangoproject.com/en/dev/',
'https://docs.djangoproject.com/en/dev/_objects/')
}
SYNNEFO_DOCS_BASE_URL = 'http://docs.dev.grnet.gr/'
SYNNEFO_PROJECTS = {
'synnefo': 'dev',
'pithos': 'dev',
'snf-webproject': 'dev',
'snf-common': 'dev',
'snf-image': 'dev',
'snf-cyclades-app': 'dev'
}
for name, ver in SYNNEFO_PROJECTS.iteritems():
intersphinx_mapping[name.replace("-", "")] = (SYNNEFO_DOCS_BASE_URL +
'%s/%s/' % (name, ver),
None)
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.viewcode']
.. _snf-astakos-client:
Component snf-astakos-client
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
synnefo component :ref:`snf-common <snf-common>` defines a default client
for the :ref:`astakos <astakos>` service. It is designed to be minimal,
hence easily debugged and unit tested.
It uses the user's authentication token to query astakos for:
* User's info
* Usernames of given uuids
* Uuids of given usernames
It can also query astakos with a service's auth token for:
* Usernames of given uuids
* Uuids of given usernames
Additionally there are options for using the objpool library to
pool the http connections.
Basic example
=============
The astakosclient module provides the AstakosClient class. This section
demonstrates how to get user's info using astakosclient.
.. code-block:: python
from astakosclient import AstakosClient
client = AstakosClient("https://accounts.example.com")
user_info = client.authenticate("UQpYas7ElzWGD5yCcEXtjw==")
print user_info['username']
Another example where we ask for the uuid of user user1@example.com
.. code-block:: python
from astakosclient import AstakosClient
client = AstakosClient("https://accounts.example.com")
username = client.getDisplayName("UQpYas7ElzWGD5yCcEXtjw==",
"b3de8eb0-3958-477e-als9-789af8dd352c")
print username
Classes and functions
=====================
This section describes in depth the API of astakosclient.
Astakos Client
--------------
*class* astakosclient.\ **AstakosClient(**\ astakos_url,
retry=0, use_pool=False, pool_size=8, logger=None\ **)**
Initialize an instance of **AstakosClient** given the *astakos_url*.
Optionally one can specify if we are going to use a pool, the pool_size
and the number of retries if the connection fails.
This class provides the following methods:
**authenticate(**\ token, usage=False\ **)**
Given a valid authentication token it returns a dict with the
correspoinding user's info. If usage is set to True more
information about user's resources will be returned.
In case of error raise an AstakosClientException exception.
**getDisplayNames(**\ token, uuids\ **)**
Given a valid authentication token and a list of uuids
return a uuid_catalog, that is a dictionary with the given
uuids as keys and the corresponding user names as values.
Invalid uuids will not be in the dictionary.
In case of error raise an AstakosClientException exception.
**getDisplayName(**\ token, uuid\ **)**
Given a valid authentication token and a uuid (as string)
return the corresponding user name (as string).
In case of invalid uuid raise NoDisplayName exception.
In case of error raise an AstakosClientException exception.
**getServiceDisplayNames(**\ token, uuids\ **)**
Same as getDisplayNames but called with a service's token.
**getServiceDisplayName(**\ token, uuid\ **)**
Same as getDisplayName but called with a service's token.
**getUUIDs(**\ token, display_names\ **)**
Given a valid authentication token and a list of usernames
return a displayname_catalog, that is a dictionary with the given
usernames as keys and the corresponding uuids as values.
Invalid usernames will not be in the dictionary.
In case of error raise an AstakosClientException exception.
**getUUID(**\ token, display_name\ **)**
Given a valid authentication token and a username (as string)
return the corresponding uuid (as string).
In case of invalid user name raise NoUUID exception.
In case of error raise an AstakosClientException exception.
**getServiceUUIDs(**\ token, uuids\ **)**
Same as getUUIDs but called with a service's token.
**getServiceUUID(**\ token, uuid\ **)**
Same as getUUID but called with a service's token.
**getServices()**
Return a list of dicts with the registered services.
Public Functions
----------------
**getTokenFromCookie(**\ request, cookie_name\ **)**
Given a django request object and astako's cookie name
extract user's token from it.
Exceptions and Errors
=====================
*exception* **AstakosClientException**
Raised in case of an error. It contains an error message and the
corresponding http status code. Other exceptions raise by astakosclient
module are derived from this one.
*exception* **BadRequest**
Raised in case of a Bad Request, with status 400.
*exception* **Unauthorized**
Raised in case of Invalid token (unauthorized access), with status 401.
*exception* **Forbidden**
The server understood the request, but is refusing to fulfill it.
Status 401.
*exception* **NotFound**
The server has not found anything matching the Request-URI. Status 404.
*exception* **NoDisplayName**
Raised by getDisplayName and getServiceDisplayName when an invalid
uuid was given.
*exception* **NoUUID**
Raised by *getUUID* and *getServiceUUID* when an invalid
username was given.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment