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
135 changes: 129 additions & 6 deletions api/notificationservice/notificationservice_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ const docTemplatenotificationservice = `{
"KeycloakAuth": []
}
],
"description": "Create a new notification",
"description": "Create a new notification. It will always be stored by the notification service and it will possibly also trigger actions like sending mails, depending on the cofigured rules.",
"consumes": [
"application/json"
],
Expand Down Expand Up @@ -942,9 +942,105 @@ const docTemplatenotificationservice = `{
}
}
}
},
"/origins/{serviceID}": {
"put": {
"security": [
{
"KeycloakAuth": []
}
],
"description": "Registers a set of origins in the given service. Replaces origins of this service if they already existed. The origins can be ulitized to set trigger conditions for actions.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"origin"
],
"summary": "Register Origins",
"parameters": [
{
"type": "string",
"description": "serviceID of the calling service, needs to be unique among all services registering origins",
"name": "serviceID",
"in": "path",
"required": true
},
{
"description": "origins provided by the calling service",
"name": "origins",
"in": "body",
"required": true,
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Origin"
}
}
}
],
"responses": {
"204": {
"description": "origins registered",
"headers": {
"api-version": {
"type": "string",
"description": "API version"
}
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/errorResponses.ErrorResponse"
},
"headers": {
"api-version": {
"type": "string",
"description": "API version"
}
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/errorResponses.ErrorResponse"
},
"headers": {
"api-version": {
"type": "string",
"description": "API version"
}
}
}
}
}
}
},
"definitions": {
"errorResponses.ErrorResponse": {
"type": "object",
"properties": {
"details": {
"type": "string"
},
"errors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"title": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"filter.CompareOperator": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -1233,7 +1329,7 @@ const docTemplatenotificationservice = `{
],
"properties": {
"customFields": {
"description": "can contain arbitrary structured information about the notification",
"description": "can contain arbitrary structured information about the event",
"type": "object",
"additionalProperties": {}
},
Expand All @@ -1249,26 +1345,53 @@ const docTemplatenotificationservice = `{
"enum": [
"info",
"warning",
"error"
"error",
"urgent"
]
},
"origin": {
"description": "name of the origin, e.g. ` + "`" + `SBOM - React` + "`" + `",
"type": "string"
},
"originClass": {
"description": "unique identifier for the class of origins, e.g. ` + "`" + `/vi/SBOM` + "`" + `, for now optional for backwards compatibility, will be required in future",
"type": "string"
},
"originUri": {
"description": "can be used to provide a link to the origin",
"originResourceID": {
"description": "together with class it can be used to provide a link to the origin, e.g. ` + "`" + `\u003cid of react sbom object\u003e` + "`" + `",
"type": "string"
},
"timestamp": {
"type": "string",
"format": "date-time"
},
"title": {
"description": "can also be seen as the 'type'",
"type": "string"
}
}
},
"models.Origin": {
"type": "object",
"required": [
"class",
"name"
],
"properties": {
"class": {
"description": "unique identifier",
"type": "string"
},
"name": {
"description": "human readable name representation",
"type": "string"
},
"serviceID": {
"description": "service in which this origin is defined",
"type": "string",
"readOnly": true
}
}
},
"paging.Request": {
"type": "object",
"properties": {
Expand Down
99 changes: 94 additions & 5 deletions api/notificationservice/notificationservice_swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
basePath: /api/notification-service
definitions:
errorResponses.ErrorResponse:
properties:
details:
type: string
errors:
additionalProperties:
type: string
type: object
title:
type: string
type:
type: string
type: object
filter.CompareOperator:
enum:
- beginsWith
Expand Down Expand Up @@ -213,7 +226,7 @@ definitions:
properties:
customFields:
additionalProperties: {}
description: can contain arbitrary structured information about the notification
description: can contain arbitrary structured information about the event
type: object
detail:
type: string
Expand All @@ -225,17 +238,23 @@ definitions:
- info
- warning
- error
- urgent
type: string
origin:
description: name of the origin, e.g. `SBOM - React`
type: string
originUri:
description: can be used to provide a link to the origin
originClass:
description: unique identifier for the class of origins, e.g. `/vi/SBOM`,
for now optional for backwards compatibility, will be required in future
type: string
originResourceID:
description: together with class it can be used to provide a link to the origin,
e.g. `<id of react sbom object>`
type: string
timestamp:
format: date-time
type: string
title:
description: can also be seen as the 'type'
type: string
required:
- detail
Expand All @@ -244,6 +263,22 @@ definitions:
- timestamp
- title
type: object
models.Origin:
properties:
class:
description: unique identifier
type: string
name:
description: human readable name representation
type: string
serviceID:
description: service in which this origin is defined
readOnly: true
type: string
required:
- class
- name
type: object
paging.Request:
properties:
index:
Expand Down Expand Up @@ -899,7 +934,9 @@ paths:
post:
consumes:
- application/json
description: Create a new notification
description: Create a new notification. It will always be stored by the notification
service and it will possibly also trigger actions like sending mails, depending
on the cofigured rules.
parameters:
- description: notification to add
in: body
Expand Down Expand Up @@ -969,6 +1006,58 @@ paths:
summary: Notification filter options
tags:
- notification
/origins/{serviceID}:
put:
consumes:
- application/json
description: Registers a set of origins in the given service. Replaces origins
of this service if they already existed. The origins can be ulitized to set
trigger conditions for actions.
parameters:
- description: serviceID of the calling service, needs to be unique among all
services registering origins
in: path
name: serviceID
required: true
type: string
- description: origins provided by the calling service
in: body
name: origins
required: true
schema:
items:
$ref: '#/definitions/models.Origin'
type: array
produces:
- application/json
responses:
"204":
description: origins registered
headers:
api-version:
description: API version
type: string
"400":
description: Bad Request
headers:
api-version:
description: API version
type: string
schema:
$ref: '#/definitions/errorResponses.ErrorResponse'
"500":
description: Internal Server Error
headers:
api-version:
description: API version
type: string
schema:
$ref: '#/definitions/errorResponses.ErrorResponse'
security:
- KeycloakAuth: []
summary: Register Origins
tags:
- origin
securityDefinitions:
KeycloakAuth:
authorizationUrl: '{{.KeycloakAuthUrl}}/realms/{{.KeycloakRealm}}/protocol/openid-connect/auth'
Expand Down
9 changes: 9 additions & 0 deletions cmd/notification-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ import (
"github.com/greenbone/opensight-notification-service/pkg/config/secretfiles"
"github.com/greenbone/opensight-notification-service/pkg/repository"
"github.com/greenbone/opensight-notification-service/pkg/repository/notificationrepository"
"github.com/greenbone/opensight-notification-service/pkg/repository/originrepository"
"github.com/greenbone/opensight-notification-service/pkg/services/healthservice"
"github.com/greenbone/opensight-notification-service/pkg/services/notificationservice"
"github.com/greenbone/opensight-notification-service/pkg/services/originservice"
"github.com/greenbone/opensight-notification-service/pkg/web"
"github.com/greenbone/opensight-notification-service/pkg/web/healthcontroller"
"github.com/greenbone/opensight-notification-service/pkg/web/notificationcontroller"
"github.com/greenbone/opensight-notification-service/pkg/web/origincontroller"
)

func main() {
Expand Down Expand Up @@ -102,6 +105,10 @@ func run(config config.Config) error {
if err != nil {
return fmt.Errorf("error creating Notification Repository: %w", err)
}
originsRepository, err := originrepository.NewOriginRepository(pgClient)
if err != nil {
return err
}

// Encrypt
manager := security.NewEncryptManager()
Expand All @@ -121,6 +128,7 @@ func run(config config.Config) error {
notificationTransport := http.Client{Timeout: 15 * time.Second}
teamsChannelService := notificationchannelservice.NewTeamsChannelService(
notificationChannelService, config.ChannelLimit.TeamsLimit, notificationTransport)
originService := originservice.NewOriginService(originsRepository)
healthService := healthservice.NewHealthService(pgClient)

// scheduler
Expand Down Expand Up @@ -153,6 +161,7 @@ func run(config config.Config) error {
mailcontroller.AddCheckMailServerController(notificationServiceRouter, mailChannelService, authMiddleware, registry)
mattermostcontroller.NewMattermostController(notificationServiceRouter, notificationChannelService, mattermostChannelService, authMiddleware, registry)
teamsController.AddTeamsController(notificationServiceRouter, notificationChannelRepository, teamsChannelService, authMiddleware, registry)
origincontroller.NewOriginController(notificationServiceRouter, originService, authMiddleware)

// health router
rootRouter := router.Group("/")
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
ports:
- 8085:8085
networks:
- notification-service-net
- opensight-notification-net
depends_on:
postgres:
condition: service_healthy
Expand Down
11 changes: 11 additions & 0 deletions pkg/entities/origin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-FileCopyrightText: 2026 Greenbone AG <https://greenbone.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

package entities

type Origin struct {
Name string
Class string
ServiceID string // read-only
}
Loading
Loading