plan

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 12 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownloadURL

func DownloadURL(url string) (string, error)

DownloadURL gets the contents of the given url. The provided url can contain a checksum parameter that matches the file being downloaded. If there isn't an error, the content returned by the url will be returned as a string. Returns an error if:

  • The url is not a URL or does not contain a checksum parameter (when required).
  • Downloading the URL fails.
  • The checksum does not match what is returned by the URL.
  • The URL does not return a regular file.
  • The downloaded file is empty or only whitespace.

func DownloadUpgrade

func DownloadUpgrade(dstRoot, url, daemonName string) error

DownloadUpgrade downloads the given url into the provided directory. If this returns nil, the download was successful, and {dstRoot}/bin/{daemonName} is a regular executable file. This is an opinionated directory structure that corresponds with Cosmovisor requirements. If the url is not an archive, it is downloaded and saved to {dstRoot}/bin/{daemonName}. If the url is an archive, it is downloaded and unpacked to {dstRoot}.

If the archive does not contain a /bin/{daemonName} file, then this will attempt to move /{daemonName} to /bin/{daemonName}.
If the archive does not contain either /bin/{daemonName} or /{daemonName}, an error is returned.

If dstRoot already exists, some or all of its contents might be updated. NOTE: This functions does not check the provided url for validity.

func EnsureBinary

func EnsureBinary(path string) error

EnsureBinary checks that the given file exists as a regular file and is executable. An error is returned if:

  • The file does not exist.
  • The path exists, but is one of: Dir, Symlink, NamedPipe, Socket, Device, CharDevice, or Irregular.
  • The file exists, is not executable by all three of User, Group, and Other, and cannot be made executable.

func ValidateURL

func ValidateURL(urlStr string, mustChecksum bool) error

ValidateURL checks that the given string is a valid url and optionally contains a checksum query parameter.

Types

type BinaryDownloadURLMap

type BinaryDownloadURLMap map[string]string

BinaryDownloadURLMap is a map of os/architecture stings to a URL where the binary can be downloaded.

func (BinaryDownloadURLMap) CheckURLs

func (m BinaryDownloadURLMap) CheckURLs(daemonName string, enforceChecksum bool) error

CheckURLs checks that all entries have valid URLs that return expected data. The provided daemonName is the name of the executable file expected in all downloaded directories. Warning: This is an expensive process. It will make an HTTP GET request to each URL and download the response.

func (BinaryDownloadURLMap) ValidateBasic

func (m BinaryDownloadURLMap) ValidateBasic(enforceChecksum bool) error

ValidateBasic does stateless validation of this BinaryDownloadURLMap. It validates that:

  • This has at least one entry.
  • All entry keys have the format "os/arch" or are "any".
  • All entry values are valid URLs.
  • When `enforceChecksum` is true all URLs must contain a checksum query parameter.

type Info

type Info struct {
	Binaries BinaryDownloadURLMap `json:"binaries"`
	// contains filtered or unexported fields
}

Info is the special structure that the Plan.Info string can be (as json).

func ParseInfo

func ParseInfo(infoStr string, opts ...ParseOption) (*Info, error)

ParseInfo parses an info string into a map of os/arch strings to URL string. If the infoStr is a url, an GET request will be made to it, and its response will be parsed instead.

func (Info) ValidateFull

func (m Info) ValidateFull(daemonName string) error

ValidateFull does all possible validation of this Info. The provided daemonName is the name of the executable file expected in all downloaded directories. It checks that:

  • Binaries.ValidateBasic() doesn't return an error
  • Binaries.CheckURLs(daemonName) doesn't return an error.

Warning: This is an expensive process. See BinaryDownloadURLMap.CheckURLs for more info.

type ParseConfig

type ParseConfig struct {
	// EnforceChecksum, if true, will cause all downloaded files to be checked against their checksums.
	// When false, checksums are not enforced to be present in the url.
	EnforceChecksum bool
}

ParseConfig is used to configure the parsing of a Plan.Info string.

type ParseOption

type ParseOption func(*ParseConfig)

ParseOption is used to configure the parsing of a Plan.Info string.

func ParseOptionEnforceChecksum

func ParseOptionEnforceChecksum(enforce bool) ParseOption

ParseOptionEnforceChecksum returns a ParseOption that sets the EnforceChecksum field of the ParseConfig.

Jump to

Keyboard shortcuts

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