config

package
v0.0.0-...-b25b198 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: Apache-2.0 Imports: 16 Imported by: 16

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

func AcquireTanzuConfigNextGenLock()

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

func AcquireTanzuMetadataLock

func AcquireTanzuMetadataLock()

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

func AddContext

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

AddContext add or update context and currentContext

func AddServer

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

AddServer add or update server and currentServer

func CfgMetadataFilePath

func CfgMetadataFilePath() (path string, err error)

func ClientConfigNextGenPath

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

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

func DeleteCLIDiscoverySource(name string) error

DeleteCLIDiscoverySource delete cli discoverySource by name

func DeleteCLIRepository

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

func DeleteClientConfigNextGen() error

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

func DeleteConfigMetadataSetting

func DeleteConfigMetadataSetting(key string) error

DeleteConfigMetadataSetting delete the env entry of specified key

func DeleteContext

func DeleteContext(name string) error

DeleteContext delete a context by name

func DeleteEnv

func DeleteEnv(key string) error

DeleteEnv delete the env entry of specified key

func DeleteFeature

func DeleteFeature(plugin, key string) error

DeleteFeature deletes the specified plugin key

func DeleteServer

func DeleteServer(name string) error

DeleteServer deletes the server specified by name

func EndpointFromContext

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

EndpointFromContext retrieved the endpoint from the specified context

func EndpointFromServer

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

EndpointFromServer returns the endpoint from server.

func GetAllCurrentContextsList

func GetAllCurrentContextsList() ([]string, error)

GetAllCurrentContextsList returns all current context names as list

func GetAllCurrentContextsMap

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

GetAllCurrentContextsMap returns all current context per Target

func GetAllEnvs

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

GetAllEnvs retrieves all env values from config

func GetCLIDiscoverySource

func GetCLIDiscoverySource(name string) (*configapi.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

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

GetCLIDiscoverySources retrieves cli discovery sources

func GetCLIRepositories

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

GetCLIRepositories retrieves cli repositories

func GetCLIRepository

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

GetCLIRepository retrieves cli repository by name

func GetClientConfig

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

GetClientConfig retrieves the config from the local directory with file lock

func GetClientConfigNoLock

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

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

func GetConfigMetadata

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

GetConfigMetadata retrieves configMetadata

func GetConfigMetadataPatchStrategy

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

GetConfigMetadataPatchStrategy retrieves patch strategies

func GetConfigMetadataSetting

func GetConfigMetadataSetting(key string) (string, error)

func GetConfigMetadataSettings

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

GetConfigMetadataSettings retrieves feature flags

func GetContext

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

GetContext retrieves the context by name

func GetCurrentContext

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

GetCurrentContext retrieves the current context for the specified target

func GetCurrentServer

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

GetCurrentServer retrieves the current server

func GetEdition

func GetEdition() (string, error)

GetEdition retrieves ClientOptions Edition

func GetEnv

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

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

GetMetadata retrieves Metadata

func GetServer

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

GetServer retrieves server by name

func IsConfigMetadataSettingsEnabled

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

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 *configapi.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 *configapi.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

func ReleaseTanzuConfigNextGenLock()

ReleaseTanzuConfigNextGenLock releases the lock if the tanzuConfigLock was acquired

func ReleaseTanzuMetadataLock

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

func RemoveCurrentContext(target cliapi.Target) error

RemoveCurrentContext removed the current context of specified context type

func RemoveCurrentServer

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

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

SetCLIDiscoverySource add or update a cli discoverySource

func SetCLIDiscoverySources

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

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

func SetCLIRepository

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

SetCLIRepository add or update a repository

func SetConfigMetadataPatchStrategies

func SetConfigMetadataPatchStrategies(patchStrategies map[string]string) error

SetConfigMetadataPatchStrategies add or update map of patch strategies

func SetConfigMetadataPatchStrategy

func SetConfigMetadataPatchStrategy(key, value string) error

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

func SetConfigMetadataSetting

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

SetConfigMetadataSetting add or update a env key and value

func SetContext

func SetContext(c *configapi.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

func SetEdition(val string) (err error)

SetEdition adds or updates edition value

func SetEnv

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

SetEnv add or update a env key and value

func SetFeature

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

SetFeature add or update plugin key value

func SetServer

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

SetServer add or update server and currentServer

func StoreClientConfig

func StoreClientConfig(cfg *configapi.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

func UseUnifiedConfig() (bool, error)

UseUnifiedConfig checks useUnifiedConfig feature flag

Types

type CfgOptions

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

type CfgOpts

type CfgOpts func(config *CfgOptions)

func WithCfgPath

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

Jump to

Keyboard shortcuts

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