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
- Variables
- func PropertyNames() map[string]struct{}
- type ActiveProfile
- type Core
- type Loader
- func (l *Loader) DefaultActiveProfile() *ActiveProfile
- func (l *Loader) DefaultProfile() *Profile
- func (l *Loader) DeleteProfile(name string) error
- func (l *Loader) GetActiveProfile() (*ActiveProfile, error)
- func (l *Loader) ListProfiles() ([]string, error)
- func (l *Loader) LoadProfile(name string) (*Profile, error)
- func (l *Loader) LoadProfiles() ([]*Profile, error)
- func (l *Loader) NewProfile(name string) (*Profile, error)
- type Profile
- func (p *Profile) Clean()
- func (p *Profile) GetOrgResourcePart() resourcename.Part
- func (p *Profile) GetProjectResourcePart() resourcename.Part
- func (p *Profile) Predict(args complete.Args) []string
- func (p *Profile) SetOrgID(id string) *Profile
- func (p *Profile) SetProjectID(id string) *Profile
- func (p *Profile) String() string
- func (p *Profile) Validate() error
- func (p *Profile) Write() error
Constants ¶
const ( // ConfigDir is the directory that contains HCP CLI configuration. ConfigDir = "~/.config/hcp/" // ProfileDir is the directory that contains HCP CLI profiles. ProfileDir = "profiles/" )
const ( // ActiveProfileFileName is the file name of the active profile stored in // the ConfigDir. ActiveProfileFileName = "active_profile.hcl" )
Variables ¶
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") )
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"` // 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 ¶
GetOutputFormat returns the set output format or an empty string if it has not been configured.
func (*Core) GetVerbosity ¶
GetVerbosity returns the set verbosity or an empty string if it has not been configured.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader is used to load and interact with profiles on disk.
func TestLoader ¶
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 ¶
DefaultProfile returns the minimal default profile. If environment variables related to organization and project are set, they are honored here.
func (*Loader) DeleteProfile ¶
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 ¶
ListProfiles returns the available profile names
func (*Loader) LoadProfile ¶
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 ¶
LoadProfiles loads all the available profiles
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"` // 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 ¶
TestProfile returns a profile appropriate for use during testing. If interacting with more than one profile, prefer using TestLoader.
func (*Profile) GetOrgResourcePart ¶
func (p *Profile) GetOrgResourcePart() resourcename.Part
func (*Profile) GetProjectResourcePart ¶
func (p *Profile) GetProjectResourcePart() resourcename.Part
func (*Profile) SetProjectID ¶
SetProjectID sets the ProjectID