8687.15.22
by Karl Fogel
Add the copyright header block to the remaining .py files. |
1 |
# Copyright 2009 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
7516.2.1
by Julian Edwards
Add content and interface classes for ArchiveAuthToken |
4 |
# pylint: disable-msg=E0211,E0213
|
5 |
||
6 |
"""ArchiveAuthToken interface."""
|
|
7 |
||
8 |
__metaclass__ = type |
|
9 |
||
10 |
__all__ = [ |
|
11 |
'IArchiveAuthToken', |
|
7516.2.3
by Julian Edwards
Add tests and security wrappers |
12 |
'IArchiveAuthTokenSet', |
7516.2.1
by Julian Edwards
Add content and interface classes for ArchiveAuthToken |
13 |
]
|
14 |
||
11403.1.4
by Henning Eggers
Reformatted imports using format-imports script r32. |
15 |
from lazr.restful.fields import Reference |
7862.2.9
by Michael Nelson
Removed some lint. |
16 |
from zope.interface import Interface |
11403.1.4
by Henning Eggers
Reformatted imports using format-imports script r32. |
17 |
from zope.schema import ( |
18 |
Datetime, |
|
19 |
Int, |
|
20 |
TextLine, |
|
21 |
)
|
|
7516.2.1
by Julian Edwards
Add content and interface classes for ArchiveAuthToken |
22 |
|
23 |
from canonical.launchpad import _ |
|
11403.1.4
by Henning Eggers
Reformatted imports using format-imports script r32. |
24 |
from lp.registry.interfaces.person import IPerson |
8294.6.1
by Julian Edwards
First stab at code-reorg. Still got a discrepancy on stuff I assigned to registry but not migrated yet. |
25 |
from lp.soyuz.interfaces.archive import IArchive |
7516.2.1
by Julian Edwards
Add content and interface classes for ArchiveAuthToken |
26 |
|
27 |
||
7516.2.3
by Julian Edwards
Add tests and security wrappers |
28 |
class IArchiveAuthTokenView(Interface): |
29 |
"""Interface for Archive Authorisation Tokens requiring launchpad.View."""
|
|
7516.2.1
by Julian Edwards
Add content and interface classes for ArchiveAuthToken |
30 |
id = Int(title=_('ID'), required=True, readonly=True) |
31 |
||
32 |
archive = Reference( |
|
7516.2.5
by Julian Edwards
More review comments from salgado |
33 |
IArchive, title=_("Archive"), required=True, readonly=True, |
7516.2.1
by Julian Edwards
Add content and interface classes for ArchiveAuthToken |
34 |
description=_("The archive for this authorisation token.")) |
35 |
||
36 |
person = Reference( |
|
7516.2.5
by Julian Edwards
More review comments from salgado |
37 |
IPerson, title=_("Person"), required=True, readonly=True, |
7516.2.1
by Julian Edwards
Add content and interface classes for ArchiveAuthToken |
38 |
description=_("The person for this authorisation token.")) |
39 |
||
40 |
date_created = Datetime( |
|
7516.2.5
by Julian Edwards
More review comments from salgado |
41 |
title=_("Date Created"), required=True, readonly=True, |
7516.2.1
by Julian Edwards
Add content and interface classes for ArchiveAuthToken |
42 |
description=_("The timestamp when the token was created.")) |
43 |
||
44 |
date_deactivated = Datetime( |
|
45 |
title=_("Date De-activated"), required=False, |
|
46 |
description=_("The timestamp when the token was de-activated.")) |
|
47 |
||
48 |
token = TextLine( |
|
7516.2.5
by Julian Edwards
More review comments from salgado |
49 |
title=_("Token"), required=True, readonly=True, |
7516.2.1
by Julian Edwards
Add content and interface classes for ArchiveAuthToken |
50 |
description=_("The access token to the archive for this person.")) |
7516.2.3
by Julian Edwards
Add tests and security wrappers |
51 |
|
7862.2.5
by Michael Nelson
Added IArchiveAuthToken.archive_url which returns the url with basic auth. |
52 |
archive_url = TextLine( |
53 |
title=_("Archive url"), readonly=True, |
|
54 |
description=_( |
|
55 |
"External archive URL including basic auth for this person")) |
|
7516.2.3
by Julian Edwards
Add tests and security wrappers |
56 |
|
8137.3.1
by Michael Nelson
Manually merged previously approved exposure code. |
57 |
def deactivate(self): |
58 |
"""Deactivate the token by setting date_deactivated to UTC_NOW."""
|
|
59 |
||
60 |
||
7675.107.1
by Michael Nelson
Applying bzr diff -r 7934..7933 to revert exposure of p3a subscriptions UI. |
61 |
class IArchiveAuthTokenEdit(Interface): |
62 |
"""Interface for Archive Auth Tokens requiring launchpad.Edit."""
|
|
7516.2.3
by Julian Edwards
Add tests and security wrappers |
63 |
|
64 |
||
65 |
class IArchiveAuthToken(IArchiveAuthTokenView, IArchiveAuthTokenEdit): |
|
66 |
"""An interface for Archive Auth Tokens."""
|
|
67 |
||
68 |
||
69 |
class IArchiveAuthTokenSet(Interface): |
|
70 |
"""An interface for `ArchiveAuthTokenSet`."""
|
|
71 |
||
72 |
def get(token_id): |
|
73 |
"""Retrieve a token by its database ID.
|
|
74 |
||
75 |
:param token_id: The database ID
|
|
76 |
:return: An object conforming to IArchiveAuthToken
|
|
77 |
"""
|
|
78 |
||
79 |
def getByToken(token): |
|
80 |
"""Retrieve a token by its token text.
|
|
81 |
||
82 |
:param token: The token text for the token.
|
|
7924.7.2
by Julian Edwards
Add IArchiveAuthTokenSet.getByArchive |
83 |
:return: An object conforming to IArchiveAuthToken
|
84 |
"""
|
|
85 |
||
86 |
def getByArchive(archive): |
|
87 |
"""Retrieve all the tokens for an archive.
|
|
88 |
||
89 |
:param archive: The context archive.
|
|
90 |
:return: A result set containing `IArchiveAuthToken`s.
|
|
7516.2.3
by Julian Edwards
Add tests and security wrappers |
91 |
"""
|
7862.1.3
by Michael Nelson
Updated IArchiveAuthTokenSet with getByArchiveAndPerson() method. |
92 |
|
7862.1.6
by Michael Nelson
Changes after al-maisan's review. Mainly clarifying the names of methods. |
93 |
def getActiveTokenForArchiveAndPerson(archive, person): |
7862.1.3
by Michael Nelson
Updated IArchiveAuthTokenSet with getByArchiveAndPerson() method. |
94 |
"""Retrieve an active token for the given archive and person.
|
95 |
||
96 |
:param archive: The archive to which the token corresponds.
|
|
97 |
:param person: The person to which the token corresponds.
|
|
98 |
:return An object conforming to IArchiveAuthToken or None.
|
|
99 |
"""
|