Added support to --os-cacert

Closes-Bug: #1224343

Change-Id: Ib0549d4496c47900c81cc970b99bcff25cad0040
This commit is contained in:
Stefano Zilli
2013-09-13 09:08:19 +02:00
parent b961738765
commit 544e6217e5
3 changed files with 22 additions and 12 deletions

View File

@@ -21,6 +21,7 @@ def _get_ksclient(**kwargs):
* username: name of user * username: name of user
* password: user's password * password: user's password
* auth_url: endpoint to authenticate against * auth_url: endpoint to authenticate against
* cacert: path of CA TLS certificate
* insecure: allow insecure SSL (no cert verification) * insecure: allow insecure SSL (no cert verification)
* tenant_{name|id}: name or ID of tenant * tenant_{name|id}: name or ID of tenant
""" """
@@ -30,6 +31,7 @@ def _get_ksclient(**kwargs):
tenant_name=kwargs.get('tenant_name'), tenant_name=kwargs.get('tenant_name'),
auth_url=kwargs.get('auth_url'), auth_url=kwargs.get('auth_url'),
region_name=kwargs.get('region_name'), region_name=kwargs.get('region_name'),
cacert=kwargs.get('cacert'),
insecure=kwargs.get('insecure')) insecure=kwargs.get('insecure'))
@@ -52,6 +54,7 @@ def get_client(api_version, **kwargs):
* os_username: name of user * os_username: name of user
* os_password: user's password * os_password: user's password
* os_auth_url: endpoint to authenticate against * os_auth_url: endpoint to authenticate against
* os_cacert: path of CA TLS certificate
* insecure: allow insecure SSL (no cert verification) * insecure: allow insecure SSL (no cert verification)
* os_tenant_{name|id}: name or ID of tenant * os_tenant_{name|id}: name or ID of tenant
""" """
@@ -72,6 +75,7 @@ def get_client(api_version, **kwargs):
'region_name': kwargs.get('os_region_name'), 'region_name': kwargs.get('os_region_name'),
'service_type': kwargs.get('os_service_type'), 'service_type': kwargs.get('os_service_type'),
'endpoint_type': kwargs.get('os_endpoint_type'), 'endpoint_type': kwargs.get('os_endpoint_type'),
'cacert': kwargs.get('os_cacert'),
'insecure': kwargs.get('insecure'), 'insecure': kwargs.get('insecure'),
} }
_ksclient = _get_ksclient(**ks_kwargs) _ksclient = _get_ksclient(**ks_kwargs)
@@ -86,7 +90,7 @@ def get_client(api_version, **kwargs):
'token': token, 'token': token,
'insecure': kwargs.get('insecure'), 'insecure': kwargs.get('insecure'),
'timeout': kwargs.get('timeout'), 'timeout': kwargs.get('timeout'),
'ca_file': kwargs.get('ca_file'), 'cacert': kwargs.get('cacert'),
'cert_file': kwargs.get('cert_file'), 'cert_file': kwargs.get('cert_file'),
'key_file': kwargs.get('key_file'), 'key_file': kwargs.get('key_file'),
} }

View File

@@ -63,7 +63,7 @@ class HTTPClient(object):
if parts.scheme == 'https': if parts.scheme == 'https':
_class = VerifiedHTTPSConnection _class = VerifiedHTTPSConnection
_kwargs['ca_file'] = kwargs.get('ca_file', None) _kwargs['ca_cert'] = kwargs.get('cacert', None)
_kwargs['cert_file'] = kwargs.get('cert_file', None) _kwargs['cert_file'] = kwargs.get('cert_file', None)
_kwargs['key_file'] = kwargs.get('key_file', None) _kwargs['key_file'] = kwargs.get('key_file', None)
_kwargs['insecure'] = kwargs.get('insecure', False) _kwargs['insecure'] = kwargs.get('insecure', False)
@@ -93,7 +93,7 @@ class HTTPClient(object):
conn_params_fmt = [ conn_params_fmt = [
('key_file', '--key %s'), ('key_file', '--key %s'),
('cert_file', '--cert %s'), ('cert_file', '--cert %s'),
('ca_file', '--cacert %s'), ('cacert', '--cacert %s'),
] ]
for (key, fmt) in conn_params_fmt: for (key, fmt) in conn_params_fmt:
value = self.connection_params[2].get(key) value = self.connection_params[2].get(key)
@@ -215,21 +215,21 @@ class VerifiedHTTPSConnection(httplib.HTTPSConnection):
""" """
def __init__(self, host, port, key_file=None, cert_file=None, def __init__(self, host, port, key_file=None, cert_file=None,
ca_file=None, timeout=None, insecure=False): cacert=None, timeout=None, insecure=False):
httplib.HTTPSConnection.__init__(self, host, port, key_file=key_file, httplib.HTTPSConnection.__init__(self, host, port, key_file=key_file,
cert_file=cert_file) cert_file=cert_file)
self.key_file = key_file self.key_file = key_file
self.cert_file = cert_file self.cert_file = cert_file
if ca_file is not None: if cacert is not None:
self.ca_file = ca_file self.cacert = cacert
else: else:
self.ca_file = self.get_system_ca_file() self.cacert = self.get_system_ca_file()
self.timeout = timeout self.timeout = timeout
self.insecure = insecure self.insecure = insecure
def connect(self): def connect(self):
"""Connect to a host on a given (SSL) port. """Connect to a host on a given (SSL) port.
If ca_file is pointing somewhere, use it to check Server Certificate. If cacert is pointing somewhere, use it to check Server Certificate.
Redefined/copied and extended from httplib.py:1105 (Python 2.6.x). Redefined/copied and extended from httplib.py:1105 (Python 2.6.x).
This is needed to pass cert_reqs=ssl.CERT_REQUIRED as parameter to This is needed to pass cert_reqs=ssl.CERT_REQUIRED as parameter to
@@ -245,7 +245,7 @@ class VerifiedHTTPSConnection(httplib.HTTPSConnection):
if self.insecure is True: if self.insecure is True:
kwargs = {'cert_reqs': ssl.CERT_NONE} kwargs = {'cert_reqs': ssl.CERT_NONE}
else: else:
kwargs = {'cert_reqs': ssl.CERT_REQUIRED, 'ca_certs': self.ca_file} kwargs = {'cert_reqs': ssl.CERT_REQUIRED, 'ca_certs': self.cacert}
if self.cert_file: if self.cert_file:
kwargs['certfile'] = self.cert_file kwargs['certfile'] = self.cert_file

View File

@@ -76,11 +76,17 @@ class CeilometerShell(object):
' This option is not necessary if your key is ' ' This option is not necessary if your key is '
'prepended to your cert file.') 'prepended to your cert file.')
parser.add_argument('--ca-file', parser.add_argument('--os-cacert',
help='Path of CA SSL certificate(s) used to verify' metavar='<ca-certificate-file>',
' the remote server certificate. Without this ' dest='os_cacert',
default=utils.env('OS_CACERT'),
help='Path of CA TLS certificate(s) used to verify'
'the remote server\'s certificate. Without this '
'option ceilometer looks for the default system ' 'option ceilometer looks for the default system '
'CA certificates.') 'CA certificates.')
parser.add_argument('--ca-file',
dest='os_cacert',
help='DEPRECATED! Use --os-cacert.')
parser.add_argument('--timeout', parser.add_argument('--timeout',
default=600, default=600,