This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from maruno/amqp_ssl_url_user_pass
Add support for amqp+ssl URL's and configured username and password
- Loading branch information
Showing
5 changed files
with
151 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,11 +89,31 @@ Available tools | |
* ``qb session outgoing`` - List outgoing sessions from the server. | ||
|
||
|
||
Environment variables | ||
--------------------- | ||
Configuration & Environment variables | ||
------------------------------------- | ||
Several options exist to configure Qpid Bow. In order of preference: | ||
|
||
``AMQP_SERVERS`` - comma-separated list of main and failover servers to connect to | ||
**Pass in arguments** | ||
One can always override the used server URL using arguments: | ||
|
||
``AMQP_TEST_SERVERS`` - Same as ``AMQP_SERVERS``, used solely for unittests | ||
* For the CLI tools, use the ``--broker-url`` command line argument. | ||
* For the library pass in the keyword argument ``server_url``. | ||
|
||
**Configure using a dict** | ||
When using Qpid Bow as a library, one can pass in config using a dict to: | ||
``qpid_bow.config.configure`` | ||
|
||
The dict can contain the following entries: | ||
|
||
* ``amqp_url`` - Comma-separated list of main and failover servers to connect to. | ||
* ``username`` - Username to use when no username is provided in the URL. | ||
* ``password`` - Password to use when no password is provided in the URL. | ||
|
||
**Environment variables** | ||
The easiest way to configure Qpid Bow's tools and library is to use environment variables. | ||
These variables can be added to your shell's profile and will automatically get picked up. | ||
|
||
* ``AMQP_SERVERS`` - Comma-separated list of main and failover servers to connect to. | ||
* ``AMQP_TEST_SERVERS`` - Same as ``AMQP_SERVERS``, used solely for unittests. | ||
|
||
example: ``AMQP_SERVERS=amqp://user:[email protected]:5672,amqp://user:[email protected]:5672`` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.0.2 | ||
1.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
from contextlib import suppress | ||
from os import environ | ||
from unittest import TestCase | ||
|
||
from qpid_bow.config import configure, config, get_urls, process_url | ||
|
||
class TestGetURLs(TestCase): | ||
def setUp(self): | ||
self.old_config = config | ||
self.old_env = environ.get('AMQP_SERVERS') | ||
|
||
def tearDown(self): | ||
config.clear() | ||
config.update(self.old_config) | ||
if self.old_env: | ||
environ['AMQP_SERVERS'] = self.old_env | ||
else: | ||
with suppress(KeyError): | ||
del environ['AMQP_SERVERS'] | ||
|
||
def test_no_config(self): | ||
with suppress(KeyError): | ||
del environ['AMQP_SERVERS'] | ||
|
||
with self.assertRaises(ValueError): | ||
get_urls() | ||
|
||
def test_get_urls_priority_from_environ(self): | ||
environ['AMQP_SERVERS'] = 'amqps://environ.example' | ||
self.assertEqual(get_urls(), ['amqps://environ.example']) | ||
|
||
def test_get_urls_priority_from_config(self): | ||
environ['AMQP_SERVERS'] = 'amqps://environ.example' | ||
configure({'amqp_url': 'amqps://config.example'}) | ||
|
||
self.assertEqual(get_urls(), ['amqps://config.example']) | ||
|
||
def test_get_urls_priority_from_args(self): | ||
environ['AMQP_SERVERS'] = 'amqps://environ.example' | ||
configure({'amqp_url': 'amqps://config.example'}) | ||
|
||
self.assertEqual(get_urls('amqps://args.example'), | ||
['amqps://args.example']) | ||
|
||
def test_get_urls_comma_seperated(self): | ||
self.assertEqual( | ||
get_urls('amqps://args1.example, amqps://args2.example'), | ||
['amqps://args1.example', 'amqps://args2.example']) | ||
|
||
def test_get_urls_activemq_format(self): | ||
self.assertEqual(get_urls('amqp+ssl://args.example'), | ||
['amqps://args.example']) | ||
|
||
def test_get_urls_activemq_format_comma_seperated(self): | ||
self.assertEqual( | ||
get_urls('amqp+ssl://args1.example, amqp+ssl://args2.example'), | ||
['amqps://args1.example', 'amqps://args2.example']) | ||
|
||
def test_get_urls_user_passwd_config_mixed(self): | ||
config['username'] = 'otheruser' | ||
config['password'] = 'otherpass' | ||
self.assertEqual( | ||
get_urls('amqps://args1.example,amqps://user:[email protected]'), | ||
['amqps://otheruser:[email protected]', | ||
'amqps://user:[email protected]']) | ||
|
||
def test_process_url_noop(self): | ||
valid_url = 'amqp://some.example' | ||
self.assertEqual(process_url(valid_url), valid_url) | ||
|
||
def test_process_url_activemq(self): | ||
self.assertEqual(process_url('amqp+ssl://some.example'), | ||
'amqps://some.example') | ||
|
||
def test_process_url_user_passwd_config(self): | ||
config['username'] = 'user' | ||
config['password'] = 'pass' | ||
self.assertEqual(process_url('amqps://some.example'), | ||
'amqps://user:[email protected]') | ||
|
||
def test_process_url_user_passwd_no_override(self): | ||
config['username'] = 'otheruser' | ||
config['password'] = 'otherpass' | ||
valid_url = 'amqps://user:[email protected]' | ||
self.assertEqual(process_url(valid_url), valid_url) |