config

package
v0.0.0-...-7f2378c Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package config defines all the configuration variables used across the diginfractl commands.

Index

Constants

View Source
const (
	// EnvPrefix is the prefix for all the environment variables.
	EnvPrefix = "DIGINFRACTL"
	// ConfigPath is the path to the default config.
	ConfigPath = "/etc/diginfractl/diginfractl.yaml"
	// PluginsDir default path where plugins are installed.
	PluginsDir = "/usr/share/diginfra/plugins"
	// RulesfilesDir default path where rulesfiles are installed.
	RulesfilesDir = "/etc/diginfra"
	// AssetsDir default path where assets are installed.
	AssetsDir = "/etc/diginfra/assets"
	// FollowResync time interval how often it checks for newer version of the artifact.
	// Default values is set every 24 hours.
	FollowResync = time.Hour * 24

	// RegistryCredentialConfigKey is the Viper key for the credentials store path configuration.
	//#nosec G101 -- false positive
	RegistryCredentialConfigKey = "registry.creds.config"
	// RegistryAuthOauthKey is the Viper key for OAuth authentication configuration.
	RegistryAuthOauthKey = "registry.auth.oauth"
	// RegistryAuthBasicKey is the Viper key for basic authentication configuration.
	RegistryAuthBasicKey = "registry.auth.basic"
	// RegistryAuthGcpKey is the Viper key for gcp authentication configuration.
	RegistryAuthGcpKey = "registry.auth.gcp"

	// IndexesKey is the Viper key for indexes configuration.
	IndexesKey = "indexes"

	// ArtifactFollowEveryKey is the Viper key for follower "every" configuration.
	ArtifactFollowEveryKey = "artifact.follow.every"
	// ArtifactFollowCronKey is the Viper key for follower "cron" configuration.
	ArtifactFollowCronKey = "artifact.follow.cron"
	// ArtifactFollowRefsKey is the Viper key for follower "artifacts" configuration.
	ArtifactFollowRefsKey = "artifact.follow.refs"
	// ArtifactFollowDiginfraVersionsKey is the Viper key for follower "diginfraVersions" configuration.
	ArtifactFollowDiginfraVersionsKey = "artifact.follow.diginfraversions"
	// ArtifactFollowRulesfilesDirKey is the Viper key for follower "rulesFilesDir" configuration.
	ArtifactFollowRulesfilesDirKey = "artifact.follow.rulesfilesdir"
	// ArtifactFollowPluginsDirKey is the Viper key for follower "pluginsDir" configuration.
	ArtifactFollowPluginsDirKey = "artifact.follow.pluginsdir"
	// ArtifactFollowAssetsDirKey is the Viper key for follower "pluginsDir" configuration.
	ArtifactFollowAssetsDirKey = "artifact.follow.assetsdir"
	// ArtifactFollowTmpDirKey is the Viper key for follower "pluginsDir" configuration.
	ArtifactFollowTmpDirKey = "artifact.follow.tmpdir"

	// ArtifactInstallArtifactsKey is the Viper key for installer "artifacts" configuration.
	ArtifactInstallArtifactsKey = "artifact.install.refs"
	// ArtifactInstallRulesfilesDirKey is the Viper key for installer "rulesFilesDir" configuration.
	ArtifactInstallRulesfilesDirKey = "artifact.install.rulesfilesdir"
	// ArtifactInstallPluginsDirKey is the Viper key for installer "pluginsDir" configuration.
	ArtifactInstallPluginsDirKey = "artifact.install.pluginsdir"
	// ArtifactInstallAssetsDirKey is the Viper key for installer "pluginsDir" configuration.
	ArtifactInstallAssetsDirKey = "artifact.install.assetsdir"
	// ArtifactInstallResolveDepsKey is the Viper key for installer "resolveDeps" configuration.
	ArtifactInstallResolveDepsKey = "artifact.install.resolveDeps"

	// ArtifactAllowedTypesKey is the Viper key for the whitelist of artifacts to be installed in the system.
	ArtifactAllowedTypesKey = "artifact.allowedTypes"
	// ArtifactNoVerifyKey is the Viper key for skipping signature verification.
	ArtifactNoVerifyKey = "artifact.noVerify"

	// DriverKey is the Viper key for driver structure.
	DriverKey = "driver"
	// DriverTypeKey is the Viper key for the driver type.
	DriverTypeKey = "driver.type"
	// DriverVersionKey is the Viper key for the driver version.
	DriverVersionKey = "driver.version"
	// DriverReposKey is the Viper key for the driver repositories.
	DriverReposKey = "driver.repos"
	// DriverNameKey is the Viper key for the driver name.
	DriverNameKey = "driver.name"
	// DriverHostRootKey is the Viper key for the driver host root.
	DriverHostRootKey = "driver.hostRoot"
	// DriverNamespaceKey is the Viper key for the driver config namespace flag.
	DriverNamespaceKey = "driver.config.namespace"
	// DriverUpdateDiginfraKey is the Viper key for the driver config update-diginfra flag.
	DriverUpdateDiginfraKey = "driver.config.update-diginfra"
)

Variables

View Source
var (
	// ConfigDir configuration directory for diginfractl.
	ConfigDir string
	// DiginfractlPath path inside the configuration directory where the diginfractl stores its config files.
	DiginfractlPath string
	// IndexesFile name of the file where the indexes info is stored. It lives under DiginfractlPath.
	IndexesFile string
	// IndexesDir is where the actual indexes are stored. It is a directory that lives under DiginfractlPath.
	IndexesDir string
	// ClientCredentialsFile name of the file where oauth client credentials are stored. It lives under DiginfractlPath.
	ClientCredentialsFile string
	// DefaultIndex is the default index for the diginfra organization.
	DefaultIndex Index
	// DefaultRegistryCredentialConfPath is the default path for the credential store configuration file.
	DefaultRegistryCredentialConfPath = filepath.Join(config.Dir(), "config.json")
	// DefaultDriver is the default config for the diginfra organization.
	DefaultDriver Driver

	// SemicolonSeparatedRegexp is a regexp matching semi-colon separated values, without trailing separator.
	SemicolonSeparatedRegexp = regexp.MustCompile(`^([^;]+)(;[^;]+)*$`)
	// CommaSeparatedRegexp is a regexp matching comma separated values, without trailing separator.
	CommaSeparatedRegexp = regexp.MustCompile(`^([^,]+)(,[^,]+)*$`)
)

Functions

func AddGcp

func AddGcp(gcps []GcpAuth, configFile string) error

AddGcp appends the provided gcps to a configuration file if not present.

func AddIndexes

func AddIndexes(indexes []Index, configFile string) error

AddIndexes appends the provided indexes to a configuration file if not present.

func ArtifactAllowedTypes

func ArtifactAllowedTypes() (*oci.ArtifactTypeSlice, error)

ArtifactAllowedTypes retrieves the allowed types section of the config file.

func ClientCredentials

func ClientCredentials(reg string) (*clientcredentials.Config, error)

ClientCredentials retrieves the client credentials for a specific registry.

func DriverRepos

func DriverRepos() ([]string, error)

DriverRepos retrieves the driver repos of the config file.

func DriverTypes

func DriverTypes() ([]string, error)

DriverTypes retrieves the driver types of the config file.

func Load

func Load(path string) error

Load is used to load the config file.

func RegistryCredentialConfPath

func RegistryCredentialConfPath() string

RegistryCredentialConfPath retrieves the path to the credential store configuration.

func RemoveIndexes

func RemoveIndexes(names []string, configFile string) error

RemoveIndexes removes the index entries from a configuration file if any is found.

func StoreDriver

func StoreDriver(driverCfg *Driver, configFile string) error

StoreDriver stores a driver conf in config file.

func UpdateConfigFile

func UpdateConfigFile(key string, value interface{}, path string) error

UpdateConfigFile is used to update a section of the config file. We create a brand new viper instance for doing it so that we are sure that modifications are scoped to the passed key with no side effects (e.g user forgot to unset one env variable for another config setting, avoid to mistakenly update it).

func WriteClientCredentials

func WriteClientCredentials(registry string, cred *clientcredentials.Config) error

WriteClientCredentials writes client credentials to config file.

Types

type BasicAuth

type BasicAuth struct {
	Registry string `mapstructure:"registry"`
	User     string `mapstructure:"user"`
	Password string `mapstructure:"password"`
}

BasicAuth represents a Basic credential.

func BasicAuths

func BasicAuths() ([]BasicAuth, error)

BasicAuths retrieves the basicAuths section of the config file.

type DiginfraVersions

type DiginfraVersions map[string]string

DiginfraVersions represent the map for Diginfra requirements In general, it should be a map[string]semver.Version, but given that we have fields like engine_version that are only numbers, we shoud be as muche generic as possible.

type Driver

type Driver struct {
	Type     []string `mapstructure:"type"`
	Name     string   `mapstructure:"name"`
	Repos    []string `mapstructure:"repos"`
	Version  string   `mapstructure:"version"`
	HostRoot string   `mapstructure:"hostRoot"`
}

Driver represents the internal driver configuration (with Type string).

type Follow

type Follow struct {
	Every            time.Duration `mapstructure:"every"`
	Artifacts        []string      `mapstructure:"artifacts"`
	DiginfraVersions string        `mapstructure:"diginfraVersions"`
	RulesfilesDir    string        `mapstructure:"rulesFilesDir"`
	PluginsDir       string        `mapstructure:"pluginsDir"`
	TmpDir           string        `mapstructure:"pluginsDir"`
	NoVerify         bool          `mapstructure:"noVerify"`
}

Follow represents the follower configuration.

func Follower

func Follower() (Follow, error)

Follower retrieves the follower section of the config file.

type GcpAuth

type GcpAuth struct {
	Registry string `mapstructure:"registry"`
}

GcpAuth represents a Gcp activation setting.

func Gcps

func Gcps() ([]GcpAuth, error)

Gcps retrieves the gcp auth section of the config file.

type Index

type Index struct {
	Name    string `mapstructure:"name"`
	URL     string `mapstructure:"url"`
	Backend string `mapstructure:"backend"`
}

Index represents a configured index.

func Indexes

func Indexes() ([]Index, error)

Indexes retrieves the indexes section of the config file.

type Install

type Install struct {
	Artifacts     []string `mapstructure:"artifacts"`
	RulesfilesDir string   `mapstructure:"rulesFilesDir"`
	PluginsDir    string   `mapstructure:"pluginsDir"`
	ResolveDeps   bool     `mapstructure:"resolveDeps"`
	NoVerify      bool     `mapstructure:"noVerify"`
}

Install represents the installer configuration.

func Installer

func Installer() (Install, error)

Installer retrieves the installer section of the config file.

type OauthAuth

type OauthAuth struct {
	Registry     string `mapstructure:"registry"`
	ClientSecret string `mapstructure:"clientSecret"`
	ClientID     string `mapstructure:"clientID"`
	TokenURL     string `mapstructure:"tokenURL"`
}

OauthAuth represents an OAuth credential.

func OauthAuths

func OauthAuths() ([]OauthAuth, error)

OauthAuths retrieves the oauthAuths section of the config file.

type RegistryClientCredentials

type RegistryClientCredentials map[string]clientcredentials.Config

RegistryClientCredentials is used to store registry:clientCrendetials key value. This is done to be in accordance with the way Docker stores credentials, so that users will be able to store only one credential per registry.

Jump to

Keyboard shortcuts

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