notifications

package
v1.35.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2026 License: GPL-3.0 Imports: 9 Imported by: 5

README

notifications

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

Package Notifications provides a client to communicate with the OpenSight Notification Service github.com/greenbone/opensight\-notification\-service

Index

Variables

var AllowedLevels = []Level{
    LevelInfo,
    LevelWarning,
    LevelError,
    LevelUrgent,
}

type AuthClient

type AuthClient interface {
    GetToken(ctx context.Context) (string, error)
}

type Client

Client can be used to send notifications

type Client struct {
    // contains filtered or unexported fields
}

func NewClient
func NewClient(httpClient *http.Client, config Config, authClient AuthClient) *Client

NewClient returns a new Client with the notification service address (host:port) set. As httpClient you can use e.g. [http.DefaultClient].

func (*Client) CreateNotification
func (c *Client) CreateNotification(ctx context.Context, notification Notification) error

CreateNotification sends a notification to the notification service. It is retried up to the configured number of retries with an exponential backoff, So it can take some time until the functions returns.

func (*Client) RegisterOrigins
func (c *Client) RegisterOrigins(ctx context.Context, serviceID string, origins []Origin) error

type Config

Config configures the notification service client

type Config struct {
    Address      string
    MaxRetries   int
    RetryWaitMin time.Duration
    RetryWaitMax time.Duration
}

type Level

Level describes the severity of the notification

type Level string

const (
    LevelInfo    Level = "info"
    LevelWarning Level = "warning"
    LevelError   Level = "error"
    LevelUrgent  Level = "urgent"
)

type Notification

type Notification struct {
    // omit property `Id` here, as it is read only
    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. `<id of react sbom object>`
    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
}

type Origin

type Origin struct {
    Name  string `json:"name"`
    Class string `json:"class"`
}

Generated by gomarkdoc

Documentation

Overview

Package Notifications provides a client to communicate with the OpenSight Notification Service github.com/greenbone/opensight-notification-service

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type AuthClient added in v1.32.0

type AuthClient interface {
	GetToken(ctx context.Context) (string, error)
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client can be used to send notifications

func NewClient

func NewClient(httpClient *http.Client, config Config, authClient AuthClient) *Client

NewClient returns a new Client with the notification service address (host:port) set. As httpClient you can use e.g. http.DefaultClient.

func (*Client) CreateNotification

func (c *Client) CreateNotification(ctx context.Context, notification Notification) error

CreateNotification sends a notification to the notification service. It is retried up to the configured number of retries with an exponential backoff, So it can take some time until the functions returns.

func (*Client) RegisterOrigins added in v1.27.0

func (c *Client) RegisterOrigins(ctx context.Context, serviceID string, origins []Origin) error

type Config

type Config struct {
	Address      string
	MaxRetries   int
	RetryWaitMin time.Duration
	RetryWaitMax time.Duration
}

Config configures the notification service client

type Level

type Level string

Level describes the severity of the notification

const (
	LevelInfo    Level = "info"
	LevelWarning Level = "warning"
	LevelError   Level = "error"
	LevelUrgent  Level = "urgent"
)

type Notification

type Notification struct {
	// omit property `Id` here, as it is read only
	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. `<id of react sbom object>`
	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
}

type Origin added in v1.27.0

type Origin struct {
	Name  string `json:"name"`
	Class string `json:"class"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL