config

package
v0.79.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: Apache-2.0 Imports: 15 Imported by: 21

Documentation

Overview

Package config Provide API methods to Read/Write specific stanza of config file

Package config Provide API methods to Read/Write specific stanza of config file

Package config Provide API methods to Read/Write specific stanza of config file

Package config Provide API methods to Read/Write specific stanza of config file

Index

Constants

View Source
const (
	// EnvConfigKey is the environment variable that points to a tanzu config.
	EnvConfigKey = "TANZU_CONFIG"

	// ConfigName is the name of the config
	ConfigName = "config.yaml"
)
View Source
const (
	// EnvConfigNextGenKey is the environment variable that points to a tanzu config.
	EnvConfigNextGenKey = "TANZU_CONFIG_NEXT_GEN"

	// CfgNextGenName is the name of the config metadata
	CfgNextGenName = "config-ng.yaml"
)
View Source
const (
	LocalTanzuConfigNextGenFileLock = ".tanzu-config-ng.lock"
	// DefaultConfigNextGenLockTimeout is the default time waiting on the filelock
	DefaultConfigNextGenLockTimeout = 10 * time.Minute
)
View Source
const (

	// EnvEndpointKey is the environment variable that overrides the tanzu endpoint.
	EnvEndpointKey = "TANZU_ENDPOINT"

	//nolint:gosec // Avoid "hardcoded credentials" false positive.
	// EnvAPITokenKey is the environment variable that overrides the tanzu API token for global auth.
	EnvAPITokenKey = "TANZU_API_TOKEN"
)
View Source
const (
	KeyServers                 = "servers"
	KeyContexts                = "contexts"
	KeyCurrentServer           = "current"
	KeyCurrentContext          = "currentContext"
	KeyClientOptions           = "clientOptions"
	KeyCLI                     = "cli"
	KeyFeatures                = "features"
	KeyEnv                     = "env"
	KeyDiscoverySources        = "discoverySources"
	KeyRepositories            = "repositories"
	KeyUnstableVersionSelector = "unstableVersionSelector"
	KeyEdition                 = "edition"
	KeyKind                    = "kind"
	KeyMetadata                = "metadata"
	KeyAPIVersion              = "apiVersion"
	KeyBomRepo                 = "bomRepo"
	KeyCompatibilityFilePath   = "compatibilityFilePath"
)

Keys used to parse the yaml node to retrieve specific stanza of the config file

View Source
const (
	DiscoveryTypeOCI        = "oci"
	DiscoveryTypeLocal      = "local"
	DiscoveryTypeGCP        = "gcp"
	DiscoveryTypeKubernetes = "kubernetes"
	DiscoveryTypeREST       = "rest"
)

DiscoveryType constants

View Source
const (
	LocalTanzuFileLock = ".tanzu.lock"
	// DefaultLockTimeout is the default time waiting on the filelock
	DefaultLockTimeout = 10 * time.Minute
)
View Source
const (
	// EnvConfigMetadataKey is the environment variable that points to a tanzu config.
	EnvConfigMetadataKey = "TANZU_CONFIG_METADATA"

	// CfgMetadataName is the name of the config metadata hidden file
	CfgMetadataName = ".config-metadata.yaml"
)
View Source
const (
	KeyConfigMetadata = "configMetadata"
	KeyPatchStrategy  = "patchStrategy"
	KeySettings       = "settings"
)

Keys used to parse the yaml node to retrieve specific stanza of the config file

View Source
const (
	LocalTanzuMetadataFileLock = ".tanzu-metadata.lock"
	// DefaultMetadataLockTimeout is the default time waiting on the filelock
	DefaultMetadataLockTimeout = 10 * time.Minute
)
View Source
const (
	Default = "default"
)
View Source
const (
	SettingUseUnifiedConfig = "useUnifiedConfig"
)

Variables

View Source
var (
	// LocalDirName is the name of the local directory in which tanzu state is stored.
	LocalDirName = ".config/tanzu"
	// TestLocalDirName is the name of the local directory in which tanzu state is stored for testing.
	TestLocalDirName = ".tanzu-test"
)
View Source
var DiscardedConfigNodeKeys = []string{
	KeyContexts,
	KeyCurrentContext,
}

LegacyConfigNodeKeys config nodes that goes to config.yaml

Functions

func AcquireTanzuConfigLock

func AcquireTanzuConfigLock()

AcquireTanzuConfigLock tries to acquire lock to update tanzu config file with timeout

func AcquireTanzuConfigNextGenLock added in v0.0.2

func AcquireTanzuConfigNextGenLock()

AcquireTanzuConfigNextGenLock tries to acquire lock to update tanzu config file with timeout

func AcquireTanzuMetadataLock added in v0.0.2

func AcquireTanzuMetadataLock()

AcquireTanzuMetadataLock tries to acquire lock to update tanzu config metadata file with timeout

func AddContext

func AddContext(c *configtypes.Context, setCurrent bool) error

AddContext add or update context and currentContext

func AddServer

func AddServer(s *configtypes.Server, setCurrent bool) error

AddServer add or update server and currentServer

func CfgMetadataFilePath added in v0.0.2

func CfgMetadataFilePath() (path string, err error)

func ClientConfigNextGenPath added in v0.0.2

func ClientConfigNextGenPath() (path string, err error)

ClientConfigNextGenPath retrieved config-alt file path

func ClientConfigPath

func ClientConfigPath() (path string, err error)

ClientConfigPath returns the tanzu config path, checking for environment overrides.

func ConfigureDefaultFeatureFlagsIfMissing added in v0.0.2

func ConfigureDefaultFeatureFlagsIfMissing(plugin string, defaultFeatureFlags map[string]bool) error

ConfigureDefaultFeatureFlagsIfMissing add or update plugin features based on specified default feature flags

func ContextExists

func ContextExists(name string) (bool, error)

ContextExists checks if context by name already exists

func CopyLegacyConfigDir

func CopyLegacyConfigDir() error

CopyLegacyConfigDir copies configuration files from legacy config dir to the new location. This is a no-op if the legacy dir does not exist or if the new config dir already exists.

func DeleteCLIDiscoverySource added in v0.0.2

func DeleteCLIDiscoverySource(name string) error

DeleteCLIDiscoverySource delete cli discoverySource by name

func DeleteCLIRepository added in v0.0.2

func DeleteCLIRepository(name string) error

DeleteCLIRepository delete a cli repository by name

func DeleteClientConfig

func DeleteClientConfig() error

DeleteClientConfig deletes the config yaml from the local directory.

func DeleteClientConfigNextGen added in v0.0.2

func DeleteClientConfigNextGen() error

DeleteClientConfigNextGen deletes the config-ng yaml from the local directory.

func DeleteConfigMetadataSetting added in v0.0.2

func DeleteConfigMetadataSetting(key string) error

DeleteConfigMetadataSetting delete the env entry of specified key

func DeleteContext added in v0.0.2

func DeleteContext(name string) error

DeleteContext delete a context by name

func DeleteEnv added in v0.0.2

func DeleteEnv(key string) error

DeleteEnv delete the env entry of specified key

func DeleteFeature added in v0.0.2

func DeleteFeature(plugin, key string) error

DeleteFeature deletes the specified plugin key

func DeleteServer added in v0.0.2

func DeleteServer(name string) error

DeleteServer deletes the server specified by name

func EndpointFromContext

func EndpointFromContext(s *configtypes.Context) (endpoint string, err error)

EndpointFromContext retrieved the endpoint from the specified context

func EndpointFromServer

func EndpointFromServer(s *configtypes.Server) (endpoint string, err error)

EndpointFromServer returns the endpoint from server.

func GetAllCurrentContextsList added in v0.0.2

func GetAllCurrentContextsList() ([]string, error)

GetAllCurrentContextsList returns all current context names as list

func GetAllCurrentContextsMap added in v0.0.2

func GetAllCurrentContextsMap() (map[configtypes.Target]*configtypes.Context, error)

GetAllCurrentContextsMap returns all current context per Target

func GetAllEnvs added in v0.0.2

func GetAllEnvs() (map[string]string, error)

GetAllEnvs retrieves all env values from config

func GetCLIDiscoverySource added in v0.0.2

func GetCLIDiscoverySource(name string) (*configtypes.PluginDiscovery, error)

GetCLIDiscoverySource retrieves cli discovery source by name assuming that there should only be one source with the name, returns the first match

func GetCLIDiscoverySources added in v0.0.2

func GetCLIDiscoverySources() ([]configtypes.PluginDiscovery, error)

GetCLIDiscoverySources retrieves cli discovery sources

func GetCLIRepositories added in v0.0.2

func GetCLIRepositories() ([]configtypes.PluginRepository, error)

GetCLIRepositories retrieves cli repositories

func GetCLIRepository added in v0.0.2

func GetCLIRepository(name string) (*configtypes.PluginRepository, error)

GetCLIRepository retrieves cli repository by name

func GetClientConfig

func GetClientConfig() (cfg *configtypes.ClientConfig, err error)

GetClientConfig retrieves the config from the local directory with file lock

func GetClientConfigNoLock

func GetClientConfigNoLock() (cfg *configtypes.ClientConfig, err error)

GetClientConfigNoLock retrieves the config from the local directory without acquiring the lock

func GetConfigMetadata added in v0.0.2

func GetConfigMetadata() (*configtypes.ConfigMetadata, error)

GetConfigMetadata retrieves configMetadata

func GetConfigMetadataPatchStrategy added in v0.0.2

func GetConfigMetadataPatchStrategy() (map[string]string, error)

GetConfigMetadataPatchStrategy retrieves patch strategies

func GetConfigMetadataSetting added in v0.0.2

func GetConfigMetadataSetting(key string) (string, error)

func GetConfigMetadataSettings added in v0.0.2

func GetConfigMetadataSettings() (map[string]string, error)

GetConfigMetadataSettings retrieves feature flags

func GetContext

func GetContext(name string) (*configtypes.Context, error)

GetContext retrieves the context by name

func GetCurrentContext

func GetCurrentContext(target configtypes.Target) (c *configtypes.Context, err error)

GetCurrentContext retrieves the current context for the specified target

func GetCurrentServer

func GetCurrentServer() (*configtypes.Server, error)

GetCurrentServer retrieves the current server

func GetEdition

func GetEdition() (string, error)

GetEdition retrieves ClientOptions Edition

func GetEnv added in v0.0.2

func GetEnv(key string) (string, error)

GetEnv retrieves env value by key

func GetEnvConfigurations

func GetEnvConfigurations() map[string]string

GetEnvConfigurations returns a map of configured environment variables to values as part of tanzu configuration file it returns nil if configuration is not yet defined

func GetMetadata added in v0.0.2

func GetMetadata() (*configtypes.Metadata, error)

GetMetadata retrieves Metadata

func GetServer

func GetServer(name string) (*configtypes.Server, error)

GetServer retrieves server by name

func IsConfigMetadataSettingsEnabled added in v0.0.2

func IsConfigMetadataSettingsEnabled(key string) (bool, error)

IsConfigMetadataSettingsEnabled checks and returns whether specific plugin and key is true

func IsFeatureActivated

func IsFeatureActivated(feature string) bool

IsFeatureActivated returns true if the given feature is activated User can set this CLI feature flag using `tanzu config set features.global.<feature> true`

func IsFeatureEnabled added in v0.0.2

func IsFeatureEnabled(plugin, key string) (bool, error)

IsFeatureEnabled checks and returns whether specific plugin and key is true

func LocalDir

func LocalDir() (path string, err error)

LocalDir returns the local directory in which tanzu state is stored.

func PopulateContexts

func PopulateContexts(cfg *configtypes.ClientConfig) bool

PopulateContexts converts the known servers that are missing in contexts. This is needed when reading the config file persisted by an older core or plugin, so that it is forwards compatible with a new core plugin. Returns true if there was any delta.

func PutServer

func PutServer(s *configtypes.Server, setCurrent bool) error

PutServer add or update server and currentServer

func ReleaseTanzuConfigLock

func ReleaseTanzuConfigLock()

ReleaseTanzuConfigLock releases the lock if the tanzuConfigLock was acquired

func ReleaseTanzuConfigNextGenLock added in v0.0.2

func ReleaseTanzuConfigNextGenLock()

ReleaseTanzuConfigNextGenLock releases the lock if the tanzuConfigLock was acquired

func ReleaseTanzuMetadataLock added in v0.0.2

func ReleaseTanzuMetadataLock()

ReleaseTanzuMetadataLock releases the lock if the tanzuMetadataLock was acquired

func RemoveContext

func RemoveContext(name string) error

RemoveContext delete a context by name

func RemoveCurrentContext added in v0.0.2

func RemoveCurrentContext(target configtypes.Target) error

RemoveCurrentContext removed the current context of specified context type

func RemoveCurrentServer added in v0.0.2

func RemoveCurrentServer(name string) error

RemoveCurrentServer removes the current server if server exists by specified name

func RemoveServer

func RemoveServer(name string) error

RemoveServer removed the server by name

func ServerExists

func ServerExists(name string) (bool, error)

ServerExists checks if server by specified name is present in config

func SetCLIDiscoverySource added in v0.0.2

func SetCLIDiscoverySource(discoverySource configtypes.PluginDiscovery) (err error)

SetCLIDiscoverySource add or update a cli discoverySource

func SetCLIDiscoverySources added in v0.0.2

func SetCLIDiscoverySources(discoverySources []configtypes.PluginDiscovery) (err error)

SetCLIDiscoverySources Add/Update array of cli discovery sources to the yaml node

func SetCLIRepository added in v0.0.2

func SetCLIRepository(repository configtypes.PluginRepository) (err error)

SetCLIRepository add or update a repository

func SetConfigMetadataPatchStrategies added in v0.0.2

func SetConfigMetadataPatchStrategies(patchStrategies map[string]string) error

SetConfigMetadataPatchStrategies add or update map of patch strategies

func SetConfigMetadataPatchStrategy added in v0.0.2

func SetConfigMetadataPatchStrategy(key, value string) error

SetConfigMetadataPatchStrategy add or update patch strategy specified by key-value pair

func SetConfigMetadataSetting added in v0.0.2

func SetConfigMetadataSetting(key, value string) (err error)

SetConfigMetadataSetting add or update a env key and value

func SetContext added in v0.0.2

func SetContext(c *configtypes.Context, setCurrent bool) error

SetContext add or update context and currentContext

func SetCurrentContext

func SetCurrentContext(name string) error

SetCurrentContext sets the current context to the specified name if context is present

func SetCurrentServer

func SetCurrentServer(name string) error

SetCurrentServer add or update current server

func SetEdition added in v0.0.2

func SetEdition(val string) (err error)

SetEdition adds or updates edition value

func SetEnv added in v0.0.2

func SetEnv(key, value string) (err error)

SetEnv add or update a env key and value

func SetFeature added in v0.0.2

func SetFeature(plugin, key, value string) (err error)

SetFeature add or update plugin key value

func SetServer added in v0.0.2

func SetServer(s *configtypes.Server, setCurrent bool) error

SetServer add or update server and currentServer

func StoreClientConfig

func StoreClientConfig(cfg *configtypes.ClientConfig) error

StoreClientConfig stores the config in the local directory. Make sure to Acquire and Release tanzu lock when reading/writing to the tanzu client configuration Deprecated: StoreClientConfig is deprecated. Avoid using this method for Delete operations. Use New Config API methods.

func UseUnifiedConfig added in v0.0.2

func UseUnifiedConfig() (bool, error)

UseUnifiedConfig checks useUnifiedConfig feature flag

Types

type CfgOptions added in v0.0.2

type CfgOptions struct {
	CfgPath string // file path to the config file
}

type CfgOpts added in v0.0.2

type CfgOpts func(config *CfgOptions)

func WithCfgPath added in v0.0.2

func WithCfgPath(path string) CfgOpts

Directories

Path Synopsis
Package collectionutils provide helper functions to operate on collections like array, map
Package collectionutils provide helper functions to operate on collections like array, map
Package nodeutils provides utility methods to perform operations on yaml node
Package nodeutils provides utility methods to perform operations on yaml node
Package types specifies the types for clientconfig
Package types specifies the types for clientconfig

Jump to

Keyboard shortcuts

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