Documentation
¶
Index ¶
- Variables
- func ResolveProfile(ctx context.Context, opts ResolveProfileOptions) (*Profile, Profiles, error)
- func SetSelectionInContext(ctx context.Context, selection SelectionFunc) context.Context
- type Credentials
- type LoadProfilesOptions
- type Name
- type Profile
- func (p Profile) Credentials(ctx context.Context) (out Credentials, err error)
- func (p Profile) EndpointSource() setting.FallbackSource
- func (p Profile) Label() string
- func (p Profile) RemoveCredentials(ctx context.Context) error
- func (p Profile) String() string
- func (p Profile) WorkspaceSource() setting.FallbackSource
- type Profiles
- func (ps *Profiles) CheckNameFree(name Name, original *Profile) error
- func (ps *Profiles) EndpointHolding(requestURL *url.URL) (endpoint xurl.URL, held bool)
- func (ps *Profiles) Endpoints() []string
- func (ps *Profiles) Find(name Name) (*Profile, error)
- func (ps *Profiles) ForEndpoint(endpoint xurl.URL, requestURL *url.URL) (p Profile, current bool, err error)
- func (ps *Profiles) Holding(requestURL *url.URL) (p Profile, current bool, err error)
- func (ps *Profiles) MatchingEndpoint(endpoint xurl.URL) (matching []Profile)
- func (ps *Profiles) Put(ctx context.Context, original *Profile, edited Profile) error
- func (ps *Profiles) Remove(ctx context.Context, name Name) (currentChanged bool, err error)
- func (ps *Profiles) Selection() Selection
- func (ps *Profiles) SelectionFor(ctx context.Context, opts ResolveProfileOptions) (Selection, error)
- func (ps *Profiles) SetCurrent(ctx context.Context, name Name) error
- func (ps *Profiles) Store(ctx context.Context) error
- func (ps *Profiles) Unlock() error
- type ResolveProfileOptions
- type Selection
- type SelectionFunc
- type SettingSources
Constants ¶
This section is empty.
Variables ¶
var ErrInUse = errors.New("another meshstack command is changing the profiles")
ErrInUse is what LoadProfiles returns with ExclusiveLock while another command holds the profiles.
var ErrNoStoredProfile = errors.New("no stored profile")
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 ¶
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:"-"`
}
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 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) 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
CheckNameFree lets original keep its own name, and takes a nil original for a new profile.
func (*Profiles) EndpointHolding ¶ added in v0.3.0
EndpointHolding returns the scheme and host of requestURL where no profile holds it: the endpoint a profile for it would need.
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) MatchingEndpoint ¶ added in v0.3.0
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
Put stores edited in place of original, or adds it where original is nil.
func (*Profiles) SelectionFor ¶ added in v0.3.0
func (*Profiles) SetCurrent ¶ added in v0.3.0
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
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.