Files
python-solumclient/solumclient/common/auth.py
Noorul Islam K M 04fbabadc0 Add solum builder client
This client will be used to communicate with builder service from solum.

Generalize KeystoneAuthPlugin so that it can be used by both solumclient and
builder client.

Fixed a bug in solumclient/common/base.py

Change-Id: I86630f40b32c6fcada5aa292fae8e36cecab9908
2014-03-11 21:20:27 +05:30

75 lines
2.4 KiB
Python

# Copyright 2013 - Noorul Islam K M
#
# 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.
from keystoneclient.v2_0 import client as ksclient
from solumclient.openstack.common.apiclient import auth
from solumclient.openstack.common.apiclient import exceptions
class KeystoneAuthPlugin(auth.BaseAuthPlugin):
opt_names = [
"username",
"password",
"tenant_name",
"token",
"auth_url",
"endpoint"
]
def _do_authenticate(self, http_client):
if self.opts.get('token') is None:
ks_kwargs = {
'username': self.opts.get('username'),
'password': self.opts.get('password'),
'tenant_name': self.opts.get('tenant_name'),
'auth_url': self.opts.get('auth_url'),
}
self._ksclient = ksclient.Client(**ks_kwargs)
def token_and_endpoint(self, endpoint_type, service_type):
token = endpoint = None
if self.opts.get('token') and self.opts.get('endpoint'):
token = self.opts.get('token')
endpoint = self.opts.get('endpoint')
elif hasattr(self, '_ksclient'):
token = self._ksclient.auth_token
endpoint = (self.opts.get('endpoint') or
self._ksclient.service_catalog.url_for(
service_type=service_type,
endpoint_type=endpoint_type))
return (token, endpoint)
def sufficient_options(self):
"""Check if all required options are present.
:raises: AuthPluginOptionsMissing
"""
if self.opts.get('token'):
lookup_table = ["token", "endpoint"]
else:
lookup_table = ["username", "password", "tenant_name", "auth_url"]
missing = [opt
for opt in lookup_table
if not self.opts.get(opt)]
if missing:
raise exceptions.AuthPluginOptionsMissing(missing)