config

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RecommendedConfigPathEnvVar = "MONOSKOPECONFIG"
	RecommendedHomeDir          = ".monoskope"
	RecommendedFileName         = "config"
	FileMode                    = 0644
)

Variables

View Source
var (
	ErrEmptyServer        = errors.New("has no server defined")
	ErrNoConfigExists     = errors.New("no valid monoconfig found")
	ErrAlreadyInitialized = errors.New("a configuration already exists")
)
View Source
var (
	RecommendedConfigDir = path.Join(util.HomeDir(), RecommendedHomeDir)
	RecommendedHomeFile  = path.Join(RecommendedConfigDir, RecommendedFileName)
)

Functions

This section is empty.

Types

type AuthInformation

type AuthInformation struct {
	Username string    `yaml:"username,omitempty"`
	Token    string    `yaml:"-"`
	Expiry   time.Time `yaml:"expiry,omitempty"`
}

func (*AuthInformation) HasToken

func (a *AuthInformation) HasToken() bool

HasToken checks that Token is not empty

func (*AuthInformation) IsTokenExpired

func (a *AuthInformation) IsTokenExpired() bool

IsTokenExpired checks if the auth token is expired with an offset

func (*AuthInformation) IsTokenExpiredExact

func (a *AuthInformation) IsTokenExpiredExact() bool

IsTokenExpiredExact checks if the auth token is expired

func (*AuthInformation) IsValid

func (a *AuthInformation) IsValid() bool

IsValid checks that Token is not empty and is not expired with an offset

func (*AuthInformation) IsValidExact

func (a *AuthInformation) IsValidExact() bool

IsValidExact checks that Token is not empty and is not expired

type ClientConfigManager

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

func NewLoader

func NewLoader() *ClientConfigManager

NewLoader is a convenience function that returns a new ClientConfigManager object with defaults

func NewLoaderFromConfig

func NewLoaderFromConfig(conf *Config) *ClientConfigManager

NewLoaderFromConfig is mainly intended to be used for tests. It allows setting the config without the need of an external file.

func NewLoaderFromExplicitFile

func NewLoaderFromExplicitFile(explicitFile string) *ClientConfigManager

NewLoaderFromExplicitFile is a convenience function that returns a new ClientConfigManager object with explicitFile set

func (*ClientConfigManager) GetConfig

func (l *ClientConfigManager) GetConfig() *Config

GetConfig returns the previously loaded config

func (*ClientConfigManager) GetConfigLocation

func (l *ClientConfigManager) GetConfigLocation() string

GetConfigLocation returns the location of the previously loaded config

func (*ClientConfigManager) InitConfig

func (l *ClientConfigManager) InitConfig(config *Config, force bool) error

func (*ClientConfigManager) LoadConfig

func (l *ClientConfigManager) LoadConfig() error

LoadConfig loads the config either from env or home file.

func (*ClientConfigManager) LoadFromBytes

func (*ClientConfigManager) LoadFromBytes(data []byte) (*Config, error)

LoadFromBytes takes a byte slice and deserializes the contents into Config object. Encapsulates deserialization without assuming the source is a file.

func (*ClientConfigManager) LoadFromFile

func (l *ClientConfigManager) LoadFromFile(filename string) (*Config, error)

LoadFromFile takes a filename and deserializes the contents into Config object

func (*ClientConfigManager) SaveConfig

func (l *ClientConfigManager) SaveConfig() error

func (*ClientConfigManager) SaveToFile

func (l *ClientConfigManager) SaveToFile(config *Config, filename string, permission os.FileMode) error

SaveToFile takes a config, serializes the contents and stores them into a file.

type Config

type Config struct {
	// Server is the address of the Monoskope Gateway (https://hostname:port).
	Server string `yaml:"server"`
	// KubeConfigPath is the filepath, where m8 will write its kubeConfig
	KubeConfigPath string `yaml:"KubeConfigPath"`
	// AuthInformation contains information to authenticate against Monoskope
	AuthInformation *AuthInformation `yaml:"authInformation,omitempty"`
	// ClusterAuthInformation contains information to authenticate against K8s clusters
	ClusterAuthInformation map[string]*AuthInformation `yaml:"clusterAuthInformation,omitempty"`
}

Config holds the information needed to build connect to remote monoskope instance as a given user

func NewConfig

func NewConfig() *Config

NewConfig is a convenience function that returns a new Config object with defaults

func (*Config) GetClusterAuthInformation

func (c *Config) GetClusterAuthInformation(clusterId, username, role string) *AuthInformation

func (*Config) HasAuthInformation

func (c *Config) HasAuthInformation() bool

HasAuthInformation checks if the the config contains AuthInformation

func (*Config) LoadToken

func (c *Config) LoadToken()

func (*Config) SetClusterAuthInformation

func (c *Config) SetClusterAuthInformation(clusterId, username, role, token string, expiry time.Time)

func (*Config) StoreToken

func (c *Config) StoreToken() error

func (*Config) String

func (c *Config) String() (string, error)

func (*Config) Validate

func (c *Config) Validate() error

Validate validates if the config is valid

Jump to

Keyboard shortcuts

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