Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-client / docs / index.rst @ f74d2b69

History | View | Annotate | Download (5.2 kB)

1
.. _snf-astakos-client:
2

    
3
Component snf-astakos-client
4
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5

    
6
The Synnefo component :ref:`snf-astakos-client <snf-astakos-client>` defines a
7
default client for the :ref:`Astakos <astakos>` service. It is designed to be
8
simple and minimal, hence easy to debug and test.
9

    
10
It uses the user's authentication token to query Astakos for:
11

    
12
    * User's info
13
    * Usernames for given UUIDs
14
    * UUIDs for given usernames
15

    
16
It can also query Astakos with another service's (Cyclades or Pithos)
17
authentication token for:
18

    
19
    * Usernames for given UUIDs
20
    * UUIDs for given usernames
21

    
22
Additionally, there are options for using the `objpool
23
<https://github.com/grnet/objpool>`_ library to pool the http connections.
24

    
25

    
26
Basic example
27
=============
28

    
29
The ``astakosclient`` module provides the ``AstakosClient`` class. This section
30
demonstrates how to get user's info using ``astakosclient``.
31

    
32
.. code-block:: python
33

    
34
    from astakosclient import AstakosClient
35

    
36
    client = AstakosClient("https://accounts.example.com")
37
    user_info = client.getUserInfo("UQpYas7ElzWGD5yCcEXtjw==")
38
    print user_info['username']
39

    
40
Another example where we ask for the username of a user with UUID:
41
``b3de8eb0-3958-477e-als9-789af8dd352c``
42

    
43
.. code-block:: python
44

    
45
    from astakosclient import AstakosClient
46

    
47
    client = AstakosClient("https://accounts.example.com")
48
    username = client.getDisplayName("UQpYas7ElzWGD5yCcEXtjw==",
49
                                     "b3de8eb0-3958-477e-als9-789af8dd352c")
50
    print username
51

    
52

    
53
Classes and functions
54
=====================
55

    
56
This section describes in depth the API of ``astakosclient``.
57

    
58
Astakos Client
59
--------------
60

    
61
*class* astakosclient.\ **AstakosClient(**\ astakos_url,
62
retry=0, use_pool=False, pool_size=8, logger=None\ **)**
63

    
64
    Initialize an instance of **AstakosClient** given the *astakos_url*.
65
    Optionally one can specify if we are going to use a pool, the pool_size
66
    and the number of retries if the connection fails.
67

    
68
    This class provides the following methods:
69

    
70
    **getUserInfo(**\ token, usage=False\ **)**
71
        Given a valid authentication token it returns a dict with the
72
        correspoinding user's info. If usage is set to True more
73
        information about user's resources will be returned.
74
        In case of error raise an AstakosClientException exception.
75

    
76
    **getDisplayNames(**\ token, uuids\ **)**
77
        Given a valid authentication token and a list of UUIDs
78
        return a uuid_catalog, that is a dictionary with the given
79
        UUIDs as keys and the corresponding user names as values.
80
        Invalid UUIDs will not be in the dictionary.
81
        In case of error raise an AstakosClientException exception.
82

    
83
    **getDisplayName(**\ token, uuid\ **)**
84
        Given a valid authentication token and a UUID (as string)
85
        return the corresponding user name (as string).
86
        In case of invalid UUID raise NoDisplayName exception.
87
        In case of error raise an AstakosClientException exception.
88

    
89
    **getServiceDisplayNames(**\ token, uuids\ **)**
90
        Same as getDisplayNames but called with a service's token.
91

    
92
    **getServiceDisplayName(**\ token, uuid\ **)**
93
        Same as getDisplayName but called with a service's token.
94

    
95
    **getUUIDs(**\ token, display_names\ **)**
96
        Given a valid authentication token and a list of usernames
97
        return a displayname_catalog, that is a dictionary with the given
98
        usernames as keys and the corresponding UUIDs as values.
99
        Invalid usernames will not be in the dictionary.
100
        In case of error raise an AstakosClientException exception.
101

    
102
    **getUUID(**\ token, display_name\ **)**
103
        Given a valid authentication token and a username (as string)
104
        return the corresponding UUID (as string).
105
        In case of invalid user name raise NoUUID exception.
106
        In case of error raise an AstakosClientException exception.
107

    
108
    **getServiceUUIDs(**\ token, uuids\ **)**
109
        Same as getUUIDs but called with a service's token.
110

    
111
    **getServiceUUID(**\ token, uuid\ **)**
112
        Same as getUUID but called with a service's token.
113

    
114
    **getServices()**
115
        Return a list of dicts with the registered services.
116

    
117

    
118
Public Functions
119
----------------
120

    
121
**getTokenFromCookie(**\ request, cookie_name\ **)**
122
    Given a Django request object and an Astakos cookie name
123
    extract the user's token from it.
124

    
125

    
126
Exceptions and Errors
127
=====================
128

    
129
*exception* **AstakosClientException**
130
    Raised in case of an error. It contains an error message and the
131
    corresponding http status code. Other exceptions raise by astakosclient
132
    module are derived from this one.
133

    
134
*exception* **BadRequest**
135
    Raised in case of a Bad Request, with status 400.
136

    
137
*exception* **Unauthorized**
138
    Raised in case of Invalid token (unauthorized access), with status 401.
139

    
140
*exception* **Forbidden**
141
    The server understood the request, but is refusing to fulfill it.
142
    Status 401.
143

    
144
*exception* **NotFound**
145
    The server has not found anything matching the Request-URI. Status 404.
146

    
147
*exception* **NoDisplayName**
148
    Raised by getDisplayName and getServiceDisplayName when an invalid
149
    UUID was given.
150

    
151
*exception* **NoUUID**
152
    Raised by *getUUID* and *getServiceUUID* when an invalid
153
    username was given.