Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 99 additions & 2 deletions api/notificationservice/notificationservice_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,40 @@ const docTemplatenotificationservice = `{
}
}
},
"/rules/ruleoptions": {
"get": {
"security": [
{
"KeycloakAuth": []
}
],
"description": "Returns all required options to create a new alert rule",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"rule"
],
"summary": "Options to create a new alert rule",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.RuleOptions"
},
"headers": {
"api-version": {
"type": "string",
"description": "API version"
}
}
}
}
}
},
"/rules/{id}": {
"put": {
"security": [
Expand Down Expand Up @@ -1672,12 +1706,16 @@ const docTemplatenotificationservice = `{
"readOnly": true
},
"level": {
"type": "string",
"enum": [
"info",
"warning",
"error",
"urgent"
],
"allOf": [
{
"$ref": "#/definitions/notifications.Level"
}
]
},
"origin": {
Expand Down Expand Up @@ -1777,6 +1815,50 @@ const docTemplatenotificationservice = `{
}
}
},
"models.RuleOptionChannel": {
"type": "object",
"required": [
"channelType"
],
"properties": {
"channelName": {
"type": "string"
},
"channelType": {
"$ref": "#/definitions/models.ChannelType"
},
"hasRecipient": {
"type": "boolean"
},
"id": {
"type": "string",
"readOnly": true
}
}
},
"models.RuleOptions": {
"type": "object",
"properties": {
"channels": {
"type": "array",
"items": {
"$ref": "#/definitions/models.RuleOptionChannel"
}
},
"levels": {
"type": "array",
"items": {
"$ref": "#/definitions/notifications.Level"
}
},
"origins": {
"type": "array",
"items": {
"$ref": "#/definitions/models.OriginReference"
}
}
}
},
"models.Trigger": {
"type": "object",
"required": [
Expand All @@ -1787,7 +1869,7 @@ const docTemplatenotificationservice = `{
"levels": {
"type": "array",
"items": {
"type": "string"
"$ref": "#/definitions/notifications.Level"
}
},
"origins": {
Expand All @@ -1804,6 +1886,21 @@ const docTemplatenotificationservice = `{
"type": "string"
}
},
"notifications.Level": {
"type": "string",
"enum": [
"info",
"warning",
"error",
"urgent"
],
"x-enum-varnames": [
"LevelInfo",
"LevelWarning",
"LevelError",
"LevelUrgent"
]
},
"paging.Request": {
"type": "object",
"properties": {
Expand Down
67 changes: 65 additions & 2 deletions api/notificationservice/notificationservice_swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,13 @@ definitions:
readOnly: true
type: string
level:
allOf:
- $ref: '#/definitions/notifications.Level'
enum:
- info
- warning
- error
- urgent
type: string
origin:
description: name of the origin, e.g. `SBOM - React`
type: string
Expand Down Expand Up @@ -351,11 +352,40 @@ definitions:
- name
- trigger
type: object
models.RuleOptionChannel:
properties:
channelName:
type: string
channelType:
$ref: '#/definitions/models.ChannelType'
hasRecipient:
type: boolean
id:
readOnly: true
type: string
required:
- channelType
type: object
models.RuleOptions:
properties:
channels:
items:
$ref: '#/definitions/models.RuleOptionChannel'
type: array
levels:
items:
$ref: '#/definitions/notifications.Level'
type: array
origins:
items:
$ref: '#/definitions/models.OriginReference'
type: array
type: object
models.Trigger:
properties:
levels:
items:
type: string
$ref: '#/definitions/notifications.Level'
type: array
origins:
items:
Expand All @@ -369,6 +399,18 @@ definitions:
additionalProperties:
type: string
type: object
notifications.Level:
enum:
- info
- warning
- error
- urgent
type: string
x-enum-varnames:
- LevelInfo
- LevelWarning
- LevelError
- LevelUrgent
paging.Request:
properties:
index:
Expand Down Expand Up @@ -1287,6 +1329,27 @@ paths:
summary: Update Rule
tags:
- rule
/rules/ruleoptions:
get:
consumes:
- application/json
description: Returns all required options to create a new alert rule
produces:
- application/json
responses:
"200":
description: OK
headers:
api-version:
description: API version
type: string
schema:
$ref: '#/definitions/models.RuleOptions'
security:
- KeycloakAuth: []
summary: Options to create a new alert rule
tags:
- rule
/rulse/{id}:
get:
description: Returns the rule
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/golang-migrate/migrate/v4 v4.19.1
github.com/google/uuid v1.6.0
github.com/greenbone/keycloak-client-golang v0.2.3
github.com/greenbone/opensight-golang-libraries v1.31.1
github.com/greenbone/opensight-golang-libraries v1.31.2-alpha1
github.com/jmoiron/sqlx v1.4.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/lib/pq v1.11.2
Expand Down Expand Up @@ -51,6 +51,8 @@ require (
github.com/go-resty/resty/v2 v2.17.2 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/goccy/go-yaml v1.19.2 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.8 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/jonboulle/clockwork v0.5.0 // indirect
Expand Down
12 changes: 10 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ github.com/docker/go-connections v0.6.0 h1:LlMG9azAe1TqfR7sO+NJttz1gy6KO7VJBh+pM
github.com/docker/go-connections v0.6.0/go.mod h1:AahvXYshr6JgfUJGdDCs2b5EZG/vmaMAntpSFH5BFKE=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/gabriel-vasile/mimetype v1.4.13 h1:46nXokslUBsAJE/wMsp5gtO500a4F3Nkz9Ufpk2AcUM=
Expand Down Expand Up @@ -114,8 +116,14 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/greenbone/keycloak-client-golang v0.2.3 h1:gtTTE844ub9iwOADwPJqbrF/edmEulO2sl2rBamSOSA=
github.com/greenbone/keycloak-client-golang v0.2.3/go.mod h1:Ws0Dc9j7g3OFupux3kHDTlTd+xelygEvvRa144/+Wf8=
github.com/greenbone/opensight-golang-libraries v1.31.1 h1:H2M7TMd2tvUFr4WFC0dYGBFrhZE/EuzygYzyiVIUFho=
github.com/greenbone/opensight-golang-libraries v1.31.1/go.mod h1:69rfVIgQmz8CFpkUIB/+qexwPNa0ENRCgq9OoTlQzbI=
github.com/greenbone/opensight-golang-libraries v1.31.2-alpha1 h1:WlsHC2o6xamHXXtxjQe4hBuvhdSS3RvLTpNeP2SSlw4=
github.com/greenbone/opensight-golang-libraries v1.31.2-alpha1/go.mod h1:S0Tf7VCSVstkIqqBiCV3+8DXyjDIUD0YfQ/PgDzXanY=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-retryablehttp v0.7.8 h1:ylXZWnqa7Lhqpk0L1P1LzDtGcCR0rPVUrx/c8Unxc48=
github.com/hashicorp/go-retryablehttp v0.7.8/go.mod h1:rjiScheydd+CxvumBsIrFKlx3iS0jrZ7LvzFGFmuKbw=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
Expand Down
7 changes: 7 additions & 0 deletions pkg/models/channelType.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ const (
ChannelTypeMattermost ChannelType = "mattermost"
ChannelTypeTeams ChannelType = "teams"
)

var AllowedChannels = []ChannelType{ChannelTypeMail, ChannelTypeMattermost, ChannelTypeTeams}

// HasRecipient returns true if the channel type requires/supports an explicit recipient.
func (ct ChannelType) HasRecipient() bool {
return ct == ChannelTypeMail
}
22 changes: 12 additions & 10 deletions pkg/models/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@

package models

import "github.com/greenbone/opensight-golang-libraries/pkg/notifications"

// Notification is sent by a backend service. It will always be stored by the
// notification service and it will possibly also trigger actions like sending mails,
// depending on the cofigured rules.
// depending on the configured rules.
type Notification struct {
Id string `json:"id" readonly:"true"`
Origin string `json:"origin" binding:"required"` // name of the origin, e.g. `SBOM - React`
OriginClass string `json:"originClass"` // unique identifier for the class of origins, e.g. `/vi/SBOM`, for now optional for backwards compatibility, will be required in future
OriginResourceID string `json:"originResourceID,omitempty"` // together with class it can be used to provide a link to the origin, e.g. `<id of react sbom object>`
Timestamp string `json:"timestamp" binding:"required" format:"date-time"`
Title string `json:"title" binding:"required"`
Detail string `json:"detail" binding:"required"`
Level string `json:"level" binding:"required" enums:"info,warning,error,urgent"`
CustomFields map[string]any `json:"customFields,omitempty"` // can contain arbitrary structured information about the event
Id string `json:"id" readonly:"true"`
Origin string `json:"origin" binding:"required"` // name of the origin, e.g. `SBOM - React`
OriginClass string `json:"originClass"` // unique identifier for the class of origins, e.g. `/vi/SBOM`, for now optional for backwards compatibility, will be required in future
OriginResourceID string `json:"originResourceID,omitempty"` // together with class it can be used to provide a link to the origin, e.g. `<id of react sbom object>`
Timestamp string `json:"timestamp" binding:"required" format:"date-time"`
Title string `json:"title" binding:"required"`
Detail string `json:"detail" binding:"required"`
Level notifications.Level `json:"level" binding:"required" enums:"info,warning,error,urgent"`
CustomFields map[string]any `json:"customFields,omitempty"` // can contain arbitrary structured information about the event
}
Loading
Loading