Revision c4644612 astakosclient/astakosclient/__init__.py
b/astakosclient/astakosclient/__init__.py | ||
---|---|---|
68 | 68 |
# ---------------------------------- |
69 | 69 |
def __init__(self, astakos_url, retry=0, |
70 | 70 |
use_pool=False, pool_size=8, logger=None): |
71 |
"""Intialize AstakosClient Class |
|
71 |
"""Initialize AstakosClient Class
|
|
72 | 72 |
|
73 | 73 |
Keyword arguments: |
74 | 74 |
astakos_url -- i.e https://accounts.example.com (string) |
... | ... | |
111 | 111 |
def _call_astakos(self, token, request_path, |
112 | 112 |
headers=None, body=None, method="GET"): |
113 | 113 |
"""Make the actual call to Astakos Service""" |
114 |
hashed_token = hashlib.sha1() |
|
115 |
hashed_token.update(token) |
|
114 |
if token is not None: |
|
115 |
hashed_token = hashlib.sha1() |
|
116 |
hashed_token.update(token) |
|
117 |
using_token = "using token %s" % (hashed_token.hexdigest()) |
|
118 |
else: |
|
119 |
using_token = "without using token" |
|
116 | 120 |
self.logger.debug( |
117 |
"Make a %s request to %s using token %s " |
|
118 |
"with headers %s and body %s" |
|
119 |
% (method, request_path, hashed_token.hexdigest(), headers, body)) |
|
121 |
"Make a %s request to %s %s with headers %s and body %s" |
|
122 |
% (method, request_path, using_token, headers, body)) |
|
120 | 123 |
|
121 | 124 |
# Check Input |
122 |
if not token: |
|
123 |
m = "Token not given" |
|
124 |
self.logger.error(m) |
|
125 |
raise ValueError(m) |
|
126 | 125 |
if headers is None: |
127 | 126 |
headers = {} |
128 | 127 |
if body is None: |
... | ... | |
133 | 132 |
# Build request's header and body |
134 | 133 |
kwargs = {} |
135 | 134 |
kwargs['headers'] = copy(headers) |
136 |
kwargs['headers']['X-Auth-Token'] = token |
|
135 |
if token is not None: |
|
136 |
kwargs['headers']['X-Auth-Token'] = token |
|
137 | 137 |
if body: |
138 | 138 |
kwargs['body'] = copy(body) |
139 | 139 |
kwargs['headers'].setdefault( |
... | ... | |
166 | 166 |
return simplejson.loads(unicode(data)) |
167 | 167 |
|
168 | 168 |
# ------------------------ |
169 |
# GET /im/authenticate |
|
169 | 170 |
def get_user_info(self, token, usage=False): |
170 | 171 |
"""Authenticate user and get user's info as a dictionary |
171 | 172 |
|
... | ... | |
184 | 185 |
return self._call_astakos(token, auth_path) |
185 | 186 |
|
186 | 187 |
# ---------------------------------- |
188 |
# POST /user_catalogs (or /service/api/user_catalogs) |
|
189 |
# with {'uuids': uuids} |
|
187 | 190 |
def _uuid_catalog(self, token, uuids, req_path): |
188 | 191 |
req_headers = {'content-type': 'application/json'} |
189 | 192 |
req_body = simplejson.dumps({'uuids': uuids}) |
... | ... | |
241 | 244 |
raise NoUserName(uuid) |
242 | 245 |
|
243 | 246 |
# ---------------------------------- |
247 |
# POST /user_catalogs (or /service/api/user_catalogs) |
|
248 |
# with {'displaynames': display_names} |
|
244 | 249 |
def _displayname_catalog(self, token, display_names, req_path): |
245 | 250 |
req_headers = {'content-type': 'application/json'} |
246 | 251 |
req_body = simplejson.dumps({'displaynames': display_names}) |
... | ... | |
298 | 303 |
raise NoUUID(display_name) |
299 | 304 |
|
300 | 305 |
# ---------------------------------- |
306 |
# GET "/im/get_services" |
|
301 | 307 |
def get_services(self): |
302 | 308 |
"""Return a list of dicts with the registered services""" |
303 |
return self._call_astakos("dummy token", "/im/get_services") |
|
309 |
return self._call_astakos(None, "/im/get_services") |
|
310 |
|
|
311 |
# ---------------------------------- |
|
312 |
# GET "/astakos/api/resources" |
|
313 |
def get_resources(self): |
|
314 |
"""Return a dict of dicts with the available resources""" |
|
315 |
return self._call_astakos(None, "/astakos/api/resources") |
|
304 | 316 |
|
305 | 317 |
|
306 | 318 |
# -------------------------------------------------------------------- |
Also available in: Unified diff