plugingetter

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2023 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package plugingetter defines means to download and install plugins.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinaryInstallationOptions

type BinaryInstallationOptions struct {
	//
	APIVersionMajor, APIVersionMinor string
	// OS and ARCH usually should be runtime.GOOS and runtime.ARCH, they allow
	// to pick the correct binary.
	OS, ARCH string

	// Ext is ".exe" on windows
	Ext string

	Checksummers []Checksummer
}

func (*BinaryInstallationOptions) CheckProtocolVersion

func (binOpts *BinaryInstallationOptions) CheckProtocolVersion(remoteProt string) error

func (BinaryInstallationOptions) FilenameSuffix added in v1.8.1

func (opts BinaryInstallationOptions) FilenameSuffix() string

type Checksum

type Checksum []byte

func (Checksum) String

func (c Checksum) String() string

type ChecksumError

type ChecksumError struct {
	Hash     hash.Hash
	Actual   []byte
	Expected []byte
	File     string
}

A ChecksumError is returned when a checksum differs

func (*ChecksumError) Error

func (cerr *ChecksumError) Error() string

type ChecksumFileEntry

type ChecksumFileEntry struct {
	Filename string `json:"filename"`
	Checksum string `json:"checksum"`
	// contains filtered or unexported fields
}

func ParseChecksumFileEntries

func ParseChecksumFileEntries(f io.Reader) ([]ChecksumFileEntry, error)

func (ChecksumFileEntry) Arch

func (e ChecksumFileEntry) Arch() string

func (ChecksumFileEntry) BinVersion

func (e ChecksumFileEntry) BinVersion() string

func (ChecksumFileEntry) Ext

func (e ChecksumFileEntry) Ext() string

func (ChecksumFileEntry) Os

func (e ChecksumFileEntry) Os() string

func (ChecksumFileEntry) ProtVersion

func (e ChecksumFileEntry) ProtVersion() string

type Checksummer

type Checksummer struct {
	// Something like md5 or sha256
	Type string
	// Hash function
	hash.Hash
}

func (*Checksummer) Checksum

func (c *Checksummer) Checksum(expected []byte, f io.Reader) error

func (*Checksummer) ChecksumFile

func (c *Checksummer) ChecksumFile(expected []byte, filePath string) error

ChecksumFile compares the expected checksum to the checksum of the file in filePath using the hash function.

func (*Checksummer) FileExt

func (c *Checksummer) FileExt() string

func (*Checksummer) GetCacheChecksumOfFile

func (c *Checksummer) GetCacheChecksumOfFile(filePath string) ([]byte, error)

GetCacheChecksumOfFile will extract the checksum from file `filePath + c.FileExt()`. It expects the checksum file to only contains the checksum and nothing else.

func (*Checksummer) ParseChecksum

func (c *Checksummer) ParseChecksum(f io.Reader) (Checksum, error)

ParseChecksum expects the checksum reader to only contain the checksum and nothing else.

func (*Checksummer) Sum

func (c *Checksummer) Sum(f io.Reader) ([]byte, error)

type FileChecksum

type FileChecksum struct {
	Filename string
	Expected Checksum
	Checksummer
}

type GetOptions

type GetOptions struct {
	PluginRequirement *Requirement

	BinaryInstallationOptions
	// contains filtered or unexported fields
}

func (*GetOptions) ExpectedZipFilename

func (gp *GetOptions) ExpectedZipFilename() string

ExpectedZipFilename is the filename of the zip we expect to find, the value is known only after parsing the checksum file file.

func (*GetOptions) Version

func (gp *GetOptions) Version() string

type Getter

type Getter interface {
	// Get allows Packer to know more information about releases of a plugin in
	// order to decide which version to install. Get behaves similarly to an
	// HTTP server. Packer will stream responses from get in order to do what's
	// needed. In order to minimize the amount of requests done, Packer is
	// strict on filenames and we highly recommend on automating releases.
	// In the future, Packer will make it possible to ship plugin getters as
	// binaries this is why Packer streams from the output of get, which will
	// then be a command.
	//
	//  * 'releases', get 'releases' should return the complete list of Releases
	//    in JSON format following the format of the Release struct. It is also
	//    possible to read GetOptions to filter for a smaller response. Some
	//    getters don't. Packer will then decide the highest compatible
	//    version of the plugin to install by using the sha256 function.
	//
	//  * 'sha256', get 'sha256' should return a SHA256SUMS txt file. It will be
	//    called with the highest possible & user allowed version from get
	//   'releases'. Packer will check if the release has a binary matching what
	//    Packer can install and use. If so, get 'binary' will be called;
	//    otherwise, lower versions will be checked.
	//    For version 1.0.0 of the 'hashicorp/amazon' builder, the GitHub getter
	//    will fetch the following URL:
	//    https://github.com/hashicorp/packer-plugin-amazon/releases/download/v1.0.0/packer-plugin-amazon_v1.0.0_SHA256SUMS
	//    This URL can be parameterized to the following one:
	//    https://github.com/{plugin.path}/releases/download/{plugin.version}/packer-plugin-{plugin.name}_{plugin.version}_SHA256SUMS
	//    If Packer is running on Linux AMD 64, then Packer will check for the
	//    existence of a packer-plugin-amazon_v1.0.0_x5.0_linux_amd64 checksum in
	//    that file. This filename can be parameterized to the following one:
	//    packer-plugin-{plugin.name}_{plugin.version}_x{proto_ver.major}.{proto_ver._minor}_{os}_{arch}
	//
	//    See
	//    https://github.com/hashicorp/packer-plugin-scaffolding/blob/main/.goreleaser.yml
	//    and
	//    https://www.packer.io/docs/plugins/creation#plugin-development-basics
	//    to learn how to create and automate your releases and for docs on
	//    plugin development basics.
	//
	//  * get 'zip' is called once we know what version we want and that it is
	//    compatible with the OS and Packer. Zip expects an io stream of a zip
	//    file containing a binary. For version 1.0.0 of the 'hashicorp/amazon'
	//    builder and on darwin_amd64, the GitHub getter will fetch the
	//    following ZIP:
	//    https://github.com/hashicorp/packer-plugin-amazon/releases/download/v1.0.0/packer-plugin-amazon_v1.0.0_x5.0_darwin_amd64.zip
	//    this zip is expected to contain a
	//    packer-plugin-amazon_v1.0.0_x5.0_linux_amd64 file that will be checksum
	//    verified then copied to the correct plugin location.
	Get(what string, opts GetOptions) (io.ReadCloser, error)
}

A Getter helps get the appropriate files to download a binary.

type InstallList

type InstallList []*Installation

InstallList is a list of installed plugins (binaries) with their versions, ListInstallations should be used to get an InstallList.

ListInstallations sorts binaries by version and one binary per version is returned.

func (*InstallList) InsertSortedUniq

func (l *InstallList) InsertSortedUniq(install *Installation)

InsertSortedUniq inserts the installation in the right spot in the list by comparing the version lexicographically. A Duplicate version will replace any already present version.

func (InstallList) String

func (l InstallList) String() string

type InstallOptions

type InstallOptions struct {
	// Different means to get releases, sha256 and binary files.
	Getters []Getter

	// Any downloaded binary and checksum file will be put in the last possible
	// folder of this list.
	InFolders []string

	BinaryInstallationOptions
}

InstallOptions describes the possible options for installing the plugin that fits the plugin Requirement.

type Installation

type Installation struct {
	// path to where binary is installed, if installed.
	// Ex: /usr/azr/.packer.d/plugins/github.com/hashicorp/packer-plugin-amazon/packer-plugin-amazon_v1.2.3_darwin_amd64
	BinaryPath string

	// Version of this plugin, if installed and versionned. Ex:
	//  * v1.2.3 for packer-plugin-amazon_v1.2.3_darwin_x5
	//  * empty  for packer-plugin-amazon
	Version string
}

Installation describes a plugin installation

type ListInstallationsOptions

type ListInstallationsOptions struct {
	// FromFolders where plugins could be installed. Paths should be absolute for
	// safety but can also be relative.
	FromFolders []string

	BinaryInstallationOptions
}

type RateLimitError added in v1.7.7

type RateLimitError struct {
	SetableEnvVar string
	ResetTime     time.Time
	Err           error
}

RateLimitError is returned when a getter is being rate limited.

func (*RateLimitError) Error added in v1.7.7

func (rlerr *RateLimitError) Error() string

type Release

type Release struct {
	Version string `json:"version"`
}

func ParseReleases

func ParseReleases(f io.ReadCloser) ([]Release, error)

type Requirement

type Requirement struct {
	// Plugin accessor as defined in the config file.
	// For Packer, using :
	//  required_plugins { amazon = {...} }
	// Will set Accessor to `amazon`.
	Accessor string

	// Something like github.com/hashicorp/packer-plugin-amazon, from the
	// previous example.
	Identifier *addrs.Plugin

	// VersionConstraints as defined by user. Empty ( to be avoided ) means
	// highest found version.
	VersionConstraints version.Constraints

	// was this require implicitly guessed ?
	Implicit bool
}

Requirement describes a required plugin and how it is installed. Usually a list of required plugins is generated from a config file. From it we check what is actually installed and what needs to happen to get in the desired state.

func (Requirement) FilenamePrefix

func (pr Requirement) FilenamePrefix() string

func (*Requirement) InstallLatest

func (pr *Requirement) InstallLatest(opts InstallOptions) (*Installation, error)

func (Requirement) ListInstallations

func (pr Requirement) ListInstallations(opts ListInstallationsOptions) (InstallList, error)

ListInstallations lists unique installed versions of plugin Requirement pr with opts as a filter.

Installations are sorted by version and one binary per version is returned. Last binary detected takes precedence: in the order 'FromFolders' option.

At least one opts.Checksumers must be given for a binary to be even considered.

type Requirements

type Requirements []*Requirement

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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