Skip to content

Commit

Permalink
Sanity check client message before trying to process any request
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaeon committed Mar 31, 2014
1 parent 6025e31 commit a5feb8c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/vpoller/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,15 @@ def run(self, config):
_empty = self.worker_socket.recv()
msg = self.worker_socket.recv_json()
result = self.process_client_msg(msg)

# Return result back to client
self.worker_socket.send(_id, zmq.SNDMORE)
self.worker_socket.send("", zmq.SNDMORE)
self.worker_socket.send_json(result)
try:
self.worker_socket.send_json(result)
except TypeError as e:
logging.warning('Cannot serialize result: %s', e)
self.worker_socket.send_json({ 'success': -1, 'msg': 'Cannot serialize result: %s' % e})

# Management socket
if socks.get(self.mgmt_socket) == zmq.POLLIN:
Expand Down Expand Up @@ -279,10 +284,13 @@ def process_client_msg(self, msg):
"""
logging.debug('Processing client message: %s', msg)

if not isinstance(msg, dict):
return { 'success': -1, 'msg': 'Expected a JSON message, received %s' % msg.__class__ }

vsphere_host = msg.get('hostname')

if not self.agents.get(vsphere_host):
return { 'success': -1, 'msg': 'Unknown vSphere Agent requested' }
return { 'success': -1, 'msg': 'Unknown or missing vSphere Agent requested' }

# The methods that the vSphere Agents support and process
# In the below dict the key is the method name requested by the client,
Expand Down

0 comments on commit a5feb8c

Please sign in to comment.