diff --git a/pkg/notifications/README.md b/pkg/notifications/README.md index 6c2dd27..46c8e42 100644 --- a/pkg/notifications/README.md +++ b/pkg/notifications/README.md @@ -64,7 +64,7 @@ type Config struct { ``` -## type [Level]() +## type [Level]() Level describes the severity of the notification @@ -83,20 +83,21 @@ const ( ``` -## type [Notification]() +## type [Notification]() ```go type Notification struct { // omit property `Id` here, as it is read only - Origin string - OriginUri string // can be used to provide a link to the origin - Timestamp time.Time // client will set timestamp if not set - Title string // can also be seen as the 'type' - Detail string - Level Level - CustomFields map[string]any // can contain arbitrary structured information about the notification + Origin string // name of the origin, e.g. `SBOM - React` + OriginClass string // unique identifier for the class of origins, e.g. `/vi/SBOM` + OriginResourceID string // optional, together with class it can be used to provide a link to the origin, e.g. `` + Timestamp time.Time // client will set timestamp if not set + Title string // can also be seen as the 'type' + Detail string + Level Level + CustomFields map[string]any // optional, can contain arbitrary structured information about the notification } ``` diff --git a/pkg/notifications/model.go b/pkg/notifications/model.go index 61c3f76..5a42a38 100644 --- a/pkg/notifications/model.go +++ b/pkg/notifications/model.go @@ -8,26 +8,28 @@ import "time" type Notification struct { // omit property `Id` here, as it is read only - Origin string - OriginUri string // can be used to provide a link to the origin - Timestamp time.Time // client will set timestamp if not set - Title string // can also be seen as the 'type' - Detail string - Level Level - CustomFields map[string]any // can contain arbitrary structured information about the notification + Origin string // name of the origin, e.g. `SBOM - React` + OriginClass string // unique identifier for the class of origins, e.g. `/vi/SBOM` + OriginResourceID string // optional, together with class it can be used to provide a link to the origin, e.g. `` + Timestamp time.Time // client will set timestamp if not set + Title string // can also be seen as the 'type' + Detail string + Level Level + CustomFields map[string]any // optional, can contain arbitrary structured information about the notification } // notification is the object which is to the notification service. // It is defined in notification service REST API: https://github.com/greenbone/opensight-notification-service/tree/main/api/notificationservice type notificationModel struct { // omit property `Id` here, as it is read only - Origin string `json:"origin"` - OriginUri string `json:"originUri,omitempty"` - Timestamp string `json:"timestamp" format:"date-time"` - Title string `json:"title"` - Detail string `json:"detail"` - Level Level `json:"level"` - CustomFields map[string]any `json:"customFields,omitempty"` + Origin string `json:"origin"` + OriginClass string `json:"originClass"` + OriginResourceID string `json:"originResourceID,omitempty"` + Timestamp string `json:"timestamp" format:"date-time"` + Title string `json:"title"` + Detail string `json:"detail"` + Level Level `json:"level"` + CustomFields map[string]any `json:"customFields,omitempty"` } // Level describes the severity of the notification @@ -47,12 +49,13 @@ func toNotificationModel(n Notification) notificationModel { } return notificationModel{ - Origin: n.Origin, - OriginUri: n.OriginUri, - Timestamp: n.Timestamp.UTC().Format(time.RFC3339Nano), - Title: n.Title, - Detail: n.Detail, - Level: n.Level, - CustomFields: n.CustomFields, + Origin: n.Origin, + OriginClass: n.OriginClass, + OriginResourceID: n.OriginResourceID, + Timestamp: n.Timestamp.UTC().Format(time.RFC3339Nano), + Title: n.Title, + Detail: n.Detail, + Level: n.Level, + CustomFields: n.CustomFields, } } diff --git a/pkg/notifications/notification_test.go b/pkg/notifications/notification_test.go index 6b7caea..a3e093f 100644 --- a/pkg/notifications/notification_test.go +++ b/pkg/notifications/notification_test.go @@ -30,24 +30,28 @@ const checkForCurrentTimestamp = "marker to check for current timestamp" func TestClient_CreateNotification(t *testing.T) { notification := Notification{ - Origin: "Example Task XY", - Timestamp: time.Date(1, 2, 3, 4, 5, 6, 7, time.UTC), - Title: "Example Task XY failed", - Detail: "Example Task XY failed because ...", - Level: LevelError, - CustomFields: map[string]any{"extraProperty": "value"}, + Origin: "Example Task XY - 1", + OriginClass: "ab/exampletaskxy", + OriginResourceID: "1", + Timestamp: time.Date(1, 2, 3, 4, 5, 6, 7, time.UTC), + Title: "Example Task XY failed", + Detail: "Example Task XY failed because ...", + Level: LevelError, + CustomFields: map[string]any{"extraProperty": "value"}, } notificationWithoutTimestamp := notification notificationWithoutTimestamp.Timestamp = time.Time{} wantNotification := notificationModel{ - Origin: "Example Task XY", - Timestamp: "0001-02-03T04:05:06.000000007Z", - Title: "Example Task XY failed", - Detail: "Example Task XY failed because ...", - Level: LevelError, - CustomFields: map[string]any{"extraProperty": "value"}, + Origin: "Example Task XY - 1", + OriginClass: "ab/exampletaskxy", + OriginResourceID: "1", + Timestamp: "0001-02-03T04:05:06.000000007Z", + Title: "Example Task XY failed", + Detail: "Example Task XY failed because ...", + Level: LevelError, + CustomFields: map[string]any{"extraProperty": "value"}, } wantNotificationWithoutTimestamp := wantNotification wantNotificationWithoutTimestamp.Timestamp = checkForCurrentTimestamp // can't test exact timestamp