~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Copyright 2009 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

# pylint: disable-msg=E0211,E0213

"""ArchiveAuthToken interface."""

__metaclass__ = type

__all__ = [
    'IArchiveAuthToken',
    'IArchiveAuthTokenSet',
    ]

from lazr.restful.fields import Reference
from zope.interface import Interface
from zope.schema import (
    Datetime,
    Int,
    TextLine,
    )

from lp import _
from lp.registry.interfaces.person import IPerson
from lp.soyuz.interfaces.archive import IArchive


class IArchiveAuthTokenView(Interface):
    """Interface for Archive Authorisation Tokens requiring launchpad.View."""
    id = Int(title=_('ID'), required=True, readonly=True)

    archive = Reference(
        IArchive, title=_("Archive"), required=True, readonly=True,
        description=_("The archive for this authorisation token."))

    person = Reference(
        IPerson, title=_("Person"), required=True, readonly=True,
        description=_("The person for this authorisation token."))

    date_created = Datetime(
        title=_("Date Created"), required=True, readonly=True,
        description=_("The timestamp when the token was created."))

    date_deactivated = Datetime(
        title=_("Date De-activated"), required=False,
        description=_("The timestamp when the token was de-activated."))

    token = TextLine(
        title=_("Token"), required=True, readonly=True,
        description=_("The access token to the archive for this person."))

    archive_url = TextLine(
        title=_("Archive url"), readonly=True,
        description=_(
            "External archive URL including basic auth for this person"))

    def deactivate(self):
        """Deactivate the token by setting date_deactivated to UTC_NOW."""


class IArchiveAuthTokenEdit(Interface):
    """Interface for Archive Auth Tokens requiring launchpad.Edit."""


class IArchiveAuthToken(IArchiveAuthTokenView, IArchiveAuthTokenEdit):
    """An interface for Archive Auth Tokens."""


class IArchiveAuthTokenSet(Interface):
    """An interface for `ArchiveAuthTokenSet`."""

    def get(token_id):
        """Retrieve a token by its database ID.

        :param token_id: The database ID
        :return: An object conforming to IArchiveAuthToken
        """

    def getByToken(token):
        """Retrieve a token by its token text.

        :param token: The token text for the token.
        :return: An object conforming to IArchiveAuthToken
        """

    def getByArchive(archive):
        """Retrieve all the tokens for an archive.

        :param archive: The context archive.
        :return: A result set containing `IArchiveAuthToken`s.
        """

    def getActiveTokenForArchiveAndPerson(archive, person):
        """Retrieve an active token for the given archive and person.

        :param archive: The archive to which the token corresponds.
        :param person: The person to which the token corresponds.
        :return An object conforming to IArchiveAuthToken or None.
        """