~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/interfaces/accesspolicy.py

  • Committer: Julian Edwards
  • Date: 2011-07-28 20:46:18 UTC
  • mfrom: (13553 devel)
  • mto: This revision was merged to the branch mainline in revision 13555.
  • Revision ID: julian.edwards@canonical.com-20110728204618-tivj2wx2oa9s32bx
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2011 Canonical Ltd.  This software is licensed under the
2
 
# GNU Affero General Public License version 3 (see the file LICENSE).
3
 
 
4
 
"""Interfaces for pillar and artifact access policies."""
5
 
 
6
 
__metaclass__ = type
7
 
 
8
 
__all__ = [
9
 
    'AccessPolicyType',
10
 
    'IAccessPolicy',
11
 
    'IAccessPolicyArtifact',
12
 
    'IAccessPolicyArtifactSource',
13
 
    'IAccessPolicyGrant',
14
 
    'IAccessPolicySource',
15
 
    'UnsuitableAccessPolicyError',
16
 
    ]
17
 
 
18
 
import httplib
19
 
 
20
 
from lazr.enum import (
21
 
    DBEnumeratedType,
22
 
    DBItem,
23
 
    )
24
 
from lazr.restful.declarations import error_status
25
 
from zope.interface import (
26
 
    Attribute,
27
 
    Interface,
28
 
    )
29
 
 
30
 
 
31
 
@error_status(httplib.BAD_REQUEST)
32
 
class UnsuitableAccessPolicyError(Exception):
33
 
    pass
34
 
 
35
 
 
36
 
class AccessPolicyType(DBEnumeratedType):
37
 
    """Access policy type."""
38
 
 
39
 
    PRIVATE = DBItem(1, """
40
 
        Private
41
 
 
42
 
        This policy covers general private information.
43
 
        """)
44
 
 
45
 
    SECURITY = DBItem(2, """
46
 
        Security
47
 
 
48
 
        This policy covers information relating to confidential security
49
 
        vulnerabilities.
50
 
        """)
51
 
 
52
 
 
53
 
class IAccessPolicy(Interface):
54
 
    id = Attribute("ID")
55
 
    pillar = Attribute("Pillar")
56
 
    type = Attribute("Type")
57
 
 
58
 
 
59
 
class IAccessPolicyArtifact(Interface):
60
 
    id = Attribute("ID")
61
 
    concrete_artifact = Attribute("Concrete artifact")
62
 
    policy = Attribute("Access policy")
63
 
 
64
 
 
65
 
class IAccessPolicyGrant(Interface):
66
 
    id = Attribute("ID")
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")
72
 
 
73
 
    concrete_artifact = Attribute("Concrete artifact")
74
 
 
75
 
 
76
 
class IAccessPolicySource(Interface):
77
 
 
78
 
    def create(pillar, display_name):
79
 
        """Create an `IAccessPolicy` for the pillar with the given name."""
80
 
 
81
 
    def getByID(id):
82
 
        """Return the `IAccessPolicy` with the given ID."""
83
 
 
84
 
    def getByPillarAndType(pillar, type):
85
 
        """Return the pillar's `IAccessPolicy` with the given type."""
86
 
 
87
 
    def findByPillar(pillar):
88
 
        """Return a ResultSet of all `IAccessPolicy`s for the pillar."""
89
 
 
90
 
 
91
 
class IAccessPolicyArtifactSource(Interface):
92
 
 
93
 
    def ensure(concrete_artifact):
94
 
        """Return the `IAccessPolicyArtifact` for a concrete artifact.
95
 
 
96
 
        Creates the abstract artifact if it doesn't already exist.
97
 
        """
98
 
 
99
 
    def get(concrete_artifact):
100
 
        """Return the `IAccessPolicyArtifact` for an artifact, if it exists.
101
 
 
102
 
        Use ensure() if you want to create one if it doesn't yet exist.
103
 
        """
104
 
 
105
 
    def delete(concrete_artifact):
106
 
        """Delete the `IAccessPolicyArtifact` for a concrete artifact.
107
 
 
108
 
        Also removes any AccessPolicyGrants for the artifact.
109
 
        """
110
 
 
111
 
 
112
 
class IAccessPolicyGrantSource(Interface):
113
 
 
114
 
    def grant(grantee, grantor, object):
115
 
        """Create an `IAccessPolicyGrant`.
116
 
 
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
120
 
            grant access to.
121
 
        """
122
 
 
123
 
    def getByID(id):
124
 
        """Return the `IAccessPolicyGrant` with the given ID."""
125
 
 
126
 
    def findByPolicy(policy):
127
 
        """Return all `IAccessPolicyGrant` objects for the policy."""