Documentation ¶
Index ¶
- Constants
- func NoopDataLoader(_ context.Context, _ *Config, _ map[string]interface{}) error
- type Config
- func (c *Config) ExportRemoteConfigAsEnvironmentVariables() []string
- func (c *Config) GetBuildDriver() string
- func (c *Config) GetBundleArchiveLogs() (string, error)
- func (c *Config) GetBundlesCache() (string, error)
- func (c *Config) GetFeatureFlags() experimental.FeatureFlags
- func (c *Config) GetHomeDir() (string, error)
- func (c *Config) GetPluginPath(plugin string) (string, error)
- func (c *Config) GetPluginsDir() (string, error)
- func (c *Config) GetPorterPath(ctx context.Context) (string, error)
- func (c *Config) GetSchemaCheckStrategy(ctx context.Context) schema.CheckStrategy
- func (c *Config) GetSecretsPlugin(name string) (SecretsPlugin, error)
- func (c *Config) GetStorage(name string) (StoragePlugin, error)
- func (c *Config) GetVerbosity() LogLevel
- func (c *Config) IsFeatureEnabled(flag experimental.FeatureFlags) bool
- func (c *Config) Load(ctx context.Context, ...) (context.Context, error)
- func (c *Config) NewLogConfiguration() portercontext.LogConfiguration
- func (c *Config) SetExperimentalFlags(flags experimental.FeatureFlags)
- func (c *Config) SetHomeDir(home string)
- func (c *Config) SetPorterPath(path string)
- type Data
- type DataStoreLoaderFunc
- type LogConfig
- type LogLevel
- type PluginConfig
- type SecretsPlugin
- type StoragePlugin
- type TelemetryConfig
- type TestConfig
Constants ¶
const ( // Name is the file name of the porter configuration file. Name = "porter.yaml" // EnvHOME is the name of the environment variable containing the porter home directory path. EnvHOME = "PORTER_HOME" // EnvBundleName is the name of the environment variable containing the name of the bundle. EnvBundleName = "CNAB_BUNDLE_NAME" // EnvInstallationName is the name of the environment variable containing the name of the installation. EnvInstallationName = "CNAB_INSTALLATION_NAME" // EnvACTION is the requested action to be executed EnvACTION = "CNAB_ACTION" // EnvDEBUG is a custom porter parameter that signals that --debug flag has been passed through from the client to the runtime. EnvDEBUG = "PORTER_DEBUG" // CustomPorterKey is the key in the bundle.json custom section that contains the Porter stamp // It holds all the metadata that Porter includes that is specific to Porter about the bundle. CustomPorterKey = "sh.porter" // BundleOutputsDir is the directory where outputs are expected to be placed // during the execution of a bundle action. BundleOutputsDir = "/cnab/app/outputs" // ClaimFilepath is the filepath to the claim.json inside of an invocation image ClaimFilepath = "/cnab/claim.json" // EnvPorterInstallationNamespace is the name of the environment variable which is injected into the // invocation image, containing the namespace of the installation. EnvPorterInstallationNamespace = "PORTER_INSTALLATION_NAMESPACE" // EnvPorterInstallationName is the name of the environment variable which is injected into the // invocation image, containing the name of the installation. EnvPorterInstallationName = "PORTER_INSTALLATION_NAME" // DefaultVerbosity is the default value for the --verbosity flag. DefaultVerbosity = "info" )
const ( // BuildDriverDocker is no longer supported. BuildDriverDocker = "docker" // BuildDriverBuildkit is the configuration value for specifying BuildKit as // the build driver. BuildDriverBuildkit = "buildkit" // RuntimeDriverDocker specifies that the invocation image should be executed on docker. RuntimeDriverDocker = "docker" // RuntimeDriverKubernetes specifies that the invocation image should be executed on kubernetes. RuntimeDriverKubernetes = "kubernetes" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { *portercontext.Context Data Data DataLoader DataStoreLoaderFunc // ConfigFilePath is the path to the loaded configuration file ConfigFilePath string // contains filtered or unexported fields }
func NewFor ¶ added in v1.0.1
func NewFor(pCtx *portercontext.Context) *Config
NewFor initializes a porter configuration, using an existing porter context.
func (*Config) ExportRemoteConfigAsEnvironmentVariables ¶ added in v1.0.1
ExportRemoteConfigAsEnvironmentVariables represents the current configuration as environment variables suitable for a remote Porter actor, such as a mixin or plugin. Only a subset of values are exported, such as tracing and logging, and not plugin configuration (since it's not relevant when running a plugin and may contain sensitive data). For example, if Config.Data.Logs is set to warn, it would return PORTER_LOGS_LEVEL=warn in the resulting set of environment variables. This is used to pass config from porter to a mixin or plugin.
func (*Config) GetBuildDriver ¶ added in v1.0.1
GetBuildDriver determines the correct build driver to use, taking into account experimental flags. Use this instead of Config.Data.BuildDriver directly.
func (*Config) GetBundleArchiveLogs ¶
GetBundleArchiveLogs locates the output for Bundle Archive Operations.
func (*Config) GetBundlesCache ¶
GetBundlesCache locates the bundle cache from the porter home directory.
func (*Config) GetFeatureFlags ¶ added in v1.0.1
func (c *Config) GetFeatureFlags() experimental.FeatureFlags
GetFeatureFlags indicates which experimental feature flags are enabled
func (*Config) GetHomeDir ¶
GetHomeDir determines the absolute path to the porter home directory. Hierarchy of checks: - PORTER_HOME - HOME/.porter or USERPROFILE/.porter
func (*Config) GetPluginsDir ¶
func (*Config) GetSchemaCheckStrategy ¶ added in v1.0.1
func (c *Config) GetSchemaCheckStrategy(ctx context.Context) schema.CheckStrategy
func (*Config) GetSecretsPlugin ¶ added in v1.0.1
func (c *Config) GetSecretsPlugin(name string) (SecretsPlugin, error)
func (*Config) GetStorage ¶ added in v1.0.1
func (c *Config) GetStorage(name string) (StoragePlugin, error)
func (*Config) GetVerbosity ¶ added in v1.0.1
GetVerbosity converts the user-specified verbosity flag into a LogLevel enum.
func (*Config) IsFeatureEnabled ¶ added in v1.0.1
func (c *Config) IsFeatureEnabled(flag experimental.FeatureFlags) bool
IsFeatureEnabled returns true if the specified experimental flag is enabled.
func (*Config) Load ¶ added in v1.0.1
func (c *Config) Load(ctx context.Context, resolveSecret func(ctx context.Context, secretKey string) (string, error)) (context.Context, error)
Load loads the configuration file, rendering any templating used in the config file such as ${secret.NAME} or ${env.NAME}. Pass nil for resolveSecret to skip resolving secrets.
func (*Config) NewLogConfiguration ¶ added in v1.0.1
func (c *Config) NewLogConfiguration() portercontext.LogConfiguration
func (*Config) SetExperimentalFlags ¶ added in v1.0.1
func (c *Config) SetExperimentalFlags(flags experimental.FeatureFlags)
SetExperimentalFlags programmatically, overriding Config.Data.ExperimentalFlags. Example: Config.SetExperimentalFlags(experimental.FlagStructuredLogs | ...)
func (*Config) SetHomeDir ¶
SetHomeDir is a test function that allows tests to use an alternate Porter home directory.
func (*Config) SetPorterPath ¶ added in v0.30.1
SetPorterPath is a test function that allows tests to use an alternate Porter binary location.
type Data ¶
type Data struct { // BuildDriver is the driver to use when building bundles. // Available values are: buildkit. // Do not use directly, use Config.GetBuildDriver. BuildDriver string `mapstructure:"build-driver"` // RuntimeDriver is the driver to use when executing bundles. // Available values are: docker, kubernetes. // It is both a global variable and a command flag because some of our commands, like porter installation apply, // do not expose all the bundle execution flags. This allows us to later manually use the global config value // to ensure that the global config value works even for those commands. RuntimeDriver string `mapstructure:"runtime-driver"` // ForceOverwrite specifies OCI artifacts can be overwritten when pushed. // By default, Porter requires the --force flag to be specified to overwrite a bundle or image. ForceOverwrite bool `mapstructure:"force-overwrite"` // AllowDockerHostAccess grants bundles access to the underlying docker host // upon which it is running so that it can do things like build and run containers. // It's a security risk. // It is both a global variable and a command flag because some of our commands, like porter installation apply, // do not expose all the bundle execution flags. This allows us to later manually use the global config value // to ensure that the global config value works even for those commands. AllowDockerHostAccess bool `mapstructure:"allow-docker-host-access"` // DefaultStoragePlugin is the storage plugin to use when no named storage is specified. DefaultStoragePlugin string `mapstructure:"default-storage-plugin"` // DefaultStorage to use when a named storage is not specified by a flag. DefaultStorage string `mapstructure:"default-storage"` // ExperimentalFlags is a list of enabled experimental.FeatureFlags. // Use Config.IsFeatureEnabled instead of parsing directly. ExperimentalFlags []string `mapstructure:"experimental"` // StoragePlugins defined in the configuration file. StoragePlugins []StoragePlugin `mapstructure:"storage"` // DefaultSecretsPlugin is the plugin to use when no plugin is specified. DefaultSecretsPlugin string `mapstructure:"default-secrets-plugin"` // DefaultSecrets to use when one is not specified by a flag. DefaultSecrets string `mapstructure:"default-secrets"` // Namespace is the default namespace for commands that do not override it with a flag. Namespace string `mapstructure:"namespace"` // SecretsPlugin defined in the configuration file. SecretsPlugin []SecretsPlugin `mapstructure:"secrets"` // Logs are settings related to Porter's log files. Logs LogConfig `mapstructure:"logs"` // Telemetry are settings related to Porter's tracing with open telemetry. Telemetry TelemetryConfig `mapstructure:"telemetry"` // SchemaCheck specifies how strict Porter should be when comparing the // schemaVersion field on a resource with the supported schemaVersion. // Supported values are: exact, minor, major, none. SchemaCheck string `mapstructure:"schema-check"` // Verbosity controls the level of messages output to the console. // Use Logs.LogLevel if you want to change what is output to the logfile. // Traces sent to an OpenTelemetry collector always include all levels of messages. Verbosity string `mapstructure:"verbosity"` }
Data is the data stored in PORTER_HOME/porter.toml|yaml|json. Use the accessor functions to ensure default values are handled properly.
func DefaultDataStore ¶ added in v1.0.1
func DefaultDataStore() Data
DefaultDataStore used when no config file is found.
type DataStoreLoaderFunc ¶
DataStoreLoaderFunc defines the Config.DataLoader function signature used to load data into Config.DataStore.
func LoadFromEnvironment ¶ added in v1.0.1
func LoadFromEnvironment() DataStoreLoaderFunc
LoadFromEnvironment loads data with the following precedence: * Environment variables where --flag is assumed to be PORTER_FLAG * Config file * Flag default (lowest)
func LoadFromFilesystem ¶ added in v1.0.1
func LoadFromFilesystem() DataStoreLoaderFunc
LoadFromFilesystem loads data with the following precedence: * Config file * Flag default (lowest) This is used for testing only.
func LoadFromViper ¶ added in v1.0.1
func LoadFromViper(viperCfg func(v *viper.Viper)) DataStoreLoaderFunc
LoadFromViper loads data from a configurable viper instance.
type LogConfig ¶ added in v1.0.1
type LogConfig struct { // Structured indicates if the logs sent to the console should include timestamp and log levels Structured bool `mapstructure:"structured"` LogToFile bool `mapstructure:"log-to-file"` Level LogLevel `mapstructure:"level"` }
LogConfig are settings related to Porter's log files.
type LogLevel ¶ added in v1.0.1
type LogLevel string
func ParseLogLevel ¶ added in v1.0.1
ParseLogLevel reads the string representation of a LogLevel and converts it to a LogLevel. Unrecognized values default to info.
type PluginConfig ¶
type PluginConfig struct { Name string `mapstructure:"name"` PluginSubKey string `mapstructure:"plugin"` Config map[string]interface{} `mapstructure:"config"` }
PluginConfig is a standardized config stanza that defines which plugin to use and its custom configuration.
func (PluginConfig) GetConfig ¶
func (p PluginConfig) GetConfig() interface{}
func (PluginConfig) GetName ¶
func (p PluginConfig) GetName() string
func (PluginConfig) GetPluginSubKey ¶
func (p PluginConfig) GetPluginSubKey() string
type SecretsPlugin ¶ added in v1.0.1
type SecretsPlugin struct {
PluginConfig `mapstructure:",squash"`
}
SecretsPlugin is the plugin stanza for secrets.
type StoragePlugin ¶ added in v1.0.1
type StoragePlugin struct {
PluginConfig `mapstructure:",squash"`
}
StoragePlugin is the plugin stanza for storage.
type TelemetryConfig ¶ added in v1.0.1
type TelemetryConfig struct { Enabled bool `mapstructure:"enabled"` Endpoint string `mapstructure:"endpoint"` Protocol string `mapstructure:"protocol"` Insecure bool `mapstructure:"insecure"` Certificate string `mapstructure:"certificate"` Headers map[string]string `mapstructure:"headers"` Timeout string `mapstructure:"timeout"` Compression string `mapstructure:"compression"` // RedirectToFile instructs Porter to write telemetry data to a file in // PORTER_HOME/traces instead of exporting it to a collector RedirectToFile bool `mapstructure:"redirect-to-file"` // StartTimeout sets the amount of time to wait while establishing a connection // to the OpenTelemetry collector. StartTimeout string `mapstructure:"start-timeout"` }
TelemetryConfig specifies how to connect to an open telemetry collector. See https://github.com/open-telemetry/opentelemetry-go/tree/main/exporters/otlp/otlptrace
func (TelemetryConfig) GetStartTimeout ¶ added in v1.0.1
func (c TelemetryConfig) GetStartTimeout() time.Duration
GetStartTimeout returns the amount of time to wait for the collector to start if a value was not configured, return the default timeout.
type TestConfig ¶
type TestConfig struct { *Config TestContext *portercontext.TestContext TestSpan tracing.RootTraceLogger }
func NewTestConfig ¶
func NewTestConfig(t *testing.T) *TestConfig
NewTestConfig initializes a configuration suitable for testing: * buffered output, * in-memory file system, * does not automatically load config from ambient environment.
func (*TestConfig) Close ¶ added in v1.0.1
func (c *TestConfig) Close()
func (*TestConfig) SetupIntegrationTest ¶
func (c *TestConfig) SetupIntegrationTest() (ctx context.Context, testDir string, homeDir string)
SetupIntegrationTest initializes the filesystem with the supporting files in a temp PORTER_HOME directory.
func (*TestConfig) SetupUnitTest ¶ added in v0.31.0
func (c *TestConfig) SetupUnitTest()
SetupUnitTest initializes the unit test filesystem with the supporting files in the PORTER_HOME directory.