Documentation
¶
Overview ¶
Package connections stores explicitly named dispatcher connections for local commands. Saved profiles are not a global dispatcher discovery service.
Index ¶
- Constants
- Variables
- func CredentialPath(path string) (string, error)
- func DefaultPath() (string, error)
- func Remove(path, name string) error
- func RemoveCredential(path, name string) error
- func ResolveCredentialStorage(mode string) (string, error)
- func Save(path string, profile Profile, selectCurrent bool) error
- func SaveCredential(path, name string, credential Credential) error
- func Select(path, name string) error
- func ValidateName(name string) error
- type Config
- type Credential
- type CredentialStorageResult
- type CredentialStore
- type Profile
Constants ¶
const CredentialFileMode fs.FileMode = 0600
CredentialFileMode is the permission the credential file is written with and required to have; one readable by anyone else is refused rather than used.
const CredentialFileName = "credentials.json"
CredentialFileName is the credential file, beside the connections file.
Variables ¶
var ErrCredentialEndpointMismatch = errors.New("stored credential belongs to another dispatcher endpoint")
ErrCredentialEndpointMismatch means a saved session belongs to a different endpoint than the profile now selects. Callers may forget it locally, but must never present it to the newly selected endpoint.
Functions ¶
func CredentialPath ¶
CredentialPath returns the credential file beside the given connections file, or beside the default one when path is empty.
func DefaultPath ¶
func RemoveCredential ¶
RemoveCredential forgets the credential of one profile. Forgetting one that is not there is the state the caller asked for, not an error.
func ResolveCredentialStorage ¶ added in v0.3.0
ResolveCredentialStorage selects the requested backend before login issues a credential. Auto falls back only when the desktop facility is absent.
func Save ¶
Save replaces a named profile chosen by the operator and selects it when requested, or when there is no current connection yet.
func SaveCredential ¶
func SaveCredential(path, name string, credential Credential) error
SaveCredential records the credential of one profile, replacing its own.
func ValidateName ¶
Types ¶
type Config ¶
type Credential ¶
type Credential struct {
Endpoint string `json:"endpoint"`
Token string `json:"token,omitempty"`
Storage string `json:"storage,omitempty"`
SecretID string `json:"secret_id,omitempty"`
ExpiresAt int64 `json:"expires_at,omitempty"`
AccountID string `json:"account_id,omitempty"`
}
Credential is what one CLI profile presents to one dispatcher. Endpoint records which dispatcher issued it, so it can never be sent to another one. Only the session is kept, so a copy of this file yields one expiring session rather than permanent access to the account.
func CredentialFor ¶
func CredentialFor(ctx context.Context, path, name, endpoint string) (Credential, error)
CredentialFor returns the credential to present at endpoint for one saved connection. One recorded for a different endpoint is refused rather than sent, so selecting another profile can never deliver one dispatcher's credential to another origin; a connection with none stored yields an empty credential, because unauthenticated requests still reach a dispatcher serving the local development profile. An empty name is an endpoint the operator named directly, so nothing is looked up and the client configuration directory is not even located: commands that need no saved connection keep working where there is no such directory.
type CredentialStorageResult ¶ added in v0.3.0
CredentialStorageResult describes a committed local login. Failure to remove an older secret is reported separately, since the replacement is already saved.
func SaveCredentialWithStorage ¶ added in v0.3.0
func SaveCredentialWithStorage(ctx context.Context, path, name string, credential Credential, storage string) (CredentialStorageResult, error)
SaveCredentialWithStorage saves a credential using the selected backend.
type CredentialStore ¶
type CredentialStore struct {
SchemaVersion int `json:"schema_version"`
Credentials map[string]Credential `json:"credentials"`
}
CredentialStore is the on-disk credential file.
func LoadCredentials ¶
func LoadCredentials(path string) (CredentialStore, error)
LoadCredentials reads the credential file. An absent file is an empty store; one other users can read is refused rather than used.
type Profile ¶
type Profile struct {
Name string `json:"name"`
Endpoint string `json:"endpoint"`
GRPCAddress string `json:"grpc_address"`
YamuxAddress string `json:"yamux_address"`
}