Use abstract base class for policy driver
Use the abc module for managing abstract base classes in the driver layer. bp abstract-base-class-drivers Change-Id: I33da50d35c932399aaec8e005215a0f8e7e2acdc
This commit is contained in:
parent
9a0f7408b8
commit
9d5ca8e5b6
@ -16,6 +16,9 @@
|
||||
|
||||
"""Main entry point into the Policy service."""
|
||||
|
||||
import abc
|
||||
|
||||
import six
|
||||
|
||||
from keystone.common import dependency
|
||||
from keystone.common import manager
|
||||
@ -59,7 +62,10 @@ class Manager(manager.Manager):
|
||||
raise exception.PolicyNotFound(policy_id=policy_id)
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class Driver(object):
|
||||
|
||||
@abc.abstractmethod
|
||||
def enforce(self, context, credentials, action, target):
|
||||
"""Verify that a user is authorized to perform action.
|
||||
|
||||
@ -68,6 +74,7 @@ class Driver(object):
|
||||
"""
|
||||
raise exception.NotImplemented()
|
||||
|
||||
@abc.abstractmethod
|
||||
def create_policy(self, policy_id, policy):
|
||||
"""Store a policy blob.
|
||||
|
||||
@ -76,10 +83,12 @@ class Driver(object):
|
||||
"""
|
||||
raise exception.NotImplemented()
|
||||
|
||||
@abc.abstractmethod
|
||||
def list_policies(self):
|
||||
"""List all policies."""
|
||||
raise exception.NotImplemented()
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_policy(self, policy_id):
|
||||
"""Retrieve a specific policy blob.
|
||||
|
||||
@ -88,6 +97,7 @@ class Driver(object):
|
||||
"""
|
||||
raise exception.NotImplemented()
|
||||
|
||||
@abc.abstractmethod
|
||||
def update_policy(self, policy_id, policy):
|
||||
"""Update a policy blob.
|
||||
|
||||
@ -96,6 +106,7 @@ class Driver(object):
|
||||
"""
|
||||
raise exception.NotImplemented()
|
||||
|
||||
@abc.abstractmethod
|
||||
def delete_policy(self, policy_id):
|
||||
"""Remove a policy blob.
|
||||
|
||||
|
@ -20,7 +20,6 @@ import testtools
|
||||
from keystone.contrib import endpoint_filter
|
||||
from keystone.contrib import oauth1
|
||||
from keystone import exception
|
||||
from keystone import policy
|
||||
|
||||
|
||||
class TestDrivers(testtools.TestCase):
|
||||
@ -49,10 +48,6 @@ class TestDrivers(testtools.TestCase):
|
||||
if name[0] != '_' and callable(method):
|
||||
self.assertMethodNotImplemented(method)
|
||||
|
||||
def test_policy_driver_unimplemented(self):
|
||||
interface = policy.Driver()
|
||||
self.assertInterfaceNotImplemented(interface)
|
||||
|
||||
def test_oauth1_driver_unimplemented(self):
|
||||
interface = oauth1.Driver()
|
||||
self.assertInterfaceNotImplemented(interface)
|
||||
|
Loading…
Reference in New Issue
Block a user