config

package
v1.13.2 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Plugin = iota
	ManagementClient
)

Variables

View Source
var Defaults = Config{
	Debug: Debug{
		Listen: ":9001",
	},
	Log: Log{
		Format: "console",
		Level:  slog.LevelInfo,
	},
	HTTP: HTTP{
		BaseURL: &url.URL{
			Scheme: "http",
			Host:   "localhost:9000",
		},
		Listen: ":9000",
		TLS:    false,
		Check: HTTPCheck{
			IPAddr: false,
		},
		CallbackTemplate: template.Must(template.New("index.gohtml").ParseFS(ui.Template, "index.gohtml")),
	},
	OpenVpn: OpenVpn{
		Addr: &url.URL{
			Scheme:   "unix",
			Path:     "/run/openvpn/server.sock",
			OmitHost: true,
		},
		AuthTokenUser:      true,
		AuthPendingTimeout: 3 * time.Minute,
		CommonName: OpenVPNCommonName{
			Mode: CommonNameModePlain,
		},
		Bypass: OpenVpnBypass{
			CommonNames: make([]string, 0),
		},
	},
	OAuth2: OAuth2{
		Provider: "generic",
		Issuer:   &url.URL{Scheme: "", Host: ""},
		Endpoints: OAuth2Endpoints{
			Auth:      &url.URL{Scheme: "", Host: ""},
			Discovery: &url.URL{Scheme: "", Host: ""},
			Token:     &url.URL{Scheme: "", Host: ""},
		},
		Pkce:   true,
		Nonce:  true,
		Client: OAuth2Client{},
		Validate: OAuth2Validate{
			Groups: make([]string, 0),
			Roles:  make([]string, 0),
			IPAddr: false,
			Issuer: true,
		},
		Refresh: OAuth2Refresh{
			Expires: time.Hour * 8,
		},
		Scopes: []string{},
	},
}
View Source
var ErrRequired = errors.New("required")

Functions

func FlagSet added in v1.0.0

func FlagSet(name string) *flag.FlagSet

FlagSet configure the command line parser using the flag library.

func IsURLEmpty added in v1.12.0

func IsURLEmpty(url *url.URL) bool

func StringToTemplateHookFunc added in v1.6.0

func StringToTemplateHookFunc() mapstructure.DecodeHookFuncType

StringToTemplateHookFunc parse a string to template.Template.

func StringToURLHookFunc added in v1.7.0

func StringToURLHookFunc() mapstructure.DecodeHookFuncType

StringToURLHookFunc parse a string to url.URL.

func Validate added in v1.0.0

func Validate(mode int, conf Config) error

Validate validates the config.

Types

type Config

type Config struct {
	ConfigFile string  `koanf:"config"`
	Debug      Debug   `koanf:"debug"`
	Log        Log     `koanf:"log"`
	HTTP       HTTP    `koanf:"http"`
	OpenVpn    OpenVpn `koanf:"openvpn"`
	OAuth2     OAuth2  `koanf:"oauth2"`
}

func Load added in v1.8.0

func Load(mode int, configFile string, flagSet *flag.FlagSet) (Config, error)

type Debug added in v1.13.1

type Debug struct {
	Pprof  bool   `koanf:"pprof"`
	Listen string `koanf:"listen"`
}

type HTTP added in v1.7.0

type HTTP struct {
	Listen             string             `koanf:"listen"`
	CertFile           string             `koanf:"cert"`
	KeyFile            string             `koanf:"key"`
	TLS                bool               `koanf:"tls"`
	BaseURL            *url.URL           `koanf:"baseurl"`
	Secret             Secret             `koanf:"secret"`
	CallbackTemplate   *template.Template `koanf:"template"`
	Check              HTTPCheck          `koanf:"check"`
	EnableProxyHeaders bool               `koanf:"enable-proxy-headers"`
}

type HTTPCheck added in v1.7.0

type HTTPCheck struct {
	IPAddr bool `koanf:"ipaddr"`
}

type Log added in v1.0.0

type Log struct {
	Format string     `koanf:"format"`
	Level  slog.Level `koanf:"level"`
}

type OAuth2 added in v1.0.0

type OAuth2 struct {
	Issuer          *url.URL        `koanf:"issuer"`
	Provider        string          `koanf:"provider"`
	AuthorizeParams string          `koanf:"authorize-params"`
	Endpoints       OAuth2Endpoints `koanf:"endpoint"`
	Client          OAuth2Client    `koanf:"client"`
	Scopes          StringSlice     `koanf:"scopes"`
	Nonce           bool            `koanf:"nonce"`
	Pkce            bool            `koanf:"pkce"`
	Validate        OAuth2Validate  `koanf:"validate"`
	Refresh         OAuth2Refresh   `koanf:"refresh"`
}

type OAuth2Client added in v1.0.0

type OAuth2Client struct {
	ID     string `koanf:"id"`
	Secret Secret `koanf:"secret"`
}

type OAuth2Endpoints added in v1.2.0

type OAuth2Endpoints struct {
	Discovery *url.URL `koanf:"discovery"`
	Auth      *url.URL `koanf:"auth"`
	Token     *url.URL `koanf:"token"`
}

type OAuth2Refresh added in v1.13.0

type OAuth2Refresh struct {
	Enabled bool          `koanf:"enabled"`
	Expires time.Duration `koanf:"expires"`
	Secret  Secret        `koanf:"secret"`
}

type OAuth2Validate added in v1.0.0

type OAuth2Validate struct {
	Groups     StringSlice `koanf:"groups"`
	Roles      StringSlice `koanf:"roles"`
	IPAddr     bool        `koanf:"ipaddr"`
	Issuer     bool        `koanf:"issuer"`
	CommonName string      `koanf:"common_name"`
}

type OpenVPNCommonName added in v1.12.0

type OpenVPNCommonName struct {
	Mode OpenVPNCommonNameMode `koanf:"mode"`
}

type OpenVPNCommonNameMode added in v1.12.0

type OpenVPNCommonNameMode int
const (
	CommonNameModePlain OpenVPNCommonNameMode = iota
	CommonNameModeOmit
	CommonNameModeOmitValue = "-"
)

func (OpenVPNCommonNameMode) MarshalText added in v1.12.0

func (s OpenVPNCommonNameMode) MarshalText() ([]byte, error)

func (OpenVPNCommonNameMode) String added in v1.12.0

func (s OpenVPNCommonNameMode) String() string

func (*OpenVPNCommonNameMode) UnmarshalText added in v1.12.0

func (s *OpenVPNCommonNameMode) UnmarshalText(text []byte) error

type OpenVpn added in v1.0.0

type OpenVpn struct {
	Addr               *url.URL          `koanf:"addr"`
	Password           Secret            `koanf:"password"`
	Bypass             OpenVpnBypass     `koanf:"bypass"`
	AuthTokenUser      bool              `koanf:"auth-token-user"`
	AuthPendingTimeout time.Duration     `koanf:"auth-pending-timeout"`
	CommonName         OpenVPNCommonName `koanf:"common-name"`
}

type OpenVpnBypass added in v1.1.0

type OpenVpnBypass struct {
	CommonNames StringSlice `koanf:"cn"`
}

type Secret added in v1.13.0

type Secret string

func (Secret) MarshalText added in v1.13.0

func (secret Secret) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler interface for Secret

func (Secret) String added in v1.13.0

func (secret Secret) String() string

String reassembles the Secret into a valid string.

func (*Secret) UnmarshalText added in v1.13.0

func (secret *Secret) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for Secret

type StringSlice added in v1.13.0

type StringSlice []string

func (StringSlice) MarshalText added in v1.13.0

func (stringSlice StringSlice) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler interface for StringSlice

func (*StringSlice) UnmarshalText added in v1.13.0

func (stringSlice *StringSlice) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for StringSlice

Jump to

Keyboard shortcuts

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