~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
= GPG Keys =

Launchpad models GPG keys in a GPGKey class.

    >>> from zope.component import getUtility
    >>> from lp.registry.interfaces.gpg import (
    ...     GPGKeyAlgorithm,
    ...     IGPGKeySet,
    ...     )
    >>> from lp.registry.interfaces.person import IPersonSet
    >>> personset = getUtility(IPersonSet)
    >>> foobar = personset.getByName('name16')
    >>> gpgkeyset = getUtility(IGPGKeySet)
    >>> keys = gpgkeyset.getGPGKeys(ownerid=foobar.id)
    >>> [key.keyid for key in keys]
    [u'12345678']

Adding new keys is pretty easy:

    >>> name12 = personset.getByName('name12')
    >>> gpgkeyset.new(name12.id, u'DEADBEEF',
    ...     'DEADBEEF12345678DEADBEEF12345678DEADBEEF', 1024, 
    ...     GPGKeyAlgorithm.LITTLE_G)
    <GPGKey...>
    >>> gpgkeyset.new(name12.id, u'DEADBEED',
    ...     'DEADBEED12345678DEADBEED12345678DEADBEED', 2048, GPGKeyAlgorithm.G)
    <GPGKey...>

As is pulling it based on the key ID:

    >>> key = gpgkeyset.getByFingerprint(
    ...     'DEADBEEF12345678DEADBEEF12345678DEADBEEF')
    >>> key.owner.name
    u'name12'

There's also a convenience method for fetching multiple GPG keys at
once:

    >>> keys = gpgkeyset.getGPGKeysForPeople([foobar, name12])
    >>> [(key.owner.name, key.keyid) for key in keys]
    [(u'name12', u'DEADBEED'),
     (u'name12', u'DEADBEEF'),
     (u'name16', u'12345678')]