config

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package config provides utilities for configuration keys in the configuration files.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ConfigFileOverrides contains the CLI flags that override the values in the config file.
	//
	// It is a map of flag key to usage.
	ConfigFileOverrides = map[string]string{
		"cb-api-id":  "the API ID to be used for authorization",
		"cb-api-key": "the API Key to be used for authorization",
		"org-key":    "the Org key of the organization in CBC",
		"saas-url":   "the Base URL of the CBC backend",
	}
)

Functions

func ConvertToValidProfileName

func ConvertToValidProfileName(input string) string

ConvertToValidProfileName will convert input to valid profile name.

func GetConfig

func GetConfig(o Option) string

GetConfig will get the config by a given option from the active profile.

func LoadAppConfig

func LoadAppConfig()

LoadAppConfig will initialize application config from viper.

func PersistConfig

func PersistConfig() error

PersistConfig will persist all the configs.

func SetConfigByOption

func SetConfigByOption(user string, o Option, value string)

SetConfigByOption will set the config by a given option-value to the active profile.

func SuggestionsFor

func SuggestionsFor(typedName string) []string

SuggestionsFor provides suggestions for the typedName.

Types

type AppConfig

type AppConfig struct {
	ActiveUserProfile string
	AccessToKeyring   bool
	Properties        map[string]*Property
	CliOpt            *CliOption
}

AppConfig is the config of the cli app.

func Config

func Config() *AppConfig

Config will return the appConfig singleton instance.

type CliOption

type CliOption struct {
	ConfigFile  string `mapstructure:"config"`
	UserProfile string `mapstructure:"user-profile"`
	PlainMode   bool   `mapstructure:"plain-mode"`
}

CliOption contains all the cli flag options.

type Option

type Option int

Option is the behind number of a config, used for enum.

const (
	// ActiveUserProfile is the current active profile.
	ActiveUserProfile Option = iota
	// SaasURL is the cloud SaaS url.
	SaasURL
	// OrgKey is the org_id.
	OrgKey
	// DefaultBuildStep in the default build step.
	DefaultBuildStep

	// CBApiID is the carbon black api id;
	// put under cntOfOptions since the following two options are for auth.
	CBApiID
	// CBApiKey is the carbon black api key.
	CBApiKey
)

func Contains

func Contains(typedName string) (bool, Option)

Contains will check if an input config is a valid one or not.

func (Option) String

func (o Option) String() string

String will return the option string.

func (Option) StringWithPrefix

func (o Option) StringWithPrefix(prefix string) string

StringWithPrefix will return the option string with a prefix.

type Property

type Property struct {
	SaasURL          string
	OrgKey           string
	AuthByKeyring    bool
	CBApiID          string
	CBApiKey         string
	DefaultBuildStep string
}

Property is the property of a single user.

Jump to

Keyboard shortcuts

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