Documentation ¶
Index ¶
- Variables
- func IsConfigured() bool
- func ListContexts() ([]string, error)
- func Save(cfg *Config) error
- func SwitchContext(contextName string) error
- type Config
- type Context
- type EnvSource
- type FileSource
- type InitializeOpts
- type Key
- type Opts
- type StaticSource
- type TokenStore
- type URLConfigJSON
- type URLSource
Constants ¶
This section is empty.
Variables ¶
var ErrConfigFileNotFound = errors.New("config file does not exist")
ErrConfigFileNotFound is returned if the config file (~/.cf/config by default) does not exist.
var Keys = []string{"oidc_issuer", "oidc_client_id", "api_url", "authz_url", "access_url", "oidc_client_secret"}
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 SwitchContext ¶
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"` }
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 GetContextByURL ¶ added in v1.32.1
func LoadDefault ¶
LoadDefault is a shorthand function which loads the default SDK configuration by calling New() with default values.
By default, config is loaded from environment variables, and then falling back to a TOML configuration file for any config values which are not set.
The file is ~/.cf/config by default, but this can be overridden with the CF_CONFIG_PATH environment variable.
Environment variables follow the pattern 'CF_CONFIG_VARIABLE_NAME', where CONFIG_VARIABLE_NAME is the name of the configuration value in upper snake-case. For example, 'CF_API_URL'.
func New ¶
New creates an initialised SDK context to be used for creating SDK clients. For example:
import "github.com/common-fate/sdk/config" import "github.com/common-fate/sdk/service/access" cfg, err := config.New(ctx, opts{}) if err != nil { return err } client := access.NewClient(cfg)
Configuration values, such as the API URL and OIDC Client ID to use, can be provided via the Opts{} argument.
The New() method will look configuration values up from environment variables and the config file (~/.cf/config by default) if they are not provided in Opts{}. By default, the order of priority is:
1. Static value, set in Opts{}
2. Environment variable ('env')
3. Config file ('file')
This behaviour can be customised by setting opts.ConfigSources or by providing the 'CF_CONFIG_SOURCES' environment variable, for example: CF_CONFIG_SOURCES=file,env
Environment variables follow the pattern 'CF_CONFIG_VARIABLE_NAME', where CONFIG_VARIABLE_NAME is the name of the configuration value in upper snake-case. For example, 'CF_API_URL'.
func NewServerContext ¶
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 FileSource ¶ added in v1.18.0
type FileSource struct {
// contains filtered or unexported fields
}
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 // The token storage backend to use for OIDC tokens. // If not provided, will use the keychain backend. TokenStore TokenStore // the config sources to load config from. // Must be 'env', 'file', or may be a URL to fetch remote config from. // Defaults to ['env', 'file'] if not provided. // // Can be overridden by providing the 'CF_CONFIG_SOURCES' environment variable, // for example: CF_CONFIG_SOURCES=file,env,https://commonfate.example.com/config.json ConfigSources []string }
type StaticSource ¶ added in v1.18.0
type StaticSource struct {
Result string
}