config

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2019 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const SchemaVersion = 1

SchemaVersion indicates the current config struct version.

Variables

This section is empty.

Functions

func Handler

func Handler(next http.Handler, src Source) http.Handler

Handler will return a new http.Handler that provides config to all requests.

Types

type Config

type Config struct {
	General struct {
		PublicURL              string `info:"Publicly routable URL for UI links and API calls."`
		GoogleAnalyticsID      string `public:"true"`
		NotificationDisclaimer string `public:"true" info:"Disclaimer text for receiving pre-recorded notifications (appears on profile page)."`
		DisableLabelCreation   bool   `public:"true" info:"Disables the ability to create new labels for services."`
	}

	Auth struct {
		RefererURLs  []string `info:"Allowed referer URLs for auth and redirects."`
		DisableBasic bool     `public:"true" info:"Disallow username/password login."`
	}

	GitHub struct {
		Enable bool `public:"true" info:"Enable GitHub authentication."`

		NewUsers bool `info:"Allow new user creation via GitHub authentication."`

		ClientID     string
		ClientSecret string `password:"true"`

		AllowedUsers []string `info:"Allow any of the listed GitHub usernames to authenticate. Use '*' to allow any user."`
		AllowedOrgs  []string `info:"Allow any member of any listed GitHub org (or team, using the format 'org/team') to authenticate."`

		EnterpriseURL string `info:"GitHub URL (without /api) when used with GitHub Enterprise."`
	}

	OIDC struct {
		Enable bool `public:"true" info:"Enable OpenID Connect authentication."`

		NewUsers     bool   `info:"Allow new user creation via OIDC authentication."`
		OverrideName string `info:"Set the name/label on the login page to something other than OIDC."`

		IssuerURL    string
		ClientID     string
		ClientSecret string `password:"true"`
	}

	Mailgun struct {
		Enable bool `public:"true"`

		APIKey      string `password:"true"`
		EmailDomain string `info:"The TO address for all incoming alerts."`
	}

	Slack struct {
		Enable bool `public:"true"`

		ClientID     string
		ClientSecret string `password:"true"`

		AccessToken string `password:"true" info:"Slack app OAuth access token."`
	}

	Twilio struct {
		Enable bool `public:"true" info:"Enables sending and processing of Voice and SMS messages through the Twilio notification provider."`

		AccountSID string
		AuthToken  string `password:"true" info:"The primary Auth Token for Twilio. Must be primary (not secondary) for request valiation."`
		FromNumber string `public:"true" info:"The Twilio number to use for outgoing notifications."`
	}

	Feedback struct {
		Enable      bool   `public:"true" info:"Enables Feedback link in nav bar."`
		OverrideURL string `public:"true" info:"Use a custom URL for Feedback link in nav bar."`
	}
	// contains filtered or unexported fields
}

Config contains GoAlert application settings.

func FromContext

func FromContext(ctx context.Context) Config

FromContext will return the Config carried in the provided Context.

It panics if config is not available on the current context.

func (Config) CallbackURL

func (cfg Config) CallbackURL(path string, mergeParams ...url.Values) string

CallbackURL will return a public-routable URL to the given path. It will use PublicURL() to fill in missing pieces.

It will panic if provided an invalid URL.

func (Config) Context

func (cfg Config) Context(ctx context.Context) context.Context

Context returns a new Context that carries the provided Config.

func (Config) PublicURL

func (cfg Config) PublicURL() string

PublicURL will return the General.PublicURL or a fallback address (i.e. the app listening port).

func (Config) ValidReferer

func (cfg Config) ValidReferer(reqURL, ref string) bool

ValidReferer returns true if the URL is an allowed referer source.

func (Config) Validate

func (cfg Config) Validate() error

Validate will check that the Config values are valid.

type Source

type Source interface {
	Config() Config
}

A Source will provide a snapshot of a Config struct.

type Static

type Static Config

Static implements a config.Source that never changes it's values.

func (Static) Config

func (s Static) Config() Config

Config will return the current value of s.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store handles saving and loading configuration from a postgres database.

func NewStore

func NewStore(ctx context.Context, db *sql.DB, keys keyring.Keys, fallbackURL string) (*Store, error)

NewStore will create a new Store with the given parameters. It will automatically detect new configuration changes.

func (*Store) Config

func (s *Store) Config() Config

Config will return the current config state.

func (*Store) ConfigData

func (s *Store) ConfigData(ctx context.Context, tx *sql.Tx) (id, schemaVersion int, data []byte, err error)

ConfigData will return the current raw config data from the DB.

func (*Store) Reload

func (s *Store) Reload(ctx context.Context) error

Reload will re-read and update the current config state from the DB.

func (*Store) ServeConfig

func (s *Store) ServeConfig(w http.ResponseWriter, req *http.Request)

ServeConfig handles requests to read and write the config json.

func (*Store) SetConfig

func (s *Store) SetConfig(ctx context.Context, cfg Config) error

SetConfig will replace the configuration in the DB and perform an immediate reload.

func (*Store) SetConfigData

func (s *Store) SetConfigData(ctx context.Context, tx *sql.Tx, data []byte) (int, error)

SetConfigData will replace the current DB config with data.

func (*Store) UpdateConfig

func (s *Store) UpdateConfig(ctx context.Context, fn func(Config) (Config, error)) error

UpdateConfig will update the configuration in the DB and perform an immediate reload.

Jump to

Keyboard shortcuts

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