root / snf-astakos-client / docs / index.rst @ 1acf67a7
History | View | Annotate | Download (5 kB)
1 |
.. _snf-astakos-client: |
---|---|
2 |
|
3 |
Component snf-astakos-client |
4 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
5 |
|
6 |
synnefo component :ref:`snf-common <snf-common>` defines a default client |
7 |
for the :ref:`astakos <astakos>` service. It is designed to be minimal, |
8 |
hence easily debugged and unit tested. |
9 |
|
10 |
It uses the user's authentication token to query astakos for: |
11 |
* User's info |
12 |
* Usernames of given uuids |
13 |
* Uuids of given usernames |
14 |
|
15 |
It can also query astakos with a service's auth token for: |
16 |
* Usernames of given uuids |
17 |
* Uuids of given usernames |
18 |
|
19 |
Additionally there are options for using the objpool library to |
20 |
pool the http connections. |
21 |
|
22 |
|
23 |
Basic example |
24 |
============= |
25 |
|
26 |
The astakosclient module provides the AstakosClient class. This section |
27 |
demonstrates how to get user's info using astakosclient. |
28 |
|
29 |
.. code-block:: python |
30 |
|
31 |
from astakosclient import AstakosClient |
32 |
|
33 |
client = AstakosClient("https://accounts.example.com") |
34 |
user_info = client.authenticate("UQpYas7ElzWGD5yCcEXtjw==") |
35 |
print user_info['username'] |
36 |
|
37 |
Another example where we ask for the uuid of user user1@example.com |
38 |
|
39 |
.. code-block:: python |
40 |
|
41 |
from astakosclient import AstakosClient |
42 |
|
43 |
client = AstakosClient("https://accounts.example.com") |
44 |
username = client.getDisplayName("UQpYas7ElzWGD5yCcEXtjw==", |
45 |
"b3de8eb0-3958-477e-als9-789af8dd352c") |
46 |
print username |
47 |
|
48 |
|
49 |
Classes and functions |
50 |
===================== |
51 |
|
52 |
This section describes in depth the API of astakosclient. |
53 |
|
54 |
Astakos Client |
55 |
-------------- |
56 |
|
57 |
*class* astakosclient.\ **AstakosClient(**\ astakos_url, |
58 |
retry=0, use_pool=False, pool_size=8, logger=None\ **)** |
59 |
|
60 |
Initialize an instance of **AstakosClient** given the *astakos_url*. |
61 |
Optionally one can specify if we are going to use a pool, the pool_size |
62 |
and the number of retries if the connection fails. |
63 |
|
64 |
This class provides the following methods: |
65 |
|
66 |
**authenticate(**\ token, usage=False\ **)** |
67 |
Given a valid authentication token it returns a dict with the |
68 |
correspoinding user's info. If usage is set to True more |
69 |
information about user's resources will be returned. |
70 |
In case of error raise an AstakosClientException exception. |
71 |
|
72 |
**getDisplayNames(**\ token, uuids\ **)** |
73 |
Given a valid authentication token and a list of uuids |
74 |
return a uuid_catalog, that is a dictionary with the given |
75 |
uuids as keys and the corresponding user names as values. |
76 |
Invalid uuids will not be in the dictionary. |
77 |
In case of error raise an AstakosClientException exception. |
78 |
|
79 |
**getDisplayName(**\ token, uuid\ **)** |
80 |
Given a valid authentication token and a uuid (as string) |
81 |
return the corresponding user name (as string). |
82 |
In case of invalid uuid raise NoDisplayName exception. |
83 |
In case of error raise an AstakosClientException exception. |
84 |
|
85 |
**getServiceDisplayNames(**\ token, uuids\ **)** |
86 |
Same as getDisplayNames but called with a service's token. |
87 |
|
88 |
**getServiceDisplayName(**\ token, uuid\ **)** |
89 |
Same as getDisplayName but called with a service's token. |
90 |
|
91 |
**getUUIDs(**\ token, display_names\ **)** |
92 |
Given a valid authentication token and a list of usernames |
93 |
return a displayname_catalog, that is a dictionary with the given |
94 |
usernames as keys and the corresponding uuids as values. |
95 |
Invalid usernames will not be in the dictionary. |
96 |
In case of error raise an AstakosClientException exception. |
97 |
|
98 |
**getUUID(**\ token, display_name\ **)** |
99 |
Given a valid authentication token and a username (as string) |
100 |
return the corresponding uuid (as string). |
101 |
In case of invalid user name raise NoUUID exception. |
102 |
In case of error raise an AstakosClientException exception. |
103 |
|
104 |
**getServiceUUIDs(**\ token, uuids\ **)** |
105 |
Same as getUUIDs but called with a service's token. |
106 |
|
107 |
**getServiceUUID(**\ token, uuid\ **)** |
108 |
Same as getUUID but called with a service's token. |
109 |
|
110 |
**getServices()** |
111 |
Return a list of dicts with the registered services. |
112 |
|
113 |
|
114 |
Public Functions |
115 |
---------------- |
116 |
|
117 |
**getTokenFromCookie(**\ request, cookie_name\ **)** |
118 |
Given a django request object and astako's cookie name |
119 |
extract user's token from it. |
120 |
|
121 |
|
122 |
Exceptions and Errors |
123 |
===================== |
124 |
|
125 |
*exception* **AstakosClientException** |
126 |
Raised in case of an error. It contains an error message and the |
127 |
corresponding http status code. Other exceptions raise by astakosclient |
128 |
module are derived from this one. |
129 |
|
130 |
*exception* **BadRequest** |
131 |
Raised in case of a Bad Request, with status 400. |
132 |
|
133 |
*exception* **Unauthorized** |
134 |
Raised in case of Invalid token (unauthorized access), with status 401. |
135 |
|
136 |
*exception* **Forbidden** |
137 |
The server understood the request, but is refusing to fulfill it. |
138 |
Status 401. |
139 |
|
140 |
*exception* **NotFound** |
141 |
The server has not found anything matching the Request-URI. Status 404. |
142 |
|
143 |
*exception* **NoDisplayName** |
144 |
Raised by getDisplayName and getServiceDisplayName when an invalid |
145 |
uuid was given. |
146 |
|
147 |
*exception* **NoUUID** |
148 |
Raised by *getUUID* and *getServiceUUID* when an invalid |
149 |
username was given. |