config

package
v1.2.91 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const ApiServerEnvVarKey = "CHALK_API_SERVER"
View Source
const ClientIdEnvVarKey = "CHALK_CLIENT_ID"
View Source
const ClientSecretEnvVarKey = "CHALK_CLIENT_SECRET"
View Source
const EnvironmentEnvVarKey = "CHALK_ACTIVE_ENVIRONMENT"

Variables

This section is empty.

Functions

func ContextWithEnvironmentGetter

func ContextWithEnvironmentGetter(ctx context.Context, getter EnvironmentGetter) context.Context

Types

type ClientId

type ClientId string

type ClientSecret

type ClientSecret string

type DefaultEnvironmentGetter

type DefaultEnvironmentGetter struct {
	EnvironmentGetter
}

func (DefaultEnvironmentGetter) Abs

func (DefaultEnvironmentGetter) Getenv

func (d DefaultEnvironmentGetter) Getenv(key string) string

func (DefaultEnvironmentGetter) Getwd

func (d DefaultEnvironmentGetter) Getwd() (string, error)

type DirectoryOverrideEnvironmentGetter

type DirectoryOverrideEnvironmentGetter struct {
	EnvironmentGetter
	// contains filtered or unexported fields
}

DirectoryOverrideEnvironmentGetter wraps another EnvironmentGetter but overrides the working directory

func NewDirectoryOverrideEnvironmentGetter

func NewDirectoryOverrideEnvironmentGetter(base EnvironmentGetter, dir string) *DirectoryOverrideEnvironmentGetter

func (*DirectoryOverrideEnvironmentGetter) Abs

func (*DirectoryOverrideEnvironmentGetter) Getenv

func (*DirectoryOverrideEnvironmentGetter) Getwd

type EnvironmentGetter

type EnvironmentGetter interface {
	Getenv(key string) string
	Getwd() (string, error)
	Abs(path string) (string, error)
}

EnvironmentGetter is an interface for getting environment variables and the current working directory. This can help with testing by making otherwise impure functions pure.

func EnvironmentGetterFromContext

func EnvironmentGetterFromContext(ctx context.Context) EnvironmentGetter

type JWT

type JWT struct {
	Token      string    `yaml:"value"`
	ValidUntil time.Time `yaml:"validUntil"`
}

func (*JWT) IsValid

func (t *JWT) IsValid() bool

type Manager

type Manager struct {
	ApiServer     SourcedConfig[string]
	ClientId      SourcedConfig[ClientId]
	ClientSecret  SourcedConfig[ClientSecret]
	EnvironmentId SourcedConfig[string]
	Scope         SourcedConfig[string]
}

func NewManager

func NewManager(
	ctx context.Context,
	apiServer SourcedConfig[string],
	clientId SourcedConfig[ClientId],
	clientSecret SourcedConfig[ClientSecret],
	environmentId SourcedConfig[string],
	configDir *string,
) (*Manager, error)

NewManager creates a new configuration manager with the specified parameters

type MapEnvironmentGetter

type MapEnvironmentGetter struct {
	EnvironmentGetter
	Env map[string]string
	Wd  string
}

func NewMockEnvironmentGetter

func NewMockEnvironmentGetter(
	env map[string]string,
	wd string,
) *MapEnvironmentGetter

func (MapEnvironmentGetter) Abs

func (m MapEnvironmentGetter) Abs(path string) (string, error)

func (MapEnvironmentGetter) Getenv

func (m MapEnvironmentGetter) Getenv(key string) string

func (MapEnvironmentGetter) Getwd

func (m MapEnvironmentGetter) Getwd() (string, error)

type ProjectToken

type ProjectToken struct {
	Name              string       `yaml:"name"`
	ClientId          ClientId     `yaml:"clientId"`
	ClientSecret      ClientSecret `yaml:"clientSecret"`
	ValidUntil        string       `yaml:"validUntil"`
	ApiServer         string       `yaml:"apiServer"`
	ActiveEnvironment string       `yaml:"activeEnvironment"`
	JWT               JWT          `yaml:"jwt,omitempty"`
}

func GetProjectAuthConfig

func GetProjectAuthConfig(ctx context.Context, configDir *string) (*ProjectToken, string, error)

type ProjectTokens

type ProjectTokens struct {
	Tokens map[string]*ProjectToken `yaml:"tokens,omitempty"`
}

type SourcedConfig

type SourcedConfig[T SourcedValueT] struct {
	Value  T
	Source string
}

SourcedConfig represents a configuration value along with information about where it came from

func GetFirstNonEmpty

func GetFirstNonEmpty[T SourcedValueT](configs ...SourcedConfig[T]) SourcedConfig[T]

GetFirstNonEmpty returns the first non-empty SourcedConfig from the provided list using the provided zero-check function

func NewFromArg

func NewFromArg[T SourcedValueT](value T) SourcedConfig[T]

NewFromArg creates a SourcedConfig from a direct argument

func NewFromEnvVar

func NewFromEnvVar[T ~string](ctx context.Context, key string) SourcedConfig[T]

func NewFromFile

func NewFromFile[T SourcedValueT](path string, value T) SourcedConfig[T]

NewFromFile creates a SourcedConfig from a config file

type SourcedValueT

type SourcedValueT interface {
	~int | ~int64 | ~float32 | ~float64 | ~string
}

Jump to

Keyboard shortcuts

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