config

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2020 License: Apache-2.0 Imports: 25 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.

func LongPath added in v0.24.0

func LongPath(shortPath string) string

LongPath will attempt to convert a shortened GoAlert URL into the original. If unable, it will return an empty string.

func ShortPath added in v0.24.0

func ShortPath(longPath string) string

ShortPath will attempt to convert a normal/long GoAlert URL into a shorter version.

If unable/unknown it will return an empty string.

func ShortURLMiddleware added in v0.24.0

func ShortURLMiddleware(next http.Handler) http.Handler

ShortURLMiddleware will issue redirects for requests to generated short URLs.

Unknown/unhandled paths will be left as-is.

Types

type Config

type Config struct {
	General struct {
		PublicURL                    string `public:"true" 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)."`
		MessageBundles               bool   `` /* 134-byte string literal not displayed */
		ShortURL                     string `` /* 179-byte string literal not displayed */
		DisableSMSLinks              bool   `public:"true" info:"If set, SMS messages will not contain a URL pointing to GoAlert."`
		DisableLabelCreation         bool   `public:"true" info:"Disables the ability to create new labels for services."`
		DisableCalendarSubscriptions bool   `` /* 132-byte string literal not displayed */
		DisableV1GraphQL             bool   `info:"Disables the deprecated /v1/graphql endpoint (replaced by /api/graphql)."`
	}

	Maintenance struct {
		AlertCleanupDays int `public:"true" info:"Closed alerts will be deleted after this many days (0 means disable cleanup)."`
		APIKeyExpireDays int `public:"true" info:"Unused calendar API keys will be disabled after this many days (0 means disable cleanup)."`
	}

	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"`

		Scopes                    string `info:"Requested scopes for authentication. If left blank, openid, profile, and email will be used."`
		UserInfoEmailPath         string `` /* 140-byte string literal not displayed */
		UserInfoEmailVerifiedPath string `` /* 169-byte string literal not displayed */
		UserInfoNamePath          string `` /* 175-byte string literal not displayed */
	}

	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"`

		// The `xoxb-` prefix is documented by Slack.
		// https://api.slack.com/docs/token-types#bot
		AccessToken string `password:"true" info:"Slack app bot user OAuth access token (should start with xoxb-)."`
	}

	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."`

		DisableTwoWaySMS      bool     `info:"Disables SMS reply codes for alert messages."`
		SMSCarrierLookup      bool     `info:"Perform carrier lookup of SMS contact methods (required for SMSFromNumberOverride). Extra charges may apply."`
		SMSFromNumberOverride []string `` /* 143-byte string literal not displayed */
	}

	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) Hints added in v0.25.0

func (cfg Config) Hints() Hints

Hints returns available hints for the current configuration.

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) TwilioSMSFromNumber added in v0.25.0

func (cfg Config) TwilioSMSFromNumber(carrier string) string

TwilioSMSFromNumber will determine the appropriate FROM number to use for SMS messages to the given number

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 Hints added in v0.25.0

type Hints struct {
	GitHub struct {
		AuthCallbackURL string
	}
	OIDC struct {
		RedirectURL string
	}
	Mailgun struct {
		ForwardURL string
	}
	Twilio struct {
		MessageWebhookURL string
		VoiceWebhookURL   string
	}
}

Hints contains information helpful for configuring GoAlert and various integrations.

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) Shutdown added in v0.25.0

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

Shutdown stops the config reloader.

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