Documentation ¶
Index ¶
- Constants
- Variables
- func BoolPtr(b bool) *bool
- func EnsureDataRoot(cmd ConfiguredCommand) string
- func EnsureRepoBasePath(cmd ConfiguredCommand) string
- func GitlabPageSize(cmd ConfiguredCommand) (i int)
- func IntPtr(i int) *int
- func OsOpen(url string)
- func RandomString(length int) string
- func Redact(v interface{})
- func StrPtr(v string) *string
- func UniqueStrings(ss []string) []string
- type AccountCommand
- type AccountConfig
- type Accounts
- type BaseCommand
- type BlockName
- type BlockRef
- type BlockRefs
- type Config
- func (c *Config) AccountCredentials(account string) *GitlabCredentials
- func (c *Config) AddAccounts(vals Accounts)
- func (c *Config) AddOrRemoveAccount(val *AccountConfig, remove bool)
- func (c *Config) Equals(o *Config) bool
- func (c *Config) FindAccount(name string) *AccountConfig
- func (c *Config) Flush()
- func (c *Config) Marshal(raw bool) []byte
- func (c *Config) ReadAccountsFromViper()
- func (c *Config) SetContext(ctx *ConfigContext)
- func (c *Config) SetDefaults(val *AccountConfig)
- type ConfigContext
- type ConfigManager
- type ConfigValue
- type ConfigVersion
- type ConfiguredCommand
- type GitlabCredentials
- type MockCommand
- type RepoCommand
- type RepoInfo
- type RepoInfos
- type Validator
- type VerboseCommand
Constants ¶
const ( // default logger configuration. LoggingConfig = log.LstdFlags | log.Ldate | log.Ltime | log.LUTC | log.Lmicroseconds // the default name of the config file. CfgFileDefault = ".mkactl" // the default (relative) path below the local config path root that will // contain cloned control repositories. CfgPathRepo = "repo" // the default gitlab endpoint address. CfgAddressDefault = "code.syseleven.de:443" // config key: protocol version. CfgKeyAPIVersion = "apiVersion" // the environment variable containing the path to the kubectl configuration file. EnvVarKubeconfig = clientcmd.RecommendedConfigPathEnvVar // the default env var pointing to the editor app on the CLI. EnvVarEditor = "EDITOR" // for paginated results, max value. GitlabMaxList = 100 // the gitlab group on code.syseleven.de containing building blocks repositories. GitlabGroupBuildingBlocks = 121 // gitlab project label added to control repositories. GitlabProjectLabel = "control-repo" // the default gitlabCI configuration file for repositories. GitlabProjectCIFile = ".gitlab-ci.yml" // path depth for local clones below the repo root directory. LocalRepositoryPathDepth = 4 // filesystem permission for user read-write access. FSPermUserOnly = 0o600 // filesystem permission for user read-write as well as group and other read-only access. FSPermAllRO = 0o644 // for tabular output extra padding size for cell entries. FormatTablePadding = 2 // for masked credentials, max mask length. PasswordMaskLength = 12 // random part length (in generated names). RandomPartLength = 12 // minimum display size for variable-length values. MinDisplayNameLength = 6 // maximum display size for variable-length values. MaxDisplayNameLength = 48 GitStatusMsgOK = "clean" GitStatusMsgNOK = "dirty" // blank display values. BlankVal = "" // exit codes. ExitError = 1 // misc. YamlFileGlob = `(?i).*\.ya?ml` )
Variables ¶
var ( // project base CI template. //go:embed res/gitlab-ci.yaml.tmpl GitlabProjectCIBaseTemplate string // building block CI template. //go:embed res/gitlab-ci.bb-inc.yaml.tmpl GitlabProjectCIBlockTemplate string // to match invalid env var names. InvalidEnvVar = regexp.MustCompile(`[^a-zA-Z_]+`) // to match keys for sensitive data for redaction. Redactable = regexp.MustCompile(`(?i)pass|token\S*`) )
var ( // configuration related errors. ErrCfgVersionMismatch = errors.New("invalid api version in configuration") ErrCfgValTypeMismatch = errors.New("invalid value type in configuration") // repository related errors. ErrNoRepo = errors.New("no such control repository") ErrNoGLRepo = errors.New("no such gitlab repository") ErrNoCIDefinition = errors.New("no CI definitions found in repository") ErrCorruptRepo = errors.New("cloned repository unusable") ErrNoRemotes = errors.New("no remotes for cloned repository") ErrNoTags = errors.New("no tags for repository") ErrNoChanges = errors.New("no changes in repository") // gitlab related errors. ErrNoAddress = errors.New("missing gitlab address") ErrNoCredentials = errors.New("missing gitlab access token or user name") ErrNoAuth = errors.New("missing authentication") ErrNoPermissions = errors.New("missing sufficient gitlab permissions") ErrFoundMultiple = errors.New("found multiple repositories") ErrNoGroup = errors.New("no such gitlab group") // runtime errors. ErrUnsupported = errors.New("unsupported platform or environment") ErrBlockRef = errors.New("wrongly addressed building block") ErrNoSelection = errors.New("no argument given and no repository selected") ErrNoDir = errors.New("this is not a directory") ErrNoSuchAccount = errors.New("no such account configured") ErrArgMismatch = errors.New("invalid combination of arguments") ErrMismatchedPathElement = errors.New("invalid repository path element") ErrNil = errors.New("argument is nil") // internal errors. ErrInternal = errors.New("unexpected behaviour, please report") ErrFound = errors.New("found") )
Functions ¶
func EnsureDataRoot ¶
func EnsureDataRoot(cmd ConfiguredCommand) string
EnsureDataRoot makes sure the local data path (default: ~/.config/mkactl) exists.
func EnsureRepoBasePath ¶ added in v0.6.0
func EnsureRepoBasePath(cmd ConfiguredCommand) string
EnsureRepoBasePath makes sure the (default) local configuration path containing git repositories exists.
func GitlabPageSize ¶
func GitlabPageSize(cmd ConfiguredCommand) (i int)
gets the configured page size for gitlab paging requests from the context account or account defaults if not set, defaults to 100.
func OsOpen ¶
func OsOpen(url string)
opens the default application to handle URLs for the current environment.
func RandomString ¶
func Redact ¶ added in v0.6.0
func Redact(v interface{})
Redacts iterates recursively over a given interface and redacts any sensitive data. If a certain field is sensitive is depending on if the field name is part of the sensitive fields slice.
func UniqueStrings ¶
transforms the given slice of strings to a new one only containing unique strings from the given slice.
Types ¶
type AccountCommand ¶ added in v0.4.0
type AccountCommand interface {
Credentials() *GitlabCredentials
}
a command supporting the --account flag.
type AccountConfig ¶ added in v0.4.0
type AccountConfig struct { PageSize int Address, User, Password, Token, Name *ConfigValue }
a (gitlab) account parameters record.
func (*AccountConfig) AsCredentials ¶ added in v0.4.0
func (a *AccountConfig) AsCredentials() *GitlabCredentials
func (*AccountConfig) Equals ¶ added in v0.4.0
func (a *AccountConfig) Equals(o *AccountConfig) bool
type Accounts ¶ added in v0.4.0
type Accounts []*AccountConfig
func (Accounts) AddOrRemove ¶ added in v0.8.0
func (as Accounts) AddOrRemove(ac *AccountConfig, remove bool) (Accounts, error)
adds (or overrides if an account with the given name already exists) the given account to the returned collection. NB: does not modify this collection.
func (Accounts) MaxNameLen ¶ added in v0.4.0
returns the length of the longest account name in this collection of accounts.
type BaseCommand ¶
the base data type for all commands, wraps a cobra.Command.
type BlockName ¶
type BlockName string
represents a building block name.
func (*BlockName) Exists ¶
func (a *BlockName) Exists(ps []*gitlab.Project) *gitlab.Project
for this BlockName finds its gitlab repository in the given list of gitlab repositories returns nil if no such project exists.
type BlockRefs ¶
type BlockRefs struct {
Blocks []*BlockRef
}
a collection of block references.
func (*BlockRefs) Contain ¶
returns true if the given block name is contained in this block references collection.
func (*BlockRefs) MaxNameLen ¶
returns the length of the longest block name in the block references collection.
func (*BlockRefs) RefVersion ¶
returns the version reference for the given block name in this block references collection or the empty string if the given block name is not contained.
type Config ¶ added in v0.4.0
type Config struct { APIVersion ConfigVersion Context *ConfigContext AccountDefaults *AccountConfig Accounts Accounts }
represents a complete application configuration.
func ReadOrInitConfig ¶ added in v0.4.0
func ReadOrInitConfig(file string, cmd ConfiguredCommand) (*Config, *bytes.Buffer)
ReadOrInitConfig reads the configuration from the given file or - if omitted - from the default location if no configuration is provided and none can be found at the default location, a minimal config file with defaults is written to the default location.
func (*Config) AccountCredentials ¶ added in v0.4.0
func (c *Config) AccountCredentials(account string) *GitlabCredentials
returns the account for the given name (or in the current context if name is empty) will return nil if unset.
func (*Config) AddAccounts ¶ added in v0.4.0
convenience, calls c.AddOrRemoveAccount(a, false) for each given account record.
func (*Config) AddOrRemoveAccount ¶ added in v0.8.0
func (c *Config) AddOrRemoveAccount(val *AccountConfig, remove bool)
implements ConfigManager.AddOrRemoveAccount: adds an account record, will also fill in a blank name and possibly auto-select it if it is the only record.
func (*Config) FindAccount ¶ added in v0.4.0
func (c *Config) FindAccount(name string) *AccountConfig
implements ConfigManager.FindAccount.
func (*Config) Flush ¶ added in v0.4.0
func (c *Config) Flush()
Flush updates the currently used config file with the current configuration object.
func (*Config) ReadAccountsFromViper ¶ added in v0.6.0
func (c *Config) ReadAccountsFromViper()
"reads" all accounts from the externalized configuration for configuration version v1.
func (*Config) SetContext ¶ added in v0.4.0
func (c *Config) SetContext(ctx *ConfigContext)
implements ConfigManager.SetContext.
func (*Config) SetDefaults ¶ added in v0.4.0
func (c *Config) SetDefaults(val *AccountConfig)
implements ConfigManager.SetDefaults.
type ConfigContext ¶ added in v0.4.0
type ConfigContext struct { Account *AccountConfig Repository string LocalBaseDir string }
the current configuration context.
func (*ConfigContext) Equals ¶ added in v0.4.0
func (c *ConfigContext) Equals(o *ConfigContext) bool
type ConfigManager ¶ added in v0.4.0
type ConfigManager interface { // overrides values in the configuration default // section with non-empty ones from the given record SetDefaults(val *AccountConfig) // overrides values in the configuration context // section from the given context SetContext(ctx *ConfigContext) // adds an account parameters record to the configuration AddOrRemoveAccount(val *AccountConfig, remove bool) // finds the account with the given name // if provided param is the empty string, returns // the currently selected account (if set) FindAccount(name string) *AccountConfig }
generic management tasks for configuration settings.
type ConfigValue ¶
an encodable value in the application configuration.
func (*ConfigValue) Equals ¶ added in v0.4.0
func (c *ConfigValue) Equals(o *ConfigValue) bool
type ConfigVersion ¶ added in v0.4.0
type ConfigVersion int
the apiVersion of the serialized configuration.
const ( // available API versions enum. V0 ConfigVersion = iota V1 LATEST = V1 )
func (ConfigVersion) Marshal ¶ added in v0.4.0
func (v ConfigVersion) Marshal() string
type ConfiguredCommand ¶ added in v0.4.0
type ConfiguredCommand interface { VerboseCommand GetConfig() *Config }
a command that is verbose and also has a config.
type GitlabCredentials ¶
type GitlabCredentials struct {
Token, User, Pass, Address string
}
gitlab authentication parameters.
func (*GitlabCredentials) GetAddress ¶ added in v0.6.0
func (creds *GitlabCredentials) GetAddress() *net.TCPAddr
returns a valid tcp address or panics.
func (*GitlabCredentials) UpdateFromConfig ¶
func (creds *GitlabCredentials) UpdateFromConfig(cmd ConfiguredCommand) *GitlabCredentials
updates all missing fields in this object from the current configuration object from the current context account if set and falling back to account defaults if set returns this object for chaining.
func (*GitlabCredentials) VerifyAuthExists ¶
func (creds *GitlabCredentials) VerifyAuthExists() error
VerifyAuthExists verifies sufficient gitlab credentials (user/password or token) are provided.
type MockCommand ¶ added in v0.4.0
this is for testing purposes.
func (*MockCommand) GetConfig ¶ added in v0.4.0
func (c *MockCommand) GetConfig() *Config
func (*MockCommand) IsVerbose ¶ added in v0.4.0
func (c *MockCommand) IsVerbose() bool
func (*MockCommand) TargetRepository ¶ added in v0.4.0
func (c *MockCommand) TargetRepository(_ *GitlabCredentials) *RepoInfo
func (*MockCommand) Verbosef ¶ added in v0.4.0
func (c *MockCommand) Verbosef(format string, args ...interface{})
type RepoCommand ¶
type RepoCommand interface {
TargetRepository(*GitlabCredentials) *RepoInfo
}
a command targeting a control repository.
type RepoInfo ¶ added in v0.6.0
holds information on local clones.
type RepoInfos ¶ added in v0.6.0
type RepoInfos []*RepoInfo
a collection of local repo clone infos.
func (*RepoInfos) DoFor ¶ added in v0.6.0
calls the given function for all repo infos with the given name returns the first error it encounters.
func (*RepoInfos) MaxNameLen ¶ added in v0.6.0
returns the length of the longest file name in this collection.
type VerboseCommand ¶
a verbose command will emit verbose output if verbosity is true.