manifest

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2022 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// Filename is the name of the package manifest file.
	// It is expected to be a project specific configuration file.
	//
	// TODO: The filename needs to be referenced outside of the compute package
	// so consider moving this constant to a different location in the top-level
	// pkg directory instead or even moving the whole manifest package up to the
	// top-level pkg directory as finding a suitable package for just the
	// manifest filename could be tricky.
	Filename = "fastly.toml"

	// ManifestLatestVersion represents the latest known manifest schema version
	// supported by the CLI.
	//
	// NOTE: The CLI is the primary consumer of the fastly.toml manifest so its
	// code is typically coupled to the specification.
	ManifestLatestVersion = 2

	// FilePermissions represents a read/write file mode.
	FilePermissions = 0666

	// SourceUndefined indicates the parameter isn't provided in any of the
	// available sources, similar to "not found".
	SourceUndefined Source = iota

	// SourceFile indicates the parameter came from a manifest file.
	SourceFile

	// SourceEnv indicates the parameter came from the user's shell environment.
	SourceEnv

	// SourceFlag indicates the parameter came from an explicit flag.
	SourceFlag

	// SpecIntro informs the user of what the manifest file is for.
	SpecIntro = "This file describes a Fastly Compute@Edge package. To learn more visit:"

	// SpecURL points to the fastly.toml manifest specification reference.
	SpecURL = "https://developer.fastly.com/reference/fastly-toml/"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	File File
	Flag Flag
}

Data holds global-ish manifest data from manifest files, and flag sources. It has methods to give each parameter to the components that need it, including the place the parameter came from, which is a requirement.

If the same parameter is defined in multiple places, it is resolved according to the following priority order: the manifest file (lowest priority) and then explicit flags (highest priority).

func (*Data) Authors

func (d *Data) Authors() ([]string, Source)

Authors yields an Authors.

func (*Data) Description

func (d *Data) Description() (string, Source)

Description yields a Description.

func (*Data) Name

func (d *Data) Name() (string, Source)

Name yields a Name.

func (*Data) ServiceID

func (d *Data) ServiceID() (string, Source)

ServiceID yields a ServiceID.

type File

type File struct {
	Authors         []string    `toml:"authors"`
	Description     string      `toml:"description"`
	Language        string      `toml:"language"`
	LocalServer     LocalServer `toml:"local_server,omitempty"`
	ManifestVersion Version     `toml:"manifest_version"`
	Name            string      `toml:"name"`
	Scripts         Scripts     `toml:"scripts,omitempty"`
	ServiceID       string      `toml:"service_id"`
	Setup           Setup       `toml:"setup,omitempty"`
	// contains filtered or unexported fields
}

File represents all of the configuration parameters in the fastly.toml manifest file schema.

func (*File) AutoMigrateVersion

func (f *File) AutoMigrateVersion(data []byte, path string) ([]byte, error)

AutoMigrateVersion updates the manifest_version value to ManifestLatestVersion if the current version is less than the latest supported and only if there is no [setup] configuration defined.

NOTE: It contains similar conversions to the custom Version.UnmarshalText(). Specifically, it type switches the interface{} into various types before attempting to convert the underlying value into an integer.

func (*File) Exists

func (f *File) Exists() bool

Exists yields whether the manifest exists.

Specifically, it indicates that a toml.Unmarshal() of the toml disk content to data in memory was successful without error.

func (*File) Read

func (f *File) Read(path string) (err error)

Read loads the manifest file content from disk.

func (*File) ReadError

func (f *File) ReadError() error

ReadError yields the error returned from Read().

NOTE: We no longer call Read() from every command. We only call it once within app.Run() but we don't handle any errors that are returned from the Read() method. This is because failing to read the manifest is fine if the error is caused by the file not existing in a directory where the user is working on a non-C@E project. This will enable code elsewhere in the CLI to understand why the Read() failed. For example, we can use errors.Is() to allow returning a specific remediation error from a C@E related command.

func (*File) SetErrLog

func (f *File) SetErrLog(errLog fsterr.LogInterface)

SetErrLog sets an instance of errors.LogInterface.

func (*File) SetOutput

func (f *File) SetOutput(output io.Writer)

SetOutput sets the output stream for any messages.

func (*File) Write

func (f *File) Write(path string) error

Write persists the manifest content to disk.

type Flag

type Flag struct {
	Name        string
	Description string
	Authors     []string
	ServiceID   string
}

Flag represents all of the manifest parameters that can be set with explicit flags. Consumers should bind their flag values to these fields directly.

type LocalBackend

type LocalBackend struct {
	URL          string `toml:"url"`
	OverrideHost string `toml:"override_host,omitempty"`
}

LocalBackend represents a backend to be mocked by the local testing server.

type LocalDictionary

type LocalDictionary struct {
	File   string `toml:"file"`
	Format string `toml:"format"`
}

LocalDictionary represents a dictionary to be mocked by the local testing server.

type LocalServer

type LocalServer struct {
	Backends     map[string]LocalBackend    `toml:"backends"`
	Dictionaries map[string]LocalDictionary `toml:"dictionaries,omitempty"`
}

LocalServer represents a list of backends that should be mocked as per the configuration values.

type Scripts

type Scripts struct {
	Build string `toml:"build,omitempty"`
}

Scripts represents custom operations.

type Setup

type Setup struct {
	Backends     map[string]*SetupBackend    `toml:"backends,omitempty"`
	Dictionaries map[string]*SetupDictionary `toml:"dictionaries,omitempty"`
	Loggers      map[string]*SetupLogger     `toml:"log_endpoints,omitempty"`
}

Setup represents a set of service configuration that works with the code in the package. See https://developer.fastly.com/reference/fastly-toml/.

type SetupBackend

type SetupBackend struct {
	Address     string `toml:"address,omitempty"`
	Port        uint   `toml:"port,omitempty"`
	Description string `toml:"description,omitempty"`
}

SetupBackend represents a '[setup.backends.<T>]' instance.

type SetupDictionary

type SetupDictionary struct {
	Items       map[string]SetupDictionaryItems `toml:"items,omitempty"`
	Description string                          `toml:"description,omitempty"`
}

SetupDictionary represents a '[setup.dictionaries.<T>]' instance.

type SetupDictionaryItems

type SetupDictionaryItems struct {
	Value       string `toml:"value,omitempty"`
	Description string `toml:"description,omitempty"`
}

SetupDictionaryItems represents a '[setup.dictionaries.<T>.items]' instance.

type SetupLogger

type SetupLogger struct {
	Provider string `toml:"provider,omitempty"`
}

SetupLogger represents a '[setup.log_endpoints.<T>]' instance.

type Source

type Source uint8

Source enumerates where a manifest parameter is taken from.

type Version

type Version int

Version represents the currently supported schema for the fastly.toml manifest file that determines the configuration for a compute@edge service.

NOTE: the File object has a field called ManifestVersion which this type is assigned. The reason we don't name this type ManifestVersion is to appease the static analysis linter which complains re: stutter in the import manifest.ManifestVersion.

func (*Version) UnmarshalText

func (v *Version) UnmarshalText(text []byte) error

UnmarshalText manages multiple scenarios where historically the manifest version was a string value and not an integer.

Example mappings:

"0.1.0" -> 1 "1" -> 1 1 -> 1 "1.0.0" -> 1 0.1 -> 1 "0.2.0" -> 1 "2.0.0" -> 2

We also constrain the version so that if a user has a manifest_version defined as "99.0.0" then we won't accidentally store it as the integer 99 but instead will return an error because it exceeds the current ManifestLatestVersion version.

Jump to

Keyboard shortcuts

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