Documentation ¶
Index ¶
- Constants
- Variables
- func AccountID(config aws.Config) string
- func ByteCountSI(b int64) string
- func CommitSha() string
- func EcrRepoURI(accountID, region, repoName string) string
- func IsRunningInCI() bool
- func MustReadFile(path string) []byte
- func MustWalk(root string, handler func(string, os.FileInfo) error)
- func MustWriteFile(path string, data []byte)
- func NodePath(binary string) string
- func ParseTemplate(path string, out interface{}) error
- func PipPath(lib string) string
- func PublicAssetsBucket(region string) string
- func RunTask(results chan<- TaskResult, name string, task func() error)
- func RunWithCapturedOutput(cmd string, args ...string) error
- func S3ObjectURL(region, bucket, key string) string
- func S3URI(bucket, key string) string
- func Semver() string
- func URLSuffix(region string) string
- func WaitForTasks(log *zap.SugaredLogger, results chan TaskResult, start, end, total int) error
- type TaskResult
Constants ¶
const ( NpmDir = "node_modules" SetupDir = ".setup" )
Variables ¶
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", } )
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 AccountID ¶ added in v1.16.0
Returns the 12-digit account ID associated with the current session.
The result will be cached for subsequent queries.
func ByteCountSI ¶ added in v1.16.0
Returns human-readable byte size, e.g. "5.1 MB" or "1.2 kB" From https://yourbasic.org/golang/formatting-byte-size-to-human-readable-format
func CommitSha ¶ added in v1.14.0
func CommitSha() string
Returns short commit string. For example, "64391f1e"
func EcrRepoURI ¶ added in v1.16.0
Returns ECR image repo uri
func IsRunningInCI ¶
func IsRunningInCI() bool
Returns true if the mage command is running inside the CI environment
func MustReadFile ¶
Wrapper around ioutil.ReadFile, logging errors as fatal.
func MustWriteFile ¶
Wrapper around ioutil.WriteFile, creating the parent dirs if needed and logging errors as fatal.
func ParseTemplate ¶
Parse a CloudFormation template and unmarshal into the out parameter. The out parameter must be a map or a pointer to a struct.
Short-form functions like "!If" and "!Sub" will be replaced with "Fn::" objects.
func PublicAssetsBucket ¶
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 ¶
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 S3ObjectURL ¶ added in v1.16.0
Returns S3 URL using virtual addressing ("BUCKET.s3.REGION.SUFFIX/KEY")
func Semver ¶ added in v1.14.0
func Semver() string
Returns semantic version (from VERSION file). For example, "1.14.0-RC"
func URLSuffix ¶ added in v1.16.0
Return the URL suffix for the partition associated with the given region.
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 ¶
Track results when executing similar tasks in parallel