1
# Copyright 2011 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Interfaces for pillar and artifact access policies."""
11
'IAccessPolicyArtifact',
12
'IAccessPolicyArtifactSource',
14
'IAccessPolicySource',
15
'UnsuitableAccessPolicyError',
20
from lazr.enum import (
24
from lazr.restful.declarations import error_status
25
from zope.interface import (
31
@error_status(httplib.BAD_REQUEST)
32
class UnsuitableAccessPolicyError(Exception):
36
class AccessPolicyType(DBEnumeratedType):
37
"""Access policy type."""
39
PRIVATE = DBItem(1, """
42
This policy covers general private information.
45
SECURITY = DBItem(2, """
48
This policy covers information relating to confidential security
53
class IAccessPolicy(Interface):
55
pillar = Attribute("Pillar")
56
type = Attribute("Type")
59
class IAccessPolicyArtifact(Interface):
61
concrete_artifact = Attribute("Concrete artifact")
62
policy = Attribute("Access policy")
65
class IAccessPolicyGrant(Interface):
67
grantee = Attribute("Grantee")
68
grantor = Attribute("Grantor")
69
date_created = Attribute("Date created")
70
policy = Attribute("Access policy")
71
abstract_artifact = Attribute("Abstract artifact")
73
concrete_artifact = Attribute("Concrete artifact")
76
class IAccessPolicySource(Interface):
78
def create(pillar, display_name):
79
"""Create an `IAccessPolicy` for the pillar with the given name."""
82
"""Return the `IAccessPolicy` with the given ID."""
84
def getByPillarAndType(pillar, type):
85
"""Return the pillar's `IAccessPolicy` with the given type."""
87
def findByPillar(pillar):
88
"""Return a ResultSet of all `IAccessPolicy`s for the pillar."""
91
class IAccessPolicyArtifactSource(Interface):
93
def ensure(concrete_artifact):
94
"""Return the `IAccessPolicyArtifact` for a concrete artifact.
96
Creates the abstract artifact if it doesn't already exist.
99
def get(concrete_artifact):
100
"""Return the `IAccessPolicyArtifact` for an artifact, if it exists.
102
Use ensure() if you want to create one if it doesn't yet exist.
105
def delete(concrete_artifact):
106
"""Delete the `IAccessPolicyArtifact` for a concrete artifact.
108
Also removes any AccessPolicyGrants for the artifact.
112
class IAccessPolicyGrantSource(Interface):
114
def grant(grantee, grantor, object):
115
"""Create an `IAccessPolicyGrant`.
117
:param grantee: the `IPerson` to hold the access.
118
:param grantor: the `IPerson` that grants the access.
119
:param object: the `IAccessPolicy` or `IAccessPolicyArtifact` to
124
"""Return the `IAccessPolicyGrant` with the given ID."""
126
def findByPolicy(policy):
127
"""Return all `IAccessPolicyGrant` objects for the policy."""