Documentation
¶
Index ¶
- Constants
- Variables
- func GetClientConfigurationPath() string
- func GetClientPath() string
- func IsAccessToken(token []byte) bool
- func IsEphemeralConfig() bool
- func IsExchangeToken(token []byte) bool
- type APIInfo
- type AuthInfo
- type Config
- func (c *Config) AddAuthInfo(name string, auth *AuthInfo)
- func (c *Config) AddProfile(name string, ctx *Profile)
- func (c *Config) AddServer(name string, server *Server)
- func (c *Config) CreateProfile(name, endpoint string)
- func (c *Config) GetAuthInfo(name string) *AuthInfo
- func (c *Config) GetProfile(name string) *Profile
- func (c *Config) GetProfileAuthMethod(name string) string
- func (c *Config) GetServer(name string) *Server
- func (c *Config) HasAuth(name string) bool
- func (c *Config) HasAuthInfo(name string) bool
- func (c *Config) HasProfile(name string) bool
- func (c *Config) HasServer(name string) bool
- func (c *Config) HasValidProfile(name string) error
- func (c *Config) IsAccessToken() bool
- func (c *Config) IsValid() error
- func (c *Config) ListProfiles() []string
- func (c *Config) NewProfileWithAuth(name, endpoint string, auth *AuthInfo) error
- func (c *Config) RemoveProfile(name string)
- func (c *Config) RemoveServer(name string)
- func (c *Config) RemoveUserInfo(name string)
- func (c *Config) Update(w io.Writer) error
- type Identity
- type Profile
- type Server
Constants ¶
const ( EnvWayfinderServer = "WAYFINDER_SERVER" EnvWayfinderToken = "WAYFINDER_TOKEN" EnvWayfinderWorkspace = "WAYFINDER_WORKSPACE" )
Variables ¶
var ( // ErrNoProfileSelected indicates the current profile is empty ErrNoProfileSelected = errors.New("no profile selected") // ErrNoProfileEndpoint indicates the profile does not have a endpoint ErrNoProfileEndpoint = errors.New("profile does not have a server endpoint") // ErrNoProfileAuth indicates the profile does not any auth configured ErrNoProfileAuth = errors.New("profile does not have any authentication configured") )
var ( // DefaultWayfinderConfigPath is the default path for the wayfinder configuration file DefaultWayfinderConfigPath = path.Join(osutils.UserHomeDir(), ".wayfinder", "config") // DefaultWayfinderConfigPathEnv is the default name of the env variable for config DefaultWayfinderConfigPathEnv = "WAYFINDER_CONFIG" )
var GetOrCreateClientConfiguration = func() (*Config, error) { path := GetClientConfigurationPath() common.LogWithoutContext().WithField("path", path).Debug("using wayfinder configration file") if found, err := fileExists(path); err != nil { return nil, err } else if !found { if err := UpdateConfig(NewEmpty(), path); err != nil { return nil, err } return NewEmpty(), nil } file, err := os.Open(path) if err != nil { return nil, err } return New(file) }
GetOrCreateClientConfiguration is responsible for retrieving the client configuration
var UpdateConfig = func(config *Config, path string) error { data, err := yaml.Marshal(config) if err != nil { return err } if err := os.MkdirAll(filepath.Dir(path), os.FileMode(0750)); err != nil { return err } return os.WriteFile(path, data, os.FileMode(0640)) }
UpdateConfig is responsible for writing the configuration to disk
Functions ¶
func GetClientConfigurationPath ¶
func GetClientConfigurationPath() string
GetClientConfigurationPath returns the path to the client config
func GetClientPath ¶
func GetClientPath() string
GetClientPath returns the base of the client configuration
func IsAccessToken ¶
IsAccessToken checks if the token is an access token
func IsEphemeralConfig ¶
func IsEphemeralConfig() bool
func IsExchangeToken ¶
IsExchangeToken checks if the token is an exchange token
Types ¶
type APIInfo ¶
type APIInfo struct { // NonResourceAPI is the base path for the non-resource API (i.e. our non-CRD API endpoints such // as login) NonResourceAPI string `json:"nonResourceAPI,omitempty"` // ResourceAPI is the base path for the resource API (i.e. access to our CRDs) ResourceAPI string `json:"resourceAPI,omitempty"` // KubeProxyAPI is the base path for the kube proxy API (i.e. access to managed clusters) KubeProxyAPI string `json:"kubeProxyAPI,omitempty"` }
APIInfo is a representation of the structure returned from the API server on the unauthenticated /apiinfo endpoint. This needs to be kept in sync with the APIInfo struct from /pkg/apiserver/types/types.go
type AuthInfo ¶
type AuthInfo struct { // Identity is a wayfinder managed identity Identity *Identity `json:"identity,omitempty" yaml:"identity,omitempty"` // Token is a static token to use Token *string `json:"token,omitempty" yaml:"token,omitempty"` }
AuthInfo defines a credential to the api endpoint
type Config ¶
type Config struct { // AuthInfos is a collection of credentials AuthInfos map[string]*AuthInfo `json:"users,omitempty" yaml:"users,omitempty"` // CurrentProfile is the profile in use at the moment CurrentProfile string `json:"current-profile,omitempty" yaml:"current-profile,omitempty"` // Profiles is a collection of profiles Profiles map[string]*Profile `json:"profiles,omitempty" yaml:"profiles,omitempty"` // Servers is a collection of api endpoints Servers map[string]*Server `json:"servers,omitempty" yaml:"servers,omitempty"` // Version is the version of the configuration Version string `json:"version,omitempty" yaml:"version,omitempty"` }
Config is the configuration for the api
func CreateEphemeralConfiguration ¶
func CreateEphemeralConfiguration() *Config
CreateEphemeralConfiguration creates a fake configuration from the environments variables - largely used for CI
func GetConfig ¶
GetConfig returns either the ephemeral configuration from environment variables if provided, or the current configured file - creating it if it does not exist.
func (*Config) AddAuthInfo ¶
AddAuthInfo adds a authentication
func (*Config) AddProfile ¶
AddProfile adds a profile to the config
func (*Config) CreateProfile ¶
CreateProfile is used to create a profile
func (*Config) GetAuthInfo ¶
GetAuthInfo returns the auth for a profile
func (*Config) GetProfile ¶
GetProfile returns the profile
func (*Config) GetProfileAuthMethod ¶
GetProfileAuthMethod returns the method of authentication for a profile
func (*Config) HasAuthInfo ¶
HasAuthInfo checks if the context exists in the config
func (*Config) HasProfile ¶
HasProfile checks if the context exists in the config
func (*Config) HasValidProfile ¶
HasValidProfile checks we have a current context
func (*Config) IsAccessToken ¶
IsAccessToken returns true if the current profile is for an access token user
func (*Config) ListProfiles ¶
ListProfiles returns a list of profile names
func (*Config) NewProfileWithAuth ¶
NewProfileWithAuth creates the profile
func (*Config) RemoveProfile ¶
RemoveProfile removes the profile
func (*Config) RemoveServer ¶
RemoveServer removes a server instance
func (*Config) RemoveUserInfo ¶
RemoveUserInfo removes the user info
type Identity ¶
type Identity struct { // RefreshToken represents a wayfinder managed refresh token issued by the wayfinder RefreshToken string `json:"refresh-token,omitempty" yaml:"refresh-token,omitempty"` // Token represents a wayfinder managed token issued by the wayfinder service Token string `json:"token,omitempty" yaml:"token,omitempty"` }
Identity is a wayfinder manage identity
func (*Identity) IsAccessToken ¶
IsExchangeToken is used to check if the authentication is an access token
func (*Identity) IsExchangeToken ¶
IsExchangeToken is used to check with the authentication is an exchange token
type Profile ¶
type Profile struct { // AuthInfo is the credentials to use AuthInfo string `json:"user,omitempty" yaml:"user,omitempty"` // Server is a reference to the server config Server string `json:"server,omitempty" yaml:"server,omitempty"` // Workspace is the default workspace for this profile Workspace string `json:"workspace,omitempty" yaml:"workspace,omitempty"` }
Profile links endpoint and a credential together
type Server ¶
type Server struct { // Endpoint the url for the api endpoint of wayfinder Endpoint string `json:"server,omitempty" yaml:"server,omitempty"` // CACertificate is the ca bundle used to verify a self-signed api CACertificate string `json:"caCertificate,omitempty" yaml:"caCertificate,omitempty"` // APIInfo is a set of metadata about this instance of Wayfinder APIInfo *APIInfo `json:"apiInfo,omitempty"` }
Server defines an endpoint for the api server