diff options
author | Gordon Sim <gsim@apache.org> | 2008-05-09 11:15:35 +0000 |
---|---|---|
committer | Gordon Sim <gsim@apache.org> | 2008-05-09 11:15:35 +0000 |
commit | 539672f9fa39dd22bb68fc50c22608aec2bdfe22 (patch) | |
tree | 5c78311f958e5bc45d90d02cb61c3274a0de651b /python/qpid/managementdata.py | |
parent | 53428ae6d4d2705a5df7eda2d43fdfbc92da3670 (diff) | |
download | qpid-python-539672f9fa39dd22bb68fc50c22608aec2bdfe22.tar.gz |
Enabled PLAIN authentication and setting of username and password for 0-10 python client.
Added options to all command line tools to allow a username and password to be specified.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@654759 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python/qpid/managementdata.py')
-rw-r--r-- | python/qpid/managementdata.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/python/qpid/managementdata.py b/python/qpid/managementdata.py index c908483354..a0197ba7d2 100644 --- a/python/qpid/managementdata.py +++ b/python/qpid/managementdata.py @@ -20,6 +20,7 @@ # import qpid +import re import socket import struct import os @@ -32,14 +33,18 @@ from qpid.util import connect class Broker: def __init__ (self, text): - colon = text.find (":") - if colon == -1: - host = text - self.port = 5672 - else: - host = text[:colon] - self.port = int (text[colon+1:]) + rex = re.compile(r""" + # [ <user> [ / <password> ] @] <host> [ :<port> ] + ^ (?: ([^/]*) (?: / ([^@]*) )? @)? ([^:]+) (?: :([0-9]+))?$""", re.X) + match = rex.match(text) + if not match: raise ValueError("'%s' is not a valid broker url" % (text)) + user, password, host, port = match.groups() + self.host = socket.gethostbyname (host) + if port: self.port = int(port) + else: self.port = 5672 + self.username = user or "guest" + self.password = password or "guest" def name (self): return self.host + ":" + str (self.port) @@ -174,7 +179,8 @@ class ManagementData: self.sessionId = "%s.%d" % (os.uname()[1], os.getpid()) self.broker = Broker (host) - self.conn = Connection (connect (self.broker.host, self.broker.port), self.spec) + self.conn = Connection (connect (self.broker.host, self.broker.port), self.spec, + username=self.broker.username, password=self.broker.password) self.conn.start () self.mclient = managementClient (self.spec, self.ctrlHandler, self.configHandler, |