config

package
v0.7.8 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package config implements general handling for configuration files and adds definition for the configuration file YAML structure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetOrDefaultStringSlice

func GetOrDefaultStringSlice(value []string, defaultValue []string) []string

GetOrDefaultStringSlice returns an array or a default array if the given array is empty.

func Initialize added in v0.7.7

func Initialize(config *Config) error

Initialize initializes a given Config. Checks for OIDC configuration on given Client entries. Initializes maps for faster Client and User access in the Config. Generates a server secret when none was provided. Loads a logo image into []byte to use in the web user interface. Checks for ForwardAuth settings. Sets the singleton for the current Config

Types

type Claim

type Claim interface {
	GetName() string
	GetValues() any
}

type Classification added in v0.7.8

type Classification struct {
	User    string   `yaml:"user"`
	Users   []string `yaml:"users"`
	Client  string   `yaml:"client"`
	Clients []string `yaml:"clients"`
	Scope   string   `yaml:"scope"`
	Scopes  []string `yaml:"scopes"`
	Claims  []claim  `yaml:"claims"`
	// contains filtered or unexported fields
}

type Client

type Client struct {
	Id                      string   `yaml:"id"`
	ClientSecret            string   `yaml:"clientSecret"`
	Salt                    string   `yaml:"salt"`
	Oidc                    bool     `yaml:"oidc"`
	AccessTTL               int      `yaml:"accessTTL"`
	RefreshTTL              int      `yaml:"refreshTTL"`
	IdTTL                   int      `yaml:"idTTL"`
	Introspect              bool     `yaml:"introspect"`
	Revoke                  bool     `yaml:"revoke"`
	Redirects               []string `yaml:"redirects"`
	OpaqueToken             bool     `yaml:"opaqueToken"`
	PasswordFallbackAllowed bool     `yaml:"passwordFallbackAllowed"`
	Audience                []string `yaml:"audience"`
	PrivateKey              string   `yaml:"privateKey"`
	// contains filtered or unexported fields
}

Client defines the general client entry in the configuration.

func (*Client) GetAccessTTL

func (client *Client) GetAccessTTL() int

GetAccessTTL returns access token time to live. When no time to live is provided a default value will be returned.

func (*Client) GetAudience

func (client *Client) GetAudience() []string

GetAudience returns the audience value. When no audience value is provided a default value will be returned.

func (*Client) GetClientType added in v0.7.6

func (client *Client) GetClientType() oauth2.ClientType

GetClientType returns the client type value. When no client secret is provided the client will be a public client, confidential otherwise. See oauth2.ClientType

func (*Client) GetIdTTL added in v0.7.6

func (client *Client) GetIdTTL() int

GetIdTTL returns id token time to live. When no time to live is provided a default value will be returned.

func (*Client) GetRefreshTTL

func (client *Client) GetRefreshTTL() int

GetRefreshTTL returns refresh token time to live. When no time to live is provided a default value will be returned.

func (*Client) ValidateRedirect added in v0.7.7

func (client *Client) ValidateRedirect(redirect string) bool

ValidateRedirect returns whether the redirect is valid for a given Client or not.

type Config

type Config struct {
	Server         Server           `yaml:"server"`
	Clients        []Client         `yaml:"clients"`
	Users          []User           `yaml:"users"`
	UI             UI               `yaml:"ui"`
	Classification []Classification `yaml:"classification"`
	// contains filtered or unexported fields
}

Config defines the root entry for the configuration.

func GetConfigInstance added in v0.7.7

func GetConfigInstance() *Config

GetConfigInstance returns the current singleton of Config when it was initialized by Initialize before.

func (*Config) GetAuthCookieName

func (config *Config) GetAuthCookieName() string

GetAuthCookieName returns the name of the authentication cookie. When no name is provided a default value will be returned.

func (*Config) GetClaims added in v0.7.8

func (config *Config) GetClaims(username string, clientId string, scopes []string) []*Claim

GetClaims returns an array of claims related to the username, client id and scopes.

func (*Config) GetClient

func (config *Config) GetClient(clientId string) (*Client, bool)

GetClient returns a Client for the given clientId. Also returns a bool which indicates, whether the Client exists or not.

func (*Config) GetExpiredLoginMessage added in v0.7.7

func (config *Config) GetExpiredLoginMessage() string

GetExpiredLoginMessage returns the configured login expired message. When no login expired message is provided a default value will be returned.

func (*Config) GetFooterText

func (config *Config) GetFooterText() string

GetFooterText returns whether the text shown in the footer of the web user interface. When no footer text is provided a default value will be returned.

func (*Config) GetForwardAuthClient added in v0.7.7

func (config *Config) GetForwardAuthClient() (*Client, bool)

GetForwardAuthClient return a Client used for Traefik Forward Auth, also returns a bool indicating whether such a Client exists or not.

func (*Config) GetForwardAuthCookieName added in v0.7.8

func (config *Config) GetForwardAuthCookieName() string

GetForwardAuthCookieName returns the name of the authentication cookie for ForwardAuth. When no name is provided a default value will be returned.

func (*Config) GetForwardAuthEnabled added in v0.7.7

func (config *Config) GetForwardAuthEnabled() bool

GetForwardAuthEnabled returns whether Traefik Forward Auth is enabled or not. Check in general whether the ForwardAuth ExternalUrl value is set.

func (*Config) GetForwardAuthEndpoint added in v0.7.7

func (config *Config) GetForwardAuthEndpoint() string

GetForwardAuthEndpoint returns the endpoint which will use used for Traefik Forward Auth. When no endpoint is provided a default value will be returned.

func (*Config) GetForwardAuthParameterName added in v0.7.7

func (config *Config) GetForwardAuthParameterName() string

GetForwardAuthParameterName returns the query parameter name which will use used for Traefik Forward Auth. When no query parameter name is provided a default value will be returned.

func (*Config) GetHideFooter

func (config *Config) GetHideFooter() bool

GetHideFooter returns whether the footer should be hidden in the web user interface.

func (config *Config) GetHideLogo() bool

GetHideLogo returns whether the logo should be hidden in the web user interface.

func (*Config) GetHtmlTitle added in v0.7.8

func (config *Config) GetHtmlTitle() string

GetHtmlTitle returns whether the HTML title shown in the web user interface.

func (*Config) GetIntrospectScope

func (config *Config) GetIntrospectScope() string

GetIntrospectScope returns the scope which can be used to introspect tokens. When no scope is provided a default value will be returned.

func (*Config) GetInvalidCredentialsMessage added in v0.7.7

func (config *Config) GetInvalidCredentialsMessage() string

GetInvalidCredentialsMessage returns the configured invalid credentials message. When no invalid credentials message is provided a default value will be returned.

func (*Config) GetIssuer added in v0.7.7

func (config *Config) GetIssuer(requestData *internalHttp.RequestData) string

GetIssuer returns the issuer, either by mirroring from request, from Server configuration or default value.

func (*Config) GetLogoImage added in v0.7.7

func (config *Config) GetLogoImage() *[]byte

GetLogoImage returns a pointer to the loaded logo image. Can be nil if no image was provided.

func (*Config) GetMessageCookieName added in v0.7.6

func (config *Config) GetMessageCookieName() string

GetMessageCookieName returns the name of the message cookie. When no name is provided a default value will be returned.

func (*Config) GetOidc added in v0.7.6

func (config *Config) GetOidc() bool

GetOidc returns whether one of the existing clients has OIDC flag set or not.

func (*Config) GetRevokeScope

func (config *Config) GetRevokeScope() string

GetRevokeScope returns the scope which can be used to revoke tokens. When no scope is provided a default value will be returned.

func (*Config) GetServerSecret

func (config *Config) GetServerSecret() string

GetServerSecret returns the server secret. When no secret is provided a previously generated value will be returned.

func (*Config) GetSessionTimeoutSeconds

func (config *Config) GetSessionTimeoutSeconds() int

GetSessionTimeoutSeconds returns the session timeout in seconds. When no session timeout is provided a default value will be returned.

func (*Config) GetTitle

func (config *Config) GetTitle() string

GetTitle returns whether the title shown in the web user interface.

func (*Config) GetUser

func (config *Config) GetUser(username string) (*User, bool)

GetUser returns a User for the given username. Also returns a bool which indicates, whether the User exists or not.

func (*Config) Validate added in v0.7.7

func (config *Config) Validate() error

Validate validates the current Config and returns an error when necessary values are missing.

type Cookies added in v0.7.6

type Cookies struct {
	AuthName        string `yaml:"authName"`
	MessageName     string `yaml:"messageName"`
	ForwardAuthName string `yaml:"forwardAuthName"`
}

Cookies defines the name for HTTP cookies used by STOPnik.

type ForwardAuth added in v0.7.7

type ForwardAuth struct {
	Endpoint      string   `yaml:"endpoint"`
	ExternalUrl   string   `yaml:"externalUrl"`
	ParameterName string   `yaml:"parameterName"`
	Redirects     []string `yaml:"redirects"`
}

ForwardAuth defines the configuration related to Traefik Forward Auth, only used when ExternalUrl is provided.

type Keys

type Keys struct {
	Cert string `yaml:"cert"`
	Key  string `yaml:"key"`
}

Keys defines path to TSL certificate and key file.

type Loader

type Loader interface {
	// LoadConfig loads the given configuration and validates if necessary.
	LoadConfig(name string, validate bool) error
}

Loader defines how a configuration is loaded.

func NewConfigLoader

func NewConfigLoader(fileReader ReadFile, unmarshaler Unmarshal) Loader

NewConfigLoader combines the ReadFile and Unmarshal functions into a Loader.

type ReadFile

type ReadFile func(filename string) ([]byte, error)

ReadFile function definition to read a file by name into []byte.

type Server

type Server struct {
	LogLevel              string      `yaml:"logLevel"`
	Addr                  string      `yaml:"addr"`
	Cookies               Cookies     `yaml:"cookies"`
	Secret                string      `yaml:"secret"`
	PrivateKey            string      `yaml:"privateKey"`
	TLS                   TLS         `yaml:"tls"`
	LogoutRedirect        string      `yaml:"logoutRedirect"`
	IntrospectScope       string      `yaml:"introspectScope"`
	RevokeScope           string      `yaml:"revokeScopeScope"`
	SessionTimeoutSeconds int         `yaml:"sessionTimeoutSeconds"`
	Issuer                string      `yaml:"issuer"`
	ForwardAuth           ForwardAuth `yaml:"forwardAuth"`
}

Server defines the main STOPnik server configuration.

type TLS

type TLS struct {
	Addr string `yaml:"addr"`
	Keys Keys   `yaml:"keys"`
}

TLS defines the Go like address to listen to and references the necessary Keys.

type UI

type UI struct {
	HideFooter                bool   `yaml:"hideFooter"`
	HtmlTitle                 string `yaml:"htmlTitle"`
	Title                     string `yaml:"title"`
	FooterText                string `yaml:"footerText"`
	LogoImage                 string `yaml:"logoImage"`
	InvalidCredentialsMessage string `yaml:"invalidCredentialsMessage"`
	ExpiredLoginMessage       string `yaml:"expiredLoginMessage"`
}

UI defines the general web user interface entry in the configuration.

type Unmarshal

type Unmarshal func(in []byte, out interface{}) (err error)

Unmarshal function definition to unmarshal a []byte into a general interface.

type User

type User struct {
	Username        string          `yaml:"username"`
	Password        string          `yaml:"password"`
	Salt            string          `yaml:"salt"`
	UserProfile     UserProfile     `yaml:"userProfile"`
	UserInformation UserInformation `yaml:"userInformation"`
}

User defines the general user entry in the configuration.

func (*User) GetFormattedAddress added in v0.7.6

func (user *User) GetFormattedAddress() string

GetFormattedAddress return the formatted address for a User.

func (*User) GetName added in v0.7.8

func (user *User) GetName() string

GetName returns the name for a given User.

func (*User) GetPreferredUsername added in v0.7.6

func (user *User) GetPreferredUsername() string

GetPreferredUsername returns the preferred username for a given User, or just the username.

type UserAddress added in v0.7.6

type UserAddress struct {
	Formatted  string `json:"formatted,omitempty"`
	Street     string `yaml:"street" json:"street_address,omitempty"`
	City       string `yaml:"city" json:"locality,omitempty"`
	PostalCode string `yaml:"postalCode" json:"postal_code,omitempty"`
	Region     string `yaml:"region" json:"region,omitempty"`
	Country    string `yaml:"country" json:"country,omitempty"`
}

UserAddress defines the address for a specific user, the definition provided in the YAML file will be mapped into values inside a JSON response.

type UserInformation added in v0.7.8

type UserInformation struct {
	Email         string       `yaml:"email" json:"email,omitempty"`
	EmailVerified bool         `yaml:"emailVerified" json:"email_verified,omitempty"`
	PhoneNumber   string       `yaml:"phoneNumber" json:"phone_number,omitempty"`
	PhoneVerified bool         `yaml:"phoneVerified" json:"phone_verified,omitempty"`
	Address       *UserAddress `yaml:"address" json:"address,omitempty"`
}

type UserProfile added in v0.7.6

type UserProfile struct {
	Subject           string `json:"sub,omitempty"`
	Name              string `json:"name,omitempty"`
	GivenName         string `yaml:"givenName" json:"given_name,omitempty"`
	FamilyName        string `yaml:"familyName" json:"family_name,omitempty"`
	Nickname          string `yaml:"nickname" json:"nickname,omitempty"`
	PreferredUserName string `yaml:"preferredUserName" json:"preferred_username,omitempty"`
	Gender            string `yaml:"gender" json:"gender,omitempty"`
	BirthDate         string `yaml:"birthDate" json:"birth_date,omitempty"`
	ZoneInfo          string `yaml:"zoneInfo" json:"zone_info,omitempty"`
	Locale            string `yaml:"locale" json:"locale,omitempty"`
	Website           string `yaml:"website" json:"website,omitempty"`
	Profile           string `yaml:"profile" json:"profile,omitempty"`
	Picture           string `yaml:"picture" json:"picture,omitempty"`
	UpdatedAt         int64  `json:"updated_at,omitempty"`
}

UserProfile defines the profile for a specific user, the definition provided in the YAML file will be mapped into values inside a JSON response.

Jump to

Keyboard shortcuts

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