summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2014-09-23 12:10:56 +0200
committerPetr Viktorin <pviktori@redhat.com>2014-09-24 13:57:56 +0200
commitb7a6d7937efae894dad0c28759d01042b663ba30 (patch)
tree4de09e980d2bdddf5aaebaf0f3d45ed2138d3e5a
parentccb91f5970537df6362ec7f41cded369b668e91a (diff)
downloadfreeipa-b7a6d7937efae894dad0c28759d01042b663ba30.tar.gz
freeipa-b7a6d7937efae894dad0c28759d01042b663ba30.tar.xz
freeipa-b7a6d7937efae894dad0c28759d01042b663ba30.zip
JSON client: Log pretty-printed request and response with -vv or above
The whole HTTP request is now printed with -vvv or above. Changes `verbose` in the connection to be the level from api.env, rather than a boolean value. For XML-RPC, the whole request will be shown already with -v. https://fedorahosted.org/freeipa/ticket/4233 Reviewed-By: David Kupka <dkupka@redhat.com>
-rw-r--r--ipa.13
-rw-r--r--ipalib/backend.py2
-rw-r--r--ipalib/rpc.py11
3 files changed, 12 insertions, 4 deletions
diff --git a/ipa.1 b/ipa.1
index fc39fceaa..cadd9aa98 100644
--- a/ipa.1
+++ b/ipa.1
@@ -56,7 +56,8 @@ Prompt for all parameters of \fICOMMAND\fR, even if they are optional.
Don't fall back to other IPA servers if the default doesn't work.
.TP
\fB\-v\fR, \fB\-\-verbose\fR
-Produce verbose output. A second \-v displays the XML\-RPC request.
+Produce verbose output. A second -v pretty-prints the JSON request and response. A third \-v displays the HTTP request and response.
+.TP
\fB\-\-version\fR
Display the IPA version and API version.
.SH "COMMANDS"
diff --git a/ipalib/backend.py b/ipalib/backend.py
index b94264236..210058981 100644
--- a/ipalib/backend.py
+++ b/ipalib/backend.py
@@ -113,7 +113,7 @@ class Executioner(Backend):
if self.env.in_server:
self.Backend.ldap2.connect(ccache=ccache)
else:
- self.Backend.rpcclient.connect(verbose=(self.env.verbose >= 2),
+ self.Backend.rpcclient.connect(verbose=self.env.verbose,
fallback=self.env.fallback, delegate=self.env.delegate)
if client_ip is not None:
setattr(context, "client_ip", client_ip)
diff --git a/ipalib/rpc.py b/ipalib/rpc.py
index 1bfc4c3d3..e7e60f414 100644
--- a/ipalib/rpc.py
+++ b/ipalib/rpc.py
@@ -761,7 +761,7 @@ class RPCClient(Connectible):
return session_url
- def create_connection(self, ccache=None, verbose=False, fallback=True,
+ def create_connection(self, ccache=None, verbose=0, fallback=True,
delegate=False, nss_dir=None):
try:
rpc_uri = self.env[self.env_rpc_uri_key]
@@ -965,11 +965,15 @@ class JSONServerProxy(object):
payload = {'method': unicode(name), 'params': args, 'id': 0}
version = args[1].get('version', VERSION_WITHOUT_CAPABILITIES)
+ if self.__verbose >= 2:
+ root_logger.info('Request: %s',
+ json.dumps(payload, sort_keys=True, indent=4))
+
response = self.__transport.request(
self.__host,
self.__handler,
json.dumps(json_encode_binary(payload, version)),
- verbose=self.__verbose,
+ verbose=self.__verbose >= 3,
)
try:
@@ -977,6 +981,9 @@ class JSONServerProxy(object):
except ValueError, e:
raise JSONError(str(e))
+ if self.__verbose >= 2:
+ root_logger.info('Response: %s',
+ json.dumps(response, sort_keys=True, indent=4))
error = response.get('error')
if error:
try: