Revision 85115c12 kamaki/clients/astakos/__init__.py
b/kamaki/clients/astakos/__init__.py | ||
---|---|---|
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 | 34 |
from logging import getLogger |
35 |
from astakosclient import AstakosClient as SynnefoAstakosClient |
|
35 |
from astakosclient import AstakosClient as SynnefoAstakosClientOrig
|
|
36 | 36 |
from astakosclient import AstakosClientException as SynnefoAstakosClientError |
37 | 37 |
|
38 |
from kamaki.clients import Client, ClientError |
|
38 |
from kamaki.clients import ( |
|
39 |
Client, ClientError, Logged, RequestManager, recvlog) |
|
39 | 40 |
|
40 | 41 |
|
41 | 42 |
def _astakos_error(foo): |
... | ... | |
47 | 48 |
return wrap |
48 | 49 |
|
49 | 50 |
|
51 |
class SynnefoAstakosClient(SynnefoAstakosClientOrig, Logged): |
|
52 |
"""A synnefo astakosclient.AstakosClient wrapper, that logs""" |
|
53 |
|
|
54 |
def _dump_response(self, request, status, message, data): |
|
55 |
plog = '' |
|
56 |
if self.LOG_PID: |
|
57 |
recvlog.info('\n%s <-- [req: %s]\n' % (self, request)) |
|
58 |
plog = '\t[%s]' % self |
|
59 |
recvlog.info('%d %s%s' % (status, message, plog)) |
|
60 |
recvlog.info('data size: %s%s' % (len(data), plog)) |
|
61 |
if self.LOG_DATA and data: |
|
62 |
data = '%s%s' % (data, plog) |
|
63 |
if not self.LOG_TOKEN: |
|
64 |
token = request.headers.get('X-Auth-Token', '') |
|
65 |
if token: |
|
66 |
data = data.replace(token, '...') |
|
67 |
recvlog.info(data) |
|
68 |
recvlog.info('- - - - - - -') |
|
69 |
|
|
70 |
def _call_astakos(self, *args, **kwargs): |
|
71 |
r = super(SynnefoAstakosClient, self)._call_astakos(*args, **kwargs) |
|
72 |
try: |
|
73 |
log_request = getattr(self, 'log_request', None) |
|
74 |
if log_request: |
|
75 |
req = RequestManager( |
|
76 |
method=log_request['method'], |
|
77 |
url='%s://%s' % (self.scheme, self.astakos_base_url), |
|
78 |
path=log_request['path'], |
|
79 |
data=log_request.get('body', None), |
|
80 |
headers=log_request.get('headers', dict())) |
|
81 |
req.dump_log() |
|
82 |
log_response = getattr(self, 'log_response', None) |
|
83 |
if log_response: |
|
84 |
self._dump_response( |
|
85 |
req, |
|
86 |
status=log_response['status'], |
|
87 |
message=log_response['message'], |
|
88 |
data=log_response.get('data', '')) |
|
89 |
except Exception as e: |
|
90 |
print 'GOT EXCEPTION', e |
|
91 |
finally: |
|
92 |
return r |
|
93 |
|
|
94 |
|
|
50 | 95 |
class AstakosClient(Client): |
51 | 96 |
"""Synnefo Astakos cached client wraper""" |
52 | 97 |
|
Also available in: Unified diff