Adding upstream version 0.8.9.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
3b2c48b5e4
commit
c0c4addb85
285 changed files with 25880 additions and 0 deletions
7
pkg/types/config_prop.go
Normal file
7
pkg/types/config_prop.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package types
|
||||
|
||||
// ConfigProp interface is used to de-/serialize structs from/to a string representation.
|
||||
type ConfigProp interface {
|
||||
SetFromProp(propValue string) error
|
||||
GetPropValue() (string, error)
|
||||
}
|
9
pkg/types/custom_url_config.go
Normal file
9
pkg/types/custom_url_config.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package types
|
||||
|
||||
import "net/url"
|
||||
|
||||
// CustomURLService is the interface that needs to be implemented to support custom URLs in services.
|
||||
type CustomURLService interface {
|
||||
Service
|
||||
GetConfigURLFromCustom(customURL *url.URL) (serviceURL *url.URL, err error)
|
||||
}
|
8
pkg/types/enum_formatter.go
Normal file
8
pkg/types/enum_formatter.go
Normal file
|
@ -0,0 +1,8 @@
|
|||
package types
|
||||
|
||||
// EnumFormatter translate enums between strings and numbers.
|
||||
type EnumFormatter interface {
|
||||
Print(e int) string
|
||||
Parse(s string) int
|
||||
Names() []string
|
||||
}
|
30
pkg/types/field.go
Normal file
30
pkg/types/field.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package types
|
||||
|
||||
import "sort"
|
||||
|
||||
// Field is a Key/Value pair used for extra data in log messages.
|
||||
type Field struct {
|
||||
Key string
|
||||
Value string
|
||||
}
|
||||
|
||||
// FieldsFromMap creates a Fields slice from a map, optionally sorting keys.
|
||||
func FieldsFromMap(fieldMap map[string]string, sorted bool) []Field {
|
||||
keys := make([]string, 0, len(fieldMap))
|
||||
fields := make([]Field, 0, len(fieldMap))
|
||||
|
||||
for key := range fieldMap {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
|
||||
if sorted {
|
||||
sort.Strings(keys)
|
||||
}
|
||||
|
||||
for i, key := range keys {
|
||||
fields[i].Key = key
|
||||
fields[i].Value = fieldMap[key]
|
||||
}
|
||||
|
||||
return fields
|
||||
}
|
6
pkg/types/generator.go
Normal file
6
pkg/types/generator.go
Normal file
|
@ -0,0 +1,6 @@
|
|||
package types
|
||||
|
||||
// Generator is the interface for tools that generate service configurations from a user dialog.
|
||||
type Generator interface {
|
||||
Generate(service Service, props map[string]string, args []string) (ServiceConfig, error)
|
||||
}
|
71
pkg/types/message_item.go
Normal file
71
pkg/types/message_item.go
Normal file
|
@ -0,0 +1,71 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
// Unknown is the default message level.
|
||||
Unknown MessageLevel = iota
|
||||
// Debug is the lowest kind of known message level.
|
||||
Debug
|
||||
// Info is generally used as the "normal" message level.
|
||||
Info
|
||||
// Warning is generally used to denote messages that might be OK, but can cause problems.
|
||||
Warning
|
||||
// Error is generally used for messages about things that did not go as planned.
|
||||
Error
|
||||
messageLevelCount
|
||||
// MessageLevelCount is used to create arrays that maps levels to other values.
|
||||
MessageLevelCount = int(messageLevelCount)
|
||||
)
|
||||
|
||||
var messageLevelStrings = [MessageLevelCount]string{
|
||||
"Unknown",
|
||||
"Debug",
|
||||
"Info",
|
||||
"Warning",
|
||||
"Error",
|
||||
}
|
||||
|
||||
// MessageLevel is used to denote the urgency of a message item.
|
||||
type MessageLevel uint8
|
||||
|
||||
// MessageItem is an entry in a notification being sent by a service.
|
||||
type MessageItem struct {
|
||||
Text string
|
||||
Timestamp time.Time
|
||||
Level MessageLevel
|
||||
Fields []Field
|
||||
}
|
||||
|
||||
func (level MessageLevel) String() string {
|
||||
if level >= messageLevelCount {
|
||||
return messageLevelStrings[0]
|
||||
}
|
||||
|
||||
return messageLevelStrings[level]
|
||||
}
|
||||
|
||||
// WithField appends the key/value pair to the message items fields.
|
||||
func (mi *MessageItem) WithField(key, value string) *MessageItem {
|
||||
mi.Fields = append(mi.Fields, Field{
|
||||
Key: key,
|
||||
Value: value,
|
||||
})
|
||||
|
||||
return mi
|
||||
}
|
||||
|
||||
// ItemsToPlain joins together the MessageItems' Text using newlines.
|
||||
// Used implement the rich sender API by redirecting to the plain sender implementation.
|
||||
func ItemsToPlain(items []MessageItem) string {
|
||||
builder := strings.Builder{}
|
||||
for _, item := range items {
|
||||
builder.WriteString(item.Text)
|
||||
builder.WriteRune('\n')
|
||||
}
|
||||
|
||||
return builder.String()
|
||||
}
|
10
pkg/types/message_limit.go
Normal file
10
pkg/types/message_limit.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package types
|
||||
|
||||
// MessageLimit is used for declaring the payload limits for services upstream APIs.
|
||||
type MessageLimit struct {
|
||||
ChunkSize int
|
||||
TotalChunkSize int
|
||||
|
||||
// Maximum number of chunks (including the last chunk for meta data)
|
||||
ChunkCount int
|
||||
}
|
28
pkg/types/params.go
Normal file
28
pkg/types/params.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package types
|
||||
|
||||
const (
|
||||
// TitleKey is the common key for the title prop.
|
||||
TitleKey = "title"
|
||||
// MessageKey is the common key for the message prop.
|
||||
MessageKey = "message"
|
||||
)
|
||||
|
||||
// Params is the string map used to provide additional variables to the service templates.
|
||||
type Params map[string]string
|
||||
|
||||
// SetTitle sets the "title" param to the specified value.
|
||||
func (p Params) SetTitle(title string) {
|
||||
p[TitleKey] = title
|
||||
}
|
||||
|
||||
// Title returns the "title" param.
|
||||
func (p Params) Title() (string, bool) {
|
||||
title, found := p[TitleKey]
|
||||
|
||||
return title, found
|
||||
}
|
||||
|
||||
// SetMessage sets the "message" param to the specified value.
|
||||
func (p Params) SetMessage(message string) {
|
||||
p[MessageKey] = message
|
||||
}
|
9
pkg/types/queued_sender.go
Normal file
9
pkg/types/queued_sender.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package types
|
||||
|
||||
// QueuedSender is the interface for a proxied sender that queues messages before sending.
|
||||
type QueuedSender interface {
|
||||
Enqueuef(format string, v ...any)
|
||||
Enqueue(message string)
|
||||
Flush(params *map[string]string)
|
||||
Service() Service
|
||||
}
|
6
pkg/types/rich_sender.go
Normal file
6
pkg/types/rich_sender.go
Normal file
|
@ -0,0 +1,6 @@
|
|||
package types
|
||||
|
||||
// RichSender is the interface needed to implement to send rich notifications.
|
||||
type RichSender interface {
|
||||
SendItems(items []MessageItem, params Params) error
|
||||
}
|
9
pkg/types/sender.go
Normal file
9
pkg/types/sender.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package types
|
||||
|
||||
// Sender is the interface needed to implement to send notifications.
|
||||
type Sender interface {
|
||||
Send(message string, params *Params) error
|
||||
|
||||
// Rich sender API:
|
||||
// SendItems(items []MessageItem, params *Params) error
|
||||
}
|
14
pkg/types/service.go
Normal file
14
pkg/types/service.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Service is the public common interface for all notification services.
|
||||
type Service interface {
|
||||
Sender
|
||||
Templater
|
||||
Initialize(serviceURL *url.URL, logger StdLogger) error
|
||||
SetLogger(logger StdLogger)
|
||||
GetID() string
|
||||
}
|
22
pkg/types/service_config.go
Normal file
22
pkg/types/service_config.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package types
|
||||
|
||||
import "net/url"
|
||||
|
||||
// Enummer contains fields that have associated EnumFormatter instances.
|
||||
type Enummer interface {
|
||||
Enums() map[string]EnumFormatter
|
||||
}
|
||||
|
||||
// ServiceConfig is the common interface for all types of service configurations.
|
||||
type ServiceConfig interface {
|
||||
Enummer
|
||||
GetURL() *url.URL
|
||||
SetURL(url *url.URL) error
|
||||
}
|
||||
|
||||
// ConfigQueryResolver is the interface used to get/set and list service config query fields.
|
||||
type ConfigQueryResolver interface {
|
||||
Get(key string) (value string, err error)
|
||||
Set(key string, value string) error
|
||||
QueryFields() []string
|
||||
}
|
10
pkg/types/service_opts.go
Normal file
10
pkg/types/service_opts.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package types
|
||||
|
||||
import "log"
|
||||
|
||||
// ServiceOpts is the interface describing the service options.
|
||||
type ServiceOpts interface {
|
||||
Verbose() bool
|
||||
Logger() *log.Logger
|
||||
Props() map[string]string
|
||||
}
|
8
pkg/types/std_logger.go
Normal file
8
pkg/types/std_logger.go
Normal file
|
@ -0,0 +1,8 @@
|
|||
package types
|
||||
|
||||
// StdLogger is an interface for outputting log information from services that are non-fatal.
|
||||
type StdLogger interface {
|
||||
Print(args ...any)
|
||||
Printf(format string, args ...any)
|
||||
Println(args ...any)
|
||||
}
|
12
pkg/types/templater.go
Normal file
12
pkg/types/templater.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"text/template"
|
||||
)
|
||||
|
||||
// Templater is the interface for the service template API.
|
||||
type Templater interface {
|
||||
GetTemplate(id string) (template *template.Template, found bool)
|
||||
SetTemplateString(id string, body string) error
|
||||
SetTemplateFile(id string, file string) error
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue