config

package
v0.0.0-...-3b3e3cc Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package config manages project-independent configurations. Configurations describe the environment for the projects for a user, and system-wide stored in /etc/cneconfig

Index

Constants

View Source
const (
	UserConfigFile    = ".cneconfig"
	SystemConfigFile  = "/etc/cneconfig"
	ProjectConfigFile = "cneconfig"
	ConfigFilePerms   = 0644

	DefaultPackageVersion = "latest"

	DefaultContextName = "default"

	DefaultRuntimeName       = "containerd"
	DefaultRuntimeEngine     = "containerd"
	DefaultRuntimeSocketName = "/run/containerd/containerd.sock"
	DefaultRuntimeNamespace  = "cne"

	DefaultRegistryName     = "docker.io"
	DefaultRegistryDomain   = "docker.io"
	DefaultRegistryRepoName = "library"
)
View Source
const (
	UpgradeNone  = ""
	UpgradeImage = "image"
	UpgradeApt   = "apt"
)

Variables

View Source
var CneVersion string

CneVersion is set in Makefile by a linker option to the git hash/version

Functions

func SetContextName

func SetContextName(name string)

Types

type Config

type Config struct {
	Settings Settings
	Context  map[string]*Context
	Runtime  map[string]*Runtime
	Registry map[string]*Registry
}

func NewConfig

func NewConfig() *Config

NewConfig returns an empty confguration

func NewDefault

func NewDefault() *Config

NewDefault returns a new default configuration

func (*Config) CreateContext

func (conf *Config) CreateContext(name string) (*Context, error)

func (*Config) CreateRegistry

func (conf *Config) CreateRegistry(name string) (*Registry, error)

func (*Config) CreateRuntime

func (conf *Config) CreateRuntime(name, engine string) (*Runtime, error)

func (*Config) FullImageName

func (conf *Config) FullImageName(name string) (string, error)

func (*Config) GetAllByName

func (conf *Config) GetAllByName(name string) (string, interface{}, error)

GetAllByName returns a 'reflect.Value' for the selected field, which can be a structure for nested structures.

func (*Config) GetByName

func (conf *Config) GetByName(name string) (string, string, error)

Get returns the value of the configuration field specified by name Errors:

  • ErrNotFound if the specified configuration field cannot be found

func (*Config) GetContext

func (conf *Config) GetContext() (*Context, string, error)

GetContext returns the context defined in the configuration files or from the --context flag when CNE was started.

func (*Config) GetEntryValue

func (conf *Config) GetEntryValue(entry string) (interface{}, error)

func (*Config) GetRegistry

func (conf *Config) GetRegistry(args ...string) (*Registry, error)

GetRegistry returns the specified registry or context-specific registry if name is empty

func (*Config) GetRuntime

func (conf *Config) GetRuntime(args ...string) (*Runtime, error)

GetRuntime returns the specified runtime or context-specific runtime if name is empty

func (*Config) RemoveContext

func (conf *Config) RemoveContext(name string) error

func (*Config) RemoveRegistry

func (conf *Config) RemoveRegistry(name string) error

func (*Config) RemoveRuntime

func (conf *Config) RemoveRuntime(name string) error

func (*Config) RenameContext

func (conf *Config) RenameContext(from, to string) error

func (*Config) RenameEntry

func (conf *Config) RenameEntry(entry, from, to string) error

func (*Config) RenameRegistry

func (conf *Config) RenameRegistry(from, to string) error

func (*Config) RenameRuntime

func (conf *Config) RenameRuntime(from, to string) error

func (*Config) SetByName

func (conf *Config) SetByName(name string, value string) (string, string, error)

func (*Config) Update

func (conf *Config) Update(path string) error

Update updates the configuration with the values from the specified configuration file

func (*Config) UpdateProjectConfig

func (conf *Config) UpdateProjectConfig(path string) error

UpdateProjectConfig updates the configuration from the config file in the project path

func (*Config) User

func (conf *Config) User() (User, error)

GetUser returns the details and credentials of the current user

func (*Config) WriteProjectConfig

func (conf *Config) WriteProjectConfig(path string) error

WriteLocalConfig writes the configuration to the project directory

func (*Config) WriteSystemConfig

func (conf *Config) WriteSystemConfig() error

WriteSystemConfig writes the system configuration to /etc/cneconfig.

func (*Config) WriteUserConfig

func (conf *Config) WriteUserConfig() error

WriteUserConfig writes the user configuration in the home directory of the current user.

type Context

type Context struct {
	Runtime  string
	Registry string
	Options  map[string]string `cne:"inline"`
}

func (*Context) UpdateContextOptions

func (confCtx *Context) UpdateContextOptions(line string) error

type Parameters

type Parameters struct {
	Upgrade string // upgrade the listed components during container rebuilt
}

type Registry

type Registry struct {
	Domain   string
	RepoName string
}

type Runtime

type Runtime struct {
	Engine     string `toml:"Engine,omitempty"`
	SocketName string `toml:"SocketName,omitempty"`
	Namespace  string `cne:"ReadOnly" toml:"Namespace,omitempty"`
}

type Settings

type Settings struct {
	Context string `toml:",omitempty"`
}

type User

type User struct {
	Username  string
	Groupname string
	Shell     string
	IsSudo    bool
	IsSuid    bool
	UID       uint32
	EUID      uint32
	GID       uint32
	HomeDir   string
	Pwd       string
	BuildUID  uint32
	BuildGID  uint32
}

func CurrentUser

func CurrentUser() (User, error)

CurrentUser returns information about the current user. Note that for IsSudo, the CNE binary must run as root and SUDO_ envvars must be set.

Jump to

Keyboard shortcuts

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