Statistics
| Branch: | Tag: | Revision:

root / astakosclient / docs / index.rst @ 0d069390

History | View | Annotate | Download (10.3 kB)

1 fa7a3ca1 Ilias Tsitsimpis
.. _astakosclient:
2 1acf67a7 Ilias Tsitsimpis
3 fa7a3ca1 Ilias Tsitsimpis
Component astakosclient
4 f8958a97 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 5b33b8e5 Giorgos Korfiatis
    * Quotas for all related resources
23 5c418e94 Ilias Tsitsimpis
    * Issue commissions
24 5c418e94 Ilias Tsitsimpis
    * Get pending commissions
25 5c418e94 Ilias Tsitsimpis
    * Accept or reject commissions
26 1acf67a7 Ilias Tsitsimpis
27 4b92d3f7 Constantinos Venetsanopoulos
Additionally, there are options for using the `objpool
28 4b92d3f7 Constantinos Venetsanopoulos
<https://github.com/grnet/objpool>`_ library to pool the http connections.
29 1acf67a7 Ilias Tsitsimpis
30 1acf67a7 Ilias Tsitsimpis
31 1acf67a7 Ilias Tsitsimpis
Basic example
32 1acf67a7 Ilias Tsitsimpis
=============
33 1acf67a7 Ilias Tsitsimpis
34 4b92d3f7 Constantinos Venetsanopoulos
The ``astakosclient`` module provides the ``AstakosClient`` class. This section
35 4b92d3f7 Constantinos Venetsanopoulos
demonstrates how to get user's info using ``astakosclient``.
36 1acf67a7 Ilias Tsitsimpis
37 1acf67a7 Ilias Tsitsimpis
.. code-block:: python
38 1acf67a7 Ilias Tsitsimpis
39 1acf67a7 Ilias Tsitsimpis
    from astakosclient import AstakosClient
40 1acf67a7 Ilias Tsitsimpis
41 1acf67a7 Ilias Tsitsimpis
    client = AstakosClient("https://accounts.example.com")
42 26498848 Giorgos Korfiatis
    user_info = client.get_user_info("UQpYas7ElzWGD5yCcEXtjw")
43 1acf67a7 Ilias Tsitsimpis
    print user_info['username']
44 1acf67a7 Ilias Tsitsimpis
45 4b92d3f7 Constantinos Venetsanopoulos
Another example where we ask for the username of a user with UUID:
46 4b92d3f7 Constantinos Venetsanopoulos
``b3de8eb0-3958-477e-als9-789af8dd352c``
47 1acf67a7 Ilias Tsitsimpis
48 1acf67a7 Ilias Tsitsimpis
.. code-block:: python
49 1acf67a7 Ilias Tsitsimpis
50 1acf67a7 Ilias Tsitsimpis
    from astakosclient import AstakosClient
51 1acf67a7 Ilias Tsitsimpis
52 1acf67a7 Ilias Tsitsimpis
    client = AstakosClient("https://accounts.example.com")
53 26498848 Giorgos Korfiatis
    username = client.get_username("UQpYas7ElzWGD5yCcEXtjw",
54 794c94e6 Ilias Tsitsimpis
                                   "b3de8eb0-3958-477e-als9-789af8dd352c")
55 1acf67a7 Ilias Tsitsimpis
    print username
56 1acf67a7 Ilias Tsitsimpis
57 1acf67a7 Ilias Tsitsimpis
58 1acf67a7 Ilias Tsitsimpis
Classes and functions
59 1acf67a7 Ilias Tsitsimpis
=====================
60 1acf67a7 Ilias Tsitsimpis
61 4b92d3f7 Constantinos Venetsanopoulos
This section describes in depth the API of ``astakosclient``.
62 1acf67a7 Ilias Tsitsimpis
63 1acf67a7 Ilias Tsitsimpis
Astakos Client
64 1acf67a7 Ilias Tsitsimpis
--------------
65 1acf67a7 Ilias Tsitsimpis
66 1acf67a7 Ilias Tsitsimpis
*class* astakosclient.\ **AstakosClient(**\ astakos_url,
67 1acf67a7 Ilias Tsitsimpis
retry=0, use_pool=False, pool_size=8, logger=None\ **)**
68 1acf67a7 Ilias Tsitsimpis
69 1acf67a7 Ilias Tsitsimpis
    Initialize an instance of **AstakosClient** given the *astakos_url*.
70 1acf67a7 Ilias Tsitsimpis
    Optionally one can specify if we are going to use a pool, the pool_size
71 1acf67a7 Ilias Tsitsimpis
    and the number of retries if the connection fails.
72 1acf67a7 Ilias Tsitsimpis
73 1acf67a7 Ilias Tsitsimpis
    This class provides the following methods:
74 1acf67a7 Ilias Tsitsimpis
75 794c94e6 Ilias Tsitsimpis
    **get_user_info(**\ token, usage=False\ **)**
76 5c418e94 Ilias Tsitsimpis
        Given a user's authentication token it returns a dict with the
77 1acf67a7 Ilias Tsitsimpis
        correspoinding user's info. If usage is set to True more
78 1acf67a7 Ilias Tsitsimpis
        information about user's resources will be returned.
79 1acf67a7 Ilias Tsitsimpis
        In case of error raise an AstakosClientException exception.
80 1acf67a7 Ilias Tsitsimpis
81 794c94e6 Ilias Tsitsimpis
    **get_usernames(**\ token, uuids\ **)**
82 5c418e94 Ilias Tsitsimpis
        Given a user's authentication token and a list of UUIDs
83 1acf67a7 Ilias Tsitsimpis
        return a uuid_catalog, that is a dictionary with the given
84 4b92d3f7 Constantinos Venetsanopoulos
        UUIDs as keys and the corresponding user names as values.
85 4b92d3f7 Constantinos Venetsanopoulos
        Invalid UUIDs will not be in the dictionary.
86 1acf67a7 Ilias Tsitsimpis
        In case of error raise an AstakosClientException exception.
87 1acf67a7 Ilias Tsitsimpis
88 794c94e6 Ilias Tsitsimpis
    **get_username(**\ token, uuid\ **)**
89 5c418e94 Ilias Tsitsimpis
        Given a user's authentication token and a UUID (as string)
90 1acf67a7 Ilias Tsitsimpis
        return the corresponding user name (as string).
91 794c94e6 Ilias Tsitsimpis
        In case of invalid UUID raise NoUserName exception.
92 1acf67a7 Ilias Tsitsimpis
        In case of error raise an AstakosClientException exception.
93 1acf67a7 Ilias Tsitsimpis
94 794c94e6 Ilias Tsitsimpis
    **service_get_usernames(**\ token, uuids\ **)**
95 794c94e6 Ilias Tsitsimpis
        Same as get_usernames but called with a service's token.
96 1acf67a7 Ilias Tsitsimpis
97 794c94e6 Ilias Tsitsimpis
    **service_get_username(**\ token, uuid\ **)**
98 794c94e6 Ilias Tsitsimpis
        Same as get_username but called with a service's token.
99 1acf67a7 Ilias Tsitsimpis
100 794c94e6 Ilias Tsitsimpis
    **get_uuids(**\ token, display_names\ **)**
101 5c418e94 Ilias Tsitsimpis
        Given a user's authentication token and a list of usernames
102 1acf67a7 Ilias Tsitsimpis
        return a displayname_catalog, that is a dictionary with the given
103 4b92d3f7 Constantinos Venetsanopoulos
        usernames as keys and the corresponding UUIDs as values.
104 1acf67a7 Ilias Tsitsimpis
        Invalid usernames will not be in the dictionary.
105 1acf67a7 Ilias Tsitsimpis
        In case of error raise an AstakosClientException exception.
106 1acf67a7 Ilias Tsitsimpis
107 794c94e6 Ilias Tsitsimpis
    **get_uuid(**\ token, display_name\ **)**
108 5c418e94 Ilias Tsitsimpis
        Given a user's authentication token and a username (as string)
109 4b92d3f7 Constantinos Venetsanopoulos
        return the corresponding UUID (as string).
110 1acf67a7 Ilias Tsitsimpis
        In case of invalid user name raise NoUUID exception.
111 1acf67a7 Ilias Tsitsimpis
        In case of error raise an AstakosClientException exception.
112 1acf67a7 Ilias Tsitsimpis
113 794c94e6 Ilias Tsitsimpis
    **service_get_uuids(**\ token, uuids\ **)**
114 794c94e6 Ilias Tsitsimpis
        Same as get_uuids but called with a service's token.
115 1acf67a7 Ilias Tsitsimpis
116 794c94e6 Ilias Tsitsimpis
    **service_get_uuid(**\ token, uuid\ **)**
117 794c94e6 Ilias Tsitsimpis
        Same as get_uuid but called with a service's token.
118 1acf67a7 Ilias Tsitsimpis
119 794c94e6 Ilias Tsitsimpis
    **get_services()**
120 1acf67a7 Ilias Tsitsimpis
        Return a list of dicts with the registered services.
121 1acf67a7 Ilias Tsitsimpis
122 5c418e94 Ilias Tsitsimpis
    **get_resources()**
123 5c418e94 Ilias Tsitsimpis
        Return a list of dicts with the available resources
124 5c418e94 Ilias Tsitsimpis
125 f20c20fe Ilias Tsitsimpis
    **send_feedback(**\ token, message, data\ **)**
126 f20c20fe Ilias Tsitsimpis
        Using a user's authentication token send some feedback to
127 f20c20fe Ilias Tsitsimpis
        astakos service. Additional information about the service
128 f20c20fe Ilias Tsitsimpis
        client status can be given in the data variable.
129 f20c20fe Ilias Tsitsimpis
        In case of success returns nothing.
130 f20c20fe Ilias Tsitsimpis
        Otherwise raise an AstakosClientException exception.
131 f20c20fe Ilias Tsitsimpis
132 b173906e Ilias Tsitsimpis
    **get_endpoints(**\ token, uuid=None\ **)**
133 25a04cdd Ilias Tsitsimpis
        Fallback call which receives the user token or the user uuid/token
134 25a04cdd Ilias Tsitsimpis
        and returns back the token as well as information about the token
135 25a04cdd Ilias Tsitsimpis
        holder and the services he/seh can access.
136 25a04cdd Ilias Tsitsimpis
        In case of error raise an AstakosClientException exception.
137 f20c20fe Ilias Tsitsimpis
138 5c418e94 Ilias Tsitsimpis
    **get_quotas(**\ token\ **)**
139 5c418e94 Ilias Tsitsimpis
        Given a user's authentication token return user's
140 5c418e94 Ilias Tsitsimpis
        current quotas (as dict of dicts).
141 5c418e94 Ilias Tsitsimpis
        In case of error raise an AstakosClientException exception.
142 5c418e94 Ilias Tsitsimpis
143 271d2c4c Giorgos Korfiatis
    **service_get_quotas(**\ token, user=None\ **)**
144 5b33b8e5 Giorgos Korfiatis
        Given a service's authentication token return all users'
145 5b33b8e5 Giorgos Korfiatis
        current quotas for the resources associated with the service
146 5b33b8e5 Giorgos Korfiatis
        (as dict of dicts of dicts).
147 db9f7a2b Giorgos Korfiatis
        Optionally, one can query the quotas of a specific user with
148 db9f7a2b Giorgos Korfiatis
        argument user=UUID.
149 5b33b8e5 Giorgos Korfiatis
        In case of error raise an AstakosClientException exception.
150 5b33b8e5 Giorgos Korfiatis
151 5c418e94 Ilias Tsitsimpis
    **issue_commission(**\ token, request\ **)**
152 5c418e94 Ilias Tsitsimpis
        Given a service's authentication token issue a commission.
153 5c418e94 Ilias Tsitsimpis
        In case of success return commission's id (int).
154 5c418e94 Ilias Tsitsimpis
        Otherwise raise an AstakosClientException exception.
155 5c418e94 Ilias Tsitsimpis
156 3a1bed03 Giorgos Korfiatis
    **issue_one_commission(**\ token, holder, source, provisions, name="", force=False, auto_accept=False\ **)**
157 5c418e94 Ilias Tsitsimpis
        Given a service's authentication token issue a commission.
158 5c418e94 Ilias Tsitsimpis
        In this case we specify the holder, the source and the provisions
159 567f49a2 Giorgos Korfiatis
        (a dict from string to int) and astakosclient will create the
160 5c418e94 Ilias Tsitsimpis
        corresponding commission.
161 5c418e94 Ilias Tsitsimpis
        In case of success return commission's id (int).
162 5c418e94 Ilias Tsitsimpis
        Otherwise raise an AstakosClientException exception.
163 5c418e94 Ilias Tsitsimpis
164 5c418e94 Ilias Tsitsimpis
    **get_pending_commissions(**\ token\ **)**
165 5c418e94 Ilias Tsitsimpis
        Given a service's authentication token return the pending
166 5c418e94 Ilias Tsitsimpis
        commissions (list of integers).
167 5c418e94 Ilias Tsitsimpis
        In case of error raise an AstakosClientException exception.
168 5c418e94 Ilias Tsitsimpis
169 5c418e94 Ilias Tsitsimpis
    **get_commission_info(**\ token, serial\ **)**
170 5c418e94 Ilias Tsitsimpis
        Given a service's authentication token and the id of a
171 5c418e94 Ilias Tsitsimpis
        pending commission return a dict of dicts containting
172 5c418e94 Ilias Tsitsimpis
        informations (details) about the requested commission.
173 5c418e94 Ilias Tsitsimpis
        In case of error raise an AstakosClientException exception.
174 5c418e94 Ilias Tsitsimpis
175 5c418e94 Ilias Tsitsimpis
    **commission_action(**\ token, serial, action\ **)**
176 5c418e94 Ilias Tsitsimpis
        Given a service's authentication token and the id of a
177 5c418e94 Ilias Tsitsimpis
        pending commission, request the specified action (currently
178 5c418e94 Ilias Tsitsimpis
        one of accept, reject).
179 5c418e94 Ilias Tsitsimpis
        In case of success returns nothing.
180 5c418e94 Ilias Tsitsimpis
        Otherwise raise an AstakosClientException exception.
181 5c418e94 Ilias Tsitsimpis
182 5c418e94 Ilias Tsitsimpis
    **accept_commission(**\ token, serial\ **)**
183 5c418e94 Ilias Tsitsimpis
        Accept a pending commission (see commission_action).
184 5c418e94 Ilias Tsitsimpis
185 5c418e94 Ilias Tsitsimpis
    **reject_commission(**\ token, serial\ **)**
186 5c418e94 Ilias Tsitsimpis
        Reject a pending commission (see commission_action).
187 5c418e94 Ilias Tsitsimpis
188 5c418e94 Ilias Tsitsimpis
    **resolve_commissions(**\ token, accept_serials, reject_serials\ **)**
189 5c418e94 Ilias Tsitsimpis
        Accept or Reject many pending commissions at once.
190 5c418e94 Ilias Tsitsimpis
        In case of success return a dict of dicts describing which
191 5c418e94 Ilias Tsitsimpis
        commissions accepted, which rejected and which failed to
192 5c418e94 Ilias Tsitsimpis
        resolved.
193 5c418e94 Ilias Tsitsimpis
        Otherwise raise an AstakosClientException exception.
194 5c418e94 Ilias Tsitsimpis
195 47bb45c0 Giorgos Korfiatis
    **get_projects(**\ token, name=None, state=None, owner=None\ **)**
196 47bb45c0 Giorgos Korfiatis
        Retrieve all accessible projects
197 47bb45c0 Giorgos Korfiatis
198 47bb45c0 Giorgos Korfiatis
    **get_project(**\ token, project_id\ **)**
199 47bb45c0 Giorgos Korfiatis
        Retrieve project description, if accessible
200 47bb45c0 Giorgos Korfiatis
201 47bb45c0 Giorgos Korfiatis
    **create_project(**\ token, specs\ **)**
202 47bb45c0 Giorgos Korfiatis
        Submit application to create a new project
203 47bb45c0 Giorgos Korfiatis
204 47bb45c0 Giorgos Korfiatis
    **modify_project(**\ token, project_id, specs\ **)**
205 47bb45c0 Giorgos Korfiatis
        Submit application to modify an existing project
206 47bb45c0 Giorgos Korfiatis
207 47bb45c0 Giorgos Korfiatis
    **project_action(**\ token, project_id, action, reason=""\ **)**
208 47bb45c0 Giorgos Korfiatis
        Perform action on a project
209 47bb45c0 Giorgos Korfiatis
210 47bb45c0 Giorgos Korfiatis
    **get_applications(**\ token, project=None\ **)**
211 47bb45c0 Giorgos Korfiatis
        Retrieve all accessible applications
212 47bb45c0 Giorgos Korfiatis
213 47bb45c0 Giorgos Korfiatis
    **get_application(**\ token, app_id\ **)**
214 47bb45c0 Giorgos Korfiatis
        Retrieve application description, if accessible
215 47bb45c0 Giorgos Korfiatis
216 47bb45c0 Giorgos Korfiatis
    **application_action(**\ token, app_id, action, reason=""\ **)**
217 47bb45c0 Giorgos Korfiatis
        Perform action on an application
218 47bb45c0 Giorgos Korfiatis
219 47bb45c0 Giorgos Korfiatis
    **get_memberships(**\ token, project=None\ **)**
220 47bb45c0 Giorgos Korfiatis
        Retrieve all accessible memberships
221 47bb45c0 Giorgos Korfiatis
222 47bb45c0 Giorgos Korfiatis
    **get_membership(**\ token, memb_id\ **)**
223 47bb45c0 Giorgos Korfiatis
        Retrieve membership description, if accessible
224 47bb45c0 Giorgos Korfiatis
225 47bb45c0 Giorgos Korfiatis
    **membership_action(**\ token, memb_id, action, reason=""\ **)**
226 47bb45c0 Giorgos Korfiatis
        Perform action on a membership
227 47bb45c0 Giorgos Korfiatis
228 47bb45c0 Giorgos Korfiatis
    **join_project(**\ token, project_id\ **)**
229 47bb45c0 Giorgos Korfiatis
        Join a project
230 47bb45c0 Giorgos Korfiatis
231 47bb45c0 Giorgos Korfiatis
    **enroll_member(**\ token, project_id, email\ **)**
232 47bb45c0 Giorgos Korfiatis
        Enroll a user in a project
233 1acf67a7 Ilias Tsitsimpis
234 1acf67a7 Ilias Tsitsimpis
Public Functions
235 1acf67a7 Ilias Tsitsimpis
----------------
236 1acf67a7 Ilias Tsitsimpis
237 794c94e6 Ilias Tsitsimpis
**get_token_from_cookie(**\ request, cookie_name\ **)**
238 4b92d3f7 Constantinos Venetsanopoulos
    Given a Django request object and an Astakos cookie name
239 4b92d3f7 Constantinos Venetsanopoulos
    extract the user's token from it.
240 1acf67a7 Ilias Tsitsimpis
241 1acf67a7 Ilias Tsitsimpis
242 1acf67a7 Ilias Tsitsimpis
Exceptions and Errors
243 1acf67a7 Ilias Tsitsimpis
=====================
244 1acf67a7 Ilias Tsitsimpis
245 1acf67a7 Ilias Tsitsimpis
*exception* **AstakosClientException**
246 1acf67a7 Ilias Tsitsimpis
    Raised in case of an error. It contains an error message and the
247 fa7a3ca1 Ilias Tsitsimpis
    corresponding http status code. Other exceptions raised by
248 fa7a3ca1 Ilias Tsitsimpis
    astakosclient module are derived from this one.
249 fa7a3ca1 Ilias Tsitsimpis
250 fa7a3ca1 Ilias Tsitsimpis
*exception* **BadValue**
251 fa7a3ca1 Ilias Tsitsimpis
    A redefinition of ValueError exception under AstakosClientException.
252 fa7a3ca1 Ilias Tsitsimpis
253 fa7a3ca1 Ilias Tsitsimpis
*exception* **InvalidResponse**
254 fa7a3ca1 Ilias Tsitsimpis
    This exception is raised whenever the server's response is not
255 fa7a3ca1 Ilias Tsitsimpis
    valid json (cannot be parsed by simplejson library).
256 1acf67a7 Ilias Tsitsimpis
257 1acf67a7 Ilias Tsitsimpis
*exception* **BadRequest**
258 1acf67a7 Ilias Tsitsimpis
    Raised in case of a Bad Request, with status 400.
259 1acf67a7 Ilias Tsitsimpis
260 1acf67a7 Ilias Tsitsimpis
*exception* **Unauthorized**
261 1acf67a7 Ilias Tsitsimpis
    Raised in case of Invalid token (unauthorized access), with status 401.
262 1acf67a7 Ilias Tsitsimpis
263 1acf67a7 Ilias Tsitsimpis
*exception* **Forbidden**
264 1acf67a7 Ilias Tsitsimpis
    The server understood the request, but is refusing to fulfill it.
265 1acf67a7 Ilias Tsitsimpis
    Status 401.
266 1acf67a7 Ilias Tsitsimpis
267 1acf67a7 Ilias Tsitsimpis
*exception* **NotFound**
268 1acf67a7 Ilias Tsitsimpis
    The server has not found anything matching the Request-URI. Status 404.
269 1acf67a7 Ilias Tsitsimpis
270 fa7a3ca1 Ilias Tsitsimpis
*exception* **QuotaLimit**
271 fa7a3ca1 Ilias Tsitsimpis
    Quantity fell below zero or exceeded capacity in one of the holdings.
272 fa7a3ca1 Ilias Tsitsimpis
273 794c94e6 Ilias Tsitsimpis
*exception* **NoUserName**
274 1acf67a7 Ilias Tsitsimpis
    Raised by getDisplayName and getServiceDisplayName when an invalid
275 4b92d3f7 Constantinos Venetsanopoulos
    UUID was given.
276 1acf67a7 Ilias Tsitsimpis
277 1acf67a7 Ilias Tsitsimpis
*exception* **NoUUID**
278 1acf67a7 Ilias Tsitsimpis
    Raised by *getUUID* and *getServiceUUID* when an invalid
279 1acf67a7 Ilias Tsitsimpis
    username was given.