Documentation ¶
Index ¶
- Constants
- func Handler(next http.Handler, src Source) http.Handler
- func LongPath(shortPath string) string
- func ShortPath(longPath string) string
- func ShortURLMiddleware(next http.Handler) http.Handler
- type Config
- func (cfg Config) CallbackURL(path string, mergeParams ...url.Values) string
- func (cfg Config) Context(ctx context.Context) context.Context
- func (cfg Config) Hints() Hints
- func (cfg Config) PublicURL() string
- func (cfg Config) TwilioSMSFromNumber(carrier string) string
- func (cfg Config) ValidReferer(reqURL, ref string) bool
- func (cfg Config) Validate() error
- type Hints
- type Source
- type Static
- type Store
- func (s *Store) Config() Config
- func (s *Store) ConfigData(ctx context.Context, tx *sql.Tx) (id, schemaVersion int, data []byte, err error)
- func (s *Store) Reload(ctx context.Context) error
- func (s *Store) ServeConfig(w http.ResponseWriter, req *http.Request)
- func (s *Store) SetConfig(ctx context.Context, cfg Config) error
- func (s *Store) SetConfigData(ctx context.Context, tx *sql.Tx, data []byte) (int, error)
- func (s *Store) Shutdown(ctx context.Context) error
- func (s *Store) UpdateConfig(ctx context.Context, fn func(Config) (Config, error)) error
Constants ¶
const SchemaVersion = 1
SchemaVersion indicates the current config struct version.
Variables ¶
This section is empty.
Functions ¶
func LongPath ¶ added in v0.24.0
LongPath will attempt to convert a shortened GoAlert URL into the original. If unable, it will return an empty string.
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 ¶
FromContext will return the Config carried in the provided Context.
It panics if config is not available on the current context.
func (Config) CallbackURL ¶
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) PublicURL ¶
PublicURL will return the General.PublicURL or a fallback address (i.e. the app listening port).
func (Config) TwilioSMSFromNumber ¶ added in v0.25.0
TwilioSMSFromNumber will determine the appropriate FROM number to use for SMS messages to the given number
func (Config) ValidReferer ¶
ValidReferer returns true if the URL is an allowed referer source.
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 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) 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) ServeConfig ¶
func (s *Store) ServeConfig(w http.ResponseWriter, req *http.Request)
ServeConfig handles requests to read and write the config json.
func (*Store) SetConfig ¶
SetConfig will replace the configuration in the DB and perform an immediate reload.
func (*Store) SetConfigData ¶
SetConfigData will replace the current DB config with data.