simplestreams

package
v0.0.0-...-732aecd Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2014 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

The simplestreams package supports locating, parsing, and filtering metadata in simplestreams format. See http://launchpad.net/simplestreams 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.

Index

Constants

View Source
const (
	StreamsDir       = "streams/v1"
	UnsignedIndex    = "streams/v1/index.json"
	DefaultIndexPath = "streams/v1/index"
	UnsignedMirror   = "streams/v1/mirrors.json"

	UnsignedSuffix = ".json"
)

Variables

View Source
var EmptyCloudSpec = CloudSpec{}

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

Functions

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 RegisterStructTags

func RegisterStructTags(vals ...interface{})

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

Types

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"`
}

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 DataSource

type DataSource interface {
	// Description describes the origin of this datasource.
	// eg tools-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)
	// SetAllowRetry sets the flag which determines if the datasource will retry fetching the metadata
	// if it is not immediately available.
	SetAllowRetry(allow bool)
}

A DataSource retrieves simplestreams metadata.

func NewURLDataSource

func NewURLDataSource(description, baseURL string, hostnameVerification utils.SSLHostnameVerification) DataSource

NewURLDataSource returns a new datasource reading from the specified baseURL.

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 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 {
	Indices
	MirroredProductsPath string
	Source               DataSource
	// contains filtered or unexported fields
}

Exported for testing.

func GetIndexWithFormat

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

GetIndexWithFormat returns a simplestreams index of the specified format. 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"`
	Series     string                 `json:"release,omitempty"`
	Version    string                 `json:"version,omitempty"`
	RegionName string                 `json:"region,omitempty"`
	Endpoint   string                 `json:"endpoint,omitempty"`
	// contains filtered or unexported fields
}

func (*ItemCollection) UnmarshalJSON

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

ItemsCollection.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 {
	// Generates a string array representing product ids formed similarly to an ISCSI qualified name (IQN).
	Ids() ([]string, error)
	// Returns the constraint parameters.
	Params() LookupParams
}

type LookupParams

type LookupParams struct {
	CloudSpec
	Series []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 Ids() method.

func (LookupParams) Params

func (p LookupParams) Params() LookupParams

type MetadataCatalog

type MetadataCatalog struct {
	Series     string `json:"release,omitempty"`
	Version    string `json:"version,omitempty"`
	Arch       string `json:"arch,omitempty"`
	RegionName string `json:"region,omitempty"`
	Endpoint   string `json:"endpoint,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
	Series        string
	Architectures []string
	Endpoint      string
	Sources       []DataSource
	Stream        string
}

type MetadataValidator

type MetadataValidator interface {
	MetadataLookupParams(region string) (*MetadataLookupParams, error)
}

MetadataValidator instances can provide parameters used to query simplestreams metadata to find 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 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, publicKey string) (*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"`
}

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"`
}

func GetMetadata

func GetMetadata(
	sources []DataSource, baseIndexPath string, cons LookupConstraint, onlySigned bool,
	params ValueParams) (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.

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{}
	// For signed metadata, the public key used to validate the signature.
	PublicKey string
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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