Documentation ¶
Overview ¶
Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the AWS Customer Agreement (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at
http://aws.amazon.com/agreement/
Package pluginutil implements some common functions shared by multiple plugins.
Index ¶
- Constants
- Variables
- func CreateScriptFile(log log.T, scriptPath string, runCommand []string) (err error)
- func DeleteDirectory(log log.T, dirName string)
- func DownloadFileFromSource(log log.T, source string, sourceHash string, sourceHashType string) (artifact.DownloadOutput, error)
- func GetS3Config() *s3util.Manager
- func GetShellArguments() []string
- func GetShellCommand() string
- func GetStatus(exitCode int, cancelFlag task.CancelFlag) contracts.ResultStatus
- func LoadParametersAsList(log log.T, prop interface{}) ([]interface{}, contracts.PluginResult)
- func PersistPluginInformationToCurrent(log log.T, pluginName string, config contracts.Configuration, ...)
- func ReadPrefix(input io.Reader, maxLength int, truncatedSuffix string) (out string, err error)
- func ValidateExecutionTimeout(log log.T, input interface{}) int
- type CommandExecuter
- type DefaultPlugin
- type MockDefaultPlugin
- type PluginConfig
- type S3Uploader
- type UploadOutputToS3BucketExecuter
Constants ¶
const ( // RunCommandScriptName is the script name where all downloaded or provided commands will be stored RunCommandScriptName = "_script.sh" ExitCodeTrap = "" CommandStoppedPreemptivelyExitCode = 137 // Fatal error (128) + signal for SIGKILL (9) = 137 )
Variables ¶
var S3RegionUSStandard = "us-east-1"
S3RegionUSStandard is a standard S3 Region used to upload output related documents.
var ShellArgs = []string{"-c"}
var ShellCommand = "sh"
Functions ¶
func CreateScriptFile ¶
CreateScriptFile creates a script containing the given commands.
func DeleteDirectory ¶
DeleteDirectory deletes a directory and all its content.
func DownloadFileFromSource ¶
func DownloadFileFromSource(log log.T, source string, sourceHash string, sourceHashType string) (artifact.DownloadOutput, error)
DownloadFileFromSource downloads file from source
func GetS3Config ¶
GetS3Config returns the S3 config used for uploading output files to S3
func GetShellArguments ¶
func GetShellArguments() []string
func GetShellCommand ¶
func GetShellCommand() string
func GetStatus ¶
func GetStatus(exitCode int, cancelFlag task.CancelFlag) contracts.ResultStatus
GetStatus returns a ResultStatus variable based on the received exitCode
func LoadParametersAsList ¶
func LoadParametersAsList(log log.T, prop interface{}) ([]interface{}, contracts.PluginResult)
LoadParametersAsList returns properties as a list and appropriate PluginResult if error is encountered
func PersistPluginInformationToCurrent ¶
func PersistPluginInformationToCurrent(log log.T, pluginName string, config contracts.Configuration, res contracts.PluginResult)
PersistPluginInformationToCurrent persists the plugin execution results
func ReadPrefix ¶
ReadPrefix returns the beginning data from a given Reader, truncated to the given limit.
func ValidateExecutionTimeout ¶
ValidateExecutionTimeout validates the supplied input interface and converts it into a valid int value.
Types ¶
type CommandExecuter ¶
type CommandExecuter func(log log.T, workingDir string, stdoutFilePath string, stderrFilePath string, cancelFlag task.CancelFlag, executionTimeout int, commandName string, commandArguments []string) (stdout io.Reader, stderr io.Reader, exitCode int, errs []error)
CommandExecuter is a function that can execute a set of commands.
type DefaultPlugin ¶
type DefaultPlugin struct { // ExecuteCommand is an object that can execute commands. ExecuteCommand CommandExecuter // ExecuteUploadOutputToS3Bucket is an object that can upload command outputs to S3 bucket. ExecuteUploadOutputToS3Bucket UploadOutputToS3BucketExecuter // Uploader is an object that can upload data to s3. Uploader S3Uploader // UploadToS3Sync is true if uploading to S3 should be done synchronously, false for async. UploadToS3Sync bool // StdoutFileName is the name of the file that stores standard output. StdoutFileName string // StderrFileName is the name of the file that stores standard error. StderrFileName string // MaxStdoutLength is the maximum lenght of the standard output returned in the plugin result. // If the output is longer, it will be truncated. The full output will be uploaded to s3. MaxStdoutLength int // MaxStderrLength is the maximum lenght of the standard error returned in the plugin result. MaxStderrLength int // OutputTruncatedSuffix is an optional suffix that is inserted at the end of the truncated stdout/stderr. OutputTruncatedSuffix string }
DefaultPlugin is the type for the default plugin.
func (*DefaultPlugin) UploadOutputToS3Bucket ¶
func (p *DefaultPlugin) UploadOutputToS3Bucket(log log.T, pluginID string, orchestrationDir string, outputS3BucketName string, outputS3KeyPrefix string, useTempDirectory bool, tempDir string, Stdout string, Stderr string) []string
UploadOutputToS3Bucket uploads outputs (if any) to s3
type MockDefaultPlugin ¶
MockDefaultPlugin mocks the default plugin.
func (*MockDefaultPlugin) UploadOutputToS3Bucket ¶
func (m *MockDefaultPlugin) UploadOutputToS3Bucket(log log.T, pluginID string, orchestrationDir string, outputS3BucketName string, outputS3KeyPrefix string, useTempDirectory bool, tempDir string, Stdout string, Stderr string) []string
UploadOutputToS3Bucket is a mocked method that just returns what mock tells it to.
type PluginConfig ¶
type PluginConfig struct { StdoutFileName string StderrFileName string MaxStdoutLength int MaxStderrLength int OutputTruncatedSuffix string }
PluginConfig is used for initializing plugins with default values
func DefaultPluginConfig ¶
func DefaultPluginConfig() PluginConfig
DefaultPluginConfig returns the default values for the plugin
type S3Uploader ¶
type S3Uploader interface { S3Upload(bucketName string, bucketKey string, filePath string) error UploadS3TestFile(log log.T, bucketName, key string) error IsS3ErrorRelatedToAccessDenied(errMsg string) bool IsS3ErrorRelatedToWrongBucketRegion(errMsg string) bool GetS3BucketRegionFromErrorMsg(log log.T, errMsg string) string GetS3ClientRegion() string SetS3ClientRegion(region string) }
S3Uploader is an interface for objects that can upload data to s3.
type UploadOutputToS3BucketExecuter ¶
type UploadOutputToS3BucketExecuter func(log log.T, pluginID string, orchestrationDir string, outputS3BucketName string, outputS3KeyPrefix string, useTempDirectory bool, tempDir string, Stdout string, Stderr string) []string
UploadOutputToS3BucketExecuter is a function that can upload outputs to S3 bucket.