File size: 2,130 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
package graphqlapp
import (
"context"
"github.com/target/goalert/config"
"github.com/target/goalert/expflag"
"github.com/target/goalert/graphql2"
"github.com/target/goalert/permission"
)
func (a *Query) IntegrationKeyTypes(ctx context.Context) ([]graphql2.IntegrationKeyTypeInfo, error) {
cfg := config.FromContext(ctx)
typeInfo := []graphql2.IntegrationKeyTypeInfo{
{ID: "email", Name: "Email", Label: "Email Address", Enabled: cfg.EmailIngressEnabled()},
{ID: "generic", Name: "Generic API", Label: "Generic Webhook URL", Enabled: true},
{ID: "grafana", Name: "Grafana", Label: "Grafana Webhook URL", Enabled: true},
{ID: "site24x7", Name: "Site 24x7", Label: "Site24x7 Webhook URL", Enabled: true},
{ID: "prometheusAlertmanager", Label: "Alertmanager Webhook URL", Name: "Prometheus Alertmanager", Enabled: true},
}
if expflag.ContextHas(ctx, expflag.UnivKeys) {
typeInfo = append(typeInfo, graphql2.IntegrationKeyTypeInfo{ID: "universal", Label: "Universal Integration Key URL", Name: "Universal Integration Key", Enabled: true})
}
return typeInfo, nil
}
func (q *Query) Config(ctx context.Context, all *bool) ([]graphql2.ConfigValue, error) {
perm := []permission.Checker{permission.System, permission.Admin}
var publicOnly bool
if all == nil || !*all {
publicOnly = true
perm = append(perm, permission.User)
}
err := permission.LimitCheckAny(ctx, perm...)
if err != nil {
return nil, err
}
if publicOnly {
return graphql2.MapPublicConfigValues(q.ConfigStore.Config()), nil
}
return graphql2.MapConfigValues(q.ConfigStore.Config()), nil
}
func (q *Query) ConfigHints(ctx context.Context) ([]graphql2.ConfigHint, error) {
err := permission.LimitCheckAny(ctx, permission.System, permission.Admin)
if err != nil {
return nil, err
}
return graphql2.MapConfigHints(q.ConfigStore.Config().Hints()), nil
}
func (m *Mutation) SetConfig(ctx context.Context, input []graphql2.ConfigValueInput) (bool, error) {
err := m.ConfigStore.UpdateConfig(ctx, func(cfg config.Config) (config.Config, error) {
return graphql2.ApplyConfigValues(cfg, input)
})
return err == nil, err
}
|