~rvb/maas/transaction-1.7-bug-1409852

« back to all changes in this revision

Viewing changes to src/provisioningserver/import_images/keyrings.py

merged upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
str = None
12
12
 
13
13
__metaclass__ = type
14
 
__all__ = []
 
14
__all__ = [
 
15
    'write_all_keyrings',
 
16
    ]
15
17
 
16
18
import os
17
 
import tempfile
18
19
from urlparse import urlsplit
19
20
 
20
21
from provisioningserver.import_images.helpers import maaslog
40
41
    return keyring_name
41
42
 
42
43
 
43
 
def write_all_keyrings(sources):
 
44
def write_all_keyrings(directory, sources):
44
45
    """For a given set of `sources`, write the keyrings to disk.
45
46
 
 
47
    :param directory: A directory where the key files should be written.  Use
 
48
        a dedicated temporary directory for this, and clean it up when done.
46
49
    :param sources: An iterable of the sources whose keyrings need to be
47
50
        written.
48
51
    :return: The sources iterable, with each source whose keyring has
49
52
        been written now having a "keyring" value set, pointing to the file
50
53
        on disk.
51
54
    """
52
 
    keyring_dir = tempfile.mkdtemp("maas-keyrings")
53
55
    for source in sources:
54
56
        source_url = source.get('url')
55
57
        keyring_file = source.get('keyring')
62
64
 
63
65
        if keyring_data is not None:
64
66
            keyring_file = os.path.join(
65
 
                keyring_dir, calculate_keyring_name(source_url))
 
67
                directory, calculate_keyring_name(source_url))
66
68
            write_keyring(keyring_file, keyring_data)
67
69
            source['keyring'] = keyring_file
68
70
    return sources