Help us shape the future of Go! Take the 2026 Go Developer Survey

profile

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInUse = errors.New("another meshstack command is changing the profiles")

ErrInUse is what LoadProfiles returns with ExclusiveLock while another command holds the profiles.

View Source
var ErrNoStoredProfile = errors.New("no stored profile")
View Source
var NameSetting = setting.Setting[Name]{
	Env: "MESHSTACK_PROFILE",
	Short: func(envKey string) string {
		return fmt.Sprintf("The profile whose credentials and defaults this run uses. Also read from %s.", envKey)
	},
	Long: func(envKey string) string {
		return fmt.Sprintf("The profile whose credentials and defaults this run uses, also read from `%s`.\n\n"+
			"A profile is a named bundle of endpoint and credential, written by "+
			"`meshstack auth login` into the meshStack CLI's configuration directory. It supplies each of those "+
			"only where nothing above it did, so it is never an override.\n\n"+
			"With no name given, the profile is the one whose endpoint matches the endpoint in use, else the one "+
			"the last `meshstack auth login` selected, else `default`.", envKey)
	},
	Default: setting.StaticDefault("default"),
	Parse:   setting.ParseTextUnmarshaler[Name],
}

Functions

func ResolveProfile

func ResolveProfile(ctx context.Context, opts ResolveProfileOptions) (*Profile, Profiles, error)

ResolveProfile returns a *Profile that points into Profiles.Profiles, so a change through the pointer is persisted by a later Profiles.Store.

func SetSelectionInContext added in v0.3.0

func SetSelectionInContext(ctx context.Context, selection SelectionFunc) context.Context

Types

type Credentials

type Credentials struct {
	credential.Credentials

	Version  int    `json:"version"`
	FilePath string `json:"-"`
}

func (Credentials) Store

func (c Credentials) Store(ctx context.Context) error

type LoadProfilesOptions added in v0.3.0

type LoadProfilesOptions struct {
	SettingSources

	// ExclusiveLock holds the profiles until Profiles.Unlock, for a command that stores them, so
	// that no other such command stores over what this one changes. Where another one holds them,
	// LoadProfiles fails with ErrInUse within lockWaitTime.
	ExclusiveLock bool
}

type Name

type Name string

func (Name) MarshalText

func (n Name) MarshalText() ([]byte, error)

func (Name) String

func (n Name) String() string

func (*Name) UnmarshalText

func (n *Name) UnmarshalText(text []byte) (err error)

type Profile

type Profile struct {
	Endpoint         xurl.URL            `json:"endpoint,omitzero"`
	DefaultWorkspace meshstack.Workspace `json:"default_workspace,omitzero"`
	Credential       credential.Name     `json:"credential,omitzero"`

	Name      Name             `json:"-"`
	ConfigDir config.Directory `json:"-"`
}

func (Profile) Credentials

func (p Profile) Credentials(ctx context.Context) (out Credentials, err error)

func (Profile) EndpointSource

func (p Profile) EndpointSource() setting.FallbackSource

func (Profile) Label added in v0.3.0

func (p Profile) Label() string

func (Profile) RemoveCredentials

func (p Profile) RemoveCredentials(ctx context.Context) error

func (Profile) String

func (p Profile) String() string

func (Profile) WorkspaceSource

func (p Profile) WorkspaceSource() setting.FallbackSource

type Profiles

type Profiles struct {
	Version        int               `json:"version"`
	CurrentProfile Name              `json:"currentProfile,omitzero"`
	Profiles       map[Name]*Profile `json:"profiles,omitzero"`
	// contains filtered or unexported fields
}

func LoadProfiles

func LoadProfiles(ctx context.Context, opts LoadProfilesOptions) (profiles Profiles, err error)

LoadProfiles only reads, and resolves nothing but the configuration directory: ResolveProfile creates the first profile, as it creates any other.

func (*Profiles) CheckNameFree added in v0.3.0

func (ps *Profiles) CheckNameFree(name Name, original *Profile) error

CheckNameFree lets original keep its own name, and takes a nil original for a new profile.

func (*Profiles) EndpointHolding added in v0.3.0

func (ps *Profiles) EndpointHolding(requestURL *url.URL) (endpoint xurl.URL, held bool)

EndpointHolding returns the scheme and host of requestURL where no profile holds it: the endpoint a profile for it would need.

func (*Profiles) Endpoints added in v0.3.0

func (ps *Profiles) Endpoints() []string

func (*Profiles) Find added in v0.3.0

func (ps *Profiles) Find(name Name) (*Profile, error)

func (*Profiles) ForEndpoint added in v0.3.0

func (ps *Profiles) ForEndpoint(endpoint xurl.URL, requestURL *url.URL) (p Profile, current bool, err error)

ForEndpoint takes the current one of the profiles sharing endpoint, and fails where none of them is current rather than guess, as they can hold different credentials.

func (*Profiles) Holding added in v0.3.0

func (ps *Profiles) Holding(requestURL *url.URL) (p Profile, current bool, err error)

func (*Profiles) MatchingEndpoint added in v0.3.0

func (ps *Profiles) MatchingEndpoint(endpoint xurl.URL) (matching []Profile)

MatchingEndpoint are copies of the profiles for endpoint, ordered by name, so that a caller can read them while the profiles change.

func (*Profiles) Put added in v0.3.0

func (ps *Profiles) Put(ctx context.Context, original *Profile, edited Profile) error

Put stores edited in place of original, or adds it where original is nil.

func (*Profiles) Remove added in v0.3.0

func (ps *Profiles) Remove(ctx context.Context, name Name) (currentChanged bool, err error)

func (*Profiles) Selection added in v0.3.0

func (ps *Profiles) Selection() Selection

func (*Profiles) SelectionFor added in v0.3.0

func (ps *Profiles) SelectionFor(ctx context.Context, opts ResolveProfileOptions) (Selection, error)

func (*Profiles) SetCurrent added in v0.3.0

func (ps *Profiles) SetCurrent(ctx context.Context, name Name) error

func (*Profiles) Store

func (ps *Profiles) Store(ctx context.Context) error

func (*Profiles) Unlock added in v0.3.0

func (ps *Profiles) Unlock() error

Unlock releases the lock of LoadProfilesOptions.ExclusiveLock, and does nothing for profiles loaded without it or unlocked already.

type ResolveProfileOptions

type ResolveProfileOptions struct {
	SettingSources

	// EndpointOptional lets a profile that ResolveProfile creates go without an endpoint, for a
	// command that only shows it.
	EndpointOptional bool
	// StoredOnly makes ResolveProfile return ErrNoStoredProfile rather than create a profile, for a
	// command that only acts on a stored one.
	StoredOnly bool
	// ExclusiveLock is LoadProfilesOptions.ExclusiveLock for the profiles ResolveProfile
	// returns, and holds nothing where it fails.
	ExclusiveLock bool
}

type Selection added in v0.3.0

type Selection struct {
	// Profiles are all stored profiles, ordered by name, so a numbered list stays stable.
	Profiles []*Profile
	Current  Name
	// Endpoint is nil when this run names no endpoint.
	Endpoint *xurl.URL
}

func SelectionFromContext added in v0.3.0

func SelectionFromContext(ctx context.Context) (Selection, error)

SelectionFromContext returns what a front end picks a profile from. It is only in the context while NameSetting is being resolved, so a lookup for any other setting gets an error.

func (Selection) Candidates added in v0.3.0

func (s Selection) Candidates() []*Profile

type SelectionFunc added in v0.3.0

type SelectionFunc func() (Selection, error)

type SettingSources

type SettingSources = setting.Sources

Jump to

Keyboard shortcuts

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