config

package
v1.12.3 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 15 Imported by: 26

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Keys = []string{"oidc_issuer", "oidc_client_id", "api_url"}

Keys are all of the allowed keys in the Context section.

Functions

func IsConfigured

func IsConfigured() bool

IsConfigured returns true if a Common Fate config file exists and contains a non-empty current context.

config.Load() is called to load the config file.

func ListContexts

func ListContexts() ([]string, error)

func Save

func Save(cfg *Config) error

func SwitchContext

func SwitchContext(contextName string) error

Types

type Config

type Config struct {
	CurrentContext string `toml:"current_context" json:"current_context"`
	// Contexts allows multiple Common Fate tenancies to be switched between easily.
	// We don't have official support for this yet in the CLI,
	// but the config structure supports it so that it can be easily added in future.
	Contexts map[string]Context `toml:"context" json:"context"`
}

func Default

func Default() *Config

Default returns an empty config.

func (Config) Current

func (c Config) Current() (*Context, error)

Current loads the current context as specified in the 'current_context' field in the config file. It returns an error if there are no contexts, or if the 'current_context' field doesn't match any contexts defined in the config file.

type Context

type Context struct {
	APIURL       string `toml:"api_url,omitempty" json:"api_url,omitempty"`
	AccessURL    string `toml:"access_url,omitempty" json:"access_url,omitempty"`
	AuthzURL     string `toml:"authz_url,omitempty" json:"authz_url,omitempty"`
	OIDCIssuer   string `toml:"oidc_issuer,omitempty" json:"oidc_issuer,omitempty"`
	OIDCClientID string `toml:"oidc_client_id,omitempty" json:"oidc_client_id,omitempty"`
	// OIDCClientSecret, if specified, will cause the client to use machine-to-machine OIDC authentication.
	OIDCClientSecret *string `toml:"oidc_client_secret,omitempty" json:"oidc_client_secret,omitempty"`

	// HTTPClient is filled in by calling Initialize()
	HTTPClient *http.Client

	// OIDCProvider is filled in by calling Initialize()
	OIDCProvider rp.RelyingParty

	TokenSource oauth2.TokenSource

	TokenStore TokenStore
	// contains filtered or unexported fields
}

func LoadDefault

func LoadDefault(ctx context.Context) (*Context, error)

LoadDefault is a shorthand function which calls Load() to load the configuration, and then calls cfg.Current() to get the current API context. It returns an error if either method fails.

func New

func New(ctx context.Context, opts Opts) (*Context, error)

func NewServerContext

func NewServerContext(ctx context.Context, opts Opts) (*Context, error)

NewServerContext requires all option to be passed and does not attempt to read from the local config file it also uses an in memory token store to avoid keychain access

func (*Context) Initialize

func (c *Context) Initialize(ctx context.Context, opts InitializeOpts) error

type InitializeOpts

type InitializeOpts struct {
	TokenStore TokenStore
}

type Opts

type Opts struct {
	APIURL string
	// AccessURL is the base URL of the Access Handler.
	// If empty, the API URL is used.
	AccessURL string
	// AccessURL is the base URL of the authz service.
	// If empty, the API URL is used.
	AuthzURL     string
	ClientID     string
	ClientSecret string
	OIDCIssuer   string
}

type TokenStore

type TokenStore interface {
	Clear() error
	Save(token *oauth2.Token) error
	Token() (*oauth2.Token, error)
}

Jump to

Keyboard shortcuts

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