utils

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_JSON_INDENT_STRING = "    "
	DEFAULT_JSON_PREFIX_STRING = ""
)
View Source
const ISO8601_TIME_SEPARATOR = 'T'
View Source
const REGEX_ISO_8601_DATE = "[0-9]{4}-[0-9]{2}-[0-9]{2}"
View Source
const REGEX_ISO_8601_DATE_TIME = "[0-9]{4}-[0-9]{2}-[0-9]{2}T([0-9]{2}:){2}[0-9]{2}[+|-][0-9]{2}:[0-9]{2}"

Currently, truncate

Variables

This section is empty.

Functions

func CalcLineAndCharacterPos added in v0.15.0

func CalcLineAndCharacterPos(data []byte, offset int64) (lineNum int, charNum int)

func CompileRegex added in v0.14.0

func CompileRegex(test string) (expression *regexp.Regexp, err error)

func EncodeAnyToDefaultIndentedJSONStr added in v0.14.0

func EncodeAnyToDefaultIndentedJSONStr(any interface{}) (outputBuffer bytes.Buffer, err error)

func EncodeAnyToIndentedJSONInt added in v0.14.0

func EncodeAnyToIndentedJSONInt(any interface{}, numSpaces int) (outputBuffer bytes.Buffer, err error)

func EncodeAnyToIndentedJSONStr added in v0.14.0

func EncodeAnyToIndentedJSONStr(any interface{}, indent string) (outputBuffer bytes.Buffer, err error)

NOTE: Using this custom encoder avoids the json.Marshal() default behavior of encoding utf8 characters such as: '@', '<', '>', etc. as unicode.

func FindVerifyConfigFileAbsPath

func FindVerifyConfigFileAbsPath(logger *log.MiniLogger, filename string) (absFilename string, err error)

func GenerateIndentString added in v0.14.0

func GenerateIndentString(length int) (prefix string)

Creates strings of spaces based upon provided integer length (e.g., the --indent <length> flag)

func GetCallerFunctionName added in v0.14.0

func GetCallerFunctionName(skip int) (fxName string)

func IsJsonMapType added in v0.14.0

func IsJsonMapType(any interface{}) (isMapType bool)

func IsJsonSliceType added in v0.14.0

func IsJsonSliceType(any interface{}) (isSliceType bool)

func IsValidJsonRaw

func IsValidJsonRaw(test []byte) bool

func MarshalAnyToFormattedJsonString added in v0.14.0

func MarshalAnyToFormattedJsonString(any interface{}) (string, error)

NOTE: simple wrapper method on json package to standardize parms WARNING: By default, json.Marshal() methods will use a unicode encoding which will encode utf8 characters such as: '@', '<', '>', etc.

func MarshalStructToJsonMap added in v0.14.0

func MarshalStructToJsonMap(any interface{}) (mapOut map[string]interface{}, err error)

func PrintlnJSONObject added in v0.15.0

func PrintlnJSONObject(any interface{})

func PrintlnLabeledJSONObject added in v0.15.0

func PrintlnLabeledJSONObject(any interface{}, label string)

func TruncateTimeStampISO8601Date added in v0.14.0

func TruncateTimeStampISO8601Date(fullTimestamp string) (date string, err error)

TODO we SHOULD normalize the timestamp to Z (0)

func ValidateISO8601TimestampISO8601DateTime added in v0.14.0

func ValidateISO8601TimestampISO8601DateTime(timestamp string, regex string) (valid bool)

Validates a complete Date-Time ISO8601 timestamp TODO verify it works for data, date-time, date-time-timezone formats

func WriteAnyAsEncodedJSONInt added in v0.14.0

func WriteAnyAsEncodedJSONInt(writer io.Writer, any interface{}, numSpaces int) (outputBuffer bytes.Buffer, err error)

Types

type CommandFlags

type CommandFlags struct {
	// Not flags, but "main" package var copies
	Project    string
	Binary     string
	Version    string
	WorkingDir string
	ExecDir    string

	// Configurations
	ConfigSchemaFile           string
	ConfigCustomValidationFile string
	ConfigLicensePolicyFile    string

	// persistent flags (common to all commands)
	PersistentFlags PersistentCommandFlags

	// Command-specific flags
	CustomValidationOptions CustomValidationFlags
	DiffFlags               DiffCommandFlags
	LicenseFlags            LicenseCommandFlags
	ResourceFlags           ResourceCommandFlags
	SchemaFlags             SchemaCommandFlags
	ValidateFlags           ValidateCommandFlags
	VulnerabilityFlags      VulnerabilityCommandFlags
	StatsFlags              StatsCommandFlags
	TrimFlags               TrimCommandFlags
	PatchFlags              PatchCommandFlags

	// Misc flags
	LogOutputIndentCallstack bool // Log indent
}
var GlobalFlags CommandFlags

Globals

func (*CommandFlags) String

func (flags *CommandFlags) String() string

format and output the MyFlags struct as a string using Go's Stringer interface

type CustomValidationFlags

type CustomValidationFlags struct {
	Composition bool
	License     bool
	Properties  bool
}

type DiffCommandFlags added in v0.12.0

type DiffCommandFlags struct {
	Colorize    bool
	RevisedFile string
}

type LicenseCommandFlags added in v0.10.0

type LicenseCommandFlags struct {
	Summary      bool
	ListLineWrap bool
}

type PatchCommandFlags added in v0.15.0

type PatchCommandFlags struct {
	PatchFile    string
	OutputFormat string // NOTE: needed to overcome Cobra limitation when diff. commands have diff. default values
}

type PersistentCommandFlags added in v0.12.0

type PersistentCommandFlags struct {
	Quiet        bool // suppresses all non-essential (informational) output from a command. Overrides any other log-level commands.
	Trace        bool // trace logging
	Debug        bool // debug logging
	InputFile    string
	OutputFile   string // TODO: TODO: Note: not used by `validate` command, which emits a warning if supplied
	OutputFormat string // e.g., "txt", "csv"", "md" (markdown) (normalized to lowercase)
	OutputIndent uint8
}

NOTE: These flags are shared by both the list and policy subcommands

func (PersistentCommandFlags) GetOutputIndentInt added in v0.14.0

func (persistentFlags PersistentCommandFlags) GetOutputIndentInt() int

type ResourceCommandFlags added in v0.14.0

type ResourceCommandFlags struct {
	ResourceType string
}

func NewResourceCommandFlags added in v0.14.0

func NewResourceCommandFlags(resourceType string) ResourceCommandFlags

type SchemaCommandFlags added in v0.14.0

type SchemaCommandFlags struct {
}

type StatsCommandFlags added in v0.14.0

type StatsCommandFlags struct {
}

type TrimCommandFlags added in v0.14.0

type TrimCommandFlags struct {
	RawKeys   string
	RawPaths  string
	Keys      []string
	FromPaths []string
}

TODO: write a "parse" method for the struct (i.e., from "raw" to slice)

type ValidateCommandFlags added in v0.11.0

type ValidateCommandFlags struct {
	SchemaVariant        string
	ForcedJsonSchemaFile string
	// Uses custom validation flags if "true"; defaults to config. "custom.json"
	CustomValidation bool
	// error result processing
	MaxNumErrors              int
	MaxErrorDescriptionLength int
	ColorizeErrorOutput       bool
	ShowErrorValue            bool
}

type VulnerabilityCommandFlags added in v0.11.0

type VulnerabilityCommandFlags struct {
	Summary bool
}

Jump to

Keyboard shortcuts

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