From b5a5af1c3b2528267b1e36e6c840349dd9ddf434 Mon Sep 17 00:00:00 2001 From: Brant Knudson Date: Tue, 16 Dec 2014 13:28:05 -0600 Subject: [PATCH] Add OS-SIMPLE-CERT support for v3. There was no API support for the OS-SIMPLE-CERT v3 extension. bp auth-token-use-client Change-Id: Ic3d36018fc2e5a5a0da8d37a7fa58b77b8fa8e15 --- .../tests/unit/v3/test_simple_cert.py | 40 +++++++++++++++++ keystoneclient/v3/client.py | 6 +++ keystoneclient/v3/contrib/simple_cert.py | 43 +++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 keystoneclient/tests/unit/v3/test_simple_cert.py create mode 100644 keystoneclient/v3/contrib/simple_cert.py diff --git a/keystoneclient/tests/unit/v3/test_simple_cert.py b/keystoneclient/tests/unit/v3/test_simple_cert.py new file mode 100644 index 000000000..067083a44 --- /dev/null +++ b/keystoneclient/tests/unit/v3/test_simple_cert.py @@ -0,0 +1,40 @@ +# Copyright 2014 IBM Corp. +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import testresources + +from keystoneclient.tests.unit import client_fixtures +from keystoneclient.tests.unit.v3 import utils + + +class SimpleCertTests(utils.TestCase, testresources.ResourcedTestCase): + + resources = [('examples', client_fixtures.EXAMPLES_RESOURCE)] + + def test_get_ca_certificate(self): + self.stub_url('GET', ['OS-SIMPLE-CERT', 'ca'], + headers={'Content-Type': 'application/x-pem-file'}, + text=self.examples.SIGNING_CA) + res = self.client.simple_cert.get_ca_certificates() + self.assertEqual(self.examples.SIGNING_CA, res) + + def test_get_certificates(self): + self.stub_url('GET', ['OS-SIMPLE-CERT', 'certificates'], + headers={'Content-Type': 'application/x-pem-file'}, + text=self.examples.SIGNING_CERT) + res = self.client.simple_cert.get_certificates() + self.assertEqual(self.examples.SIGNING_CERT, res) + + +def load_tests(loader, tests, pattern): + return testresources.OptimisingTestSuite(tests) diff --git a/keystoneclient/v3/client.py b/keystoneclient/v3/client.py index 8becfab92..f7becbbcd 100644 --- a/keystoneclient/v3/client.py +++ b/keystoneclient/v3/client.py @@ -25,6 +25,7 @@ from keystoneclient.v3.contrib import endpoint_filter from keystoneclient.v3.contrib import endpoint_policy from keystoneclient.v3.contrib import federation from keystoneclient.v3.contrib import oauth1 +from keystoneclient.v3.contrib import simple_cert from keystoneclient.v3.contrib import trusts from keystoneclient.v3 import credentials from keystoneclient.v3 import domains @@ -145,6 +146,10 @@ EndpointPolicyManager` :py:class:`keystoneclient.v3.roles.RoleManager` + .. py:attribute:: simple_cert + + :py:class:`keystoneclient.v3.contrib.simple_cert.SimpleCertManager` + .. py:attribute:: services :py:class:`keystoneclient.v3.services.ServiceManager` @@ -186,6 +191,7 @@ EndpointPolicyManager` role_assignments.RoleAssignmentManager(self._adapter)) self.roles = roles.RoleManager(self._adapter) self.services = services.ServiceManager(self._adapter) + self.simple_cert = simple_cert.SimpleCertManager(self._adapter) self.tokens = tokens.TokenManager(self._adapter) self.trusts = trusts.TrustManager(self._adapter) self.users = users.UserManager(self._adapter) diff --git a/keystoneclient/v3/contrib/simple_cert.py b/keystoneclient/v3/contrib/simple_cert.py new file mode 100644 index 000000000..c76234a3d --- /dev/null +++ b/keystoneclient/v3/contrib/simple_cert.py @@ -0,0 +1,43 @@ +# Copyright 2014 IBM Corp. +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +class SimpleCertManager(object): + """Manager for the OS-SIMPLE-CERT extension.""" + + def __init__(self, client): + self._client = client + + def get_ca_certificates(self): + """Get CA certificates. + + :returns: PEM-formatted string. + :rtype: str + + """ + + resp, body = self._client.get('/OS-SIMPLE-CERT/ca', + authenticated=False) + return resp.text + + def get_certificates(self): + """Get signing certificates. + + :returns: PEM-formatted string. + :rtype: str + + """ + + resp, body = self._client.get('/OS-SIMPLE-CERT/certificates', + authenticated=False) + return resp.text