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>
This commit is contained in:
Petr Viktorin
2014-09-23 12:10:56 +02:00
parent ccb91f5970
commit b7a6d7937e
3 changed files with 12 additions and 4 deletions

3
ipa.1
View File

@@ -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"

View File

@@ -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)

View File

@@ -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: