Documentation
¶
Overview ¶
Package profilestore is the shared implementation of the Hatchet CLI's profile store (~/.hatchet/profiles.yaml by default).
The hatchet CLI uses it for every profile operation, and external processes (for example an embedded engine registering itself as a discoverable profile) use the same package so that all writers agree on the file location, the lock protocol, and the on-disk format. Writes preserve comments, key ordering, and fields the store does not know about, so a profile entry may carry extra metadata that the CLI ignores.
Index ¶
- Constants
- type Store
- func (s *Store) AddProfile(name string, profile *cli.Profile) error
- func (s *Store) ClearDefaultProfile() error
- func (s *Store) Dir() string
- func (s *Store) GetDefaultProfile() string
- func (s *Store) GetProfile(name string) (*cli.Profile, error)
- func (s *Store) GetProfiles() map[string]cli.Profile
- func (s *Store) ListProfiles() []string
- func (s *Store) Path() string
- func (s *Store) RemoveProfile(name string) error
- func (s *Store) RemoveProfileIfTokenMatches(name, token string) (bool, error)
- func (s *Store) SetDefaultProfile(name string) error
- func (s *Store) SetDefaultProfileIfUnset(name string) (bool, error)
- func (s *Store) UpdateProfile(name string, profile *cli.Profile) error
- func (s *Store) UpsertProfile(name string, profile *cli.Profile, extraFields map[string]any) error
Constants ¶
const DefaultProfileFileName = "profiles.yaml"
DefaultProfileFileName is the profile file name used when none is configured via HATCHET_CLI_PROFILE_FILE_NAME or the profileFileName key in ~/.hatchet/config.yaml.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store reads and writes the profile file in a fixed directory. Reads go through viper (lenient and case-insensitive, so unknown fields are ignored and key casing does not matter); writes take the shared config.lock, surgically edit the yaml document, and replace the file atomically with 0600 permissions.
A Store is safe for concurrent use within a process, and the file lock serializes writers across processes.
func NewDefaultStore ¶
NewDefaultStore opens the profile store at the location the CLI uses: ~/.hatchet, with the profile file name taken from the HATCHET_CLI_PROFILE_FILE_NAME environment variable or the profileFileName key in ~/.hatchet/config.yaml, defaulting to profiles.yaml.
func NewStore ¶
NewStore opens the profile store in dir (the ~/.hatchet directory), using fileName as the profile file name ("" means profiles.yaml). A missing directory or file is fine: reads see an empty store and the first write creates both. An unreadable or malformed file is an error.
func (*Store) AddProfile ¶
AddProfile adds a new profile to the config (or fully overwrites the named profile's known fields). All profile fields are required; TLSStrategy defaults to "tls" when empty (the default is written back to profile). Unknown fields already stored under the same profile entry are preserved.
func (*Store) ClearDefaultProfile ¶
ClearDefaultProfile clears the default profile setting. Clearing an unset default is a no-op.
func (*Store) GetDefaultProfile ¶
GetDefaultProfile returns the name of the default profile, or empty string if none is set.
func (*Store) GetProfile ¶
GetProfile returns a specific profile by name (case-insensitive).
func (*Store) GetProfiles ¶
GetProfiles returns all profiles from the config. Profile names are reported lowercased (viper normalizes map keys).
func (*Store) ListProfiles ¶
ListProfiles returns a sorted list of all profile names.
func (*Store) RemoveProfile ¶
RemoveProfile removes a profile from the config. If the removed profile was the default profile, the default is cleared.
func (*Store) RemoveProfileIfTokenMatches ¶
RemoveProfileIfTokenMatches removes the named profile only when its stored token equals token, reporting whether an entry was removed. A missing file, profile, or non-matching token is not an error, and the default-profile setting is never touched: this is the primitive for a registration that must not delete a newer instance's entry (last writer wins).
func (*Store) SetDefaultProfile ¶
SetDefaultProfile sets the default profile. The profile must exist.
func (*Store) SetDefaultProfileIfUnset ¶
SetDefaultProfileIfUnset makes name the default profile when none is configured and reports whether it did. The check and the write happen under the same file lock against the freshly parsed file, so concurrent callers cannot both observe an unset default and both report success.
func (*Store) UpdateProfile ¶
UpdateProfile updates an existing profile with new values. Only non-empty fields are updated.
func (*Store) UpsertProfile ¶
UpsertProfile is AddProfile plus extraFields: additional entries written under the same profile mapping (keys are lowercased). The CLI ignores fields it does not know, so extraFields can carry caller metadata; values go through the yaml encoder, meaning time.Time values become unquoted yaml timestamps just like expiresAt.