util

package
v1.14.3 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2020 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NpmDir   = "node_modules"
	SetupDir = ".setup"
)

Variables

View Source
var (
	PyEnv     = filepath.Join(SetupDir, "venv")
	GoLinter  = filepath.Join(SetupDir, "golangci-lint")
	Terraform = filepath.Join(SetupDir, "terraform")

	PyTargets = []string{
		"internal/compliance/remediation_aws",
		"internal/compliance/policy_engine",
		"internal/log_analysis/rules_engine",
	}
)
View Source
var MaxWorkers = func() int {
	n := runtime.NumCPU()

	if IsRunningInCI() {
		return n
	}

	if n > 1 {
		return n - 1
	}
	return 1
}()

MaxWorkers limits CPU-intensive operations depending on the environment.

Functions

func CommitSha added in v1.14.0

func CommitSha() string

Returns short commit string. For example, "64391f1e"

func IsRunningInCI

func IsRunningInCI() bool

Returns true if the mage command is running inside the CI environment

func MustReadFile

func MustReadFile(path string) []byte

Wrapper around ioutil.ReadFile, logging errors as fatal.

func MustWalk

func MustWalk(root string, handler func(string, os.FileInfo) error)

Wrapper around filepath.Walk, logging errors as fatal.

func MustWriteFile

func MustWriteFile(path string, data []byte)

Wrapper around ioutil.WriteFile, creating the parent dirs if needed and logging errors as fatal.

func NodePath

func NodePath(binary string) string

Path to a node binary

func ParseTemplate

func ParseTemplate(path string, out interface{}) error

Parse a CloudFormation template and unmarshal into the out parameter. The caller can pass map[string]interface{} or a struct if the format is known.

Short-form functions like "!If" and "!Sub" will be replaced with "Fn::" objects.

func PipPath

func PipPath(lib string) string

Path to a pip binary

func PublicAssetsBucket

func PublicAssetsBucket(region string) string

The name of the bucket containing published Panther releases

func RunTask

func RunTask(results chan<- TaskResult, name string, task func() error)

Ugly task queue hack to limit concurrent tasks

func RunWithCapturedOutput

func RunWithCapturedOutput(cmd string, args ...string) error

Run a command, capturing stdout and stderr unless the command errors or we're in verbose mode.

This is helpful for tools which print unwanted info to stderr even when successful or, conversely, tools which output failing tests to stdout that we want to show even in non-verbose mode.

Both outputs will be printed if the command returns an error.

Similar to sh.Run(), except sh.Run() only hides stdout in non-verbose mode.

func SamDeploy

func SamDeploy(stack, path string, params ...string) error

Deploy CloudFormation template directly with SAM.

func SamPackage

func SamPackage(region, templatePath, bucket string) (string, error)

Package resources in S3 and return the path to the modified CloudFormation template.

This uses "sam package" to be compatible with SAR, which is also more complete and robust than "aws cloudformation package"

The bucket name can be blank if no S3 bucket is actually needed (e.g. bootstrap stack).

func Semver added in v1.14.0

func Semver() string

Returns semantic version (from VERSION file). For example, "1.14.0-RC"

func UploadFileToS3

func UploadFileToS3(log *zap.SugaredLogger, uploader *s3manager.Uploader, path, bucket, key string) (*s3manager.UploadOutput, error)

Upload a local file to S3.

func WaitForTasks

func WaitForTasks(log *zap.SugaredLogger, results chan TaskResult, start, end, total int) error

Wait for the given number of goroutines to finish, logging results as they come in.

This can be invoked multiple times to track progress over many parallel chunks of work:

"start" is the first message number to show in the output
"end" is the last message number to show in the output
"total" is the total number of tasks (across all invocations)

This will consume exactly (end - start) + 1 messages in the channel.

Returns a combined error message at the end if there were any failures.

Types

type TaskResult

type TaskResult struct {
	Summary string
	Err     error
}

Track results when executing similar tasks in parallel

Jump to

Keyboard shortcuts

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