Skip to content

Commit 815decb

Browse files
authored
change: notifications - split property OriginUri into OriginClass and OriginResourceID (#284)
In the notification rules we want filter/match by a class of notification. But we also want to be able to pinpoint to a specific event instance in the notification (center). So far we had this information combined in the OriginUri, but it is more structured if we have to separate fields rather than needing to split up the value of OriginUri. ## References VTI-785 Adjustment in Notification Service: greenbone/opensight-notification-service#185
1 parent 1266cd5 commit 815decb

File tree

3 files changed

+50
-42
lines changed

3 files changed

+50
-42
lines changed

pkg/notifications/README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type Config struct {
6464
```
6565

6666
<a name="Level"></a>
67-
## type [Level](<https://github.com/greenbone/opensight-golang-libraries/blob/main/pkg/notifications/model.go#L34>)
67+
## type [Level](<https://github.com/greenbone/opensight-golang-libraries/blob/main/pkg/notifications/model.go#L36>)
6868

6969
Level describes the severity of the notification
7070

@@ -83,20 +83,21 @@ const (
8383
```
8484

8585
<a name="Notification"></a>
86-
## type [Notification](<https://github.com/greenbone/opensight-golang-libraries/blob/main/pkg/notifications/model.go#L9-L18>)
86+
## type [Notification](<https://github.com/greenbone/opensight-golang-libraries/blob/main/pkg/notifications/model.go#L9-L19>)
8787

8888

8989

9090
```go
9191
type Notification struct {
9292
// omit property `Id` here, as it is read only
93-
Origin string
94-
OriginUri string // can be used to provide a link to the origin
95-
Timestamp time.Time // client will set timestamp if not set
96-
Title string // can also be seen as the 'type'
97-
Detail string
98-
Level Level
99-
CustomFields map[string]any // can contain arbitrary structured information about the notification
93+
Origin string // name of the origin, e.g. `SBOM - React`
94+
OriginClass string // unique identifier for the class of origins, e.g. `/vi/SBOM`
95+
OriginResourceID string // optional, together with class it can be used to provide a link to the origin, e.g. `<id of react sbom object>`
96+
Timestamp time.Time // client will set timestamp if not set
97+
Title string // can also be seen as the 'type'
98+
Detail string
99+
Level Level
100+
CustomFields map[string]any // optional, can contain arbitrary structured information about the notification
100101
}
101102
```
102103

pkg/notifications/model.go

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,28 @@ import "time"
88

99
type Notification struct {
1010
// omit property `Id` here, as it is read only
11-
Origin string
12-
OriginUri string // can be used to provide a link to the origin
13-
Timestamp time.Time // client will set timestamp if not set
14-
Title string // can also be seen as the 'type'
15-
Detail string
16-
Level Level
17-
CustomFields map[string]any // can contain arbitrary structured information about the notification
11+
Origin string // name of the origin, e.g. `SBOM - React`
12+
OriginClass string // unique identifier for the class of origins, e.g. `/vi/SBOM`
13+
OriginResourceID string // optional, together with class it can be used to provide a link to the origin, e.g. `<id of react sbom object>`
14+
Timestamp time.Time // client will set timestamp if not set
15+
Title string // can also be seen as the 'type'
16+
Detail string
17+
Level Level
18+
CustomFields map[string]any // optional, can contain arbitrary structured information about the notification
1819
}
1920

2021
// notification is the object which is to the notification service.
2122
// It is defined in notification service REST API: https://github.com/greenbone/opensight-notification-service/tree/main/api/notificationservice
2223
type notificationModel struct {
2324
// omit property `Id` here, as it is read only
24-
Origin string `json:"origin"`
25-
OriginUri string `json:"originUri,omitempty"`
26-
Timestamp string `json:"timestamp" format:"date-time"`
27-
Title string `json:"title"`
28-
Detail string `json:"detail"`
29-
Level Level `json:"level"`
30-
CustomFields map[string]any `json:"customFields,omitempty"`
25+
Origin string `json:"origin"`
26+
OriginClass string `json:"originClass"`
27+
OriginResourceID string `json:"originResourceID,omitempty"`
28+
Timestamp string `json:"timestamp" format:"date-time"`
29+
Title string `json:"title"`
30+
Detail string `json:"detail"`
31+
Level Level `json:"level"`
32+
CustomFields map[string]any `json:"customFields,omitempty"`
3133
}
3234

3335
// Level describes the severity of the notification
@@ -47,12 +49,13 @@ func toNotificationModel(n Notification) notificationModel {
4749
}
4850

4951
return notificationModel{
50-
Origin: n.Origin,
51-
OriginUri: n.OriginUri,
52-
Timestamp: n.Timestamp.UTC().Format(time.RFC3339Nano),
53-
Title: n.Title,
54-
Detail: n.Detail,
55-
Level: n.Level,
56-
CustomFields: n.CustomFields,
52+
Origin: n.Origin,
53+
OriginClass: n.OriginClass,
54+
OriginResourceID: n.OriginResourceID,
55+
Timestamp: n.Timestamp.UTC().Format(time.RFC3339Nano),
56+
Title: n.Title,
57+
Detail: n.Detail,
58+
Level: n.Level,
59+
CustomFields: n.CustomFields,
5760
}
5861
}

pkg/notifications/notification_test.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,28 @@ const checkForCurrentTimestamp = "marker to check for current timestamp"
3030

3131
func TestClient_CreateNotification(t *testing.T) {
3232
notification := Notification{
33-
Origin: "Example Task XY",
34-
Timestamp: time.Date(1, 2, 3, 4, 5, 6, 7, time.UTC),
35-
Title: "Example Task XY failed",
36-
Detail: "Example Task XY failed because ...",
37-
Level: LevelError,
38-
CustomFields: map[string]any{"extraProperty": "value"},
33+
Origin: "Example Task XY - 1",
34+
OriginClass: "ab/exampletaskxy",
35+
OriginResourceID: "1",
36+
Timestamp: time.Date(1, 2, 3, 4, 5, 6, 7, time.UTC),
37+
Title: "Example Task XY failed",
38+
Detail: "Example Task XY failed because ...",
39+
Level: LevelError,
40+
CustomFields: map[string]any{"extraProperty": "value"},
3941
}
4042

4143
notificationWithoutTimestamp := notification
4244
notificationWithoutTimestamp.Timestamp = time.Time{}
4345

4446
wantNotification := notificationModel{
45-
Origin: "Example Task XY",
46-
Timestamp: "0001-02-03T04:05:06.000000007Z",
47-
Title: "Example Task XY failed",
48-
Detail: "Example Task XY failed because ...",
49-
Level: LevelError,
50-
CustomFields: map[string]any{"extraProperty": "value"},
47+
Origin: "Example Task XY - 1",
48+
OriginClass: "ab/exampletaskxy",
49+
OriginResourceID: "1",
50+
Timestamp: "0001-02-03T04:05:06.000000007Z",
51+
Title: "Example Task XY failed",
52+
Detail: "Example Task XY failed because ...",
53+
Level: LevelError,
54+
CustomFields: map[string]any{"extraProperty": "value"},
5155
}
5256
wantNotificationWithoutTimestamp := wantNotification
5357
wantNotificationWithoutTimestamp.Timestamp = checkForCurrentTimestamp // can't test exact timestamp

0 commit comments

Comments
 (0)