Re: [Freeipa-devel] [PATCH][RFC] 13 - Log pretty-printed request and response

2014-09-24 Thread Petr Viktorin

On 04/16/2014 05:42 PM, Rob Crittenden wrote:

Misnyovszki Adam wrote:

Hi,
this patch enables logging json dumps of request and response, using
the --log-payload switch in ipa cli. RFC tag is to ensure that I
handled the --log-payload switch correctly in ipa cli. Be careful, it
only logs, so --log-payload without -v switch doesn't make the dump
visible in command line, -v does!

https://fedorahosted.org/freeipa/ticket/4233


Not a NACK but using -vvv makes this a much simpler operation as you can
then just compare verbose = 3. This seems like a lot of work just to
pretty-print some output.

rob


This patch has been superseded by my 0648 (commit b7a6d79).


--
PetrĀ³

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel


Re: [Freeipa-devel] [PATCH][RFC] 13 - Log pretty-printed request and response

2014-04-23 Thread Misnyovszki Adam
On Wed, 16 Apr 2014 11:42:00 -0400
Rob Crittenden rcrit...@redhat.com wrote:

 Misnyovszki Adam wrote:
  Hi,
  this patch enables logging json dumps of request and response, using
  the --log-payload switch in ipa cli. RFC tag is to ensure that I
  handled the --log-payload switch correctly in ipa cli. Be careful,
  it only logs, so --log-payload without -v switch doesn't make the
  dump visible in command line, -v does!
 
  https://fedorahosted.org/freeipa/ticket/4233
 
 Not a NACK but using -vvv makes this a much simpler operation as you
 can then just compare verbose = 3. This seems like a lot of work
 just to pretty-print some output.
 
 rob
 

I've found out, that in RPCClient.create_connection, according to
ipalib/backend.py:164, the variable verbose is not an int, rather a
bool ( verbose=(self.env.verbose = 2) ), so I decided not to break the
workflow of this variable, but rather create a new one(log-payload). I
was thinking, making verbose to an int would cause more work than to do
it this way.
Adam

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel


[Freeipa-devel] [PATCH][RFC] 13 - Log pretty-printed request and response

2014-04-16 Thread Misnyovszki Adam
Hi,
this patch enables logging json dumps of request and response, using
the --log-payload switch in ipa cli. RFC tag is to ensure that I
handled the --log-payload switch correctly in ipa cli. Be careful, it
only logs, so --log-payload without -v switch doesn't make the dump
visible in command line, -v does!

https://fedorahosted.org/freeipa/ticket/4233

Thanks
AdamFrom f2230d5200feeb6fa413f4b248736b38ba66d317 Mon Sep 17 00:00:00 2001
From: Adam Misnyovszki amisn...@redhat.com
Date: Wed, 16 Apr 2014 14:58:18 +0200
Subject: [PATCH] Log pretty-printed request and response

With the --log-payload option, every request/response is
logged with json.dumps.

https://fedorahosted.org/freeipa/ticket/4233
---
 ipalib/constants.py |  1 +
 ipalib/plugable.py  |  7 +--
 ipalib/rpc.py   | 14 +-
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/ipalib/constants.py b/ipalib/constants.py
index 6cc50eacf44678840ad0048a1ef60c05736879cb..6acd7cef549d8b06366ee07adcbeb0a4d1b411d2 100644
--- a/ipalib/constants.py
+++ b/ipalib/constants.py
@@ -158,6 +158,7 @@ DEFAULT_CONFIG = (
 ('interactive', True),
 ('fallback', True),
 ('delegate', False),
+('log_payload', False),
 
 # Enable certain optional plugins:
 ('enable_ra', False),
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 216f9c08a8b5d22bdb1e7853013967e8fe3f88b0..47e52b662f1421f0476fd7b301cd62043448a50d 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -597,7 +597,10 @@ class API(DictProxy):
 parser.add_option('-f', '--no-fallback', action='store_false',
 dest='fallback',
 help='Only use the server configured in /etc/ipa/default.conf'
-)
+)
+parser.add_option('--log-payload', action='store_true',
+help='Logs formatted json payload',
+)
 
 return parser
 
@@ -617,7 +620,7 @@ class API(DictProxy):
 pass
 overrides[str(key.strip())] = value.strip()
 for key in ('conf', 'debug', 'verbose', 'prompt_all', 'interactive',
-'fallback', 'delegate'):
+'fallback', 'delegate', 'log_payload'):
 value = getattr(options, key, None)
 if value is not None:
 overrides[key] = value
diff --git a/ipalib/rpc.py b/ipalib/rpc.py
index 2b47d1c0e25bbeec0dde38089f444e0399e1670e..fa13e5519de51a2a2e341fb94ca452f71087d102 100644
--- a/ipalib/rpc.py
+++ b/ipalib/rpc.py
@@ -738,6 +738,8 @@ class RPCClient(Connectible):
 for url in urls:
 kw = dict(allow_none=True, encoding='UTF-8')
 kw['verbose'] = verbose
+if self.server_proxy_class == JSONServerProxy:
+kw['log_payload'] = self.env.log_payload
 if url.startswith('https://'):
 if delegate:
 transport_class = DelegatedKerbTransport
@@ -783,6 +785,7 @@ class RPCClient(Connectible):
 except Exception, e:
 # This shouldn't happen if we have a session but it isn't fatal.
 pass
+
 return self.create_connection(ccache, verbose, fallback, delegate)
 if not fallback:
 raise
@@ -900,7 +903,8 @@ class xmlclient(RPCClient):
 
 
 class JSONServerProxy(object):
-def __init__(self, uri, transport, encoding, verbose, allow_none):
+def __init__(self, uri, transport, encoding, verbose, allow_none,
+log_payload):
 type, uri = urllib.splittype(uri)
 if type not in (http, https):
 raise IOError(unsupported XML-RPC protocol)
@@ -910,6 +914,7 @@ class JSONServerProxy(object):
 assert encoding == 'UTF-8'
 assert allow_none
 self.__verbose = verbose
+self.__log_payload = log_payload
 
 # FIXME: Some of our code requires ServerProxy internals.
 # But, xmlrpclib.ServerProxy's _ServerProxy__transport can be accessed
@@ -919,6 +924,10 @@ class JSONServerProxy(object):
 def __request(self, name, args):
 payload = {'method': unicode(name), 'params': args, 'id': 0}
 
+if self.__log_payload:
+root_logger.info('Request: %s', json.dumps(payload, sort_keys=True,
+   indent=4))
+
 response = self.__transport.request(
 self.__host,
 self.__handler,
@@ -931,6 +940,9 @@ class JSONServerProxy(object):
 except ValueError, e:
 raise JSONError(str(e))
 
+if self.__log_payload:
+root_logger.info('Response: %s', json.dumps(response, sort_keys=True,
+indent=4))
 error = response.get('error')
 if error:
 try:
-- 
1.9.0

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com

Re: [Freeipa-devel] [PATCH][RFC] 13 - Log pretty-printed request and response

2014-04-16 Thread Rob Crittenden

Misnyovszki Adam wrote:

Hi,
this patch enables logging json dumps of request and response, using
the --log-payload switch in ipa cli. RFC tag is to ensure that I
handled the --log-payload switch correctly in ipa cli. Be careful, it
only logs, so --log-payload without -v switch doesn't make the dump
visible in command line, -v does!

https://fedorahosted.org/freeipa/ticket/4233


Not a NACK but using -vvv makes this a much simpler operation as you can 
then just compare verbose = 3. This seems like a lot of work just to 
pretty-print some output.


rob

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel