profile

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package profile stores the CLI configuration for the named profile.

The profile stores common configuration values such as the organization and project ID to use when running commands. It also stores user settable values that customize CLI output; examples are setting the default output format or disabling color output.

Individual services may store their configuration in the profile as well, within a detected stanza.

Index

Constants

View Source
const (
	// ConfigDir is the directory that contains HCP CLI configuration.
	ConfigDir = "~/.config/hcp/"

	// ProfileDir is the directory that contains HCP CLI profiles.
	ProfileDir = "profiles/"
)
View Source
const (
	// ActiveProfileFileName is the file name of the active profile stored in
	// the ConfigDir.
	ActiveProfileFileName = "active_profile.hcl"
)

Variables

View Source
var (
	// ErrNoActiveProfileFilePresent is returned if no active profile file
	// exists.
	ErrNoActiveProfileFilePresent = errors.New("active profile file doesn't exist")

	// ErrActiveProfileFileEmpty is returned if the active profile file is
	// empty.
	ErrActiveProfileFileEmpty = errors.New("active profile is unset")
)
View Source
var (
	// ErrNoProfileFilePresent is returned when the requested profile does not
	// exist.
	ErrNoProfileFilePresent = errors.New("profile configuration file doesn't exist")

	// ErrInvalidProfileName is returned if a profile is created with an invalid
	// profile name.
	ErrInvalidProfileName = errors.New("profile name may only include a-z, A-Z, 0-9, or '-', must start with a letter, and can be no longer than 64 characters")
)

Functions

func PropertyNames

func PropertyNames() map[string]struct{}

PropertyNames returns the name of the properties in a profile. If the property is in a struct, such as Core, the property name will be <struct_name>/<property_name>, such as "core/no_color".

Types

type ActiveProfile

type ActiveProfile struct {
	Name string `hcl:"name"`
	// contains filtered or unexported fields
}

ActiveProfile stores the active profile.

func (*ActiveProfile) Write

func (c *ActiveProfile) Write() error

Write writes the active profile to disk.

type Core

type Core struct {
	// NoColor disables color output
	NoColor *bool `hcl:"no_color,optional" json:",omitempty"`

	// Quiet disables prompting for user input and minimizes output.
	Quiet *bool `hcl:"quiet,optional" json:",omitempty"`

	// OutputFormat dictates the default output format if unspecified.
	OutputFormat *string `hcl:"output_format,optional" json:",omitempty"`

	// Verbosity is the default verbosity to log at
	Verbosity *string `hcl:"verbosity,optional" json:",omitempty"`
}

Core stores configuration settings that impact the CLIs behavior.

func (*Core) GetOutputFormat

func (c *Core) GetOutputFormat() string

GetOutputFormat returns the set output format or an empty string if it has not been configured.

func (*Core) GetVerbosity

func (c *Core) GetVerbosity() string

GetVerbosity returns the set verbosity or an empty string if it has not been configured.

func (*Core) IsQuiet added in v0.4.0

func (c *Core) IsQuiet() bool

IsQueit returns whether the quiet property has been configured to be quiet.

func (*Core) Predict

func (c *Core) Predict(args complete.Args) []string

func (*Core) Validate

func (c *Core) Validate() error

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader is used to load and interact with profiles on disk.

func NewLoader

func NewLoader() (*Loader, error)

NewLoader returns a new loader or an error if the loader can't be instantiated.

func TestLoader

func TestLoader(t *testing.T) *Loader

TestLoader returns a Loader suitable for testing. All profiles that are accessed will be in the context of a temporary directory.

func (*Loader) DefaultActiveProfile

func (l *Loader) DefaultActiveProfile() *ActiveProfile

DefaultActiveProfile returns an active profile set to default.

func (*Loader) DefaultProfile

func (l *Loader) DefaultProfile() *Profile

DefaultProfile returns the minimal default profile. If environment variables related to organization and project are set, they are honored here.

func (*Loader) DeleteProfile

func (l *Loader) DeleteProfile(name string) error

DeleteProfile deletes the profile with the given name. If the profile can not be found, ErrNoProfileFilePresent will be returned. Otherwise, an error will be returned if the profile can not be deleted for any other reason..

func (*Loader) GetActiveProfile

func (l *Loader) GetActiveProfile() (*ActiveProfile, error)

GetActiveProfile returns the current profile

func (*Loader) ListProfiles

func (l *Loader) ListProfiles() ([]string, error)

ListProfiles returns the available profile names

func (*Loader) LoadProfile

func (l *Loader) LoadProfile(name string) (*Profile, error)

LoadProfile loads a profile given its name. If the profile can not be found, ErrNoProfileFilePresent will be returned. Otherwise, an error will be returned if the profile is invalid.

func (*Loader) LoadProfiles

func (l *Loader) LoadProfiles() ([]*Profile, error)

LoadProfiles loads all the available profiles

func (*Loader) NewProfile

func (l *Loader) NewProfile(name string) (*Profile, error)

NewProfile returns an empty profile with the given name.

type Profile

type Profile struct {
	// Name is the name of the profile
	Name string `hcl:"name"`

	// OrganizationID stores the organization_id to make requests against.
	OrganizationID string `hcl:"organization_id"`

	// ProjectID stores the project_id to make requests against.
	ProjectID string `hcl:"project_id"`

	// Core stores core CLI configuration values.
	Core *Core `hcl:"core,block" json:",omitempty"`

	// VaultSecrets stores vault-secrets CLI configuration values
	VaultSecrets *VaultSecretsConf `hcl:"vault-secrets,block" json:",omitempty"`
	// contains filtered or unexported fields
}

Profile is a named set of configuration for the HCP CLI. It captures common configuration values such as the organization and project being interacted with, but also allows storing service specific configuration.

func TestProfile

func TestProfile(t *testing.T) *Profile

TestProfile returns a profile appropriate for use during testing. If interacting with more than one profile, prefer using TestLoader.

func (*Profile) Clean

func (p *Profile) Clean()

Clean nils any empty component.

func (*Profile) GetOrgResourcePart

func (p *Profile) GetOrgResourcePart() resourcename.Part

func (*Profile) GetProjectResourcePart

func (p *Profile) GetProjectResourcePart() resourcename.Part

func (*Profile) Predict

func (p *Profile) Predict(args complete.Args) []string

Predict predicts the HCL key names and basic settable values

func (*Profile) SetOrgID

func (p *Profile) SetOrgID(id string) *Profile

SetOrgID sets the OrganizationID

func (*Profile) SetProjectID

func (p *Profile) SetProjectID(id string) *Profile

SetProjectID sets the ProjectID

func (*Profile) String

func (p *Profile) String() string

String returns an HCL formatted string representation of the profile.

func (*Profile) Validate

func (p *Profile) Validate() error

Validate validates that the set values are valid. It validates parameters that do not require any communication with HCP.

func (*Profile) Write

func (p *Profile) Write() error

Write writes the profile to disk.

type VaultSecretsConf added in v0.3.0

type VaultSecretsConf struct {
	// AppName stores the app name against which the requests will be made.
	AppName string `hcl:"app"`
}

VaultSecrets is a named set of configuration for the HCP CLI. It captures vault secrets related configuration values such as app name.

func (*VaultSecretsConf) Predict added in v0.3.0

func (vsc *VaultSecretsConf) Predict(args complete.Args) []string

Predict predicts the HCL key names and basic settable values

func (*VaultSecretsConf) Validate added in v0.3.0

func (vsc *VaultSecretsConf) Validate() error

Validate validates that the set values are valid. It validates parameters that do not require any communication with HCP.

Jump to

Keyboard shortcuts

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