On 09/23/2014 03:13 PM, Petr Viktorin wrote:
https://fedorahosted.org/freeipa/ticket/4233
After talking to Rob, I've changed what the -v means a bit more:
A single -v just turns on INFO logging, as before:
$ ipa -v ping
ipa: INFO: trying https://vm-073.idm.lab.eng.brq.redhat.com/ipa/json
ipa: INFO: Forwarding 'ping' to json server
'https://vm-073.idm.lab.eng.brq.redhat.com/ipa/json'
-----------------------------------------------------
IPA server version 4.0.0GIT8543d4c. API version 2.102
-----------------------------------------------------
Two -v's pretty-print the request & response:
$ ipa -vv ping
ipa: INFO: trying https://vm-073.idm.lab.eng.brq.redhat.com/ipa/json
ipa: INFO: Forwarding 'ping' to json server
'https://vm-073.idm.lab.eng.brq.redhat.com/ipa/json'
ipa: INFO: Request: {
"id": 0,
"method": "ping",
"params": [
[],
{
"version": "2.102"
}
]
}
ipa: INFO: Response: {
"error": null,
"id": 0,
"principal": "ad...@idm.lab.eng.brq.redhat.com",
"result": {
"summary": "IPA server version 4.0.0GIT8543d4c. API version 2.102"
},
"version": "4.0.0GIT8543d4c"
}
-----------------------------------------------------
IPA server version 4.0.0GIT8543d4c. API version 2.102
-----------------------------------------------------
And three -v's print everything -- the pretty-printed JSON and all of
the HTTP communication.
Also, when using XML-RPC, a single -v will now also print all the HTTP
stuff. It could respond to two -v's as before I don't think it's worth
complicating the code (keep in mind this is client only, XML-RPC is not
used unless requested in the env).
This patch also updates the man page.
--
PetrĀ³
From 721fdbc50ffd951eba2e5427233c909d0245c788 Mon Sep 17 00:00:00 2001
From: Petr Viktorin <pvikt...@redhat.com>
Date: Tue, 23 Sep 2014 12:10:56 +0200
Subject: [PATCH] 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
---
ipa.1 | 3 ++-
ipalib/backend.py | 2 +-
ipalib/rpc.py | 11 +++++++++--
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/ipa.1 b/ipa.1
index fc39fceaae5aa4c614ccaaa7e608f2326d926755..cadd9aa98d7d976f5a683b5fe83ab30ee357dd99 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 b94264236795b65905ba425ef15e452e7a66625b..210058981a6ecc5884040648e9d7929abf473af7 100644
--- a/ipalib/backend.py
+++ b/ipalib/backend.py
@@ -113,7 +113,7 @@ def create_context(self, ccache=None, client_ip=None):
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 1bfc4c3d3f8ac36c9dbb135561707eaa9f6ac7f3..e7e60f414b9a519fc98efdb0cee2205ed60b331c 100644
--- a/ipalib/rpc.py
+++ b/ipalib/rpc.py
@@ -761,7 +761,7 @@ def apply_session_cookie(self, url):
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 @@ def __request(self, name, args):
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 @@ def __request(self, name, args):
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:
--
1.9.3
_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel