Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
kamaki
Commits
d75bbed3
Commit
d75bbed3
authored
Mar 10, 2016
by
Stavros Sachtouris
Committed by
Giorgos Korfiatis
Mar 11, 2016
Browse files
Log astakosclient requests/responses on errors
parent
89a47cf1
Changes
1
Hide whitespace changes
Inline
Side-by-side
kamaki/clients/astakos/__init__.py
View file @
d75bbed3
...
...
@@ -32,6 +32,7 @@
# or implied, of GRNET S.A.
from
logging
import
getLogger
from
functools
import
wraps
import
inspect
import
ssl
...
...
@@ -54,11 +55,39 @@ class AstakosClientError(ClientError, AstakosClientException):
super
(
ClientError
,
self
).
__init__
(
message
,
details
,
status
)
def
_astakos_error
(
foo
):
def
_log_astakosclient_request
(
cls
):
"""
:param cls: An AstakosClient instance
"""
try
:
log_request
=
getattr
(
cls
,
'log_request'
,
None
)
if
log_request
:
req
=
RequestManager
(
method
=
log_request
[
'method'
],
url
=
'%s://%s'
%
(
cls
.
scheme
,
cls
.
astakos_base_url
),
path
=
log_request
[
'path'
],
data
=
log_request
.
get
(
'body'
,
None
),
headers
=
log_request
.
get
(
'headers'
,
dict
()))
req
.
LOG_TOKEN
,
req
.
LOG_DATA
=
cls
.
LOG_TOKEN
,
cls
.
LOG_DATA
req
.
dump_log
()
log_response
=
getattr
(
cls
,
'log_response'
,
None
)
if
log_response
:
cls
.
_dump_response
(
req
,
status
=
log_response
[
'status'
],
message
=
log_response
[
'message'
],
data
=
log_response
.
get
(
'data'
,
''
))
except
Exception
:
recvlog
.
debug
(
'Kamaki failed to log an AstakosClient call'
)
def
_astakos_error
(
func
):
@
wraps
(
func
)
def
wrap
(
self
,
*
args
,
**
kwargs
):
try
:
return
f
oo
(
self
,
*
args
,
**
kwargs
)
return
f
unc
(
self
,
*
args
,
**
kwargs
)
except
AstakosClientException
as
sace
:
_log_astakosclient_request
(
self
)
if
isinstance
(
getattr
(
sace
,
'errobject'
,
None
),
ssl
.
SSLError
):
raise
KamakiSSLError
(
'SSL Connection error (%s)'
%
sace
)
raise
AstakosClientError
(
...
...
@@ -143,28 +172,8 @@ class LoggedAstakosClient(AstakosClient, Logged):
def
_call_astakos
(
self
,
*
args
,
**
kwargs
):
r
=
AstakosClient
.
_call_astakos
(
self
,
*
args
,
**
kwargs
)
try
:
log_request
=
getattr
(
self
,
'log_request'
,
None
)
if
log_request
:
req
=
RequestManager
(
method
=
log_request
[
'method'
],
url
=
'%s://%s'
%
(
self
.
scheme
,
self
.
astakos_base_url
),
path
=
log_request
[
'path'
],
data
=
log_request
.
get
(
'body'
,
None
),
headers
=
log_request
.
get
(
'headers'
,
dict
()))
req
.
LOG_TOKEN
,
req
.
LOG_DATA
=
self
.
LOG_TOKEN
,
self
.
LOG_DATA
req
.
dump_log
()
log_response
=
getattr
(
self
,
'log_response'
,
None
)
if
log_response
:
self
.
_dump_response
(
req
,
status
=
log_response
[
'status'
],
message
=
log_response
[
'message'
],
data
=
log_response
.
get
(
'data'
,
''
))
except
Exception
:
recvlog
.
debug
(
'Kamaki failed to log an AstakosClient call'
)
finally
:
return
r
_log_astakosclient_request
(
self
)
return
r
class
CachedAstakosClient
(
Client
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment