config

package
v0.1.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIConfig

type APIConfig struct {
	URL      string                  `json:"url"`
	Contexts map[string]TenantConfig `json:"contexts"`
}

APIConfig represents configuration for an instance of Observatorium.

type Config

type Config struct {
	APIs    map[string]APIConfig `json:"apis"`
	Current struct {
		API    string `json:"api"`
		Tenant string `json:"tenant"`
	} `json:"current"`
	// contains filtered or unexported fields
}

Config represents the structure of the configuration file.

func Read

func Read(logger log.Logger) (*Config, error)

Read loads configuration from disk.

func (*Config) AddAPI

func (c *Config) AddAPI(logger log.Logger, name string, apiURL string) error

AddAPI adds a new Observatorium API to the configuration and saves the config to disk. In case no name is provided, the hostname of the API URL is used instead.

func (*Config) AddTenant

func (c *Config) AddTenant(logger log.Logger, name string, api string, tenant string, oidcCfg *OIDCConfig) error

AddTenant adds configuration for a tenant under an API and saves it to disk. Also, sets new tenant to current in case current config is empty.

func (*Config) Client

func (c *Config) Client(ctx context.Context, logger log.Logger) (*http.Client, error)

Client returns an OAuth2 HTTP client based on the current context configuration.

func (*Config) GetContext

func (c *Config) GetContext(api string, tenant string) (TenantConfig, APIConfig, error)

func (*Config) GetCurrentContext

func (c *Config) GetCurrentContext() (TenantConfig, APIConfig, error)

GetCurrentContext returns the currently set context i.e, the current API and tenant configuration.

func (*Config) RemoveAPI

func (c *Config) RemoveAPI(logger log.Logger, name string) error

RemoveAPI removes a locally saved Observatorium API config as well as its tenants. If the current context is pointing to the API being removed, the context is emptied.

func (*Config) RemoveTenant

func (c *Config) RemoveTenant(logger log.Logger, name string, api string) error

RemoveTenant removes configuration of a tenant under an API and saves changes to disk.

func (*Config) Save

func (c *Config) Save(logger log.Logger) error

Save writes current config to the disk.

func (*Config) SetCurrentContext

func (c *Config) SetCurrentContext(logger log.Logger, api string, tenant string) error

SetCurrentContext switches the current context to given api and tenant.

type OIDCConfig

type OIDCConfig struct {
	Token *oauth2.Token `json:"token"`

	Audience     string `json:"audience"`
	ClientID     string `json:"clientID"`
	ClientSecret string `json:"clientSecret"`
	IssuerURL    string `json:"issuerURL"`
}

OIDCConfig represents OIDC auth config for a tenant.

type TenantConfig

type TenantConfig struct {
	Tenant string      `json:"tenant"`
	CAFile []byte      `json:"ca"`
	OIDC   *OIDCConfig `json:"oidc"`
}

TenantConfig represents configuration for a tenant.

func (*TenantConfig) Client

func (t *TenantConfig) Client(ctx context.Context, logger log.Logger) (*http.Client, error)

Client returns a OAuth2 HTTP client based on the configuration for a tenant.

Jump to

Keyboard shortcuts

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