configs

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: Apache-2.0 Imports: 13 Imported by: 3

Documentation

Overview

Package configs provides configuration structures and utilities for the application. note that only configurations that can be reused by addons will be included here

Index

Constants

View Source
const DefaultIAMRuntimeTimeoutSeconds = 15

DefaultIAMRuntimeTimeoutSeconds is the default timeout for the IAM runtime

Variables

View Source
var (
	// ErrInvalidNATSAuthMode is returned when an invalid NATS authentication mode is provided
	ErrInvalidNATSAuthMode = errors.New("invalid NATS authentication mode")
	// ErrMissingNATSCreds is returned when nats creds are not provided
	ErrMissingNATSCreds = errors.New("nats creds are required")
)

Functions

func AddFlags

func AddFlags(flags *pflag.FlagSet)

AddFlags adds all the flags for the configuration.

func AddIAMRuntimeFlags

func AddIAMRuntimeFlags(flags *pflag.FlagSet)

AddIAMRuntimeFlags adds iam-runtime flags to the given FlagSet

func AddNATSFlags

func AddNATSFlags(flags *pflag.FlagSet)

AddNATSFlags adds NATS flags to the given FlagSet

func AddWorkloadIdentityFlags

func AddWorkloadIdentityFlags(flags *pflag.FlagSet)

AddWorkloadIdentityFlags adds workload identity federation flags to the given FlagSet.

Types

type Configs

type Configs struct {
	WorkloadIdentity WorkloadIdentityConfig `mapstructure:"workload-identity"`
	IAMRuntime       IAMRuntimeConfig       `mapstructure:"iam-runtime"`
	NATS             NATSConfig             `mapstructure:"nats"`
}

Configs holds the configuration for the application.

func (*Configs) NATSConn

func (cfg *Configs) NATSConn(ctx context.Context, name string, opts ...Opt) (*nats.Conn, error)

NATSConn is a shorthand that checks the NATS auth mode and creates a NATS connection based on all the configs available

func (*Configs) Validate

func (cfg *Configs) Validate() error

Validate validates all the configs

type IAMRuntimeConfig

type IAMRuntimeConfig struct {
	Socket  string        `mapstructure:"socket"`
	Timeout time.Duration `mapstructure:"timeout"`
}

IAMRuntimeConfig holds the configuration for the IAM runtime.

func (*IAMRuntimeConfig) ToTokenSource

func (c *IAMRuntimeConfig) ToTokenSource(ctx context.Context, dialOpts ...grpc.DialOption) (oauth2.TokenSource, error)

ToTokenSource creates a new oauth2.TokenSource from the IAM runtime config.

func (*IAMRuntimeConfig) Validate

func (c *IAMRuntimeConfig) Validate() error

Validate validates the IAM runtime configuration.

type NATSAuthMode

type NATSAuthMode string

NATSAuthMode represents the authentication modes for NATS

const (
	// AuthModeCredsFileOnly is the auth mode for using a credentials file only
	AuthModeCredsFileOnly NATSAuthMode = "creds-file-only"
	// AuthModeWorkloadIdentity is the auth mode for using workload identity
	AuthModeWorkloadIdentity NATSAuthMode = "workload-identity"
	// AuthModeIAMRuntime is the auth mode for using IAM runtime
	AuthModeIAMRuntime NATSAuthMode = "iam-runtime"
)

type NATSConfig

type NATSConfig struct {
	URL           string       `mapstructure:"url"`
	CredsFile     string       `mapstructure:"creds-file"`
	SubjectPrefix string       `mapstructure:"subject-prefix"`
	AuthMode      NATSAuthMode `mapstructure:"auth-mode"`
}

NATSConfig holds the configuration for NATS

func (*NATSConfig) ToNATSConnection

func (c *NATSConfig) ToNATSConnection(name string, opts ...Opt) (*nats.Conn, error)

ToNATSConnection creates a NATS connection based on a config

func (*NATSConfig) Validate

func (c *NATSConfig) Validate() error

Validate validates the NATS configuration.

type Opt

type Opt func(*optionals)

Opt is a functional option type for configuring optional parameters.

func WithLogger

func WithLogger(l *zap.Logger) Opt

WithLogger sets the logger in the options.

func WithTokenSource

func WithTokenSource(ts oauth2.TokenSource) Opt

WithTokenSource sets the token source in the options.

type WorkloadIdentityConfig

type WorkloadIdentityConfig struct {
	TokenURL           string   `mapstructure:"token-url"`
	KubeServiceAccount string   `mapstructure:"kube-service-account"`
	Scopes             []string `mapstructure:"scopes"`
	Audience           string   `mapstructure:"audience"`
	SubjectTokenType   string   `mapstructure:"subject-token-type"`
}

WorkloadIdentityConfig holds the configuration for workload identity federation.

func (*WorkloadIdentityConfig) ToTokenSource

func (c *WorkloadIdentityConfig) ToTokenSource(ctx context.Context) (oauth2.TokenSource, error)

ToTokenSource creates a token source from a config

func (*WorkloadIdentityConfig) Validate

func (c *WorkloadIdentityConfig) Validate() error

Validate validates the workload identity configuration.

Jump to

Keyboard shortcuts

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