profilestore

package
v0.106.11 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 12 Imported by: 0

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

View Source
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

func NewDefaultStore() (*Store, error)

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

func NewStore(dir, fileName string) (*Store, error)

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

func (s *Store) AddProfile(name string, profile *cli.Profile) error

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

func (s *Store) ClearDefaultProfile() error

ClearDefaultProfile clears the default profile setting. Clearing an unset default is a no-op.

func (*Store) Dir

func (s *Store) Dir() string

Dir returns the directory containing the profile file (and its lock).

func (*Store) GetDefaultProfile

func (s *Store) GetDefaultProfile() string

GetDefaultProfile returns the name of the default profile, or empty string if none is set.

func (*Store) GetProfile

func (s *Store) GetProfile(name string) (*cli.Profile, error)

GetProfile returns a specific profile by name (case-insensitive).

func (*Store) GetProfiles

func (s *Store) GetProfiles() map[string]cli.Profile

GetProfiles returns all profiles from the config. Profile names are reported lowercased (viper normalizes map keys).

func (*Store) ListProfiles

func (s *Store) ListProfiles() []string

ListProfiles returns a sorted list of all profile names.

func (*Store) Path

func (s *Store) Path() string

Path returns the path of the profile file.

func (*Store) RemoveProfile

func (s *Store) RemoveProfile(name string) error

RemoveProfile removes a profile from the config. If the removed profile was the default profile, the default is cleared.

func (*Store) RemoveProfileIfTokenMatches

func (s *Store) RemoveProfileIfTokenMatches(name, token string) (bool, error)

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

func (s *Store) SetDefaultProfile(name string) error

SetDefaultProfile sets the default profile. The profile must exist.

func (*Store) SetDefaultProfileIfUnset

func (s *Store) SetDefaultProfileIfUnset(name string) (bool, error)

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

func (s *Store) UpdateProfile(name string, profile *cli.Profile) error

UpdateProfile updates an existing profile with new values. Only non-empty fields are updated.

func (*Store) UpsertProfile

func (s *Store) UpsertProfile(name string, profile *cli.Profile, extraFields map[string]any) error

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.

Jump to

Keyboard shortcuts

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