Exemple #1
0
def download_image_descriptions(
        path, keyring=None, user_agent=None, validate_products=True):
    """Download image metadata from upstream Simplestreams repo.

    :param path: The path to a Simplestreams repo.
    :param keyring: Optional keyring for verifying the repo's signatures.
    :param user_agent: Optional user agent string for downloading the image
        descriptions.
    :return: A `BootImageMapping` describing available boot resources.
    """
    maaslog.info("Downloading image descriptions from %s", path)
    mirror, rpath = path_from_mirror_url(path, None)
    policy = get_signing_policy(rpath, keyring)
    if user_agent is None:
        reader = UrlMirrorReader(mirror, policy=policy)
    else:
        try:
            reader = UrlMirrorReader(
                mirror, policy=policy, user_agent=user_agent)
        except TypeError:
            # UrlMirrorReader doesn't support the user_agent argument.
            # simplestream >=bzr429 is required for this feature.
            reader = UrlMirrorReader(mirror, policy=policy)

    boot_images_dict = BootImageMapping()
    dumper = RepoDumper(boot_images_dict, validate_products=validate_products)
    dumper.sync(reader, rpath)
    return boot_images_dict
Exemple #2
0
 def test_picks_nonchecking_policy_for_json_index(self):
     path = "streams/v1/index.json"
     policy = helpers.get_signing_policy(path)
     content = factory.make_string()
     self.assertEqual(
         content, policy(content, path, factory.make_name("keyring"))
     )
Exemple #3
0
 def test_injects_default_keyring_if_passed(self):
     path = 'streams/v1/index.json.gpg'
     content = factory.make_string()
     keyring = factory.make_name('keyring')
     self.patch(helpers, 'policy_read_signed')
     policy = helpers.get_signing_policy(path, keyring)
     policy(content, path)
     self.assertThat(
         helpers.policy_read_signed,
         MockCalledOnceWith(mock.ANY, mock.ANY, keyring=keyring))
Exemple #4
0
 def test_picks_checking_policy_for_json_gpg_index(self):
     path = "streams/v1/index.json.gpg"
     content = factory.make_string()
     policy = helpers.get_signing_policy(path)
     self.assertRaises(
         SignatureMissingException,
         policy,
         content,
         path,
         factory.make_name("keyring"),
     )
Exemple #5
0
def download_boot_resources(path, store, snapshot_path, product_mapping,
                            keyring_file=None):
    """Download boot resources for one simplestreams source.

    :param path: The Simplestreams URL for this source.
    :param store: A simplestreams `ObjectStore` where downloaded resources
        should be stored.
    :param snapshot_path: Filesystem path to a snapshot of current upstream
        boot resources.
    :param product_mapping: A `ProductMapping` describing the resources to be
        downloaded.
    :param keyring_file: Optional path to a keyring file for verifying
        signatures.
    """
    maaslog.info("Downloading boot resources from %s", path)
    writer = RepoWriter(snapshot_path, store, product_mapping)
    (mirror, rpath) = path_from_mirror_url(path, None)
    policy = get_signing_policy(rpath, keyring_file)
    reader = UrlMirrorReader(mirror, policy=policy)
    writer.sync(reader, rpath)