config

package
v0.2.52 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FileName denotes the name of the config file.
	FileName = "config.yml"

	AccessTokenEnvKey          = "FLY_ACCESS_TOKEN"
	AccessTokenFileKey         = "access_token"
	MetricsTokenEnvKey         = "FLY_METRICS_TOKEN"
	MetricsTokenFileKey        = "metrics_token"
	SendMetricsEnvKey          = "FLY_SEND_METRICS"
	SendMetricsFileKey         = "send_metrics"
	AutoUpdateFileKey          = "auto_update"
	WireGuardStateFileKey      = "wire_guard_state"
	WireGuardWebsocketsFileKey = "wire_guard_websockets"
	APITokenEnvKey             = "FLY_API_TOKEN"
)

Variables

This section is empty.

Functions

func Clear

func Clear(path string) (err error)

Clear clears the access token, metrics token, and wireguard-related keys of the configuration file found at path.

func MonitorTokens added in v0.2.34

func MonitorTokens(monitorCtx context.Context, t *tokens.Tokens, uucb UserURLCallback)

MonitorTokens does some housekeeping on the provided tokens. Then, in a goroutine, it continues to keep the tokens updated and fresh. The call to MonitorTokens will return as soon as the tokens are ready for use and the background job will run until the context is cancelled. Token updates include

  • Keeping the tokens synced with the config file.
  • Refreshing any expired discharge tokens.
  • Pruning expired or invalid token.
  • Fetching macaroons for any organizations the user has been added to.
  • Pruning tokens for organizations the user is no longer a member of.

func NewContext

func NewContext(ctx context.Context, cfg *Config) context.Context

NewContext derives a Context that carries the given Config from ctx.

func ReadAccessToken added in v0.1.148

func ReadAccessToken(path string) (string, error)

func SetAccessToken

func SetAccessToken(path, token string) error

SetAccessToken sets the value of the access token at the configuration file found at path.

func SetAutoUpdate added in v0.1.51

func SetAutoUpdate(path string, autoUpdate bool) error

SetAutoUpdate sets the value of the autoupdate flag at the configuration file found at path.

func SetMetricsToken added in v0.0.541

func SetMetricsToken(path, token string) error

SetMetricsToken sets the value of the metrics token at the configuration file found at path.

func SetSendMetrics added in v0.1.5

func SetSendMetrics(path string, sendMetrics bool) error

SetSendMetrics sets the value of the send metrics flag at the configuration file found at path.

func SetWireGuardState added in v0.1.118

func SetWireGuardState(path string, state wg.States) error

func SetWireGuardWebsocketsEnabled added in v0.1.118

func SetWireGuardWebsocketsEnabled(path string, enabled bool) error

func Tokens added in v0.1.114

func Tokens(ctx context.Context) *tokens.Tokens

Types

type Config

type Config struct {

	// APIBaseURL denotes the base URL of the API.
	APIBaseURL string

	// FlapsBaseURL denotes base URL for FLAPS (also known as the Machines API).
	FlapsBaseURL string

	// MetricsBaseURL denotes the base URL of the metrics API.
	MetricsBaseURL string

	// RegistryHost denotes the docker registry host.
	RegistryHost string

	// VerboseOutput denotes whether the user wants the output to be verbose.
	VerboseOutput bool

	// JSONOutput denotes whether the user wants the output to be JSON.
	JSONOutput bool

	// LogGQLErrors denotes whether the user wants the log GraphQL errors.
	LogGQLErrors bool

	// SendMetrics denotes whether the user wants to send metrics.
	SendMetrics bool

	// AutoUpdate denotes whether the user wants to automatically update flyctl.
	AutoUpdate bool

	// Organization denotes the organizational slug the user has selected.
	Organization string

	// Region denotes the region slug the user has selected.
	Region string

	// LocalOnly denotes whether the user wants only local operations.
	LocalOnly bool

	// Tokens is the user's authentication token(s). They are used differently
	// depending on where they need to be sent.
	Tokens *tokens.Tokens

	// MetricsToken denotes the user's metrics token.
	MetricsToken string
	// contains filtered or unexported fields
}

Config wraps the functionality of the configuration file.

Instances of Config are safe for concurrent use.

func FromContext

func FromContext(ctx context.Context) *Config

FromContext returns the Config ctx carries. It panics in case ctx carries no Config.

func Load added in v0.2.29

func Load(ctx context.Context, path string) (*Config, error)

func (*Config) MetricsBaseURLIsProduction added in v0.0.550

func (cfg *Config) MetricsBaseURLIsProduction() bool

type UserURLCallback added in v0.2.34

type UserURLCallback func(ctx context.Context, url string) error

UserURLCallback is a function that opens a URL in the user's browser. This is used for token discharge flows that require user interaction.

Jump to

Keyboard shortcuts

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