v0.0.0-...-8dc6826 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2023 License: AGPL-3.0 Imports: 24 Imported by: 192



Package simplestreams supports locating, parsing, and filtering metadata in simplestreams format.

See and in particular the doc/README file in that project for more information about the file formats.

Users of this package provide an empty struct and a matching function to be able to query and return a list of typed values for a given criteria.



View Source
const (

	// EXISTING_CLOUD_DATA is the lowest in priority.
	// It is mostly used in merge functions
	// where existing data does not need to be ranked.

	// DEFAULT_CLOUD_DATA is used for common cloud data that
	// is shared an is publicly available.

	// SPECIFIC_CLOUD_DATA is used to rank cloud specific data
	// above commonly available.
	// For e.g., openstack's "keystone catalogue".

	// CUSTOM_CLOUD_DATA is the highest available ranking and
	// is given to custom data.
View Source
const (
	MirrorFile = "streams/v1/cpc-mirrors.json"

	SignedSuffix   = ".sjson"
	UnsignedSuffix = ".json"

	IndexFormat   = "index:1.0"
	ProductFormat = "products:1.0"
	MirrorFormat  = "mirrors:1.0"
View Source
const SimplestreamsPublicKeyFile = "publicsimplestreamskey"


View Source
var EmptyCloudSpec = CloudSpec{}

EmptyCloudSpec is used when we want all records regardless of cloud to be loaded.

View Source
var PGPSignatureCheckFn = func(keyring openpgp.KeyRing, signed, signature io.Reader) (*openpgp.Entity, error) {
	return openpgp.CheckDetachedSignature(keyring, signed, signature)

PGPPGPSignatureCheckFn can be overridden by tests to allow signatures from non-trusted sources to be verified.


func DecodeCheckSignature

func DecodeCheckSignature(r io.Reader, armoredPublicKey string) ([]byte, error)

DecodeCheckSignature parses the inline signed PGP text, checks the signature, and returns plain text if the signature matches.

func Encode

func Encode(r io.Reader, armoredPrivateKey, passphrase string) ([]byte, error)

Encode signs the data returned by the reader and returns an inline signed copy.

func GetLatestMetadata

func GetLatestMetadata(metadata *CloudMetadata, cons LookupConstraint, source DataSource, filterFunc AppendMatchingFunc) ([]interface{}, error)

GetLatestMetadata extracts and returns the metadata records matching the given criteria.

func MirrorsPath

func MirrorsPath(streamsVersion string) string

MirrorsPath returns the mirrors path for streamsVersion.

func RegisterStructTags

func RegisterStructTags(vals ...interface{})

RegisterStructTags ensures the json tags for the given structs are able to be used when parsing the simplestreams metadata.

func UnsignedIndex

func UnsignedIndex(streamsVersion string, indexFileVersion int) string

UnsignedIndex returns an unsigned index file name for streamsVersion.

func UnsignedMirror

func UnsignedMirror(streamsVersion string) string

UnsignedMirror returns an unsigned mirror file name for streamsVersion.

func UserPublicSigningKey

func UserPublicSigningKey() (string, error)

UserPublicSigningKey returns the public signing key (if defined).


type AgentMetadataValidator

type AgentMetadataValidator interface {
	AgentMetadataLookupParams(region string) (*MetadataLookupParams, error)

AgentMetadataValidator instances can provide parameters used to query simplestreams metadata to find agent information for the specified parameters. If region is "", then the implementation may use its own default region if it has one, or else returns an error.

type AppendMatchingFunc

type AppendMatchingFunc func(DataSource, []interface{}, map[string]interface{}, LookupConstraint) ([]interface{}, error)

AppendMatchingFunc is the filter function signature used in our simple streams parsing code. It collects matching items from a DataSource in the returned interface slice.

type CloudMetadata

type CloudMetadata struct {
	Products   map[string]MetadataCatalog    `json:"products"`
	Aliases    map[string]aliasesByAttribute `json:"_aliases,omitempty"`
	Updated    string                        `json:"updated"`
	Format     string                        `json:"format"`
	ContentId  string                        `json:"content_id"`
	RegionName string                        `json:"region,omitempty"`
	Endpoint   string                        `json:"endpoint,omitempty"`
	Storage    string                        `json:"root_store,omitempty"`
	VirtType   string                        `json:"virt,omitempty"`

func ParseCloudMetadata

func ParseCloudMetadata(data []byte, format, url string, valueTemplate interface{}) (*CloudMetadata, error)

ParseCloudMetadata parses the given bytes into simplestreams metadata.

type CloudSpec

type CloudSpec struct {
	Region   string `json:"region"`
	Endpoint string `json:"endpoint"`

CloudSpec uniquely defines a specific cloud deployment.

type Config

type Config struct {
	// Description of the datasource
	Description string

	// BaseURL is the URL for this datasource.
	BaseURL string

	// HostnameVerification indicates whether to use self-signed credentials
	// and not try to verify the hostname on the TLS/SSL certificates.
	HostnameVerification bool

	// PublicSigningKey is the public key used to validate signed metadata.
	PublicSigningKey string

	// Priority is an importance factor for the datasource. Higher number means
	// higher priority. This is will facilitate sorting data sources in order of
	// importance.
	Priority int

	// RequireSigned indicates whether this datasource requires signed data.
	RequireSigned bool

	// CACertificates contains an optional list of Certificate
	// Authority certificates to be used to validate certificates
	// of cloud infrastructure components
	// The contents are Base64 encoded x.509 certs.
	CACertificates []string

	// Clock is used for retry. Will use clock.WallClock if nil.
	Clock clock.Clock

Config has values to be used in constructing a datasource.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks that the baseURL is valid and the description is set.

type DataSource

type DataSource interface {
	// Description describes the origin of this datasource.
	// eg agent-metadata-url, cloud storage, keystone catalog etc.
	Description() string

	// Fetch loads the data at the specified relative path. It returns a reader from which
	// the data can be retrieved as well as the full URL of the file. The full URL is typically
	// used in log messages to help diagnose issues accessing the data.
	Fetch(path string) (io.ReadCloser, string, error)

	// URL returns the full URL of the path, as applicable to this datasource.
	// This method is used primarily for logging purposes.
	URL(path string) (string, error)

	// PublicSigningKey returns the public key used to validate signed metadata.
	PublicSigningKey() string

	// Priority is an importance factor for Data Source. Higher number means higher priority.
	// This is will allow to sort data sources in order of importance.
	Priority() int

	// RequireSigned indicates whether this data source requires signed data.
	RequireSigned() bool

A DataSource retrieves simplestreams metadata.

func NewDataSource

func NewDataSource(cfg Config) DataSource

NewDataSource returns a new DataSource as defined by the given config.

func NewDataSourceWithClient

func NewDataSourceWithClient(cfg Config, client *jujuhttp.Client) DataSource

NewDataSourceWithClient returns a new DataSource as defines by the given Config, but with the addition of a http.Client.

type DataSourceFactory

type DataSourceFactory interface {
	// NewDataSource creates a new DataSource from a given config.
	NewDataSource(Config) DataSource

DataSourceFactory creates new DataSources for requesting index references.

func DefaultDataSourceFactory

func DefaultDataSourceFactory() DataSourceFactory

DefaultDataSourceFactory creates a generic new data source factory that creates new data sources based on the config.

type GetMetadataParams

type GetMetadataParams struct {
	StreamsVersion   string
	LookupConstraint LookupConstraint
	ValueParams      ValueParams

GetMetadataParams defines parameters used to load simplestreams metadata.

type HasRegion

type HasRegion interface {
	// Region returns the necessary attributes to uniquely identify this cloud instance.
	// Currently these attributes are "region" and "endpoint" values.
	Region() (CloudSpec, error)

HasRegion is implemented by instances which can provide a region to which they belong. A region is defined by region name and endpoint.

type ImageMetadataValidator

type ImageMetadataValidator interface {
	ImageMetadataLookupParams(region string) (*MetadataLookupParams, error)

ImageMetadataValidator instances can provide parameters used to query simplestreams metadata to find agent information for the specified parameters. If region is "", then the implementation may use its own default region if it has one, or else returns an error.

type IndexMetadata

type IndexMetadata struct {
	Updated          string      `json:"updated"`
	Format           string      `json:"format"`
	DataType         string      `json:"datatype"`
	CloudName        string      `json:"cloudname,omitempty"`
	Clouds           []CloudSpec `json:"clouds,omitempty"`
	ProductsFilePath string      `json:"path"`
	ProductIds       []string    `json:"products"`

func (*IndexMetadata) String

func (metadata *IndexMetadata) String() string

type IndexMetadataSlice

type IndexMetadataSlice []*IndexMetadata

type IndexReference

type IndexReference struct {
	MirroredProductsPath string
	Source               DataSource
	// contains filtered or unexported fields

IndexReference is exported for testing.

func (*IndexReference) GetCloudMetadataWithFormat

func (indexRef *IndexReference) GetCloudMetadataWithFormat(cons LookupConstraint, format string, requireSigned bool) (*CloudMetadata, error)

GetCloudMetadataWithFormat loads the entire cloud metadata encoded using the specified format. Exported for testing.

func (*IndexReference) GetProductsPath

func (indexRef *IndexReference) GetProductsPath(cons LookupConstraint) (string, error)

GetProductsPath returns the path to the metadata file containing products for the specified constraint. Exported for testing.

type Indices

type Indices struct {
	Indexes map[string]*IndexMetadata `json:"index"`
	Updated string                    `json:"updated"`
	Format  string                    `json:"format"`

type ItemCollection

type ItemCollection struct {
	Items      map[string]interface{} `json:"items"`
	Arch       string                 `json:"arch,omitempty"`
	Release    string                 `json:"release,omitempty"`
	Version    string                 `json:"version,omitempty"`
	RegionName string                 `json:"region,omitempty"`
	Endpoint   string                 `json:"endpoint,omitempty"`
	Storage    string                 `json:"root_store,omitempty"`
	VirtType   string                 `json:"virt,omitempty"`
	// contains filtered or unexported fields

func (*ItemCollection) UnmarshalJSON

func (c *ItemCollection) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the ItemCollection, storing the raw bytes for each item. These can later be unmarshalled again into product-specific types.

type LookupConstraint

type LookupConstraint interface {
	// IndexIds generates a string array representing index ids formed similarly to an ISCSI qualified name (IQN).
	IndexIds() []string
	// ProductIds generates a string array representing product ids formed similarly to an ISCSI qualified name (IQN).
	ProductIds() ([]string, error)
	// Params returns the constraint parameters.
	Params() LookupParams

type LookupParams

type LookupParams struct {
	Releases []string
	Arches   []string
	// Stream can be "" or "released" for the default "released" stream,
	// or "daily" for daily images, or any other stream that the available
	// simplestreams metadata supports.
	Stream string

LookupParams defines criteria used to find a metadata record. Derived structs implement the IndexIds() and ProductIds() method.

func (LookupParams) Params

func (p LookupParams) Params() LookupParams

type MetadataCatalog

type MetadataCatalog struct {
	Release    string `json:"release,omitempty"`
	Version    string `json:"version,omitempty"`
	Arch       string `json:"arch,omitempty"`
	RegionName string `json:"region,omitempty"`
	Endpoint   string `json:"endpoint,omitempty"`
	Storage    string `json:"root_store,omitempty"`
	VirtType   string `json:"virt,omitempty"`

	// Items is a mapping from version to an ItemCollection,
	// where the version is the date the items were produced,
	// in the format YYYYMMDD.
	Items map[string]*ItemCollection `json:"versions"`

type MetadataLookupParams

type MetadataLookupParams struct {
	Region        string
	Release       string
	Architectures []string
	Endpoint      string
	Sources       []DataSource
	Stream        string

type MirrorInfo

type MirrorInfo struct {
	Clouds    []CloudSpec `json:"clouds"`
	MirrorURL string      `json:"mirror"`
	Path      string      `json:"path"`

type MirrorInfoSlice

type MirrorInfoSlice []MirrorInfo

type MirrorMetadata

type MirrorMetadata struct {
	Updated string                  `json:"updated"`
	Format  string                  `json:"format"`
	Mirrors map[string][]MirrorInfo `json:"mirrors"`

func GetMirrorMetadataWithFormat

func GetMirrorMetadataWithFormat(source DataSource, mirrorPath, format string,
	requireSigned bool) (*MirrorMetadata, error)

GetMirrorMetadataWithFormat returns simplestreams mirror data of the specified format. Exported for testing.

type MirrorRefSlice

type MirrorRefSlice []MirrorReference

type MirrorReference

type MirrorReference struct {
	Updated  string      `json:"updated"`
	Format   string      `json:"format"`
	DataType string      `json:"datatype"`
	Path     string      `json:"path"`
	Clouds   []CloudSpec `json:"clouds,omitempty"`

type MirrorRefs

type MirrorRefs struct {
	Mirrors map[string][]MirrorReference `json:"mirrors"`

type NotPGPSignedError

type NotPGPSignedError struct{}

NotPGPSignedError is used when PGP text does not contain an inline signature.

func (*NotPGPSignedError) Error

func (*NotPGPSignedError) Error() string

type ResolveInfo

type ResolveInfo struct {
	Source    string `yaml:"source" json:"source"`
	Signed    bool   `yaml:"signed" json:"signed"`
	IndexURL  string `yaml:"indexURL" json:"indexURL"`
	MirrorURL string `yaml:"mirrorURL,omitempty" json:"mirrorURL,omitempty"`

type Simplestreams

type Simplestreams struct {
	// contains filtered or unexported fields

Simplestreams defines a type for encapsulating the functionality for requesting simplestreams data.

TODO (stickupkid): This requires more work. The idea is to localize all package level functions up on to this type. Passing the type through layers becomes simple.

func NewSimpleStreams

func NewSimpleStreams(factory DataSourceFactory) *Simplestreams

NewSimpleStreams creates a new simplestreams accessor.

func (Simplestreams) GetIndexWithFormat

func (s Simplestreams) GetIndexWithFormat(source DataSource,
	indexPath, indexFormat, mirrorsPath string, requireSigned bool,
	cloudSpec CloudSpec, params ValueParams) (*IndexReference, error)

GetIndexWithFormat returns a simplestreams index of the specified format. Exported for testing.

func (Simplestreams) GetMetadata

func (s Simplestreams) GetMetadata(sources []DataSource, params GetMetadataParams) (items []interface{}, resolveInfo *ResolveInfo, err error)

GetMetadata returns metadata records matching the specified constraint, looking in each source for signed metadata. If onlySigned is false and no signed metadata is found in a source, the source is used to look for unsigned metadata. Each source is tried in turn until at least one signed (or unsigned) match is found.

func (Simplestreams) NewDataSource

func (s Simplestreams) NewDataSource(config Config) DataSource

NewDataSource creates a new data source based on the config.

type ValueParams

type ValueParams struct {
	// The simplestreams data type key.
	DataType string
	// The key to use when looking for content mirrors.
	MirrorContentId string
	// A function used to filter and return records of a given type.
	FilterFunc AppendMatchingFunc
	// An struct representing the type of records to return.
	ValueTemplate interface{}

ValueParams contains the information required to pull out from the metadata structs of a particular type.


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL