You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gs...@apache.org on 2008/05/09 13:15:35 UTC
svn commit: r654759 - in /incubator/qpid/trunk/qpid/python:
commands/qpid-config commands/qpid-queue-stats commands/qpid-route
qpid/connection.py qpid/delegates.py qpid/managementdata.py qpid/testlib.py
Author: gsim
Date: Fri May 9 04:15:35 2008
New Revision: 654759
URL: http://svn.apache.org/viewvc?rev=654759&view=rev
Log:
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.
Modified:
incubator/qpid/trunk/qpid/python/commands/qpid-config
incubator/qpid/trunk/qpid/python/commands/qpid-queue-stats
incubator/qpid/trunk/qpid/python/commands/qpid-route
incubator/qpid/trunk/qpid/python/qpid/connection.py
incubator/qpid/trunk/qpid/python/qpid/delegates.py
incubator/qpid/trunk/qpid/python/qpid/managementdata.py
incubator/qpid/trunk/qpid/python/qpid/testlib.py
Modified: incubator/qpid/trunk/qpid/python/commands/qpid-config
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/commands/qpid-config?rev=654759&r1=654758&r2=654759&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/commands/qpid-config (original)
+++ incubator/qpid/trunk/qpid/python/commands/qpid-config Fri May 9 04:15:35 2008
@@ -26,6 +26,7 @@
import qpid
from threading import Condition
from qpid.management import managementClient
+from qpid.managementdata import Broker
from qpid.peer import Closed
from qpid.connection import Connection
from qpid.datatypes import uuid4
@@ -62,8 +63,8 @@
print "Options:"
print " -b [ --bindings ] Show bindings in queue or exchange list"
print " -a [ --broker-addr ] Address (localhost) Address of qpidd broker"
- print " broker-addr is in the form: hostname | ip-address [:<port>]"
- print " ex: localhost, 10.1.1.7:10000, broker-host:10000"
+ print " broker-addr is in the form: [username/password@] hostname | ip-address [:<port>]"
+ print " ex: localhost, 10.1.1.7:10000, broker-host:10000, guest/guest@localhost"
print " -s [ --spec-file] Path (" + _defspecpath + ")"
print " AMQP specification file"
print
@@ -79,20 +80,6 @@
print
sys.exit (1)
-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:])
- self.host = socket.gethostbyname (host)
-
- def name (self):
- return self.host + ":" + str (self.port)
-
class BrokerManager:
def __init__ (self):
self.dest = None
@@ -106,7 +93,8 @@
try:
self.spec = qpid.spec.load (_specpath)
self.sessionId = "%s.%d" % (os.uname()[1], os.getpid())
- 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.session = self.conn.session(str(uuid4()))
self.mclient = managementClient (self.spec)
Modified: incubator/qpid/trunk/qpid/python/commands/qpid-queue-stats
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/commands/qpid-queue-stats?rev=654759&r1=654758&r2=654759&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/commands/qpid-queue-stats (original)
+++ incubator/qpid/trunk/qpid/python/commands/qpid-queue-stats Fri May 9 04:15:35 2008
@@ -27,25 +27,12 @@
import qpid
from threading import Condition
from qpid.management import managementClient
+from qpid.managementdata import Broker
from qpid.peer import Closed
from qpid.connection import Connection
from qpid.util import connect
from time import sleep
-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:])
- self.host = socket.gethostbyname (host)
-
- def name (self):
- return self.host + ":" + str (self.port)
-
class mgmtObject (object):
""" Generic object that holds the contents of a management object with its
attributes set as object attributes. """
@@ -74,7 +61,8 @@
try:
self.spec = qpid.spec.load (self.specpath)
self.sessionId = "%s.%d" % (os.uname()[1], os.getpid())
- 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, None, self.configCb, self.instCb)
self.mchannel = self.mclient.addChannel (self.conn.session(self.sessionId))
@@ -154,7 +142,7 @@
##
def main():
p = optparse.OptionParser()
- p.add_option('--broker-address','-a', default='localhost' , help='broker-addr is in the form: hostname | ip-address [:<port>] \n ex: localhost, 10.1.1.7:10000, broker-host:10000')
+ p.add_option('--broker-address','-a', default='localhost' , help='broker-addr is in the form: [username/password@] hostname | ip-address [:<port>] \n ex: localhost, 10.1.1.7:10000, broker-host:10000, guest/guest@localhost')
p.add_option('--amqp-spec-file','-s', default='"/usr/share/amqp/amqp.0-10.xml', help='the path to the amqp spec file')
p.add_option('--filter','-f' ,default=None ,help='a list of comma separated queue names (regex are accepted) to show')
Modified: incubator/qpid/trunk/qpid/python/commands/qpid-route
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/commands/qpid-route?rev=654759&r1=654758&r2=654759&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/commands/qpid-route (original)
+++ incubator/qpid/trunk/qpid/python/commands/qpid-route Fri May 9 04:15:35 2008
@@ -25,6 +25,7 @@
import qpid
import os
from qpid.management import managementClient
+from qpid.managementdata import Broker
from qpid.peer import Closed
from qpid.connection import Connection
from qpid.util import connect
@@ -41,8 +42,8 @@
print " -v [ --verbose ] Verbose output"
print " -q [ --quiet ] Quiet output, don't print duplicate warnings"
print
- print " dest-broker and src-broker are in the form: hostname | ip-address [:<port>]"
- print " ex: localhost, 10.1.1.7:10000, broker-host:10000"
+ print " dest-broker and src-broker are in the form: [username/password@] hostname | ip-address [:<port>]"
+ print " ex: localhost, 10.1.1.7:10000, broker-host:10000, guest/guest@localhost"
print
#print " If loading the route configuration from a file, the input file has one line per route"
#print " in the form:"
@@ -55,20 +56,6 @@
_verbose = False
_quiet = False
-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:])
- self.host = socket.gethostbyname (host)
-
- def name (self):
- return self.host + ":" + str (self.port)
-
class RouteManager:
def __init__ (self, destBroker):
self.dest = Broker (destBroker)
@@ -81,7 +68,7 @@
try:
self.spec = qpid.spec.load (_specpath)
self.sessionId = "%s.%d" % (os.uname()[1], os.getpid())
- self.conn = Connection (connect (broker.host, broker.port), self.spec)
+ self.conn = Connection (connect (broker.host, broker.port), self.spec, username=broker.username, password=broker.password)
self.conn.start ()
self.mclient = managementClient (self.spec)
self.mch = self.mclient.addChannel (self.conn.session(self.sessionId))
Modified: incubator/qpid/trunk/qpid/python/qpid/connection.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/connection.py?rev=654759&r1=654758&r2=654759&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/connection.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/connection.py Fri May 9 04:15:35 2008
@@ -37,6 +37,8 @@
class SessionBusy(Exception): pass
+class ConnectionFailed(Exception): pass
+
def client(*args):
return delegates.Client(*args)
@@ -45,7 +47,7 @@
class Connection(Assembler):
- def __init__(self, sock, spec=None, delegate=client):
+ def __init__(self, sock, spec=None, delegate=client, **args):
Assembler.__init__(self, sock)
if spec == None:
spec = load(default())
@@ -58,13 +60,14 @@
self.condition = Condition()
self.opened = False
+ self.failed = False
self.thread = Thread(target=self.run)
self.thread.setDaemon(True)
self.channel_max = 65535
- self.delegate = delegate(self)
+ self.delegate = delegate(self, args)
def attach(self, name, ch, delegate, force=False):
self.lock.acquire()
@@ -127,8 +130,10 @@
def start(self, timeout=None):
self.delegate.start()
self.thread.start()
- if not wait(self.condition, lambda: self.opened, timeout):
+ if not wait(self.condition, lambda: self.opened or self.failed, timeout):
raise Timeout()
+ if (self.failed):
+ raise ConnectionFailed()
def run(self):
# XXX: we don't really have a good way to exit this loop without
Modified: incubator/qpid/trunk/qpid/python/qpid/delegates.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/delegates.py?rev=654759&r1=654758&r2=654759&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/delegates.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/delegates.py Fri May 9 04:15:35 2008
@@ -52,6 +52,9 @@
def connection_close(self, ch, close):
ch.connection_close_ok()
self.connection.sock.close()
+ if not self.connection.opened:
+ self.connection.failed = True
+ notify(self.connection.condition)
def connection_close_ok(self, ch, close_ok):
self.connection.opened = False
@@ -124,12 +127,19 @@
"version": "development",
"platform": os.name}
+ def __init__(self, connection, args={}):
+ Delegate.__init__(self, connection)
+ self.username = args.get('username', 'guest')
+ self.password = args.get('password', 'guest')
+ self.mechanism = args.get('mechanism', 'PLAIN')
+
def start(self):
self.connection.write_header(self.spec.major, self.spec.minor)
self.connection.read_header()
def connection_start(self, ch, start):
- ch.connection_start_ok(client_properties=Client.PROPERTIES, mechanism="ANONYMOUS")
+ r = "\0%s\0%s" % (self.username, self.password)
+ ch.connection_start_ok(client_properties=Client.PROPERTIES, mechanism=self.mechanism, response=r)
def connection_tune(self, ch, tune):
ch.connection_tune_ok()
Modified: incubator/qpid/trunk/qpid/python/qpid/managementdata.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/managementdata.py?rev=654759&r1=654758&r2=654759&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/managementdata.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/managementdata.py Fri May 9 04:15:35 2008
@@ -20,6 +20,7 @@
#
import qpid
+import re
import socket
import struct
import os
@@ -32,14 +33,18 @@
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 @@
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,
Modified: incubator/qpid/trunk/qpid/python/qpid/testlib.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/testlib.py?rev=654759&r1=654758&r2=654759&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/testlib.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/testlib.py Fri May 9 04:15:35 2008
@@ -353,7 +353,8 @@
def setUp(self):
spec = testrunner.spec
- self.conn = Connection(connect(testrunner.host, testrunner.port), spec)
+ self.conn = Connection(connect(testrunner.host, testrunner.port), spec,
+ username=testrunner.user, password=testrunner.password)
self.conn.start(timeout=10)
self.session = self.conn.session("test-session", timeout=10)