v0.31.1 Latest Latest

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

Go to latest
Published: Sep 6, 2023 License: Apache-2.0 Imports: 27 Imported by: 0




View Source
const SchemaVersion = 1

SchemaVersion indicates the current config struct version.


This section is empty.


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 MatchURL added in v0.28.0

func MatchURL(baseURL, testURL string) (bool, error)

MatchURL will compare two url strings and will return true if they match.

func RequestURL added in v0.30.0

func RequestURL(req *http.Request) string

RequestURL returns the full URL for the given request based on the current public url.

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.


type Config

type Config struct {
	General struct {
		ApplicationName              string `public:"true" info:"The name used in messaging and page titles. Defaults to \"GoAlert\"."`
		PublicURL                    string `` /* 138-byte string literal not displayed */
		GoogleAnalyticsID            string `public:"true" info:"If set, will post user metrics to the corresponding data stream in Google Analytics 4."`
		NotificationDisclaimer       string `public:"true" info:"Disclaimer text for receiving pre-recorded notifications (appears on profile page)."`
		DisableMessageBundles        bool   `public:"true" info:"Disable bundling status updates and alert notifications."`
		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 */

	Maintenance struct {
		AlertCleanupDays    int `public:"true" info:"Closed alerts will be deleted after this many days (0 means disable cleanup)."`
		AlertAutoCloseDays  int `` /* 137-byte string literal not displayed */
		APIKeyExpireDays    int `public:"true" info:"Unused calendar API keys will be disabled after this many days (0 means disable cleanup)."`
		ScheduleCleanupDays int `public:"true" info:"Schedule on-call history will be deleted after this many days (0 means disable cleanup)."`

	Auth struct {
		RefererURLs  []string `info:"Allowed referer URLs for auth and redirects." deprecated:"Use --public-url flag instead, which takes precedence."`
		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.
		AccessToken string `password:"true" info:"Slack app bot user OAuth access token (should start with xoxb-)."`

		SigningSecret       string `password:"true" info:"Signing secret to verify requests from slack."`
		InteractiveMessages bool   `info:"Enable interactive messages (e.g. buttons)."`

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

		VoiceName     string `` /* 159-byte string literal not displayed */
		VoiceLanguage string `` /* 168-byte string literal not displayed */

		AccountSID         string
		AuthToken          string `` /* 151-byte string literal not displayed */
		AlternateAuthToken string `` /* 194-byte string literal not displayed */

		FromNumber string `public:"true" info:"The Twilio number to use for outgoing notifications."`

		MessagingServiceSID string `public:"true" info:"If set, replaces the use of From Number for SMS 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 */

	SMTP struct {
		Enable bool `public:"true" info:"Enables email as a contact method."`

		From string `public:"true" info:"The email address messages should be sent from."`

		Address    string `` /* 193-byte string literal not displayed */
		DisableTLS bool   `info:"Disables TLS on the connection (STARTTLS will still be used if supported)."`
		SkipVerify bool   `info:"Disables certificate validation for TLS/STARTTLS (insecure)."`

		Username string `info:"Username for authentication."`
		Password string `password:"true" info:"Password for authentication."`

	Webhook struct {
		Enable      bool     `public:"true" info:"Enables webhook as a contact method."`
		AllowedURLs []string `public:"true" info:"If set, allows webhooks for these domains only."`

	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) ApplicationName added in v0.28.0

func (cfg Config) ApplicationName() string

ApplicationName will return the General.ApplicationName

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) EmailIngressDomain added in v0.31.0

func (cfg Config) EmailIngressDomain() string

EmailIngressDomain returns the domain configured to receive email for alert generation

func (Config) EmailIngressEnabled added in v0.31.0

func (cfg Config) EmailIngressEnabled() bool

EmailIngressEnabled returns true if a provider is configured for generating alerts from email, otherwise false

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) ShouldUsePublicURL added in v0.30.0

func (cfg Config) ShouldUsePublicURL() bool

ShouldUsePublicURL returns true if redirects, validation, etc.. should use the configured PublicURL instead of host/referer.

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) ValidWebhookURL added in v0.28.0

func (cfg Config) ValidWebhookURL(testURL string) bool

ValidWebhookURL returns true if the URL is an allowed webhook 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
	Slack struct {
		InteractivityResponseURL 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, cfg StoreConfig) (*Store, error)

NewStore will create a new Store with the given StoreConfig 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.

type StoreConfig added in v0.31.0

type StoreConfig struct {
	DB   *sql.DB
	Keys keyring.Keys

	// FallbackURL is the URL to use when the DB config does not specify a public URL.
	FallbackURL string

	// ExplicitURL is the full public URL to use for all links.
	ExplicitURL string

	// IngressEmailDomain is the domain to use for ingress email addresses.
	IngressEmailDomain string

Jump to

Keyboard shortcuts

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