config

package
v0.46.3 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIKey             FieldKey = "apiKey"
	Region             FieldKey = "region"
	AccountID          FieldKey = "accountID"
	LicenseKey         FieldKey = "licenseKey"
	LogLevel           FieldKey = "loglevel"
	PluginDir          FieldKey = "plugindir"
	PreReleaseFeatures FieldKey = "prereleasefeatures"
	SendUsageData      FieldKey = "sendUsageData"

	DefaultProfileName = "default"

	DefaultProfileFileName = "default-profile.json"
	ConfigFileName         = "config.json"
	CredentialsFileName    = "credentials.json"
	DefaultPluginDir       = "plugins"

	DefaultPostRetryDelaySec = 5
	DefaultPostMaxRetries    = 20
)
View Source
const (
	// DefaultLogLevel is the default log level
	DefaultLogLevel = "info"

	// DefaultLogFile is the default log file
	DefaultLogFile = "newrelic-cli.log"
)

Variables

View Source
var (
	ConfigStore         *JSONStore
	CredentialsProvider *JSONStore
	BasePath            = configBasePath()

	FlagProfileName string
	FlagDebug       bool
	FlagTrace       bool
	FlagAccountID   int
)
View Source
var (
	Logger = log.StandardLogger()
)
View Source
var TernaryValues = struct {
	// Allow the option
	Allow Ternary

	// Disallow the option
	Disallow Ternary

	// Unknown is the unknown state
	Unknown Ternary
}{
	Allow:    "ALLOW",
	Disallow: "DISALLOW",
	Unknown:  "NOT_ASKED",
}

TernaryValues provides the set of Ternary values

Functions

func GetDefaultLogFilePath added in v0.30.2

func GetDefaultLogFilePath() string

func Init added in v0.30.0

func Init(basePath string)

func InitFileLogger added in v0.22.0

func InitFileLogger(terminalLogLevel string)

func InitLogger added in v0.30.0

func InitLogger(logger *log.Logger, logLevel string)

func InitializeConfigStore added in v0.30.0

func InitializeConfigStore()

func InitializeCredentialsStore added in v0.30.0

func InitializeCredentialsStore()

func IntGreaterThan added in v0.30.0

func IntGreaterThan(greaterThan int) func(key FieldKey, value interface{}) error

IntGreaterThan is a FieldValueValidationFunc ins a validation func that ensures the field value is an integer greater than 0.

func IsTernary added in v0.30.0

func IsTernary() func(key FieldKey, value interface{}) error

IsTernary is a FieldValueValidationFunc ins a validation func that ensures the field value is a valid Ternary.

func StringInStrings added in v0.30.0

func StringInStrings(caseSensitive bool, allowedValues ...string) func(key FieldKey, value interface{}) error

StringInStrings is a FieldValueValidationFunc ins a validation func that ensures the field value appears in the given collection of allowed values.

func ToLower added in v0.30.0

func ToLower() func(key FieldKey, value interface{}) (interface{}, error)

ToLower is a FieldValueTranslationFunc translation func that ensures the provided value is case-folded to lowercase before writing to the underlying config.

Types

type FieldDefinition added in v0.30.0

type FieldDefinition struct {
	// EnvVar provides an environment variable override
	EnvVar string

	// Key represents the key that will be used to store the underlying value.
	Key FieldKey

	// EnvVar provides a default value to be returned during a get operation
	// if no value can be found for this field.
	Default interface{}

	// CaseSensitive determines whether this config key will be treated as case-sensitive
	// or not. When false, keys passed to get and set operations will be performed
	// with the canonical casing of the Key value provided in the field definition.
	CaseSensitive bool

	// Sensitive marks the underlying value as sensitive.  When true, the underlying
	// field's value will be obfuscated when printed to the console during the
	// execution of various commands.
	Sensitive bool

	// SetValidationFunc is a validation func that is run when a set operation
	// is performed for the underlying value. If the func returns an error, the
	// set operation will not succeed.
	SetValidationFunc FieldValueValidationFunc

	// SetValueFunc is a translation func that is run when a set operation
	// is performed for the underlying value. The value provided will be run
	// through the func provided and the resulting value will be set.
	SetValueFunc FieldValueTranslationFunc
}

FieldDefinition contains the information required to describe a configuration field.

type FieldKey added in v0.30.0

type FieldKey string

FieldKey is the key of a config field.

type FieldValueTranslationFunc added in v0.30.0

type FieldValueTranslationFunc func(key FieldKey, value interface{}) (interface{}, error)

FieldValueTranslationFunc is a configurable translation func that will modify a value before setting it in the underlying config instance.

type FieldValueValidationFunc added in v0.30.0

type FieldValueValidationFunc func(key FieldKey, value interface{}) error

FieldValueValidationFunc is a configurable validation func that will ensure a field value conforms to some constraints before being set.

type JSONStore added in v0.30.0

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

JSONStore is a configurable json-backed configuration store.

func NewJSONStore added in v0.30.0

func NewJSONStore(opts ...JSONStoreOption) (*JSONStore, error)

NewJSONStore creates a new instance of JSONStore.

func (*JSONStore) DeleteKey added in v0.30.0

func (p *JSONStore) DeleteKey(key FieldKey) error

Remove scope removes the provided key from this config instance. The resulting config will be persisted to disk if PersistToDisk has been used.

func (*JSONStore) DeleteKeyWithScope added in v0.30.0

func (p *JSONStore) DeleteKeyWithScope(scope string, key FieldKey) error

Remove scope removes the provided key from this config instance, prefixing the key's path with the given scope. The resulting config will be persisted to disk if PersistToDisk has been used.

func (*JSONStore) ForEachFieldDefinition added in v0.30.0

func (p *JSONStore) ForEachFieldDefinition(fn func(d FieldDefinition))

ForEachFieldDefinition iterates through the defined fields for this config instance, yielding each to the func provided.

func (*JSONStore) Get added in v0.30.0

func (p *JSONStore) Get(key FieldKey) (interface{}, error)

Get retrieves a value from this config instance for the given key.

func (*JSONStore) GetFieldDefinition added in v0.30.0

func (p *JSONStore) GetFieldDefinition(key FieldKey) *FieldDefinition

GetFieldDefinition returns a field definition for the given key if one exists.

func (*JSONStore) GetInt added in v0.30.0

func (p *JSONStore) GetInt(key FieldKey) (int64, error)

GetInt retrieves an int64 from this config instance for the given key. An attempt will be made to convert the underlying type of this field's value to an int64. If the value cannot be retrieved, a zero value will be returned.

func (*JSONStore) GetIntWithScope added in v0.30.0

func (p *JSONStore) GetIntWithScope(scope string, key FieldKey) (int64, error)

GetIntWithScope retrieves an int64 from this config instance for the given key, prefixing the key's path with the given scope. An attempt will be made to convert the underlying type of this field's value to an int64. If the value cannot be retrieved, a zero value will be returned.

func (*JSONStore) GetIntWithScopeAndOverride added in v0.30.0

func (p *JSONStore) GetIntWithScopeAndOverride(scope string, key FieldKey, override *int64) (int64, error)

GetIntWithOverride retrieves an int64 from this config instance for the given key, prefixing the key's path with the given scope and overriding with the provided value if it is not nil. An attempt will be made to convert the underlying type of this field's value to an int64. If the value cannot be retrieved, a zero value will be returned.

func (*JSONStore) GetScopes added in v0.30.0

func (p *JSONStore) GetScopes() []string

GetScopes returns a slice of all scopes defined within this config instance.

func (*JSONStore) GetString added in v0.30.0

func (p *JSONStore) GetString(key FieldKey) (string, error)

GetString retrieves a string from this config instance for the given key. An attempt will be made to convert the underlying type of this field's value to a string. If the value cannot be retrieved, a zero value will be returned.

func (*JSONStore) GetStringWithOverride added in v0.30.0

func (p *JSONStore) GetStringWithOverride(key FieldKey, override *string) (string, error)

GetStringWithOverride retrieves a string from this config instance for the given key, overriding with the provided value if is not nil. An attempt will be made to convert the underlying type of this field's value to a string. If the value cannot be retrieved, a zero value will be returned.

func (*JSONStore) GetStringWithScope added in v0.30.0

func (p *JSONStore) GetStringWithScope(scope string, key FieldKey) (string, error)

GetString retrieves a string from this config instance for the given key, prefixing the key's path with the given scope. An attempt will be made to convert the underlying type of this field's value to a string. If the value cannot be retrieved, a zero value will be returned.

func (*JSONStore) GetStringWithScopeAndOverride added in v0.30.0

func (p *JSONStore) GetStringWithScopeAndOverride(scope string, key FieldKey, override *string) (string, error)

GetStringWithOverride retrieves a string from this config instance for the given key, prefixing the key's path with the given scope and overriding with the provided value if it is not nil. An attempt will be made to convert the underlying type of this field's value to a string. If the value cannot be retrieved, a zero value will be returned.

func (*JSONStore) GetTernary added in v0.30.0

func (p *JSONStore) GetTernary(key FieldKey) (Ternary, error)

GetInt retrieves a Ternary from this config instance for the given key. An attempt will be made to convert the underlying type of this field's value to a Ternary. If the value cannot be retrieved, a zero value will be returned.

func (*JSONStore) GetTernaryWithScope added in v0.30.0

func (p *JSONStore) GetTernaryWithScope(scope string, key FieldKey) (Ternary, error)

GetTernaryWithScope retrieves a Ternary from this config instance for the given key, prefixing the key's path with the given scope. An attempt will be made to convert the underlying type of this field's value to a Ternary. If the value cannot be retrieved, a zero value will be returned.

func (*JSONStore) GetWithScope added in v0.30.0

func (p *JSONStore) GetWithScope(scope string, key FieldKey) (interface{}, error)

Get retrieves a value from this config instance for the given key, prefixing the key's path with the given scope.

func (*JSONStore) GetWithScopeAndOverride added in v0.30.0

func (p *JSONStore) GetWithScopeAndOverride(scope string, key FieldKey, override interface{}) (interface{}, error)

Get retrieves a value from this config instance for the given key, prefixing the key's path with the given scope and overriding with the provided value if it is not nil.

func (*JSONStore) RemoveScope added in v0.30.0

func (p *JSONStore) RemoveScope(scope string) error

Remove scope removes an entire scope from this config instance, including all the fields that appear underneath it. The resulting config will be persisted to disk if PersistToDisk has been used.

func (*JSONStore) Set added in v0.30.0

func (p *JSONStore) Set(key FieldKey, value interface{}) error

Set sets a value within this config instance for the given key. The resulting config will be persisted to disk if PersistToDisk has been used.

func (*JSONStore) SetWithScope added in v0.30.0

func (p *JSONStore) SetWithScope(scope string, key FieldKey, value interface{}) error

SetWithScope sets a value within this config instance for the given key, prefixing the key's path with the given scope. The resulting config will be persisted to disk if PersistToDisk has been used.

type JSONStoreOption added in v0.30.0

type JSONStoreOption func(*JSONStore) error

JSONStoreOption is a func for supplying options when creating a new JSONStore.

func ConfigureFields added in v0.30.0

func ConfigureFields(definitions ...FieldDefinition) JSONStoreOption

ConfigureFields is a JSONStoreOption func that allows the caller to describe the fields stored in this config instance with one or more field definitions.

func EnforceStrictFields added in v0.30.0

func EnforceStrictFields() JSONStoreOption

EnforceStrictFields is a JSONStoreOption func that ensures that every field accessed is backed by a FieldDefinition.

func PersistToFile added in v0.30.0

func PersistToFile(fileName string) JSONStoreOption

PersistToFile is a JSONStoreOption func that ensures all writes to this config instance are persisted to disk.

func UseGlobalScope added in v0.30.0

func UseGlobalScope(scope string) JSONStoreOption

UseGlobalScope is a JSONStoreOption func that ensures all config fields are stored under a global object scope with the passed scope string as a key.

type LogrusFileHook added in v0.8.11

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

func NewLogrusFileHook added in v0.8.11

func NewLogrusFileHook(file string, flag int, chmod os.FileMode) (*LogrusFileHook, error)

func (*LogrusFileHook) Fire added in v0.8.11

func (hook *LogrusFileHook) Fire(entry *log.Entry) error

func (*LogrusFileHook) Levels added in v0.8.11

func (hook *LogrusFileHook) Levels() []log.Level

type Ternary added in v0.8.11

type Ternary string

Ternary is like a bool, but includes the unknown state

func (Ternary) Bool added in v0.8.11

func (t Ternary) Bool() bool

Bool returns true if the ternary is set and contains the true value

func (Ternary) String added in v0.8.11

func (t Ternary) String() string

String returns the string value of the ternary

func (Ternary) Valid added in v0.8.11

func (t Ternary) Valid() error

Valid returns true for a valid value, false otherwise

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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