config

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: Apache-2.0 Imports: 7 Imported by: 2

Documentation

Overview

An abstraction of the Chef Workstation configuration file (config.toml).

Basic usage

This example is loading the Chef Workstation configuration file located by default at $HOME/.chef-workstation/config.toml and printing the log level:

package main

import "github.com/chef/go-libs/config"

func main() {
	cfg, err := config.New()
	if err != nil {
		fmt.Println("unable to read the config", err)
	}

	fmt.Println("the log level of my config is: ", cfg.Log.Level)
}

Index

Constants

View Source
const (
	ApplyExec          = "chef-apply"
	AutomateProduct    = "Chef Automate"
	ClientExec         = "chef-client"
	ClientProduct      = "Chef Infra Client"
	CompanyName        = "Chef Software"
	DirSuffix          = "chef"
	DocsWebsite        = "https://docs.chef.io"
	MainWebsite        = "https://chef.io"
	ServerProduct      = "Chef Infra Server"
	ShellExec          = "chef-shell"
	SoloExec           = "chef-solo"
	SoloProduct        = "Chef Infra Solo"
	UserConfDir        = ".chef"
	WorkstationDir     = ".chef-workstation"
	WorkstationProduct = "Chef Workstation"
	ZeroExec           = "chef-zero"
)
View Source
const (
	DefaultChefWorkstationDirectory = WorkstationDir
	DefaultChefWSUserConfigFile     = "config.toml"
	DefaultChefWSAppConfigFile      = ".app-managed-config.toml"
)
View Source
const DefaultChefDirectory = UserConfDir

Variables

View Source
var (
	UserConfigTomlNotFoundErr = fmt.Sprintf(`
  %[1]s file not found. (default: $HOME/%[2]s/%[1]s)

  setup your local configuration file by following this documentation:
    - https://www.chef.sh/docs/reference/config/
`, DefaultChefWSUserConfigFile, WorkstationDir)

	UserConfigTomlMalformedErr = fmt.Sprintf(`
  unable to parse %s file.

  verify the format of the configuration file by following this documentation:
    - https://www.chef.sh/docs/reference/config/
`, DefaultChefWSUserConfigFile)

	AppConfigTomlNotFoundErr = fmt.Sprintf(`
  %[1]s file not found. (default: $HOME/%[2]s/%[1]s)

  verify that the %[3]s App is runnig on your local workstation.
`, DefaultChefWSUserConfigFile, WorkstationDir, WorkstationProduct)

	AppConfigTomlMalformedErr = fmt.Sprintf(`
  unable to parse %s file.

  there must be a problem with the %s App, verify the format of the configuration by following this documentation:
    - https://www.chef.sh/docs/reference/config/
`, DefaultChefWSAppConfigFile, WorkstationProduct)
)

Functions

func ChefWorkstationDir

func ChefWorkstationDir() (string, error)

returns the ~/.chef-workstation directory

func FindChefWSAppConfigFile

func FindChefWSAppConfigFile() (string, error)

finds the application configuration file (default .chef-workstation/.app-managed-config.toml) inside the current directory and recursively, plus inside the $HOME directory

func FindChefWSUserConfigFile

func FindChefWSUserConfigFile() (string, error)

finds the user configuration file (default .chef-workstation/config.toml) inside the current directory and recursively, plus inside the $HOME directory

func FindConfigFile

func FindConfigFile(name string) (string, error)

finds the provided configuration file name inside the current directory, if the file is not there the, it looks up inside the users $HOME directory

Types

type Config

type Config struct {
	Telemetry     telemetrySettings `toml:"telemetry" mapstructure:"telemetry"`
	Log           logSettings       `toml:"log" mapstructure:"log"`
	Cache         cacheSettings     `toml:"cache" mapstructure:"cache"`
	Chef          chefSettings      `toml:"chef" mapstructure:"chef"`
	Updates       updatesSettings   `toml:"updates" mapstructure:"updates"`
	DataCollector dcSettings        `toml:"data_collector" mapstructure:"data_collector"`
	Connection    connSettings      `toml:"connection" mapstructure:"connection"`
	Features      map[string]bool   `toml:"features" mapstructure:"features"`
	Dev           devSettings       `toml:"dev" mapstructure:"dev"`
	Reports       reportSettings    `toml:"reports" mapstructure:"reports"`
}

abstraction of the chef-workstation configuration file (config.toml)

func App

func App(overrides ...OverrideFunc) (Config, error)

returns a new Config with only the WS App (Tray) config loaded

func New

func New(overrides ...OverrideFunc) (Config, error)

returns a new Config instance with both config loaded, the WS App (Tray) config and the User config

func User

func User(overrides ...OverrideFunc) (Config, error)

returns a new Config with only the User config loaded (`config.toml`)

func (*Config) MergeAppConfig

func (c *Config) MergeAppConfig() error

func (*Config) MergeUserConfig

func (c *Config) MergeUserConfig() error

type OverrideFunc

type OverrideFunc func(*Config)

override functions to override any particular setting

Jump to

Keyboard shortcuts

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