config

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config loads and resolves the cinc CLI credentials file: a TOML document holding a set of named connection profiles, in the same shape as Chef's `~/.chef/credentials` file.

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingServerURL = errors.New("config: profile is missing cinc_server_url (or chef_server_url)")

ErrMissingServerURL is Validate's error for a profile that names no server, such as a Supermarket-only profile or the one first-run setup writes when every prompt is left at its default.

Functions

func DefaultPath

func DefaultPath() (string, error)

DefaultPath returns the default credentials file location, ~/.cinc/credentials.

func EnvProfile added in v0.26.0

func EnvProfile() string

EnvProfile returns the profile name selected by environment variables, preferring CINC_PROFILE over CHEF_PROFILE, or "" when neither is set.

func ExpandHome added in v0.24.0

func ExpandHome(path string) (string, error)

ExpandHome expands a leading "~" or "~/" to the user's home directory and returns any other path unchanged. Every path the credentials file holds (client_key, supermarket_key, secret_file, trusted_certs_dir) goes through it when it is read, never when the file is written, so a rewritten profile keeps the portable ~ form rather than an absolute home path.

func UpdateProfile added in v0.24.0

func UpdateProfile(path, name string, mutate func(*Profile) error) error

UpdateProfile applies mutate to the profile named name in the credentials file at path and writes the result back.

This is the entry point callers should reach for when they are changing an existing profile. WriteProfile replaces every key cinc manages, so a caller that assembles a Profile from only the values it collected clears the ones it did not: `config create` never prompts for secret_file, supermarket_client_name or supermarket_key, so writing a Profile built from its answers alone silently deletes them. UpdateProfile starts from what is already on disk, so an unmentioned key keeps its value by construction rather than by every caller remembering to carry it.

A profile that does not exist yet starts empty, so this also serves create-or-update callers. Keys cinc does not model are preserved by WriteProfile regardless.

func ValidateSiteURL

func ValidateSiteURL(raw string) error

func WriteProfile

func WriteProfile(path, name string, p Profile) error

WriteProfile creates or updates one profile in the credentials file at path. Other profiles are left untouched, and within the profile being written only the keys cinc manages are rewritten; anything else the file holds is carried across verbatim. Comments and original key ordering are not retained, because the file is re-encoded as TOML.

func WriteProfileWithExtras added in v0.24.0

func WriteProfileWithExtras(path, name string, p Profile, extra map[string]any) error

WriteProfileWithExtras is WriteProfile for a profile that also carries keys cinc does not model, copied from somewhere other than the file being written: first-run migration moves a knife profile's node_name, validation_key and the like across this way. Each extra key is written verbatim, replacing any value the file already has for it. A key cinc manages is ignored in extra, because p is the source of truth for those.

Types

type Config

type Config struct {
	Profiles map[string]Profile
}

Config is the parsed contents of a cinc credentials file.

func Load

func Load(path string) (*Config, error)

Load reads and parses the credentials file at path. Each top-level TOML section becomes a named profile.

func (*Config) Profile

func (c *Config) Profile(name string) (Profile, error)

Profile resolves a connection profile by name. An empty name selects the profile named by $CINC_PROFILE, then $CHEF_PROFILE, falling back to "default". When both env vars are set CINC_PROFILE wins.

func (*Config) Validate

func (c *Config) Validate() []ValidationIssue

Validate reports configuration problems across every loaded profile. It is intentionally local-only: it validates TOML shape and URL/profile fields but does not perform network calls or authenticate.

type Profile

type Profile struct {
	ServerURL       string
	Org             string
	SupermarketSite string
	ClientName      string
	KeyPath         string
	SSLVerifyMode   string

	// SupermarketClientName and SupermarketKey optionally override the
	// identity used to sign Chef Supermarket uploads, so a user can
	// publish to the public Supermarket under a different username or key
	// than the one they use against their Cinc Server. Each field falls
	// back independently: the effective Supermarket username is
	// SupermarketClientName or, when empty, ClientName; the effective key
	// is SupermarketKey or, when empty, KeyPath. These are cinc-only keys
	// (knife has no equivalent). See SupermarketIdentity.
	SupermarketClientName string
	SupermarketKey        string

	// SecretFile is the path to the encrypted data bag secret used to
	// encrypt and decrypt `cinc databag secret` items. The on-disk key
	// is `secret_file`, matching knife's `knife[:secret_file]`, so the
	// same key serves cinc and chef users.
	SecretFile string

	// TrustedCertsDir is the trusted_certs_dir key exactly as written in
	// the credentials file: a directory of extra CA certificates to trust
	// on top of the system pool. The key name matches knife's, so the same
	// file serves cinc and chef users. It is kept unexpanded here so a
	// rewrite of the profile never bakes an absolute home path into the
	// file; ResolveTrustedCertsDir expands it and applies the defaults.
	TrustedCertsDir string

	// RawServerURL is the server URL exactly as written in the config, before
	// it is split into ServerURL + Org. It is preserved even when the URL is
	// malformed (ServerURL/Org are then empty) so validation can report the
	// precise problem instead of the whole load failing.
	RawServerURL string
}

Profile describes how to connect to a single Cinc Server. It is the resolved form of an on-disk credentials entry: the configured server URL has already been split into a bare server URL and an organization name.

func NewProfile

func NewProfile(serverURL, clientName, clientKey, sslVerifyMode, supermarketSite string) (Profile, error)

NewProfile builds a Profile from user-supplied configure values.

func (Profile) ResolveTrustedCertsDir added in v0.24.0

func (p Profile) ResolveTrustedCertsDir() (dir string, explicit bool, err error)

ResolveTrustedCertsDir returns the directory of extra CA certificates this profile trusts, and whether the profile configured it explicitly.

An explicit trusted_certs_dir has a leading ~ expanded to the home directory; any other path is returned as written, so a relative path is relative to the working directory, exactly as client_key is. The directory is not checked here: a missing explicit directory is the caller's error to report.

With nothing configured, the first of ~/.cinc/trusted_certs and ~/.chef/trusted_certs that exists as a directory is returned, with explicit false. When neither exists the result is "", meaning trust the system pool only.

func (Profile) SupermarketIdentity

func (p Profile) SupermarketIdentity() (name, keyPath string)

SupermarketIdentity returns the username and key path used to sign Chef Supermarket uploads. Each field falls back independently: the username is supermarket_client_name or, when unset, client_name; the key is supermarket_key or, when unset, client_key. This lets a user publish to the public Supermarket under a different identity than their Cinc Server client while overriding only the field that differs.

func (Profile) Validate

func (p Profile) Validate() error

Validate reports whether the profile has every field required to open a server connection.

func (Profile) ValidateIdentity

func (p Profile) ValidateIdentity() error

ValidateIdentity reports whether the profile has the fields needed to sign requests that target a Cinc Server organization.

func (Profile) ValidateSupermarketIdentity

func (p Profile) ValidateSupermarketIdentity() error

ValidateSupermarketIdentity reports whether the profile resolves to an identity that can sign Supermarket uploads, accounting for the supermarket_client_name/supermarket_key overrides and their fallback to client_name/client_key.

type ValidationIssue

type ValidationIssue struct {
	Profile string `json:"profile"`
	Field   string `json:"field"`
	Message string `json:"message"`
}

ValidationIssue describes one profile-level configuration problem.

Jump to

Keyboard shortcuts

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