Documentation ¶
Overview ¶
Package portercontext contains our common application Context structure that we should use to interact with stdin/stdout/stederr, running commands, and interacting with the file system. It is not a replacement for the Go standard library context package.
Index ¶
- Constants
- type CensoredWriter
- type CommandBuilder
- type Context
- func (c *Context) Chdir(dir string)
- func (c *Context) Clearenv()
- func (c *Context) Close() error
- func (c *Context) CommandContext(ctx context.Context, name string, arg ...string) *exec.Cmd
- func (c *Context) ConfigureLogging(ctx context.Context, cfg LogConfiguration) context.Context
- func (c *Context) CopyDirectory(srcDir, destDir string, includeBaseDir bool) error
- func (c *Context) CopyFile(src, dest string) error
- func (c *Context) Environ() []string
- func (c *Context) EnvironMap() map[string]string
- func (c *Context) ExpandEnv(s string) string
- func (c *Context) Getenv(key string) string
- func (c *Context) Getwd() string
- func (c *Context) LookPath(file string) (string, bool)
- func (c *Context) LookupEnv(key string) (string, bool)
- func (c *Context) SetSensitiveValues(vals []string)
- func (c *Context) Setenv(key string, value string)
- func (c *Context) StartRootSpan(ctx context.Context, op string, attrs ...attribute.KeyValue) (context.Context, tracing.RootTraceLogger)
- func (c *Context) Unsetenv(key string)
- func (c *Context) WriteMixinOutputToFile(filename string, bytes []byte) error
- type LogConfiguration
- type PluginDebugContext
- type TestContext
- func (c *TestContext) AddCleanupDir(dir string)
- func (c *TestContext) AddTestDirectory(srcDir, destDir string, mode ...os.FileMode)
- func (c *TestContext) AddTestDirectoryFromRoot(srcDir, destDir string)
- func (c *TestContext) AddTestDriver(src, name string) string
- func (c *TestContext) AddTestFile(src, dest string, mode ...os.FileMode) []byte
- func (c *TestContext) AddTestFileContents(file []byte, dest string) error
- func (c *TestContext) AddTestFileFromRoot(src, dest string) []byte
- func (c *TestContext) ClearOutputs()
- func (c *TestContext) Close()
- func (c *TestContext) CompareGoldenFile(goldenFile string, got string)
- func (c *TestContext) DisableUmask()
- func (c *TestContext) EditYaml(path string, transformations ...func(yq *yaml.Editor) error)
- func (c *TestContext) FindBinDir() string
- func (c *TestContext) FindRepoRoot() string
- func (c *TestContext) GetError() string
- func (c *TestContext) GetOutput() string
- func (c *TestContext) GetTestDefinitionDirectory() string
- func (c *TestContext) NewTestCommand(ctx context.Context, name string, args ...string) *exec.Cmd
- func (c *TestContext) UseFilesystem() (testDir string, homeDir string)
Constants ¶
const ( // MixinOutputsDir represents the directory where mixin output files are written/read MixinOutputsDir = "/cnab/app/porter/outputs" // EnvCorrelationID is the name of the environment variable containing the // id to correlate logs with a workflow. EnvCorrelationID = "PORTER_CORRELATION_ID" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CensoredWriter ¶
type CensoredWriter struct {
// contains filtered or unexported fields
}
CensoredWriter is a writer wrapping the provided io.Writer with logic to censor certain values
func NewCensoredWriter ¶
func NewCensoredWriter(writer io.Writer) *CensoredWriter
NewCensoredWriter returns a new CensoredWriter
func (*CensoredWriter) SetSensitiveValues ¶
func (cw *CensoredWriter) SetSensitiveValues(vals []string)
SetSensitiveValues sets values needing masking for an CensoredWriter
type CommandBuilder ¶
type Context ¶
type Context struct { FileSystem aferox.Aferox In io.Reader Out io.Writer Err io.Writer NewCommand CommandBuilder PlugInDebugContext *PluginDebugContext // IsInternalPlugin indicates that Porter is running as an internal plugin IsInternalPlugin bool // InternalPluginKey is the current plugin that Porter is running as, e.g. storage.porter.mongodb InternalPluginKey string // contains filtered or unexported fields }
Context should not be used in concurrent code, it is single threaded.
func (*Context) CommandContext ¶
CommandContext creates a new exec.Cmd in the current directory. The provided context is used to kill the process (by calling os.Process.Kill) if the context becomes done before the command completes on its own.
func (*Context) ConfigureLogging ¶
ConfigureLogging applies different configuration to our logging and tracing. Returns an updated context with the configured logger applied
func (*Context) CopyDirectory ¶
func (*Context) Environ ¶
Environ returns a copy of strings representing the environment, in the form "key=value".
func (*Context) EnvironMap ¶
EnvironMap returns a map of the current environment variables.
func (*Context) ExpandEnv ¶
ExpandEnv replaces ${var} or $var in the string according to the values of the current environment variables. References to undefined variables are replaced by the empty string.
func (*Context) Getenv ¶
Getenv retrieves the value of the environment variable named by the key. It returns the value, which will be empty if the variable is not present. To distinguish between an empty value and an unset value, use LookupEnv.
func (*Context) LookPath ¶
This is a simplified exec.LookPath that checks if command is accessible given a PATH environment variable.
func (*Context) LookupEnv ¶
LookupEnv retrieves the value of the environment variable named by the key. If the variable is present in the environment the value (which may be empty) is returned and the boolean is true. Otherwise the returned value will be empty and the boolean will be false.
func (*Context) SetSensitiveValues ¶
SetSensitiveValues sets the sensitive values needing masking on output/err streams WARNING: This does not work if you are writing to the TraceLogger. See https://github.com/getporter/porter/issues/2256 Only use this when you are calling fmt.Fprintln, not log.Debug, etc.
func (*Context) Setenv ¶
Setenv sets the value of the environment variable named by the key. It returns an error, if any.
func (*Context) StartRootSpan ¶
func (c *Context) StartRootSpan(ctx context.Context, op string, attrs ...attribute.KeyValue) (context.Context, tracing.RootTraceLogger)
StartRootSpan creates the root tracing span for the porter application. This should only be done once.
type LogConfiguration ¶
type LogConfiguration struct { // Verbosity is the threshold for printing messages to the console. Verbosity zapcore.Level LogToFile bool LogDirectory string // LogLevel is the threshold for writing messages to the log file. LogLevel zapcore.Level StructuredLogs bool TelemetryEnabled bool TelemetryEndpoint string TelemetryProtocol string TelemetryInsecure bool TelemetryCertificate string TelemetryCompression string TelemetryTimeout string TelemetryHeaders map[string]string TelemetryServiceName string TelemetryDirectory string TelemetryRedirectToFile bool TelemetryStartTimeout time.Duration }
type PluginDebugContext ¶
type PluginDebugContext struct { RunPlugInInDebugger string PlugInWorkingDirectory string DebuggerPort string }
func NewPluginDebugContext ¶
func NewPluginDebugContext(c *Context) *PluginDebugContext
type TestContext ¶
func NewTestContext ¶
func NewTestContext(t *testing.T) *TestContext
NewTestContext initializes a configuration suitable for testing, with the output buffered, and an in-memory file system, using the specified environment variables.
func (*TestContext) AddCleanupDir ¶
func (c *TestContext) AddCleanupDir(dir string)
func (*TestContext) AddTestDirectory ¶
func (c *TestContext) AddTestDirectory(srcDir, destDir string, mode ...os.FileMode)
AddTestDirectory adds a test directory where the filepath is relative to the test directory. mode is optional and should only be specified once
func (*TestContext) AddTestDirectoryFromRoot ¶
func (c *TestContext) AddTestDirectoryFromRoot(srcDir, destDir string)
Use this when the directory you are referencing is in a different directory than the test.
func (*TestContext) AddTestDriver ¶
func (c *TestContext) AddTestDriver(src, name string) string
func (*TestContext) AddTestFile ¶
func (c *TestContext) AddTestFile(src, dest string, mode ...os.FileMode) []byte
AddTestFile adds a test file where the filepath is relative to the test directory. mode is optional and only the first one passed is used.
func (*TestContext) AddTestFileContents ¶
func (c *TestContext) AddTestFileContents(file []byte, dest string) error
func (*TestContext) AddTestFileFromRoot ¶
func (c *TestContext) AddTestFileFromRoot(src, dest string) []byte
AddTestFileFromRoot should be used when the testfile you are referencing is in a different directory than the test.
func (*TestContext) ClearOutputs ¶
func (c *TestContext) ClearOutputs()
func (*TestContext) Close ¶
func (c *TestContext) Close()
func (*TestContext) CompareGoldenFile ¶
func (c *TestContext) CompareGoldenFile(goldenFile string, got string)
CompareGoldenFile checks if the specified string matches the content of a golden test file. When they are different and PORTER_UPDATE_TEST_FILES is true, the file is updated to match the new test output.
func (*TestContext) DisableUmask ¶
func (c *TestContext) DisableUmask()
func (*TestContext) EditYaml ¶ added in v1.0.8
func (c *TestContext) EditYaml(path string, transformations ...func(yq *yaml.Editor) error)
func (*TestContext) FindBinDir ¶
func (c *TestContext) FindBinDir() string
FindBinDir returns the path to the bin directory of the repository where the test is currently running
func (*TestContext) FindRepoRoot ¶
func (c *TestContext) FindRepoRoot() string
FindRepoRoot returns the path to the porter repository where the test is currently running
func (*TestContext) GetError ¶
func (c *TestContext) GetError() string
GetError returns all text printed to stderr.
func (*TestContext) GetOutput ¶
func (c *TestContext) GetOutput() string
GetOutput returns all text printed to stdout.
func (*TestContext) GetTestDefinitionDirectory ¶
func (c *TestContext) GetTestDefinitionDirectory() string
func (*TestContext) NewTestCommand ¶
func (*TestContext) UseFilesystem ¶
func (c *TestContext) UseFilesystem() (testDir string, homeDir string)
UseFilesystem has porter's context use the OS filesystem instead of an in-memory filesystem Returns the test directory, and the temp porter home directory.