Skip to content

Commit

Permalink
add type universal to integration keys (#3836)
Browse files Browse the repository at this point in the history
* add universal type to integration keys

* make generate

* make db-schema

* make check

* add exp flag checks

* revert hardcoded UI int key type

* update universal key label

Co-authored-by: Nathaniel Caza <mastercactapus@gmail.com>

* update exp flag check for universal keys

Co-authored-by: Nathaniel Caza <mastercactapus@gmail.com>

* add import

* make check

---------

Co-authored-by: Nathaniel Caza <mastercactapus@gmail.com>
  • Loading branch information
Forfold and mastercactapus authored May 3, 2024
1 parent a1268f4 commit ddd62b0
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 11 deletions.
2 changes: 1 addition & 1 deletion alert/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (a Alert) Normalize() (*Alert, error) {
err := validate.Many(
validate.Text("Summary", a.Summary, 1, MaxSummaryLength),
validate.Text("Details", a.Details, 0, MaxDetailsLength),
validate.OneOf("Source", a.Source, SourceManual, SourceGrafana, SourceSite24x7, SourcePrometheusAlertmanager, SourceEmail, SourceGeneric),
validate.OneOf("Source", a.Source, SourceManual, SourceGrafana, SourceSite24x7, SourcePrometheusAlertmanager, SourceEmail, SourceGeneric, SourceUniversal),
validate.OneOf("Status", a.Status, StatusTriggered, StatusActive, StatusClosed),
validate.UUID("ServiceID", a.ServiceID),
)
Expand Down
2 changes: 2 additions & 0 deletions alert/alertlog/legacylogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func createdSubject(msg string) *Subject {
return &Subject{Type: SubjectTypeUser, Classifier: "Web"}
case "Created via: generic":
return &Subject{Type: SubjectTypeIntegrationKey, Classifier: "Generic"}
case "Created via: universal":
return &Subject{Type: SubjectTypeIntegrationKey, Classifier: "Universal"}
}
return nil
}
1 change: 1 addition & 0 deletions alert/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
SourcePrometheusAlertmanager Source = "prometheusAlertmanager" // prometheus alertmanager alert
SourceManual Source = "manual" // manually triggered
SourceGeneric Source = "generic" // generic API
SourceUniversal Source = "universal" // universal integration
)

func (s Source) Value() (driver.Value, error) {
Expand Down
2 changes: 2 additions & 0 deletions gadb/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/target/goalert

go 1.22.0
go 1.22

require (
github.com/99designs/gqlgen v0.17.45
Expand Down
11 changes: 9 additions & 2 deletions graphql2/graphqlapp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@ 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)
return []graphql2.IntegrationKeyTypeInfo{
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},
}, nil
}

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) {
Expand Down
4 changes: 3 additions & 1 deletion graphql2/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions graphql2/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ enum IntegrationKeyType {
site24x7
prometheusAlertmanager
email
universal
}

type ServiceOnCallUser {
Expand Down
8 changes: 7 additions & 1 deletion integrationkey/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"database/sql"

"github.com/target/goalert/auth/authtoken"
"github.com/target/goalert/expflag"
"github.com/target/goalert/gadb"
"github.com/target/goalert/permission"
"github.com/target/goalert/validation"
"github.com/target/goalert/validation/validate"

"github.com/google/uuid"
Expand Down Expand Up @@ -44,7 +46,7 @@ func (s *Store) GetServiceID(ctx context.Context, id string, t Type) (string, er
keyUUID, err := validate.ParseUUID("IntegrationKeyID", id)
err = validate.Many(
err,
validate.OneOf("IntegrationType", t, TypeGrafana, TypeSite24x7, TypePrometheusAlertmanager, TypeGeneric, TypeEmail),
validate.OneOf("IntegrationType", t, TypeGrafana, TypeSite24x7, TypePrometheusAlertmanager, TypeGeneric, TypeEmail, TypeUniversal),
)
if err != nil {
return "", err
Expand Down Expand Up @@ -80,6 +82,10 @@ func (s *Store) Create(ctx context.Context, dbtx gadb.DBTX, i *IntegrationKey) (
return nil, err
}

if i.Type == TypeUniversal && !expflag.ContextHas(ctx, expflag.UnivKeys) {
return nil, validation.NewGenericError("experimental flag not enabled")
}

serviceUUID, err := uuid.Parse(n.ServiceID)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions integrationkey/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
TypePrometheusAlertmanager Type = "prometheusAlertmanager"
TypeGeneric Type = "generic"
TypeEmail Type = "email"
TypeUniversal Type = "universal"
)

func (s Type) Value() (driver.Value, error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- +migrate Up notransaction
ALTER TYPE enum_integration_keys_type
ADD VALUE IF NOT EXISTS 'universal';

ALTER TYPE enum_alert_source
ADD VALUE IF NOT EXISTS 'universal';

-- +migrate Down
12 changes: 7 additions & 5 deletions migrate/schema.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- This file is auto-generated by "make db-schema"; DO NOT EDIT
-- DATA=596edde315555fde9765e0aa166955c2d44ec2c24263bc4a46d4a94506d9c8db -
-- DISK=b269e94400bcbfc12246e820bfb30250f47a6b435092af08d9ff5a00fe7abcd8 -
-- PSQL=b269e94400bcbfc12246e820bfb30250f47a6b435092af08d9ff5a00fe7abcd8 -
-- DATA=7d93d4f1913d4f571b975bbb160ea002b2d627371957d7adaff224950903d3ff -
-- DISK=694fd850e84cde18ce1187a3da13e68897d5b0f5d049a3f309812c61b0eba330 -
-- PSQL=694fd850e84cde18ce1187a3da13e68897d5b0f5d049a3f309812c61b0eba330 -
--
-- pgdump-lite database dump
--
Expand Down Expand Up @@ -55,7 +55,8 @@ CREATE TYPE enum_alert_source AS ENUM (
'grafana',
'manual',
'prometheusAlertmanager',
'site24x7'
'site24x7',
'universal'
);

CREATE TYPE enum_alert_status AS ENUM (
Expand All @@ -75,7 +76,8 @@ CREATE TYPE enum_integration_keys_type AS ENUM (
'generic',
'grafana',
'prometheusAlertmanager',
'site24x7'
'site24x7',
'universal'
);

CREATE TYPE enum_limit_type AS ENUM (
Expand Down
1 change: 1 addition & 0 deletions web/src/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ export type IntegrationKeyType =
| 'grafana'
| 'prometheusAlertmanager'
| 'site24x7'
| 'universal'

export interface IntegrationKeyTypeInfo {
enabled: boolean
Expand Down

0 comments on commit ddd62b0

Please sign in to comment.