flagutil

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2023 License: Apache-2.0, Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package flagutil contains utilities and interfaces shared between several Prow commands.

Index

Constants

View Source
const (
	DefaultMetricsPort = 9090
	DefaultPProfPort   = 6060
	DefaultHealthPort  = 8081

	DefaultMemoryProfileInterval = 30 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool struct {
	Value    bool
	Explicit bool
}

Bool holds a boolean flag value, tracking whether it was set explicitly.

func (*Bool) IsBoolFlag

func (b *Bool) IsBoolFlag() bool

IsBoolFlag causes golang to consider --foo to mean --foo=true

func (*Bool) Set

func (b *Bool) Set(s string) error

Set the bool according to the string.

func (*Bool) String

func (b *Bool) String() string

String value of the string.

type FlagParameter

type FlagParameter func(options *flagParams)

func DisableThrottlerOptions

func DisableThrottlerOptions() FlagParameter

DisableThrottlerOptions suppresses the presence of throttler-related flags, effectively disallowing external users to parametrize default throttling behavior. This is useful mostly when a program creates multiple GH clients with different behavior.

func ThrottlerDefaults

func ThrottlerDefaults(hourlyTokens, allowedBursts int) FlagParameter

ThrottlerDefaults allows to customize the default values of flags that control the throttler behavior. Setting `hourlyTokens` to zero disables throttling by default.

type GitHubEnablementOptions

type GitHubEnablementOptions struct {
	// contains filtered or unexported fields
}

GitHubEnablementOptions allows enable/disable functionality on a github org or org/repo level. If either EnabledOrgs or EnabledRepos is set, only org/repos in those are allowed, otherwise everything that is not in DisabledOrgs or DisabledRepos is allowed.

func (*GitHubEnablementOptions) AddFlags

func (o *GitHubEnablementOptions) AddFlags(fs *flag.FlagSet)

func (*GitHubEnablementOptions) EnablementChecker

func (o *GitHubEnablementOptions) EnablementChecker() func(org, repo string) bool

func (*GitHubEnablementOptions) Validate

func (o *GitHubEnablementOptions) Validate(_ bool) error

type GitHubOptions

type GitHubOptions struct {
	Host string

	TokenPath         string
	AllowAnonymous    bool
	AllowDirectAccess bool
	AppID             string
	AppPrivateKeyPath string

	ThrottleHourlyTokens int
	ThrottleAllowBurst   int

	OrgThrottlers Strings
	// contains filtered or unexported fields
}

GitHubOptions holds options for interacting with GitHub.

Set AllowAnonymous to be true if you want to allow anonymous github access. Set AllowDirectAccess to be true if you want to suppress warnings on direct github access (without ghproxy).

func (*GitHubOptions) AddCustomizedFlags

func (o *GitHubOptions) AddCustomizedFlags(fs *flag.FlagSet, paramFuncs ...FlagParameter)

AddCustomizedFlags injects GitHub options into the given FlagSet. Behavior can be customized via the functional options.

func (*GitHubOptions) AddFlags

func (o *GitHubOptions) AddFlags(fs *flag.FlagSet)

AddFlags injects GitHub options into the given FlagSet

func (*GitHubOptions) GitClient

func (o *GitHubOptions) GitClient(dryRun bool) (client *git.Client, err error)

GitClient returns a Git client.

func (*GitHubOptions) GitClientFactory

func (o *GitHubOptions) GitClientFactory(cookieFilePath string, cacheDir *string, dryRun bool) (gitv2.ClientFactory, error)

GitClientFactory returns git.ClientFactory. Passing non-empty cookieFilePath will result in git ClientFactory to work with Gerrit. TODO(chaodaiG): move this logic to somewhere more appropriate instead of in github.go.

func (*GitHubOptions) GitHubClient

func (o *GitHubOptions) GitHubClient(dryRun bool) (github.Client, error)

GitHubClient returns a GitHub client.

func (*GitHubOptions) GitHubClientWithAccessToken

func (o *GitHubOptions) GitHubClientWithAccessToken(token string) (github.Client, error)

GitHubClientWithAccessToken creates a GitHub client from an access token.

func (*GitHubOptions) GitHubClientWithLogFields

func (o *GitHubOptions) GitHubClientWithLogFields(dryRun bool, fields logrus.Fields) (github.Client, error)

GitHubClientWithLogFields returns a GitHub client with extra logging fields

func (*GitHubOptions) Validate

func (o *GitHubOptions) Validate(bool) error

Validate validates GitHub options. Note that validate updates the GitHubOptions to add default values for TokenPath and graphqlEndpoint.

type GitOptions

type GitOptions struct {
	// contains filtered or unexported fields
}

GitOptions holds options for interacting with git.

func (*GitOptions) AddFlags

func (o *GitOptions) AddFlags(fs *flag.FlagSet)

AddFlags injects Git options into the given FlagSet.

func (*GitOptions) GitClient

func (o *GitOptions) GitClient(userClient github.UserClient, token func() []byte, censor func(content []byte) []byte, dryRun bool) (git.ClientFactory, error)

GitClient creates a new git client.

func (*GitOptions) Validate

func (o *GitOptions) Validate(dryRun bool) error

Validate validates Git options.

type InstrumentationOptions

type InstrumentationOptions struct {
	// MetricsPort is the port which is used to serve metrics
	MetricsPort int
	// PProfPort is the port which is used to serve pprof
	PProfPort int
	// HealthPort is the port which is used to serve liveness and readiness
	HealthPort int

	// ProfileMemory determines if the process should profile memory
	ProfileMemory bool
	// MemoryProfileInterval is the interval at which memory profiles should be dumped
	MemoryProfileInterval time.Duration
}

InstrumentationOptions holds common options which are used across Prow components

func DefaultInstrumentationOptions

func DefaultInstrumentationOptions() InstrumentationOptions

DefaultInstrumentationOptions returns an initialized options struct, mostly for use in tests.

func (*InstrumentationOptions) AddFlags

func (o *InstrumentationOptions) AddFlags(fs *flag.FlagSet)

AddFlags injects common options into the given FlagSet.

func (*InstrumentationOptions) Validate

func (o *InstrumentationOptions) Validate(_ bool) error

type Strings

type Strings struct {
	// contains filtered or unexported fields
}

Strings represents the value of a flag that accept multiple strings.

func NewStrings

func NewStrings(def ...string) Strings

NewStrings returns a Strings struct that defaults to the value of def if left unset.

func NewStringsBeenSet

func NewStringsBeenSet(def ...string) Strings

NewStringsBeenSet returns a Strings struct with beenSet: true

func (*Strings) Add

func (s *Strings) Add(value string)

Add records the value passes, adding to the defaults (if any)

func (*Strings) Set

func (s *Strings) Set(value string) error

Set records the value passed, overwriting the defaults (if any)

func (*Strings) String

func (s *Strings) String() string

String returns a concatenated string of all the values joined by commas.

func (*Strings) StringSet

func (s *Strings) StringSet() sets.Set[string]

StringSet returns a sets.Set[string] of strings set for this value instance.

func (*Strings) Strings

func (s *Strings) Strings() []string

Strings returns the slice of strings set for this value instance.

Jump to

Keyboard shortcuts

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