stream

package
v0.0.0-...-742b54a Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FileChecksumSHA256 is the name of the checksum file containing SHA256 hashes.
	FileChecksumSHA256 = "SHA256SUMS"

	// FileImageConfig is the name of the file that contains additional information
	// about the version.
	FileImageConfig = "image.yaml"
)

Static list of file names.

View Source
const (
	// ItemTypeMetadata represents the LXD metadata file.
	ItemTypeMetadata = "lxd.tar.xz"

	// ItemTypeSquashfs represents container's root file system (squashfs).
	ItemTypeSquashfs = "squashfs"

	// ItemTypeSquashfsDelta represents container's root file system delta (VCDiff).
	ItemTypeSquashfsDelta = "squashfs.vcdiff"

	// ItemTypeDiskKVM represents VM's root file system (qcow2).
	ItemTypeDiskKVM = "disk-kvm.img"

	// ItemTypeDiskKVMDelta represents VM's root file system delta (VCDiff).
	ItemTypeDiskKVMDelta = "disk-kvm.img.vcdiff"

	// ItemTypeRootTarXz represents root file system as a tarball.
	ItemTypeRootTarXz = "root.tar.xz"
)
View Source
const (
	// ItemExtMetadata is a file extension of LXD metadata file.
	ItemExtMetadata = ".tar.xz"

	// ItemExtSquashfs is a file extension of container's root file system.
	ItemExtSquashfs = ".squashfs"

	// ItemExtSquashfsDelta is a file extension of container's root file system delta (VCDiff).
	ItemExtSquashfsDelta = ".vcdiff"

	// ItemExtDiskKVM is a file extension of VM's root file system.
	ItemExtDiskKVM = ".qcow2"

	// ItemExtDiskKVMDelta is a file extension of VM's root file system delta (VCDiff).
	ItemExtDiskKVMDelta = ".qcow2.vcdiff"
)

Variables

View Source
var (
	// ErrVersionIncomplete indicates that version is missing some files.
	// For a version to be complete, a metadata and at least one root
	// filesystem (qcow2/squashfs) must be present.
	ErrVersionIncomplete = errors.New("Product version is incomplete")

	// ErrVersionInvalidImageConfig indicates version's image config is invalid.
	ErrVersionInvalidImageConfig = errors.New("Product version has invalid image config")

	// ErrProductInvalidPath indicates that product's path is invalid because
	// either the directory on the given path does not exist, or it's path
	// does not match the expected format.
	ErrProductInvalidPath = errors.New("Invalid product path")
)

Functions

func CreateAliases

func CreateAliases(distro string, release string, variant string) []string

CreateAliases creates aliases from the given distro, release, and variant. It appends them to the aliases slice and returns the updated slice.

func GetProducts

func GetProducts(rootDir string, streamRelPath string, options ...Option) (map[string]Product, error)

GetProducts traverses through the directories on the given path and retrieves a map of found products.

func ReadChecksumFile

func ReadChecksumFile(path string) (map[string]string, error)

ReadChecksumFile reads a checksum file and returns a map of filename checksum pairs.

Types

type Item

type Item struct {
	// Type of the file. A known ItemType is used if possible, otherwise,
	// this field is equal to the file's name.
	Ftype string `json:"ftype"`

	// Path of the file relative to the root directory (the directory where
	// the simplestream content is hosted from).
	Path string `json:"path"`

	// Size of file.
	Size int64 `json:"size"`

	// SHA256 hash of the file.
	SHA256 string `json:"sha256,omitempty"`

	// CombinedSHA256DiskKvmImg stores the combined SHA256 hash of the metadata
	// and VM file system (qcow2) files. This field is set only for the metadata
	// item when both files exist in the same product version.
	CombinedSHA256DiskKvmImg string `json:"combined_disk-kvm-img_sha256,omitempty"`

	// CombinedSHA256DiskKvmImg stores the combined SHA256 hash of the metadata
	// and container file system (squashfs) files. This field is set only for
	// the metadata item when both files exist in the same product version.
	CombinedSHA256SquashFs string `json:"combined_squashfs_sha256,omitempty"`

	// CombinedSHA256RootXz stores the combined SHA256 hash of the metadata and
	// root file system tarball files. This field is set only for the metadata
	// item when both files exist in the same product version.
	CombinedSHA256RootXz string `json:"combined_rootxz_sha256,omitempty"`

	// DeltaBase indicates the version from which the delta (.vcdiff) file was
	// calculated from. This field is set only for the delta items.
	DeltaBase string `json:"delta_base,omitempty"`
}

Item represents a file within a product version.

func GetItem

func GetItem(rootDir string, itemRelPath string, options ...Option) (*Item, error)

GetItem retrieves item metadata for the file on a given path. If calcHash is set to true, the file's hash is calculated.

type ItemExt

type ItemExt string

ItemExt is file extension of the the file that item holds.

type ItemType

type ItemType string

ItemType is a type of the file that item holds.

type Option

type Option func(*options)

Option to modify the fetching behavior.

func WithHashes

func WithHashes(val bool) Option

WithHashes ensures that item hashes are calculated.

func WithIncompleteVersions

func WithIncompleteVersions(val bool) Option

WithIncompleteVersions ensures incomplete versions are included when retrieving a version or products.

type Product

type Product struct {
	// List of aliases using which the product (image) can be referenced.
	Aliases string `json:"aliases"`

	// Architecture the image was built for. For example amd64.
	Architecture string `json:"arch"`

	// Name of the image distribution.
	Distro string `json:"distro"`

	// Pretty name of the operating system.
	OS string `json:"os"`

	// Name of the image release.
	Release string `json:"release"`

	// Release title or in other words pretty display name.
	ReleaseTitle string `json:"release_title"`

	// Name of the image variant.
	Variant string `json:"variant"`

	// Map of image versions, where the map key represents the version name.
	Versions map[string]Version `json:"versions,omitempty"`

	// Map of the requirements that need to be satisfied in order for the
	// image to work. Map key represents the configuration key and map
	// value the expected configuration value.
	Requirements map[string]string `json:"requirements"`
}

Product represents a single image with all its available versions.

func GetProduct

func GetProduct(rootDir string, productRelPath string, options ...Option) (*Product, error)

GetProduct reads the product on the given path including all of its versions. Product's relative path must match the predetermined format, otherwise, an error is returned.

func (Product) ID

func (p Product) ID() string

ID returns the ID of the product.

func (Product) RelPath

func (p Product) RelPath() string

RelPath returns the product's path relative to the stream's root directory.

type ProductCatalog

type ProductCatalog struct {
	// ContentID (e.g. images).
	ContentID string `json:"content_id"`

	// Format of the product catalog (e.g. products:1.0).
	Format string `json:"format"`

	// Data type of the product catalog (e.g. image-downloads).
	DataType string `json:"datatype"`

	// Map of products, where the map key represents a product ID.
	Products map[string]Product `json:"products"`
}

ProductCatalog contains all products.

func NewCatalog

func NewCatalog(streamName string, products map[string]Product) *ProductCatalog

NewCatalog creates a new product catalog.

type StreamIndex

type StreamIndex struct {
	Format string                      `json:"format"`
	Index  map[string]StreamIndexEntry `json:"index"`
}

func NewStreamIndex

func NewStreamIndex() StreamIndex

NewStreamIndex creates new empty index.

func (*StreamIndex) AddEntry

func (i *StreamIndex) AddEntry(streamName string, catalogPath string, catalog ProductCatalog)

AddEntry adds catalog and a list of its products to the index.

type StreamIndexEntry

type StreamIndexEntry struct {
	Datatype string   `json:"datatype"`
	Path     string   `json:"path"`
	Format   string   `json:"format"`
	Updated  string   `json:"updated"`
	Products []string `json:"products"`
}

type Version

type Version struct {

	// Checksums of files within the version.
	Checksums map[string]string `json:"-"`

	// ImageConfig contains additional information about the product version.
	ImageConfig shared.DefinitionSimplestream `json:"-"`

	// Map of items found within the version, where the map key
	// represents file name.
	Items map[string]Item `json:"items,omitempty"`
	// contains filtered or unexported fields
}

Version represents a list of items available for the given image version.

func GetVersion

func GetVersion(rootDir string, versionRelPath string, options ...Option) (*Version, error)

GetVersion retrieves metadata for a single version, by reading directory files and converting those that should be incuded in the product catalog into items. For the relevant items, the file hashes are calculated, if calcHashes is set to true.

Jump to

Keyboard shortcuts

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