Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

int keys: Add support for externally-managed integration keys #3818

Merged
merged 10 commits into from
Apr 23, 2024
9 changes: 5 additions & 4 deletions gadb/models.go

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

40 changes: 24 additions & 16 deletions gadb/queries.sql.go

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

88 changes: 82 additions & 6 deletions graphql2/generated.go

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

3 changes: 3 additions & 0 deletions graphql2/graphqlapp/integrationkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func (m *Mutation) CreateIntegrationKey(ctx context.Context, input graphql2.Crea
Name: input.Name,
Type: integrationkey.Type(input.Type),
}
if input.ExternalSystemName != nil {
key.ExternalSystemName = *input.ExternalSystemName
}
key, err = m.IntKeyStore.Create(ctx, tx, key)
return err
})
Expand Down
2 changes: 2 additions & 0 deletions graphql2/models_gen.go

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

10 changes: 10 additions & 0 deletions graphql2/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,11 @@ input CreateIntegrationKeyInput {
serviceID: ID
type: IntegrationKeyType!
name: String!

"""
Name of the external system this key is managed by.
"""
externalSystemName: String
}

input CreateHeartbeatMonitorInput {
Expand Down Expand Up @@ -1034,6 +1039,11 @@ type IntegrationKey {
type: IntegrationKeyType!
name: String!
href: String!

"""
Name of the external system this key is managed by.
"""
externalSystemName: String
}

enum IntegrationKeyType {
Expand Down
3 changes: 3 additions & 0 deletions integrationkey/integrationkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ type IntegrationKey struct {
Name string `json:"name"`
Type Type `json:"type"`
ServiceID string `json:"service_id"`

ExternalSystemName string
}

func (i IntegrationKey) Normalize() (*IntegrationKey, error) {
err := validate.Many(
validate.IDName("Name", i.Name),
validate.UUID("ServiceID", i.ServiceID),
validate.OneOf("Type", i.Type, TypeGrafana, TypeSite24x7, TypePrometheusAlertmanager, TypeGeneric, TypeEmail),
validate.ASCII("ExternalSystemName", i.ExternalSystemName, 0, 255),
)
if err != nil {
return nil, err
Expand Down
10 changes: 6 additions & 4 deletions integrationkey/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ WHERE
AND type = $2;

-- name: IntKeyCreate :exec
INSERT INTO integration_keys(id, name, type, service_id)
VALUES ($1, $2, $3, $4);
INSERT INTO integration_keys(id, name, type, service_id, external_system_name)
VALUES ($1, $2, $3, $4, $5);

-- name: IntKeyFindOne :one
SELECT
id,
name,
type,
service_id
service_id,
external_system_name
FROM
integration_keys
WHERE
Expand All @@ -27,7 +28,8 @@ SELECT
id,
name,
type,
service_id
service_id,
external_system_name
FROM
integration_keys
WHERE
Expand Down
6 changes: 6 additions & 0 deletions integrationkey/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func (s *Store) Create(ctx context.Context, dbtx gadb.DBTX, i *IntegrationKey) (
Name: n.Name,
Type: gadb.EnumIntegrationKeysType(n.Type),
ServiceID: serviceUUID,

ExternalSystemName: sql.NullString{String: n.ExternalSystemName, Valid: n.ExternalSystemName != ""},
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -142,6 +144,8 @@ func (s *Store) FindOne(ctx context.Context, id string) (*IntegrationKey, error)
Name: row.Name,
Type: Type(row.Type),
ServiceID: row.ServiceID.String(),

ExternalSystemName: row.ExternalSystemName.String,
}, nil
}

Expand All @@ -167,6 +171,8 @@ func (s *Store) FindAllByService(ctx context.Context, serviceID string) ([]Integ
Name: row.Name,
Type: Type(row.Type),
ServiceID: row.ServiceID.String(),

ExternalSystemName: row.ExternalSystemName.String,
}
}
return keys, nil
Expand Down
Loading
Loading