Merge "Move the trust abstract base class out of core"

This commit is contained in:
Jenkins 2016-07-09 03:03:22 +00:00 committed by Gerrit Code Review
commit 28d86afb88
3 changed files with 84 additions and 57 deletions

View File

@ -0,0 +1,72 @@
# Copyright 2012 OpenStack Foundation
#
# 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.
import abc
import six
from keystone import exception
@six.add_metaclass(abc.ABCMeta)
class TrustDriverV8(object):
@abc.abstractmethod
def create_trust(self, trust_id, trust, roles):
"""Create a new trust.
:returns: a new trust
"""
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def get_trust(self, trust_id, deleted=False):
"""Get a trust by the trust id.
:param trust_id: the trust identifier
:type trust_id: string
:param deleted: return the trust even if it is deleted, expired, or
has no consumptions left
:type deleted: bool
"""
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def list_trusts(self):
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def list_trusts_for_trustee(self, trustee):
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def list_trusts_for_trustor(self, trustor):
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def delete_trust(self, trust_id):
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def consume_use(self, trust_id):
"""Consume one use of a trust.
One use of a trust is consumed when the trust was created with a
limitation on its uses, provided there are still uses available.
:raises keystone.exception.TrustUseLimitReached: If no remaining uses
for trust.
:raises keystone.exception.TrustNotFound: If the trust doesn't exist.
"""
raise exception.NotImplemented() # pragma: no cover

View File

@ -19,7 +19,7 @@ from six.moves import range
from keystone.common import sql
from keystone import exception
from keystone import trust
from keystone.trust.backends import base
# The maximum number of iterations that will be attempted for optimistic
@ -56,7 +56,7 @@ class TrustRole(sql.ModelBase):
role_id = sql.Column(sql.String(64), primary_key=True, nullable=False)
class Trust(trust.TrustDriverV8):
class Trust(base.TrustDriverV8):
@sql.handle_conflicts(conflict_type='trust')
def create_trust(self, trust_id, trust, roles):
with sql.session_for_write() as session:

View File

@ -14,9 +14,7 @@
"""Main entry point into the Trust service."""
import abc
import six
from oslo_log import versionutils
from six.moves import zip
from keystone.common import dependency
@ -25,6 +23,7 @@ import keystone.conf
from keystone import exception
from keystone.i18n import _
from keystone import notifications
from keystone.trust.backends import base
CONF = keystone.conf.CONF
@ -203,57 +202,13 @@ class Manager(manager.Manager):
notifications.Audit.deleted(self._TRUST, trust_id, initiator)
@six.add_metaclass(abc.ABCMeta)
class TrustDriverV8(object):
@abc.abstractmethod
def create_trust(self, trust_id, trust, roles):
"""Create a new trust.
:returns: a new trust
"""
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def get_trust(self, trust_id, deleted=False):
"""Get a trust by the trust id.
:param trust_id: the trust identifier
:type trust_id: string
:param deleted: return the trust even if it is deleted, expired, or
has no consumptions left
:type deleted: bool
"""
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def list_trusts(self):
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def list_trusts_for_trustee(self, trustee):
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def list_trusts_for_trustor(self, trustor):
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def delete_trust(self, trust_id):
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def consume_use(self, trust_id):
"""Consume one use of a trust.
One use of a trust is consumed when the trust was created with a
limitation on its uses, provided there are still uses available.
:raises keystone.exception.TrustUseLimitReached: If no remaining uses
for trust.
:raises keystone.exception.TrustNotFound: If the trust doesn't exist.
"""
raise exception.NotImplemented() # pragma: no cover
@versionutils.deprecated(
versionutils.deprecated.NEWTON,
what='keystone.trust.TrustDriverV8',
in_favor_of='keystone.trust.backends.base.TrustDriverV8',
remove_in=+1)
class TrustDriverV8(base.TrustDriverV8):
pass
Driver = manager.create_legacy_driver(TrustDriverV8)
Driver = manager.create_legacy_driver(base.TrustDriverV8)