options

package
v0.13.0 Latest Latest
Warning

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

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

Documentation

Overview

Package options some common options for cli

Index

Constants

View Source
const (
	// LinesCoverageMetric coverage lines rule.
	LinesCoverageMetric = "lines-coverage"
	// BranchesCoverageMetric coverage branches rule.
	BranchesCoverageMetric = "branches-coverage"
	// PassedTestsRateMetric test result passed rate rule.
	PassedTestsRateMetric = "passed-tests-rate"
)
View Source
const (
	PathKtnSettingCli = "ktn-task"
)

Variables

View Source
var AutomatedTestResultDefaultParser = map[report.ReportType]report.ReportParser{report.TypeJunitXml: &report.JunitParser{}}

AutomatedTestResultDefaultParser AutomatedTestResult default parser

Functions

func NotEmptyKeyValueOptionValidation

func NotEmptyKeyValueOptionValidation(path *field.Path, option KeyValueListOption) (errs field.ErrorList)

NotEmptyKeyValueOptionValidation require to have at least one key/value pair

func RegisterFlags

func RegisterFlags(obj interface{}, flags *pflag.FlagSet)

RegisterFlags register flags

func RegisterSetup

func RegisterSetup(obj interface{}, ctx context.Context, cmd *cobra.Command, args []string) (err error)

RegisterSetup register setup function

func RequiredKeyValueOptionValidation

func RequiredKeyValueOptionValidation(path *field.Path, option KeyValueListOption) (errs field.ErrorList)

RequiredKeyValueOptionValidation requires a non-empty values for key and value in all pairs for KeyValueOption

func ValuesValidationOptionsFrom

func ValuesValidationOptionsFrom(ctx context.Context) ([]pkgargs.ValuesValidateOption, bool)

ValuesValidationOptionsFrom returns the value of the envValuesValidationKey key on the ctx

func WithValuesValidationOpts

func WithValuesValidationOpts(parent context.Context, opts []pkgargs.ValuesValidateOption) context.Context

WithValuesValidationOpts returns a copy of parent in which the []ValuesValidateOption is set

Types

type CLIPathOption

type CLIPathOption struct {
	// CLIPath direct path for CLI
	// used to store the default value
	// i.e /bin/helm
	CLIPath string
	// FlagName to be used to store
	FlagName string
}

CLIPathOption adds a generic option to store different cli paths

func (*CLIPathOption) AddFlags

func (p *CLIPathOption) AddFlags(flags *pflag.FlagSet)

AddFlags adds flags for option

func (*CLIPathOption) Execute

func (p *CLIPathOption) Execute(ctx context.Context, args ...string) ([]string, error)

Execute executes code given a context

func (*CLIPathOption) Validate

func (p *CLIPathOption) Validate(path *field.Path) (errs field.ErrorList)

Validate if values are given

type CodeLinterOption

type CodeLinterOption struct {
	v1alpha1.CodeLintResult `json:",inline"`

	QualityGateOption
	QualityGateRulesOption
}

CodeLinterOption quality gate options for tasks of codeLinter type

func (*CodeLinterOption) AddFlags

func (c *CodeLinterOption) AddFlags(flags *pflag.FlagSet)

AddFlags add flags to options

func (*CodeLinterOption) Setup

func (c *CodeLinterOption) Setup(ctx context.Context, cmd *cobra.Command, args []string) (err error)

Setup init quality gate rules from args

func (*CodeLinterOption) Validate

func (c *CodeLinterOption) Validate(path *field.Path) (errs field.ErrorList)

Validate validate params

func (*CodeLinterOption) ValidateQualityGate

func (c *CodeLinterOption) ValidateQualityGate(ctx context.Context) (errs field.ErrorList)

func (*CodeLinterOption) WriteResult

func (c *CodeLinterOption) WriteResult(err error, w io.Writer)

WriteResult save quality gate result

type CommandOption

type CommandOption struct {
	Command string
}

CommandOption describe command option

func (*CommandOption) AddFlags

func (m *CommandOption) AddFlags(flags *pflag.FlagSet)

AddFlags add flags to options

func (*CommandOption) Validate

func (m *CommandOption) Validate(path *field.Path) (errs field.ErrorList)

Validate check if command is empty

type ContainerImagesOption

type ContainerImagesOption struct {
	ContainerImages []string
	Type            artifacts.ArtifactType
	ResultPath      string
	// contains filtered or unexported fields
}

ContainerImagesOption describe container images option

func (*ContainerImagesOption) AddFlags

func (m *ContainerImagesOption) AddFlags(flags *pflag.FlagSet)

AddFlags add flags for ContainerImageOption

func (*ContainerImagesOption) GetParseError

func (m *ContainerImagesOption) GetParseError() field.ErrorList

GetParseError returns references of the container-images.

func (*ContainerImagesOption) GetReferences

func (m *ContainerImagesOption) GetReferences() []artifacts.URI

GetReferences returns references of the container-images.

func (*ContainerImagesOption) SetTagRequired

func (m *ContainerImagesOption) SetTagRequired(required bool) *ContainerImagesOption

SetTagRequired set tag is not an empty tag.

func (*ContainerImagesOption) SetValueRequired

func (m *ContainerImagesOption) SetValueRequired(required bool) *ContainerImagesOption

SetValueRequired set container-images as a required flag.

func (*ContainerImagesOption) SetWithoutDigest

func (m *ContainerImagesOption) SetWithoutDigest(required bool) *ContainerImagesOption

SetWithoutDigest set tag is not an empty tag.

func (*ContainerImagesOption) Setup

func (m *ContainerImagesOption) Setup(ctx context.Context, _ *cobra.Command, args []string) (err error)

Setup init container images from args

func (*ContainerImagesOption) Validate

func (m *ContainerImagesOption) Validate(path *field.Path) (errs field.ErrorList)

Validate check if the container images is valid

func (*ContainerImagesOption) ValidateReferences

func (m *ContainerImagesOption) ValidateReferences(path *field.Path, references []artifacts.URI) (errs field.ErrorList)

ValidateReferences check if the container images is valid

func (*ContainerImagesOption) WriteResult

func (m *ContainerImagesOption) WriteResult(artfactList []artifacts.URI) (err error)

WriteResult writes a result to the provided path if given

type ContextOption

type ContextOption struct {
	Context               string
	ValidateContextExists bool
}

ContextOption describe the work dir to execute the command

func (*ContextOption) AddFlags

func (p *ContextOption) AddFlags(flags *pflag.FlagSet)

AddFlags add flags to options

func (*ContextOption) Validate

func (p *ContextOption) Validate(path *field.Path) (errs field.ErrorList)

Validate check if command is empty

type DependencyReposOption

type DependencyReposOption struct {
	DependencyRepos []string
	FlagName        string
}

DependencyReposOption describe dependency repo option

func (*DependencyReposOption) Setup

func (m *DependencyReposOption) Setup(ctx context.Context, _ *cobra.Command, args []string) (err error)

Setup init dependency repositories from args

func (*DependencyReposOption) Validate

func (m *DependencyReposOption) Validate(path *field.Path) (errs field.ErrorList)

Validate check if the dependency repository is valid

type DeployRepositoryOption

type DeployRepositoryOption struct {
	// DeployRepository deploy registry url
	DeployRepository string

	// Required define DeployRepository is required
	Required bool

	// DeployArgs save deloy agrs.
	DeployArgs map[string]string
}

DeployRepositoryOption describe deploy repo option

func (*DeployRepositoryOption) AddFlags

func (m *DeployRepositoryOption) AddFlags(flags *pflag.FlagSet)

AddFlags add flags to options

func (*DeployRepositoryOption) Setup

func (m *DeployRepositoryOption) Setup(ctx context.Context, _ *cobra.Command, args []string) (err error)

Setup init deploy args from args

func (*DeployRepositoryOption) Validate

func (m *DeployRepositoryOption) Validate(path *field.Path) (errs field.ErrorList)

Validate check if the deploy repository is valid

type EnvFlagsOption

type EnvFlagsOption struct {
	EnvFlags map[string]string
}

EnvFlagsOption describe env flags option

func (*EnvFlagsOption) Setup

func (p *EnvFlagsOption) Setup(ctx context.Context, cmd *cobra.Command, args []string) (err error)

Setup defines how to start with env-flags option

func (*EnvFlagsOption) WriteEnvFile

func (p *EnvFlagsOption) WriteEnvFile(filename string) error

WriteEnvFile writes env variables to target file

type ExitCodeOption

type ExitCodeOption struct {
	// ExitCodePath direct path for exitCodefile
	ExitCodePath string
	// FlagName to be used to store
	FlagName string
}

ExitCodeOption adds a generic option to store different cli paths

func (*ExitCodeOption) AddFlags

func (p *ExitCodeOption) AddFlags(flags *pflag.FlagSet)

AddFlags adds flags for option

func (*ExitCodeOption) Succeed

func (m *ExitCodeOption) Succeed() (bool, string, error)

Succeed judging whether the execution status is successful or not according to the exit file.

type FlagRegister

type FlagRegister interface {
	AddFlags(flags *pflag.FlagSet)
}

FlagRegister flag register interface

type KatanomiPathOption

type KatanomiPathOption struct {
	SharePath  string
	BinPath    string
	ConfigPath string
}

KatanomiPathOption describe katanomi path option

func (*KatanomiPathOption) AddFlags

func (p *KatanomiPathOption) AddFlags(flags *pflag.FlagSet)

AddFlags add flags to options

type KeyValueListOption

type KeyValueListOption struct {
	// FlagName used to declare the flag name when interpreting arguments
	// "abc" will expect "--abc key1=value1 key2=value2" argument
	FlagName string
	// KeyValues stored after step
	KeyValues map[string]string

	// Validations stores a list of validation functions to be executed
	// during validation
	Validations []KeyValueOptionValidationFunc
}

KeyValueListOption describe a key=value array set

func (*KeyValueListOption) AddValidation

func (m *KeyValueListOption) AddValidation(validationFunc ...KeyValueOptionValidationFunc)

AddValidation adds a validation function for this option

func (*KeyValueListOption) Setup

func (p *KeyValueListOption) Setup(ctx context.Context, cmd *cobra.Command, args []string) (err error)

func (*KeyValueListOption) Validate

func (m *KeyValueListOption) Validate(path *field.Path) (errs field.ErrorList)

Validate validates with all validaton functions

type KeyValueOptionValidationFunc

type KeyValueOptionValidationFunc func(path *field.Path, option KeyValueListOption) (errs field.ErrorList)

KeyValueOptionValidationFunc simple validation function to check the whole

type Log

type Log struct {
	Logger *zap.SugaredLogger
	// contains filtered or unexported fields
}

Log Log related options

func (*Log) AddFlags

func (opts *Log) AddFlags(flags *pflag.FlagSet)

AddFlags add flags to options

func (*Log) Enabled

func (opts *Log) Enabled(l zapcore.Level) bool

Enabled decides whether a given logging level is enabled

func (*Log) Setup

func (opts *Log) Setup(ctx context.Context, cmd *cobra.Command, args []string)

Setup set up the Log

type MetricType

type MetricType string

MetricType define quaity gate rules

type QualityGateOption

type QualityGateOption struct {
	QualityGate bool
	FlagName    string
}

QualityGateOption describe quality gate option

func (*QualityGateOption) AddFlags

func (m *QualityGateOption) AddFlags(flags *pflag.FlagSet)

AddFlags add flags to options

type QualityGateRulesOption

type QualityGateRulesOption struct {
	QualityGateRules map[string]string
	FlagName         string
}

QualityGateRulesOption describe quality gate rules option

func (*QualityGateRulesOption) GetRuleValue

func (m *QualityGateRulesOption) GetRuleValue(key string) (value string, exist bool)

GetRuleValue get rule value

func (*QualityGateRulesOption) GetRuleValueFloat

func (m *QualityGateRulesOption) GetRuleValueFloat(key string) (value float64, exist bool, err error)

GetRuleValueFloat get rule value as float64

func (*QualityGateRulesOption) GetRuleValueInt

func (m *QualityGateRulesOption) GetRuleValueInt(key string) (value int, exist bool, err error)

GetRuleValueInt get rule value as int

func (*QualityGateRulesOption) Setup

func (m *QualityGateRulesOption) Setup(ctx context.Context, _ *cobra.Command, args []string) (err error)

Setup init quality gate rules from args

type RESTClientGetterOption added in v0.10.0

type RESTClientGetterOption struct {
	// ConfigFlags for interface of genericclioptions.ConfigFlags
	ConfigFlag genericclioptions.RESTClientGetter
}

RESTClientGetterOption is the generic client option for k8s client

func (*RESTClientGetterOption) GetClusterToken added in v0.10.0

func (m *RESTClientGetterOption) GetClusterToken(ctx context.Context) (string, error)

GetClusterToken get token for kubeconfig.

func (*RESTClientGetterOption) GetNamespace added in v0.10.0

func (m *RESTClientGetterOption) GetNamespace() (string, error)

GetNamespace get namespace from environment or incluster kubeconfig

func (*RESTClientGetterOption) Setup added in v0.10.0

func (m *RESTClientGetterOption) Setup(ctx context.Context, cmd *cobra.Command, args []string) (err error)

Setup is the setup function for RESTClientGetterOption

type ReportPathOption

type ReportPathOption struct {
	ReportPath string
	FlagName   string
}

ReportPathOption describe report path option

func (*ReportPathOption) AddFlags

func (m *ReportPathOption) AddFlags(flags *pflag.FlagSet)

AddFlags add flags to options

func (*ReportPathOption) Validate

func (m *ReportPathOption) Validate(path *field.Path) (errs field.ErrorList)

Validate check if command is empty

type ReportPathsByTypesOption

type ReportPathsByTypesOption struct {
	ReportPathByTypes map[report.ReportType]string
	ReportParsers     map[report.ReportType]report.ReportParser
}

ReportPathsByTypesOption is the option for multiple report types with its report paths

func (*ReportPathsByTypesOption) Setup

func (r *ReportPathsByTypesOption) Setup(ctx context.Context, cmd *cobra.Command, args []string) (err error)

Setup defines how to start up with report-configs option

func (*ReportPathsByTypesOption) TestSummariesByType

func (r *ReportPathsByTypesOption) TestSummariesByType(parentPath string) (summaries report.SummariesByType,
	err error)

TestSummariesByType gets test summaries by report type

func (*ReportPathsByTypesOption) Validate

func (m *ReportPathsByTypesOption) Validate(path *field.Path) (errs field.ErrorList)

Validate verify that the type is supported.

type ReportTypeOption

type ReportTypeOption struct {
	ReportType string
	Required   bool

	FlagName      string
	SupportedType map[report.ReportType]report.ReportParser
}

ReportTypeOption describe report type option

func (*ReportTypeOption) AddFlags

func (m *ReportTypeOption) AddFlags(flags *pflag.FlagSet)

AddFlags add flags to options

func (*ReportTypeOption) Parse

func (m *ReportTypeOption) Parse(path string) (result interface{}, err error)

Parse parse according to the message type value row, if the message type is empty, perform any operation.

func (*ReportTypeOption) Setup

func (m *ReportTypeOption) Setup(ctx context.Context, cmd *cobra.Command, args []string) (err error)

Setup perform the necessary initialization

func (*ReportTypeOption) Validate

func (m *ReportTypeOption) Validate(path *field.Path) (errs field.ErrorList)

Validate verify that the type is supported.

type ResultPathOption

type ResultPathOption struct {
	// FlagName defines the name when adding the flag
	// defaults to result-path
	FlagName string
	// ResultPath stores the value read from the flag
	ResultPath string
}

ResultPathOption describe result path option

func (*ResultPathOption) AddFlags

func (p *ResultPathOption) AddFlags(flags *pflag.FlagSet)

AddFlags add flags to options

type ResultsOCIContainerImageBuildURLOption

type ResultsOCIContainerImageBuildURLOption struct {
	OciContainerImageBuildUrl string
}

ResultsOCIContainerImageBuildURLOption describe ociContainerImageBuild-url option Deprecated: use ContainerImageOption result store mechanism instead

func (*ResultsOCIContainerImageBuildURLOption) AddFlags

AddFlags add flags to options

type ScanFlagsOption

type ScanFlagsOption struct {
	ScanFlags map[string]string
}

ScanFlagsOption describe scan flags option

func (*ScanFlagsOption) Setup

func (p *ScanFlagsOption) Setup(ctx context.Context, cmd *cobra.Command, args []string) (err error)

type SetupRegister

type SetupRegister interface {
	Setup(ctx context.Context, cmd *cobra.Command, args []string) (err error)
}

SetupRegister setup register interface

type SourcePathOption

type SourcePathOption struct {
	SourcePath string
}

SourcePathOption describe source path option

func (*SourcePathOption) AddFlags

func (p *SourcePathOption) AddFlags(flags *pflag.FlagSet)

AddFlags add flags to options

type ToolImageOption

type ToolImageOption struct {
	ToolImage string
}

ToolImageOption describe tool image option

func (*ToolImageOption) AddFlags

func (p *ToolImageOption) AddFlags(flags *pflag.FlagSet)

func (*ToolImageOption) Validate

func (p *ToolImageOption) Validate(path *field.Path) (errs field.ErrorList)

Validate check if command is empty

type UnitTestQuaityGateOption

type UnitTestQuaityGateOption struct {
	QualityGateOption
	QualityGateRulesOption
}

UnitTestQuaityGateOption unittest quaity gate option

func (*UnitTestQuaityGateOption) AddFlags

func (m *UnitTestQuaityGateOption) AddFlags(flags *pflag.FlagSet)

AddFlags add flags to options

func (*UnitTestQuaityGateOption) Setup

func (m *UnitTestQuaityGateOption) Setup(ctx context.Context, cmd *cobra.Command, args []string) (err error)

Setup init quality gate rules from args

func (*UnitTestQuaityGateOption) Validate

func (m *UnitTestQuaityGateOption) Validate(path *field.Path) (errs field.ErrorList)

Validate verify that the input rules are legal.

func (*UnitTestQuaityGateOption) ValidateQualityGate

func (m *UnitTestQuaityGateOption) ValidateQualityGate(ctx context.Context, testResults *v1alpha1.UnitTestsResult) (errs field.ErrorList)

ValidateQualityGate verify that the UnitTestsResult satisfy the quality gate.

type UnitTestReportOption

type UnitTestReportOption struct {
	ReportPathOption
	ReportTypeOption

	ResultPathOption
}

UnitTestReportOption unittest report option

func (*UnitTestReportOption) AddFlags

func (m *UnitTestReportOption) AddFlags(flags *pflag.FlagSet)

AddFlags add flags to options

func (*UnitTestReportOption) ParseReport

func (m *UnitTestReportOption) ParseReport() (interface{}, error)

ParseReport parse report

func (*UnitTestReportOption) Setup

func (m *UnitTestReportOption) Setup(ctx context.Context, cmd *cobra.Command, args []string) (err error)

Setup init quality gate rules from args

func (*UnitTestReportOption) Validate

func (m *UnitTestReportOption) Validate(path *field.Path) (errs field.ErrorList)

func (*UnitTestReportOption) WriteResult

func (c *UnitTestReportOption) WriteResult(obj interface{}) error

WriteResult save data to result path

type VulnScanMetricsOption added in v0.12.0

type VulnScanMetricsOption struct {
	// FlagName is the name of the flag
	FlagName string

	// ResultLimit is the maximum number of metrics results to write
	ResultLimit int
}

VulnScanMetricsOption describe quality gate option

func (*VulnScanMetricsOption) AddFlags added in v0.12.0

func (m *VulnScanMetricsOption) AddFlags(flags *pflag.FlagSet)

AddFlags add flags to options

func (*VulnScanMetricsOption) Validate added in v0.12.0

func (m *VulnScanMetricsOption) Validate(path *field.Path) (errs field.ErrorList)

Validate check if result limit is greater than 0

type VulnScanOption

VulnScanOption quality gate options for tasks of vulnerability type

func (*VulnScanOption) AddFlags

func (c *VulnScanOption) AddFlags(flags *pflag.FlagSet)

AddFlags add flags to options

func (*VulnScanOption) Setup

func (c *VulnScanOption) Setup(ctx context.Context, cmd *cobra.Command, args []string) (err error)

Setup init quality gate rules from args

func (*VulnScanOption) Validate

func (c *VulnScanOption) Validate(path *field.Path) (errs field.ErrorList)

Validate validate params

func (*VulnScanOption) ValidateQualityGate

func (c *VulnScanOption) ValidateQualityGate(ctx context.Context) (errs field.ErrorList)

func (*VulnScanOption) WriteMetricsResult

func (c *VulnScanOption) WriteMetricsResult(err error, w io.Writer)

WriteMetricsResult save metrics result

func (*VulnScanOption) WriteResult

func (c *VulnScanOption) WriteResult(err error, w io.Writer)

WriteResult save quality gate result

Jump to

Keyboard shortcuts

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