diff --git a/apps/alerting/notifications/definitions/alerting-notifications-manifest.yaml b/apps/alerting/notifications/definitions/alerting-notifications-manifest.yaml index aa40d7c74b3..3eb0b59f0d2 100644 --- a/apps/alerting/notifications/definitions/alerting-notifications-manifest.yaml +++ b/apps/alerting/notifications/definitions/alerting-notifications-manifest.yaml @@ -430,4 +430,100 @@ spec: type: object scope: Namespaced name: v0alpha1 + routes: + namespaced: + /testing/integration: + get: + operationId: getIntegrationTest + requestBody: + content: + application/json: + schema: + additionalProperties: false + properties: + alert: + $ref: '#/components/schemas/getIntegrationTestAlert' + integration: + $ref: '#/components/schemas/getIntegrationTestIntegration' + receiver_ref: + type: string + required: + - alert + - integration + type: object + required: true + responses: + default: + content: + application/json: + schema: + additionalProperties: false + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of + this representation of an object. Servers should convert + recognized schemas to the latest internal value, and may + reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + duration: + type: string + error: + type: string + kind: + description: 'Kind is a string value representing the REST + resource this object represents. Servers may infer this + from the endpoint the client submits requests to. Cannot + be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + timestamp: + format: date-time + type: string + required: + - timestamp + - duration + - apiVersion + - kind + type: object + description: Default OK response + schemas: + getIntegrationTestAlert: + additionalProperties: false + properties: + annotations: + additionalProperties: + type: string + type: object + labels: + additionalProperties: + type: string + type: object + required: + - labels + - annotations + type: object + getIntegrationTestIntegration: + additionalProperties: false + properties: + disableResolveMessage: + type: boolean + secureFields: + additionalProperties: + type: boolean + type: object + settings: + additionalProperties: + additionalProperties: {} + type: object + type: object + type: + type: string + uid: + type: string + version: + type: string + required: + - type + - version + - settings + type: object served: true diff --git a/apps/alerting/notifications/kinds/manifest.cue b/apps/alerting/notifications/kinds/manifest.cue index 5ad62b79cd3..93e19856686 100644 --- a/apps/alerting/notifications/kinds/manifest.cue +++ b/apps/alerting/notifications/kinds/manifest.cue @@ -1,5 +1,19 @@ package kinds +import ( + "time", + "github.com/grafana/grafana/apps/alerting/notifications/kinds/v0alpha1" +) + +#Alert: { + labels: { + [string]: string + } + annotations: { + [string]: string + } +} + manifest: { appName: "alerting-notifications" groupOverride: "notifications.alerting.grafana.app" @@ -14,7 +28,28 @@ manifest: { routeTreev0alpha1, templatev0alpha1, timeIntervalv0alpha1, - ] + ], + routes: { + namespaced: { + "/testing/integration" : { + "GET": { + name: "getIntegrationTest" + request: { + body: { + alert: #Alert + receiver_ref?: string + integration: v0alpha1.#Integration + } + } + response: { + timestamp: time.Time + duration: string + error?: string + } + } + } + } + }, } } } diff --git a/apps/alerting/notifications/pkg/apis/alertingnotifications/v0alpha1/getintegrationtest_request_body_types_gen.go b/apps/alerting/notifications/pkg/apis/alertingnotifications/v0alpha1/getintegrationtest_request_body_types_gen.go new file mode 100644 index 00000000000..f97ba4246eb --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/alertingnotifications/v0alpha1/getintegrationtest_request_body_types_gen.go @@ -0,0 +1,46 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package v0alpha1 + +type GetIntegrationTestRequestAlert struct { + Labels map[string]string `json:"labels"` + Annotations map[string]string `json:"annotations"` +} + +// NewGetIntegrationTestRequestAlert creates a new GetIntegrationTestRequestAlert object. +func NewGetIntegrationTestRequestAlert() *GetIntegrationTestRequestAlert { + return &GetIntegrationTestRequestAlert{ + Labels: map[string]string{}, + Annotations: map[string]string{}, + } +} + +type GetIntegrationTestRequestIntegration struct { + Uid *string `json:"uid,omitempty"` + Type string `json:"type"` + Version string `json:"version"` + DisableResolveMessage *bool `json:"disableResolveMessage,omitempty"` + Settings map[string]any `json:"settings"` + SecureFields map[string]bool `json:"secureFields,omitempty"` +} + +// NewGetIntegrationTestRequestIntegration creates a new GetIntegrationTestRequestIntegration object. +func NewGetIntegrationTestRequestIntegration() *GetIntegrationTestRequestIntegration { + return &GetIntegrationTestRequestIntegration{ + Settings: map[string]any{}, + } +} + +type GetIntegrationTestRequestBody struct { + Alert GetIntegrationTestRequestAlert `json:"alert"` + ReceiverRef *string `json:"receiver_ref,omitempty"` + Integration GetIntegrationTestRequestIntegration `json:"integration"` +} + +// NewGetIntegrationTestRequestBody creates a new GetIntegrationTestRequestBody object. +func NewGetIntegrationTestRequestBody() *GetIntegrationTestRequestBody { + return &GetIntegrationTestRequestBody{ + Alert: *NewGetIntegrationTestRequestAlert(), + Integration: *NewGetIntegrationTestRequestIntegration(), + } +} diff --git a/apps/alerting/notifications/pkg/apis/alertingnotifications/v0alpha1/getintegrationtest_response_body_types_gen.go b/apps/alerting/notifications/pkg/apis/alertingnotifications/v0alpha1/getintegrationtest_response_body_types_gen.go new file mode 100644 index 00000000000..1606c5eb5ee --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/alertingnotifications/v0alpha1/getintegrationtest_response_body_types_gen.go @@ -0,0 +1,19 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package v0alpha1 + +import ( + time "time" +) + +// +k8s:openapi-gen=true +type GetIntegrationTestBody struct { + Timestamp time.Time `json:"timestamp"` + Duration string `json:"duration"` + Error *string `json:"error,omitempty"` +} + +// NewGetIntegrationTestBody creates a new GetIntegrationTestBody object. +func NewGetIntegrationTestBody() *GetIntegrationTestBody { + return &GetIntegrationTestBody{} +} diff --git a/apps/alerting/notifications/pkg/apis/alertingnotifications/v0alpha1/getintegrationtest_response_object_types_gen.go b/apps/alerting/notifications/pkg/apis/alertingnotifications/v0alpha1/getintegrationtest_response_object_types_gen.go new file mode 100644 index 00000000000..f781b8f199e --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/alertingnotifications/v0alpha1/getintegrationtest_response_object_types_gen.go @@ -0,0 +1,37 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package v0alpha1 + +import ( + "github.com/grafana/grafana-app-sdk/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +// +k8s:openapi-gen=true +type GetIntegrationTest struct { + metav1.TypeMeta `json:",inline"` + GetIntegrationTestBody `json:",inline"` +} + +func NewGetIntegrationTest() *GetIntegrationTest { + return &GetIntegrationTest{} +} + +func (t *GetIntegrationTestBody) DeepCopyInto(dst *GetIntegrationTestBody) { + _ = resource.CopyObjectInto(dst, t) +} + +func (o *GetIntegrationTest) DeepCopyObject() runtime.Object { + dst := NewGetIntegrationTest() + o.DeepCopyInto(dst) + return dst +} + +func (o *GetIntegrationTest) DeepCopyInto(dst *GetIntegrationTest) { + dst.TypeMeta.APIVersion = o.TypeMeta.APIVersion + dst.TypeMeta.Kind = o.TypeMeta.Kind + o.GetIntegrationTestBody.DeepCopyInto(&dst.GetIntegrationTestBody) +} + +var _ runtime.Object = NewGetIntegrationTest() diff --git a/apps/alerting/notifications/pkg/apis/alertingnotifications_manifest.go b/apps/alerting/notifications/pkg/apis/alertingnotifications_manifest.go index 18447f62760..498d0279f86 100644 --- a/apps/alerting/notifications/pkg/apis/alertingnotifications_manifest.go +++ b/apps/alerting/notifications/pkg/apis/alertingnotifications_manifest.go @@ -79,9 +79,206 @@ var appManifestData = app.ManifestData{ }, }, Routes: app.ManifestVersionRoutes{ - Namespaced: map[string]spec3.PathProps{}, - Cluster: map[string]spec3.PathProps{}, - Schemas: map[string]spec.Schema{}, + Namespaced: map[string]spec3.PathProps{ + "/testing/integration": { + Get: &spec3.Operation{ + OperationProps: spec3.OperationProps{ + + OperationId: "getIntegrationTest", + + RequestBody: &spec3.RequestBody{ + RequestBodyProps: spec3.RequestBodyProps{ + + Required: true, + Content: map[string]*spec3.MediaType{ + "application/json": { + MediaTypeProps: spec3.MediaTypeProps{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "alert": { + SchemaProps: spec.SchemaProps{ + + Ref: spec.MustCreateRef("#/components/schemas/getIntegrationTestAlert"), + }, + }, + "integration": { + SchemaProps: spec.SchemaProps{ + + Ref: spec.MustCreateRef("#/components/schemas/getIntegrationTestIntegration"), + }, + }, + "receiver_ref": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + }, + }, + }, + Required: []string{ + "alert", + "integration", + }, + }}, + }}, + }, + }}, + Responses: &spec3.Responses{ + ResponsesProps: spec3.ResponsesProps{ + Default: &spec3.Response{ + ResponseProps: spec3.ResponseProps{ + Description: "Default OK response", + Content: map[string]*spec3.MediaType{ + "application/json": { + MediaTypeProps: spec3.MediaTypeProps{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + }, + }, + "duration": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + }, + }, + "error": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + }, + }, + "kind": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + }, + }, + "timestamp": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "date-time", + }, + }, + }, + Required: []string{ + "timestamp", + "duration", + "apiVersion", + "kind", + }, + }}, + }}, + }, + }, + }, + }}, + }, + }, + }, + }, + Cluster: map[string]spec3.PathProps{}, + Schemas: map[string]spec.Schema{ + "getIntegrationTestAlert": { + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "annotations": { + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + }, + }, + }, + }, + }, + "labels": { + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + }, + }, + }, + }, + }, + }, + Required: []string{ + "labels", + "annotations", + }, + }, + }, + "getIntegrationTestIntegration": { + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "disableResolveMessage": { + SchemaProps: spec.SchemaProps{ + Type: []string{"boolean"}, + }, + }, + "secureFields": { + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"boolean"}, + }, + }, + }, + }, + }, + "settings": { + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{}, + }, + }, + }, + }, + }, + }, + }, + "type": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + }, + }, + "uid": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + }, + }, + "version": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + }, + }, + }, + Required: []string{ + "type", + "version", + "settings", + }, + }, + }, + }, }, }, }, @@ -109,7 +306,9 @@ func ManifestGoTypeAssociator(kind, version string) (goType resource.Kind, exist return goType, exists } -var customRouteToGoResponseType = map[string]any{} +var customRouteToGoResponseType = map[string]any{ + "v0alpha1||/testing/integration|GET": v0alpha1.GetIntegrationTest{}, +} // ManifestCustomRouteResponsesAssociator returns the associated response go type for a given kind, version, custom route path, and method, if one exists. // kind may be empty for custom routes which are not kind subroutes. Leading slashes are removed from subroute paths. @@ -133,7 +332,9 @@ func ManifestCustomRouteQueryAssociator(kind, version, path, verb string) (goTyp return goType, exists } -var customRouteToGoRequestBodyType = map[string]any{} +var customRouteToGoRequestBodyType = map[string]any{ + "v0alpha1||/testing/integration|GET": v0alpha1.GetIntegrationTestRequestBody{}, +} func ManifestCustomRouteRequestBodyAssociator(kind, version, path, verb string) (goType any, exists bool) { if len(path) > 0 && path[0] == '/' {