"Fossies" - the Fresh Open Source Software Archive

Member "keystone-17.0.0/keystone/resource/backends/base.py" (13 May 2020, 8923 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 import keystone.conf
   18 from keystone import exception
   19 
   20 
   21 CONF = keystone.conf.CONF
   22 
   23 
   24 def get_project_from_domain(domain_ref):
   25     """Create a project ref from the provided domain ref."""
   26     project_ref = domain_ref.copy()
   27     project_ref['is_domain'] = True
   28     project_ref['domain_id'] = None
   29     project_ref['parent_id'] = None
   30 
   31     return project_ref
   32 
   33 
   34 # The provided SQL driver uses a special value to represent a domain_id of
   35 # None. See comment in Project class of resource/backends/sql.py for more
   36 # details.
   37 NULL_DOMAIN_ID = '<<keystone.domain.root>>'
   38 
   39 
   40 class ResourceDriverBase(object, metaclass=abc.ABCMeta):
   41 
   42     def _get_list_limit(self):
   43         return CONF.resource.list_limit or CONF.list_limit
   44 
   45     # project crud
   46     @abc.abstractmethod
   47     def list_projects(self, hints):
   48         """List projects in the system.
   49 
   50         :param hints: filter hints which the driver should
   51                       implement if at all possible.
   52 
   53         :returns: a list of project_refs or an empty list.
   54 
   55         """
   56         raise exception.NotImplemented()  # pragma: no cover
   57 
   58     @abc.abstractmethod
   59     def list_projects_from_ids(self, project_ids):
   60         """List projects for the provided list of ids.
   61 
   62         :param project_ids: list of ids
   63 
   64         :returns: a list of project_refs.
   65 
   66         This method is used internally by the assignment manager to bulk read
   67         a set of projects given their ids.
   68 
   69         """
   70         raise exception.NotImplemented()  # pragma: no cover
   71 
   72     @abc.abstractmethod
   73     def list_project_ids_from_domain_ids(self, domain_ids):
   74         """List project ids for the provided list of domain ids.
   75 
   76         :param domain_ids: list of domain ids
   77 
   78         :returns: a list of project ids owned by the specified domain ids.
   79 
   80         This method is used internally by the assignment manager to bulk read
   81         a set of project ids given a list of domain ids.
   82 
   83         """
   84         raise exception.NotImplemented()  # pragma: no cover
   85 
   86     @abc.abstractmethod
   87     def list_projects_in_domain(self, domain_id):
   88         """List projects in the domain.
   89 
   90         :param domain_id: the driver MUST only return projects
   91                           within this domain.
   92 
   93         :returns: a list of project_refs or an empty list.
   94 
   95         """
   96         raise exception.NotImplemented()  # pragma: no cover
   97 
   98     @abc.abstractmethod
   99     def get_project(self, project_id):
  100         """Get a project by ID.
  101 
  102         :returns: project_ref
  103         :raises keystone.exception.ProjectNotFound: if project_id does not
  104                                                     exist
  105 
  106         """
  107         raise exception.NotImplemented()  # pragma: no cover
  108 
  109     @abc.abstractmethod
  110     def update_project(self, project_id, project):
  111         """Update an existing project.
  112 
  113         :raises keystone.exception.ProjectNotFound: if project_id does not
  114                                                     exist
  115         :raises keystone.exception.Conflict: if project name already exists
  116 
  117         """
  118         raise exception.NotImplemented()  # pragma: no cover
  119 
  120     @abc.abstractmethod
  121     def delete_project(self, project_id):
  122         """Delete an existing project.
  123 
  124         :raises keystone.exception.ProjectNotFound: if project_id does not
  125                                                     exist
  126 
  127         """
  128         raise exception.NotImplemented()  # pragma: no cover
  129 
  130     @abc.abstractmethod
  131     def list_project_parents(self, project_id):
  132         """List all parents from a project by its ID.
  133 
  134         :param project_id: the driver will list the parents of this
  135                            project.
  136 
  137         :returns: a list of project_refs or an empty list.
  138         :raises keystone.exception.ProjectNotFound: if project_id does not
  139                                                     exist
  140 
  141         """
  142         raise exception.NotImplemented()
  143 
  144     @abc.abstractmethod
  145     def list_projects_in_subtree(self, project_id):
  146         """List all projects in the subtree of a given project.
  147 
  148         :param project_id: the driver will get the subtree under
  149                            this project.
  150 
  151         :returns: a list of project_refs or an empty list
  152         :raises keystone.exception.ProjectNotFound: if project_id does not
  153                                                     exist
  154 
  155         """
  156         raise exception.NotImplemented()
  157 
  158     @abc.abstractmethod
  159     def is_leaf_project(self, project_id):
  160         """Check if a project is a leaf in the hierarchy.
  161 
  162         :param project_id: the driver will check if this project
  163                            is a leaf in the hierarchy.
  164 
  165         :raises keystone.exception.ProjectNotFound: if project_id does not
  166                                                     exist
  167 
  168         """
  169         raise exception.NotImplemented()
  170 
  171     def _validate_default_domain(self, ref):
  172         """Validate that either the default domain or nothing is specified.
  173 
  174         Also removes the domain from the ref so that LDAP doesn't have to
  175         persist the attribute.
  176 
  177         """
  178         ref = ref.copy()
  179         domain_id = ref.pop('domain_id', CONF.identity.default_domain_id)
  180         self._validate_default_domain_id(domain_id)
  181         return ref
  182 
  183     def _validate_default_domain_id(self, domain_id):
  184         """Validate that the domain ID belongs to the default domain."""
  185         if domain_id != CONF.identity.default_domain_id:
  186             raise exception.DomainNotFound(domain_id=domain_id)
  187 
  188     @abc.abstractmethod
  189     def create_project(self, project_id, project):
  190         """Create a new project.
  191 
  192         :param project_id: This parameter can be ignored.
  193         :param dict project: The new project
  194 
  195         Project schema::
  196 
  197             type: object
  198             properties:
  199                 id:
  200                     type: string
  201                 name:
  202                     type: string
  203                 domain_id:
  204                     type: [string, null]
  205                 description:
  206                     type: string
  207                 enabled:
  208                     type: boolean
  209                 parent_id:
  210                     type: string
  211                 is_domain:
  212                     type: boolean
  213             required: [id, name, domain_id]
  214             additionalProperties: true
  215 
  216         If the project doesn't match the schema the behavior is undefined.
  217 
  218         The driver can impose requirements such as the maximum length of a
  219         field. If these requirements are not met the behavior is undefined.
  220 
  221         :raises keystone.exception.Conflict: if the project id already exists
  222             or the name already exists for the domain_id.
  223 
  224         """
  225         raise exception.NotImplemented()  # pragma: no cover
  226 
  227     @abc.abstractmethod
  228     def get_project_by_name(self, project_name, domain_id):
  229         """Get a project by name.
  230 
  231         :returns: project_ref
  232         :raises keystone.exception.ProjectNotFound: if a project with the
  233                              project_name does not exist within the domain
  234 
  235         """
  236         raise exception.NotImplemented()  # pragma: no cover
  237 
  238     @abc.abstractmethod
  239     def delete_projects_from_ids(self, project_ids):
  240         """Delete a given list of projects.
  241 
  242         Deletes a list of projects. Ensures no project on the list exists
  243         after it is successfully called. If an empty list is provided,
  244         the it is silently ignored. In addition, if a project ID in the list
  245         of project_ids is not found in the backend, no exception is raised,
  246         but a message is logged.
  247         """
  248         raise exception.NotImplemented()  # pragma: no cover
  249 
  250     @abc.abstractmethod
  251     def list_projects_acting_as_domain(self, hints):
  252         """List all projects acting as domains.
  253 
  254         :param hints: filter hints which the driver should
  255                       implement if at all possible.
  256 
  257         :returns: a list of project_refs or an empty list.
  258 
  259         """
  260         raise exception.NotImplemented()  # pragma: no cover
  261 
  262     def check_project_depth(self, max_depth):
  263         """Check the projects depth in the backend whether exceed the limit.
  264 
  265         :param max_depth: the limit depth that project depth should not exceed.
  266         :type max_depth: integer
  267 
  268         :returns: the exceeded project's id or None if no exceeding.
  269 
  270         """
  271         raise exception.NotImplemented()  # pragma: no cover