Documentation ¶
Index ¶
- Constants
- Variables
- func GetDefaultLogFilePath() string
- func Init(basePath string)
- func InitFileLogger(terminalLogLevel string)
- func InitLogger(logger *log.Logger, logLevel string)
- func InitializeConfigStore()
- func InitializeCredentialsStore()
- func IntGreaterThan(greaterThan int) func(key FieldKey, value interface{}) error
- func IsTernary() func(key FieldKey, value interface{}) error
- func StringInStrings(caseSensitive bool, allowedValues ...string) func(key FieldKey, value interface{}) error
- func ToLower() func(key FieldKey, value interface{}) (interface{}, error)
- type FieldDefinition
- type FieldKey
- type FieldValueTranslationFunc
- type FieldValueValidationFunc
- type JSONStore
- func (p *JSONStore) DeleteKey(key FieldKey) error
- func (p *JSONStore) DeleteKeyWithScope(scope string, key FieldKey) error
- func (p *JSONStore) ForEachFieldDefinition(fn func(d FieldDefinition))
- func (p *JSONStore) Get(key FieldKey) (interface{}, error)
- func (p *JSONStore) GetFieldDefinition(key FieldKey) *FieldDefinition
- func (p *JSONStore) GetInt(key FieldKey) (int64, error)
- func (p *JSONStore) GetIntWithScope(scope string, key FieldKey) (int64, error)
- func (p *JSONStore) GetIntWithScopeAndOverride(scope string, key FieldKey, override *int64) (int64, error)
- func (p *JSONStore) GetScopes() []string
- func (p *JSONStore) GetString(key FieldKey) (string, error)
- func (p *JSONStore) GetStringWithOverride(key FieldKey, override *string) (string, error)
- func (p *JSONStore) GetStringWithScope(scope string, key FieldKey) (string, error)
- func (p *JSONStore) GetStringWithScopeAndOverride(scope string, key FieldKey, override *string) (string, error)
- func (p *JSONStore) GetTernary(key FieldKey) (Ternary, error)
- func (p *JSONStore) GetTernaryWithScope(scope string, key FieldKey) (Ternary, error)
- func (p *JSONStore) GetWithScope(scope string, key FieldKey) (interface{}, error)
- func (p *JSONStore) GetWithScopeAndOverride(scope string, key FieldKey, override interface{}) (interface{}, error)
- func (p *JSONStore) RemoveScope(scope string) error
- func (p *JSONStore) Set(key FieldKey, value interface{}) error
- func (p *JSONStore) SetWithScope(scope string, key FieldKey, value interface{}) error
- type JSONStoreOption
- type LogrusFileHook
- type Ternary
Constants ¶
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 DefaultMaxTimeoutSeconds = 300 // 5 minutes )
const ( // DefaultLogLevel is the default log level DefaultLogLevel = "info" // DefaultLogFile is the default log file DefaultLogFile = "newrelic-cli.log" )
Variables ¶
var ( ConfigStore *JSONStore CredentialsProvider *JSONStore BasePath = configBasePath() FlagProfileName string FlagDebug bool FlagTrace bool FlagAccountID int )
var (
Logger = log.StandardLogger()
)
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 InitFileLogger ¶ added in v0.22.0
func InitFileLogger(terminalLogLevel string)
func InitLogger ¶ added in v0.30.0
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
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
IsTernary is a FieldValueValidationFunc ins a validation func that ensures the field value is a valid Ternary.
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 FieldValueTranslationFunc ¶ added in v0.30.0
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
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
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
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
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
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
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
GetScopes returns a slice of all scopes defined within this config instance.
func (*JSONStore) GetString ¶ added in v0.30.0
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
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
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
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
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
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
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
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
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
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 (*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
Bool returns true if the ternary is set and contains the true value