From adc61d2ff95c10ae823005da085e736b8e5412b1 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Fri, 29 Jul 2016 14:50:10 +0000 Subject: [PATCH] Add method to decode Rabbit CA cert If rabbit is running in SSL mode then it will present a base64 encoded CA cert down the relation. Add a methode to retrieve and decode the cert. Change-Id: I1806a5d1bcac6a7ac80f655d96f951f84e9db521 --- .gitreview | 4 ++++ requires.py | 10 +++++++++- tox.ini | 16 +++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 .gitreview diff --git a/.gitreview b/.gitreview new file mode 100644 index 0000000..6d7ea5f --- /dev/null +++ b/.gitreview @@ -0,0 +1,4 @@ +[gerrit] +host=review.openstack.org +port=29418 +project=openstack/charm-interface-rabbitmq.git diff --git a/requires.py b/requires.py index 7a50d66..b1a2c6d 100644 --- a/requires.py +++ b/requires.py @@ -11,6 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import base64 + from charms.reactive import RelationBase from charms.reactive import hook from charms.reactive import scopes @@ -101,7 +103,7 @@ class RabbitMQRequires(RelationBase): self.request_access(username, vhost) def get_remote_all(self, key, default=None): - '''Return a list of all values presented by remote units for key''' + """Return a list of all values presented by remote units for key""" values = [] for conversation in self.conversations(): for relation_id in conversation.relation_ids: @@ -115,3 +117,9 @@ class RabbitMQRequires(RelationBase): def rabbitmq_hosts(self): return self.get_remote_all('private-address') + + def get_ssl_cert(self): + """Return decoded CA cert from rabbit or None if no CA present""" + if self.ssl_ca(): + return base64.b64decode(self.ssl_ca()).decode('utf-8') + return None diff --git a/tox.ini b/tox.ini index c035f1a..c887b8e 100644 --- a/tox.ini +++ b/tox.ini @@ -12,8 +12,22 @@ commands = ostestr {posargs} [testenv:py27] basepython = python2.7 deps = -r{toxinidir}/test-requirements.txt +# TODO: Need to write unit tests then remove the following command. +commands = /bin/true -[testenv:lint] +[testenv:py34] +basepython = python3.4 +deps = -r{toxinidir}/test-requirements.txt +# TODO: Need to write unit tests then remove the following command. +commands = /bin/true + +[testenv:py35] +basepython = python3.5 +deps = -r{toxinidir}/test-requirements.txt +# TODO: Need to write unit tests then remove the following command. +commands = /bin/true + +[testenv:pep8] basepython = python2.7 deps = -r{toxinidir}/test-requirements.txt commands = flake8 {posargs}