root / astakosclient / docs / index.rst @ 54bac253
History | View | Annotate | Download (8 kB)
1 | fa7a3ca1 | Ilias Tsitsimpis | .. _astakosclient: |
---|---|---|---|
2 | 1acf67a7 | Ilias Tsitsimpis | |
3 | fa7a3ca1 | Ilias Tsitsimpis | Component astakosclient |
4 | 1acf67a7 | Ilias Tsitsimpis | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
5 | 1acf67a7 | Ilias Tsitsimpis | |
6 | fa7a3ca1 | Ilias Tsitsimpis | The Synnefo component :ref:`astakosclient <astakosclient>` defines a |
7 | 4b92d3f7 | Constantinos Venetsanopoulos | default client for the :ref:`Astakos <astakos>` service. It is designed to be |
8 | 4b92d3f7 | Constantinos Venetsanopoulos | simple and minimal, hence easy to debug and test. |
9 | 4b92d3f7 | Constantinos Venetsanopoulos | |
10 | 4b92d3f7 | Constantinos Venetsanopoulos | It uses the user's authentication token to query Astakos for: |
11 | 1acf67a7 | Ilias Tsitsimpis | |
12 | 1acf67a7 | Ilias Tsitsimpis | * User's info |
13 | 4b92d3f7 | Constantinos Venetsanopoulos | * Usernames for given UUIDs |
14 | 4b92d3f7 | Constantinos Venetsanopoulos | * UUIDs for given usernames |
15 | 5c418e94 | Ilias Tsitsimpis | * User's quotas |
16 | 4b92d3f7 | Constantinos Venetsanopoulos | |
17 | 4b92d3f7 | Constantinos Venetsanopoulos | It can also query Astakos with another service's (Cyclades or Pithos) |
18 | 4b92d3f7 | Constantinos Venetsanopoulos | authentication token for: |
19 | 1acf67a7 | Ilias Tsitsimpis | |
20 | 4b92d3f7 | Constantinos Venetsanopoulos | * Usernames for given UUIDs |
21 | 4b92d3f7 | Constantinos Venetsanopoulos | * UUIDs for given usernames |
22 | 5c418e94 | Ilias Tsitsimpis | * Issue commissions |
23 | 5c418e94 | Ilias Tsitsimpis | * Get pending commissions |
24 | 5c418e94 | Ilias Tsitsimpis | * Accept or reject commissions |
25 | 1acf67a7 | Ilias Tsitsimpis | |
26 | 4b92d3f7 | Constantinos Venetsanopoulos | Additionally, there are options for using the `objpool |
27 | 4b92d3f7 | Constantinos Venetsanopoulos | <https://github.com/grnet/objpool>`_ library to pool the http connections. |
28 | 1acf67a7 | Ilias Tsitsimpis | |
29 | 1acf67a7 | Ilias Tsitsimpis | |
30 | 1acf67a7 | Ilias Tsitsimpis | Basic example |
31 | 1acf67a7 | Ilias Tsitsimpis | ============= |
32 | 1acf67a7 | Ilias Tsitsimpis | |
33 | 4b92d3f7 | Constantinos Venetsanopoulos | The ``astakosclient`` module provides the ``AstakosClient`` class. This section |
34 | 4b92d3f7 | Constantinos Venetsanopoulos | demonstrates how to get user's info using ``astakosclient``. |
35 | 1acf67a7 | Ilias Tsitsimpis | |
36 | 1acf67a7 | Ilias Tsitsimpis | .. code-block:: python |
37 | 1acf67a7 | Ilias Tsitsimpis | |
38 | 1acf67a7 | Ilias Tsitsimpis | from astakosclient import AstakosClient |
39 | 1acf67a7 | Ilias Tsitsimpis | |
40 | 1acf67a7 | Ilias Tsitsimpis | client = AstakosClient("https://accounts.example.com") |
41 | 794c94e6 | Ilias Tsitsimpis | user_info = client.get_user_info("UQpYas7ElzWGD5yCcEXtjw==") |
42 | 1acf67a7 | Ilias Tsitsimpis | print user_info['username'] |
43 | 1acf67a7 | Ilias Tsitsimpis | |
44 | 4b92d3f7 | Constantinos Venetsanopoulos | Another example where we ask for the username of a user with UUID: |
45 | 4b92d3f7 | Constantinos Venetsanopoulos | ``b3de8eb0-3958-477e-als9-789af8dd352c`` |
46 | 1acf67a7 | Ilias Tsitsimpis | |
47 | 1acf67a7 | Ilias Tsitsimpis | .. code-block:: python |
48 | 1acf67a7 | Ilias Tsitsimpis | |
49 | 1acf67a7 | Ilias Tsitsimpis | from astakosclient import AstakosClient |
50 | 1acf67a7 | Ilias Tsitsimpis | |
51 | 1acf67a7 | Ilias Tsitsimpis | client = AstakosClient("https://accounts.example.com") |
52 | 794c94e6 | Ilias Tsitsimpis | username = client.get_username("UQpYas7ElzWGD5yCcEXtjw==", |
53 | 794c94e6 | Ilias Tsitsimpis | "b3de8eb0-3958-477e-als9-789af8dd352c") |
54 | 1acf67a7 | Ilias Tsitsimpis | print username |
55 | 1acf67a7 | Ilias Tsitsimpis | |
56 | 1acf67a7 | Ilias Tsitsimpis | |
57 | 1acf67a7 | Ilias Tsitsimpis | Classes and functions |
58 | 1acf67a7 | Ilias Tsitsimpis | ===================== |
59 | 1acf67a7 | Ilias Tsitsimpis | |
60 | 4b92d3f7 | Constantinos Venetsanopoulos | This section describes in depth the API of ``astakosclient``. |
61 | 1acf67a7 | Ilias Tsitsimpis | |
62 | 1acf67a7 | Ilias Tsitsimpis | Astakos Client |
63 | 1acf67a7 | Ilias Tsitsimpis | -------------- |
64 | 1acf67a7 | Ilias Tsitsimpis | |
65 | 1acf67a7 | Ilias Tsitsimpis | *class* astakosclient.\ **AstakosClient(**\ astakos_url, |
66 | 1acf67a7 | Ilias Tsitsimpis | retry=0, use_pool=False, pool_size=8, logger=None\ **)** |
67 | 1acf67a7 | Ilias Tsitsimpis | |
68 | 1acf67a7 | Ilias Tsitsimpis | Initialize an instance of **AstakosClient** given the *astakos_url*. |
69 | 1acf67a7 | Ilias Tsitsimpis | Optionally one can specify if we are going to use a pool, the pool_size |
70 | 1acf67a7 | Ilias Tsitsimpis | and the number of retries if the connection fails. |
71 | 1acf67a7 | Ilias Tsitsimpis | |
72 | 1acf67a7 | Ilias Tsitsimpis | This class provides the following methods: |
73 | 1acf67a7 | Ilias Tsitsimpis | |
74 | 794c94e6 | Ilias Tsitsimpis | **get_user_info(**\ token, usage=False\ **)** |
75 | 5c418e94 | Ilias Tsitsimpis | Given a user's authentication token it returns a dict with the |
76 | 1acf67a7 | Ilias Tsitsimpis | correspoinding user's info. If usage is set to True more |
77 | 1acf67a7 | Ilias Tsitsimpis | information about user's resources will be returned. |
78 | 1acf67a7 | Ilias Tsitsimpis | In case of error raise an AstakosClientException exception. |
79 | 1acf67a7 | Ilias Tsitsimpis | |
80 | 794c94e6 | Ilias Tsitsimpis | **get_usernames(**\ token, uuids\ **)** |
81 | 5c418e94 | Ilias Tsitsimpis | Given a user's authentication token and a list of UUIDs |
82 | 1acf67a7 | Ilias Tsitsimpis | return a uuid_catalog, that is a dictionary with the given |
83 | 4b92d3f7 | Constantinos Venetsanopoulos | UUIDs as keys and the corresponding user names as values. |
84 | 4b92d3f7 | Constantinos Venetsanopoulos | Invalid UUIDs will not be in the dictionary. |
85 | 1acf67a7 | Ilias Tsitsimpis | In case of error raise an AstakosClientException exception. |
86 | 1acf67a7 | Ilias Tsitsimpis | |
87 | 794c94e6 | Ilias Tsitsimpis | **get_username(**\ token, uuid\ **)** |
88 | 5c418e94 | Ilias Tsitsimpis | Given a user's authentication token and a UUID (as string) |
89 | 1acf67a7 | Ilias Tsitsimpis | return the corresponding user name (as string). |
90 | 794c94e6 | Ilias Tsitsimpis | In case of invalid UUID raise NoUserName exception. |
91 | 1acf67a7 | Ilias Tsitsimpis | In case of error raise an AstakosClientException exception. |
92 | 1acf67a7 | Ilias Tsitsimpis | |
93 | 794c94e6 | Ilias Tsitsimpis | **service_get_usernames(**\ token, uuids\ **)** |
94 | 794c94e6 | Ilias Tsitsimpis | Same as get_usernames but called with a service's token. |
95 | 1acf67a7 | Ilias Tsitsimpis | |
96 | 794c94e6 | Ilias Tsitsimpis | **service_get_username(**\ token, uuid\ **)** |
97 | 794c94e6 | Ilias Tsitsimpis | Same as get_username but called with a service's token. |
98 | 1acf67a7 | Ilias Tsitsimpis | |
99 | 794c94e6 | Ilias Tsitsimpis | **get_uuids(**\ token, display_names\ **)** |
100 | 5c418e94 | Ilias Tsitsimpis | Given a user's authentication token and a list of usernames |
101 | 1acf67a7 | Ilias Tsitsimpis | return a displayname_catalog, that is a dictionary with the given |
102 | 4b92d3f7 | Constantinos Venetsanopoulos | usernames as keys and the corresponding UUIDs as values. |
103 | 1acf67a7 | Ilias Tsitsimpis | Invalid usernames will not be in the dictionary. |
104 | 1acf67a7 | Ilias Tsitsimpis | In case of error raise an AstakosClientException exception. |
105 | 1acf67a7 | Ilias Tsitsimpis | |
106 | 794c94e6 | Ilias Tsitsimpis | **get_uuid(**\ token, display_name\ **)** |
107 | 5c418e94 | Ilias Tsitsimpis | Given a user's authentication token and a username (as string) |
108 | 4b92d3f7 | Constantinos Venetsanopoulos | return the corresponding UUID (as string). |
109 | 1acf67a7 | Ilias Tsitsimpis | In case of invalid user name raise NoUUID exception. |
110 | 1acf67a7 | Ilias Tsitsimpis | In case of error raise an AstakosClientException exception. |
111 | 1acf67a7 | Ilias Tsitsimpis | |
112 | 794c94e6 | Ilias Tsitsimpis | **service_get_uuids(**\ token, uuids\ **)** |
113 | 794c94e6 | Ilias Tsitsimpis | Same as get_uuids but called with a service's token. |
114 | 1acf67a7 | Ilias Tsitsimpis | |
115 | 794c94e6 | Ilias Tsitsimpis | **service_get_uuid(**\ token, uuid\ **)** |
116 | 794c94e6 | Ilias Tsitsimpis | Same as get_uuid but called with a service's token. |
117 | 1acf67a7 | Ilias Tsitsimpis | |
118 | 794c94e6 | Ilias Tsitsimpis | **get_services()** |
119 | 1acf67a7 | Ilias Tsitsimpis | Return a list of dicts with the registered services. |
120 | 1acf67a7 | Ilias Tsitsimpis | |
121 | 5c418e94 | Ilias Tsitsimpis | **get_resources()** |
122 | 5c418e94 | Ilias Tsitsimpis | Return a list of dicts with the available resources |
123 | 5c418e94 | Ilias Tsitsimpis | |
124 | 5c418e94 | Ilias Tsitsimpis | **get_quotas(**\ token\ **)** |
125 | 5c418e94 | Ilias Tsitsimpis | Given a user's authentication token return user's |
126 | 5c418e94 | Ilias Tsitsimpis | current quotas (as dict of dicts). |
127 | 5c418e94 | Ilias Tsitsimpis | In case of error raise an AstakosClientException exception. |
128 | 5c418e94 | Ilias Tsitsimpis | |
129 | 5c418e94 | Ilias Tsitsimpis | **issue_commission(**\ token, request\ **)** |
130 | 5c418e94 | Ilias Tsitsimpis | Given a service's authentication token issue a commission. |
131 | 5c418e94 | Ilias Tsitsimpis | In case of success return commission's id (int). |
132 | 5c418e94 | Ilias Tsitsimpis | Otherwise raise an AstakosClientException exception. |
133 | 5c418e94 | Ilias Tsitsimpis | |
134 | 5c418e94 | Ilias Tsitsimpis | **issue_one_commission(**\ token, holder, source, provisions, force=False, auto_accept=False\ **)** |
135 | 5c418e94 | Ilias Tsitsimpis | Given a service's authentication token issue a commission. |
136 | 5c418e94 | Ilias Tsitsimpis | In this case we specify the holder, the source and the provisions |
137 | 5c418e94 | Ilias Tsitsimpis | (a list of (string, int)) and astakosclient will create the |
138 | 5c418e94 | Ilias Tsitsimpis | corresponding commission. |
139 | 5c418e94 | Ilias Tsitsimpis | In case of success return commission's id (int). |
140 | 5c418e94 | Ilias Tsitsimpis | Otherwise raise an AstakosClientException exception. |
141 | 5c418e94 | Ilias Tsitsimpis | |
142 | 5c418e94 | Ilias Tsitsimpis | **get_pending_commissions(**\ token\ **)** |
143 | 5c418e94 | Ilias Tsitsimpis | Given a service's authentication token return the pending |
144 | 5c418e94 | Ilias Tsitsimpis | commissions (list of integers). |
145 | 5c418e94 | Ilias Tsitsimpis | In case of error raise an AstakosClientException exception. |
146 | 5c418e94 | Ilias Tsitsimpis | |
147 | 5c418e94 | Ilias Tsitsimpis | **get_commission_info(**\ token, serial\ **)** |
148 | 5c418e94 | Ilias Tsitsimpis | Given a service's authentication token and the id of a |
149 | 5c418e94 | Ilias Tsitsimpis | pending commission return a dict of dicts containting |
150 | 5c418e94 | Ilias Tsitsimpis | informations (details) about the requested commission. |
151 | 5c418e94 | Ilias Tsitsimpis | In case of error raise an AstakosClientException exception. |
152 | 5c418e94 | Ilias Tsitsimpis | |
153 | 5c418e94 | Ilias Tsitsimpis | **commission_action(**\ token, serial, action\ **)** |
154 | 5c418e94 | Ilias Tsitsimpis | Given a service's authentication token and the id of a |
155 | 5c418e94 | Ilias Tsitsimpis | pending commission, request the specified action (currently |
156 | 5c418e94 | Ilias Tsitsimpis | one of accept, reject). |
157 | 5c418e94 | Ilias Tsitsimpis | In case of success returns nothing. |
158 | 5c418e94 | Ilias Tsitsimpis | Otherwise raise an AstakosClientException exception. |
159 | 5c418e94 | Ilias Tsitsimpis | |
160 | 5c418e94 | Ilias Tsitsimpis | **accept_commission(**\ token, serial\ **)** |
161 | 5c418e94 | Ilias Tsitsimpis | Accept a pending commission (see commission_action). |
162 | 5c418e94 | Ilias Tsitsimpis | |
163 | 5c418e94 | Ilias Tsitsimpis | **reject_commission(**\ token, serial\ **)** |
164 | 5c418e94 | Ilias Tsitsimpis | Reject a pending commission (see commission_action). |
165 | 5c418e94 | Ilias Tsitsimpis | |
166 | 5c418e94 | Ilias Tsitsimpis | **resolve_commissions(**\ token, accept_serials, reject_serials\ **)** |
167 | 5c418e94 | Ilias Tsitsimpis | Accept or Reject many pending commissions at once. |
168 | 5c418e94 | Ilias Tsitsimpis | In case of success return a dict of dicts describing which |
169 | 5c418e94 | Ilias Tsitsimpis | commissions accepted, which rejected and which failed to |
170 | 5c418e94 | Ilias Tsitsimpis | resolved. |
171 | 5c418e94 | Ilias Tsitsimpis | Otherwise raise an AstakosClientException exception. |
172 | 5c418e94 | Ilias Tsitsimpis | |
173 | 1acf67a7 | Ilias Tsitsimpis | |
174 | 1acf67a7 | Ilias Tsitsimpis | Public Functions |
175 | 1acf67a7 | Ilias Tsitsimpis | ---------------- |
176 | 1acf67a7 | Ilias Tsitsimpis | |
177 | 794c94e6 | Ilias Tsitsimpis | **get_token_from_cookie(**\ request, cookie_name\ **)** |
178 | 4b92d3f7 | Constantinos Venetsanopoulos | Given a Django request object and an Astakos cookie name |
179 | 4b92d3f7 | Constantinos Venetsanopoulos | extract the user's token from it. |
180 | 1acf67a7 | Ilias Tsitsimpis | |
181 | 1acf67a7 | Ilias Tsitsimpis | |
182 | 1acf67a7 | Ilias Tsitsimpis | Exceptions and Errors |
183 | 1acf67a7 | Ilias Tsitsimpis | ===================== |
184 | 1acf67a7 | Ilias Tsitsimpis | |
185 | 1acf67a7 | Ilias Tsitsimpis | *exception* **AstakosClientException** |
186 | 1acf67a7 | Ilias Tsitsimpis | Raised in case of an error. It contains an error message and the |
187 | fa7a3ca1 | Ilias Tsitsimpis | corresponding http status code. Other exceptions raised by |
188 | fa7a3ca1 | Ilias Tsitsimpis | astakosclient module are derived from this one. |
189 | fa7a3ca1 | Ilias Tsitsimpis | |
190 | fa7a3ca1 | Ilias Tsitsimpis | *exception* **BadValue** |
191 | fa7a3ca1 | Ilias Tsitsimpis | A redefinition of ValueError exception under AstakosClientException. |
192 | fa7a3ca1 | Ilias Tsitsimpis | |
193 | fa7a3ca1 | Ilias Tsitsimpis | *exception* **InvalidResponse** |
194 | fa7a3ca1 | Ilias Tsitsimpis | This exception is raised whenever the server's response is not |
195 | fa7a3ca1 | Ilias Tsitsimpis | valid json (cannot be parsed by simplejson library). |
196 | 1acf67a7 | Ilias Tsitsimpis | |
197 | 1acf67a7 | Ilias Tsitsimpis | *exception* **BadRequest** |
198 | 1acf67a7 | Ilias Tsitsimpis | Raised in case of a Bad Request, with status 400. |
199 | 1acf67a7 | Ilias Tsitsimpis | |
200 | 1acf67a7 | Ilias Tsitsimpis | *exception* **Unauthorized** |
201 | 1acf67a7 | Ilias Tsitsimpis | Raised in case of Invalid token (unauthorized access), with status 401. |
202 | 1acf67a7 | Ilias Tsitsimpis | |
203 | 1acf67a7 | Ilias Tsitsimpis | *exception* **Forbidden** |
204 | 1acf67a7 | Ilias Tsitsimpis | The server understood the request, but is refusing to fulfill it. |
205 | 1acf67a7 | Ilias Tsitsimpis | Status 401. |
206 | 1acf67a7 | Ilias Tsitsimpis | |
207 | 1acf67a7 | Ilias Tsitsimpis | *exception* **NotFound** |
208 | 1acf67a7 | Ilias Tsitsimpis | The server has not found anything matching the Request-URI. Status 404. |
209 | 1acf67a7 | Ilias Tsitsimpis | |
210 | fa7a3ca1 | Ilias Tsitsimpis | *exception* **QuotaLimit** |
211 | fa7a3ca1 | Ilias Tsitsimpis | Quantity fell below zero or exceeded capacity in one of the holdings. |
212 | fa7a3ca1 | Ilias Tsitsimpis | |
213 | 794c94e6 | Ilias Tsitsimpis | *exception* **NoUserName** |
214 | 1acf67a7 | Ilias Tsitsimpis | Raised by getDisplayName and getServiceDisplayName when an invalid |
215 | 4b92d3f7 | Constantinos Venetsanopoulos | UUID was given. |
216 | 1acf67a7 | Ilias Tsitsimpis | |
217 | 1acf67a7 | Ilias Tsitsimpis | *exception* **NoUUID** |
218 | 1acf67a7 | Ilias Tsitsimpis | Raised by *getUUID* and *getServiceUUID* when an invalid |
219 | 1acf67a7 | Ilias Tsitsimpis | username was given. |