"Fossies" - the Fresh Open Source Software Archive

Member "keystone-17.0.0/keystone/credential/backends/base.py" (13 May 2020, 3920 Bytes) of package /linux/misc/openstack/keystone-17.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "base.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 16.0.1_vs_17.0.0.

    1 # Copyright 2012 OpenStack Foundation
    2 #
    3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
    4 # not use this file except in compliance with the License. You may obtain
    5 # a copy of the License at
    6 #
    7 #      http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 # Unless required by applicable law or agreed to in writing, software
   10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   12 # License for the specific language governing permissions and limitations
   13 # under the License.
   14 
   15 import abc
   16 
   17 from oslo_log import log
   18 
   19 from keystone import exception
   20 
   21 
   22 LOG = log.getLogger(__name__)
   23 
   24 
   25 class CredentialDriverBase(object, metaclass=abc.ABCMeta):
   26     # credential crud
   27 
   28     @abc.abstractmethod
   29     def create_credential(self, credential_id, credential):
   30         """Create a new credential.
   31 
   32         :raises keystone.exception.Conflict: If a duplicate credential exists.
   33 
   34         """
   35         raise exception.NotImplemented()  # pragma: no cover
   36 
   37     @abc.abstractmethod
   38     def list_credentials(self, hints):
   39         """List all credentials.
   40 
   41         :param hints: contains the list of filters yet to be satisfied.
   42                       Any filters satisfied here will be removed so that
   43                       the caller will know if any filters remain.
   44 
   45         :returns: a list of credential_refs or an empty list.
   46 
   47         """
   48         raise exception.NotImplemented()  # pragma: no cover
   49 
   50     @abc.abstractmethod
   51     def list_credentials_for_user(self, user_id, type=None):
   52         """List credentials for a user.
   53 
   54         :param user_id: ID of a user to filter credentials by.
   55         :param type: type of credentials to filter on.
   56 
   57         :returns: a list of credential_refs or an empty list.
   58 
   59         """
   60         raise exception.NotImplemented()  # pragma: no cover
   61 
   62     @abc.abstractmethod
   63     def get_credential(self, credential_id):
   64         """Get a credential by ID.
   65 
   66         :returns: credential_ref
   67         :raises keystone.exception.CredentialNotFound: If credential doesn't
   68             exist.
   69 
   70         """
   71         raise exception.NotImplemented()  # pragma: no cover
   72 
   73     @abc.abstractmethod
   74     def update_credential(self, credential_id, credential):
   75         """Update an existing credential.
   76 
   77         :raises keystone.exception.CredentialNotFound: If credential doesn't
   78             exist.
   79         :raises keystone.exception.Conflict: If a duplicate credential exists.
   80 
   81         """
   82         raise exception.NotImplemented()  # pragma: no cover
   83 
   84     @abc.abstractmethod
   85     def delete_credential(self, credential_id):
   86         """Delete an existing credential.
   87 
   88         :raises keystone.exception.CredentialNotFound: If credential doesn't
   89             exist.
   90 
   91         """
   92         raise exception.NotImplemented()  # pragma: no cover
   93 
   94     @abc.abstractmethod
   95     def delete_credentials_for_project(self, project_id):
   96         """Delete all credentials for a project."""
   97         self._delete_credentials(lambda cr: cr['project_id'] == project_id)
   98 
   99     @abc.abstractmethod
  100     def delete_credentials_for_user(self, user_id):
  101         """Delete all credentials for a user."""
  102         self._delete_credentials(lambda cr: cr['user_id'] == user_id)
  103 
  104     def _delete_credentials(self, match_fn):
  105         """Do the actual credential deletion work (default implementation).
  106 
  107         :param match_fn: function that takes a credential dict as the
  108                          parameter and returns true or false if the
  109                          identifier matches the credential dict.
  110         """
  111         for cr in self.list_credentials():
  112             if match_fn(cr):
  113                 try:
  114                     self.credential_api.delete_credential(cr['id'])
  115                 except exception.CredentialNotFound:
  116                     LOG.debug('Deletion of credential is not required: %s',
  117                               cr['id'])