credentials

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 credentials file (credentials).

Basic usage

In this example loading the credentials file and printing the client name from the "dev" profile:

package main

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

func main() {
    profile := "dev"
    creds, err := credentials.New(profile)
    if err != nil {
      fmt.Println("unable to read the credentials", err)
    }
    fmt.Printf("The client_name from the '%s' profile is: %s", creds.ClientName)
}

Index

Constants

View Source
const (
	DefaultProfileName = "default"
	DefaultFileName    = "credentials"
)
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"
)

Variables

View Source
var (
	ProfileNotFoundErr = fmt.Sprintf(`
  profile not found in credentials file.

  verify the format of the credentials file by following this documentation:
    - %s/knife_setup.html#knife-profiles
`, DocsWebsite)

	CredentialsNotFoundErr = fmt.Sprintf(`
  credentials file not found. (default: $HOME/%s/credentials)

  setup your local credentials config by following this documentation:
    - %s/knife_setup.html#knife-profiles
`, UserConfDir, DocsWebsite)

	MalformedCredentialsFileErr = fmt.Sprintf(`
  unable to parse credentials file.

  verify the format of the credentials file by following this documentation:
    - %s/knife_setup.html#knife-profiles
`, DocsWebsite)
)

Functions

func FindCredentialsFile

func FindCredentialsFile() (string, error)

finds the credentials file (default .chef/credentials) inside the current directory and recursively, plus inside the $HOME directory

Types

type Credentials

type Credentials struct {
	// list of all profiles available
	Profiles

	// active credentials detail from the active profile
	CredsDetail
	// contains filtered or unexported fields
}

main struct that holds all profiles, active profile and credentials

func FromViper

func FromViper(profile string, overrides ...OverrideFunc) (Credentials, error)

returns a Credentials instance from the current viper config

func New

func New(profile string, overrides ...OverrideFunc) (Credentials, error)

returns a Credentials instance using the provided profile

func NewDefault

func NewDefault() (Credentials, error)

returns a Credentials instance using the default profile

func (*Credentials) ActiveProfile

func (c *Credentials) ActiveProfile() string

returns the active profile

func (*Credentials) SwitchProfile

func (c *Credentials) SwitchProfile(name string) error

switch the active profile inside the credentials struct

type CredsDetail

type CredsDetail struct {
	ChefServerUrl string `toml:"chef_server_url" mapstructure:"chef_server_url"`
	ClientName    string `toml:"client_name" mapstructure:"client_name"`
	ClientKey     string `toml:"client_key" mapstructure:"client_key"`
}

the credentials from a single profile

type OverrideFunc

type OverrideFunc func(*Credentials)

override functions can be passed to credentials.FromViper to override any particular setting

type Profiles

type Profiles map[string]CredsDetail

a list of credentials, this type maps exactly as our .chef/credentials file

example:

[default] client_name = "foo" client_key = "foo.pem" chef_server_url = "chef-server.example.com/organizations/bubu"

[dev] client_name = "dev" client_key = "dev.pem" chef_server_url = "chef-server.example.com/organizations/dev"

Jump to

Keyboard shortcuts

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