示例#1
0
// ImageMetadataSources returns the sources to use when looking for
// simplestreams image id metadata for the given stream.
func ImageMetadataSources(env Environ) ([]simplestreams.DataSource, error) {
	config := env.Config()

	// Add configured and environment-specific datasources.
	var sources []simplestreams.DataSource
	if userURL, ok := config.ImageMetadataURL(); ok {
		verify := utils.VerifySSLHostnames
		if !config.SSLHostnameVerification() {
			verify = utils.NoVerifySSLHostnames
		}
		sources = append(sources, simplestreams.NewURLDataSource("image-metadata-url", userURL, verify, simplestreams.SPECIFIC_CLOUD_DATA, false))
	}

	envDataSources, err := environmentDataSources(env)
	if err != nil {
		return nil, err
	}
	sources = append(sources, envDataSources...)

	// Add the official image metadata datasources.
	officialDataSources, err := imagemetadata.OfficialDataSources(config.ImageStream())
	if err != nil {
		return nil, err
	}
	for _, source := range officialDataSources {
		sources = append(sources, source)
	}
	for _, ds := range sources {
		logger.Debugf("using image datasource %q", ds.Description())
	}
	return sources, nil
}
示例#2
0
func (s *simplestreamsSuite) TestOfficialSources(c *gc.C) {
	origKey := imagemetadata.SetSigningPublicKey(sstesting.SignedMetadataPublicKey)
	defer func() {
		imagemetadata.SetSigningPublicKey(origKey)
	}()
	ds, err := imagemetadata.OfficialDataSources("daily")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(ds, gc.HasLen, 2)
	url, err := ds[0].URL("")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(url, gc.Equals, "https://streams.canonical.com/juju/images/daily/")
	c.Assert(ds[0].PublicSigningKey(), gc.Equals, sstesting.SignedMetadataPublicKey)

	url, err = ds[1].URL("")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(url, gc.Equals, "http://cloud-images.ubuntu.com/daily/")
	c.Assert(ds[1].PublicSigningKey(), gc.Equals, sstesting.SignedMetadataPublicKey)
}