Example #1
0
 def _plugin_auth(self, auth_url):
     """Load plugin-based authentication"""
     ep_name = 'openstack.client.authenticate'
     for ep in pkg_resources.iter_entry_points(ep_name):
         if ep.name == self.auth_system:
             return ep.load()(self, auth_url)
     raise exceptions.AuthSystemNotFound(self.auth_system)
Example #2
0
def get_auth_system_url(auth_system):
    """Load plugin-based auth_url"""
    ep_name = 'openstack.client.auth_url'
    for ep in pkg_resources.iter_entry_points(ep_name):
        if ep.name == auth_system:
            return ep.load()()
    raise exceptions.AuthSystemNotFound(auth_system)
Example #3
0
    def __init__(self,
                 user,
                 password,
                 projectid=None,
                 auth_url=None,
                 insecure=False,
                 timeout=None,
                 proxy_tenant_id=None,
                 proxy_token=None,
                 region_name=None,
                 endpoint_type='publicURL',
                 service_type=None,
                 service_name=None,
                 volume_service_name=None,
                 timings=False,
                 bypass_url=None,
                 os_cache=False,
                 no_cache=True,
                 http_log_debug=False,
                 auth_system='keystone',
                 auth_plugin=None,
                 auth_token=None,
                 cacert=None,
                 tenant_id=None,
                 user_id=None,
                 connection_pool=False):
        self.user = user
        self.user_id = user_id
        self.password = password
        self.projectid = projectid
        self.tenant_id = tenant_id

        self._connection_pool = (_ClientConnectionPool()
                                 if connection_pool else None)

        # This will be called by #_get_password if self.password is None.
        # EG if a password can only be obtained by prompting the user, but a
        # token is available, you don't want to prompt until the token has
        # been proven invalid
        self.password_func = None

        if auth_system and auth_system != 'keystone' and not auth_plugin:
            raise exceptions.AuthSystemNotFound(auth_system)

        if not auth_url and auth_system and auth_system != 'keystone':
            auth_url = auth_plugin.get_auth_url()
            if not auth_url:
                raise exceptions.EndpointNotFound()
        self.auth_url = auth_url.rstrip('/') if auth_url else auth_url
        self.version = 'v1.1'
        self.region_name = region_name
        self.endpoint_type = endpoint_type
        self.service_type = service_type
        self.service_name = service_name
        self.volume_service_name = volume_service_name
        self.timings = timings
        self.bypass_url = bypass_url.rstrip('/') if bypass_url else bypass_url
        self.os_cache = os_cache or not no_cache
        self.http_log_debug = http_log_debug
        if timeout is not None:
            self.timeout = float(timeout)
        else:
            self.timeout = None

        self.times = []  # [("item", starttime, endtime), ...]

        self.management_url = self.bypass_url or None
        self.auth_token = auth_token
        self.proxy_token = proxy_token
        self.proxy_tenant_id = proxy_tenant_id
        self.keyring_saver = None
        self.keyring_saved = False

        if insecure:
            self.verify_cert = False
        else:
            if cacert:
                self.verify_cert = cacert
            else:
                self.verify_cert = True

        self.auth_system = auth_system
        self.auth_plugin = auth_plugin
        self._session = None
        self._current_url = None
        self._logger = logging.getLogger(__name__)

        if self.http_log_debug and not self._logger.handlers:
            # Logging level is already set on the root logger
            ch = logging.StreamHandler()
            self._logger.addHandler(ch)
            self._logger.propagate = False
            if hasattr(requests, 'logging'):
                rql = requests.logging.getLogger(requests.__name__)
                rql.addHandler(ch)
                # Since we have already setup the root logger on debug, we
                # have to set it up here on WARNING (its original level)
                # otherwise we will get all the requests logging messages
                rql.setLevel(logging.WARNING)
 def authenticate(cls, auth_url):
     raise exceptions.AuthSystemNotFound(self.auth_system)
 def authenticate(self, cls, auth_url):
     """Authenticate using plugin defined method."""
     raise exceptions.AuthSystemNotFound(self.auth_system)
Example #6
0
    def __init__(self,
                 user,
                 password,
                 projectid=None,
                 auth_url=None,
                 insecure=False,
                 timeout=None,
                 proxy_tenant_id=None,
                 proxy_token=None,
                 region_name=None,
                 endpoint_type='publicURL',
                 service_type=None,
                 service_name=None,
                 volume_service_name=None,
                 timings=False,
                 bypass_url=None,
                 os_cache=False,
                 no_cache=True,
                 http_log_debug=False,
                 auth_system='keystone',
                 auth_plugin=None,
                 cacert=None,
                 tenant_id=None):
        self.user = user
        self.password = password
        self.projectid = projectid
        self.tenant_id = tenant_id

        if auth_system and auth_system != 'keystone' and not auth_plugin:
            raise exceptions.AuthSystemNotFound(auth_system)

        if not auth_url and auth_system and auth_system != 'keystone':
            auth_url = auth_plugin.get_auth_url()
            if not auth_url:
                raise exceptions.EndpointNotFound()
        self.auth_url = auth_url.rstrip('/')
        self.version = 'v1.1'
        self.region_name = region_name
        self.endpoint_type = endpoint_type
        self.service_type = service_type
        self.service_name = service_name
        self.volume_service_name = volume_service_name
        self.timings = timings
        self.bypass_url = bypass_url
        self.os_cache = os_cache or not no_cache
        self.http_log_debug = http_log_debug
        if timeout is not None:
            self.timeout = float(timeout)
        else:
            self.timeout = None

        self.times = []  # [("item", starttime, endtime), ...]

        self.management_url = None
        self.auth_token = None
        self.proxy_token = proxy_token
        self.proxy_tenant_id = proxy_tenant_id
        self.keyring_saver = None
        self.keyring_saved = False

        if insecure:
            self.verify_cert = False
        else:
            if cacert:
                self.verify_cert = cacert
            else:
                self.verify_cert = True

        self.auth_system = auth_system
        self.auth_plugin = auth_plugin

        self._logger = logging.getLogger(__name__)
        if self.http_log_debug and not self._logger.handlers:
            # Logging level is already set on the root logger
            ch = logging.StreamHandler()
            self._logger.addHandler(ch)
            self._logger.propagate = False
            if hasattr(requests, 'logging'):
                rql = requests.logging.getLogger(requests.__name__)
                rql.addHandler(ch)
                # Since we have already setup the root logger on debug, we
                # have to set it up here on WARNING (its original level)
                # otherwise we will get all the requests logging messanges
                rql.setLevel(logging.WARNING)
        # requests within the same session can reuse TCP connections from pool
        self.http = requests.Session()