common

package
v0.0.0-...-5c79d48 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RecipientKindSchedule shows a recipient is a schedule.
	RecipientKindSchedule = "schedule"
)

Variables

This section is empty.

Functions

func GetTeleportClient

func GetTeleportClient(ctx context.Context, conf lib.TeleportConfig) (teleport.Client, error)

GetTeleportClient will return a Teleport plugin client given a config.

func StatusFromStatusCode

func StatusFromStatusCode(httpCode int) types.PluginStatus

Types

type App

type App interface {
	Init(baseApp *BaseApp) error
	Start(process *lib.Process)
	WaitReady(ctx context.Context) (bool, error)
	WaitForDone()
	Err() error
}

type BaseApp

type BaseApp struct {
	PluginName string
	APIClient  teleport.Client
	Conf       PluginConfiguration
	Bot        MessagingBot
	Clock      clockwork.Clock

	*lib.Process
	// contains filtered or unexported fields
}

BaseApp is responsible for handling the common features for a plugin. It will start a Teleport client, listen for events and treat them. It also handles signals and watches its thread. To instantiate a new BaseApp, use NewApp()

func NewApp

func NewApp(conf PluginConfiguration, pluginName string) *BaseApp

NewApp creates a new BaseApp and initialize its main job

func (*BaseApp) Err

func (a *BaseApp) Err() error

Err returns the error app finished with.

func (*BaseApp) Run

func (a *BaseApp) Run(ctx context.Context) error

Run initializes and runs a watcher and a callback server

func (*BaseApp) WaitReady

func (a *BaseApp) WaitReady(ctx context.Context) (bool, error)

WaitReady waits for http and watcher service to start up.

type BaseConfig

type BaseConfig struct {
	Teleport   lib.TeleportConfig `toml:"teleport"`
	Recipients RawRecipientsMap   `toml:"role_to_recipients"`
	Log        logger.Config      `toml:"log"`
	PluginType types.PluginType
}

func (BaseConfig) GetPluginType

func (c BaseConfig) GetPluginType() types.PluginType

GetPluginType returns the type of plugin this config is for.

func (BaseConfig) GetRecipients

func (c BaseConfig) GetRecipients() RawRecipientsMap

func (BaseConfig) GetTeleportClient

func (c BaseConfig) GetTeleportClient(ctx context.Context) (teleport.Client, error)

GetTeleportClient returns a Teleport plugin client for the given config.

type GenericAPIConfig

type GenericAPIConfig struct {
	Token string
	// DELETE IN 11.0.0 (Joerger) - use "role_to_recipients["*"]" instead
	Recipients []string
	APIURL     string
}

GenericAPIConfig holds common configuration use by a messaging service. MessagingBots requiring more custom configuration (MSTeams for example) can implement their own APIConfig instead.

type MessagingBot

type MessagingBot interface {
	// CheckHealth checks if the bot can connect to its messaging service
	CheckHealth(ctx context.Context) error
	// FetchRecipient fetches recipient data from the messaging service API. It can also be used to check and initialize
	// a communication channel (e.g. MsTeams needs to install the app for the user before being able to send
	// notifications)
	FetchRecipient(ctx context.Context, recipient string) (*Recipient, error)
	// SupportedApps are the apps supported by this bot.
	SupportedApps() []App
}

MessagingBot is a generic interface with all methods required to send notifications through a messaging service. A messaging bot contains an API client to send/edit messages and is able to resolve a Recipient from a string. Implementing this interface allows to leverage BaseApp logic without customization.

type PluginConfiguration

type PluginConfiguration interface {
	GetTeleportClient(ctx context.Context) (teleport.Client, error)
	GetRecipients() RawRecipientsMap
	NewBot(clusterName string, webProxyAddr string) (MessagingBot, error)
	GetPluginType() types.PluginType
}

type RawRecipientsMap

type RawRecipientsMap map[string][]string

RawRecipientsMap is a mapping of roles to recipient(s).

func (RawRecipientsMap) GetAllRawRecipients

func (r RawRecipientsMap) GetAllRawRecipients() []string

GetAllRawRecipients returns unique set of raw recipients

func (RawRecipientsMap) GetRawRecipientsFor

func (r RawRecipientsMap) GetRawRecipientsFor(roles, suggestedReviewers []string) []string

GetRawRecipientsFor will return the set of raw recipients given a list of roles and suggested reviewers. We create a unique list based on: - the list of suggestedReviewers - for each role, the list of reviewers - if the role doesn't exist in the map (or it's empty), we add the list of recipients for the default role ("*") instead

func (*RawRecipientsMap) UnmarshalTOML

func (r *RawRecipientsMap) UnmarshalTOML(in interface{}) error

UnmarshalTOML will convert the input into map[string][]string The input can be one of the following: "key" = "value" "key" = ["multiple", "values"]

type Recipient

type Recipient struct {
	// Name is the original string that was passed to create the recipient. This can be an id, email, channel name
	// URL, ... This is the user input (through suggested reviewers or plugin configuration)
	Name string
	// ID represents the recipient from the messaging service point of view.
	// e.g. if Name is a Slack user email address, ID will be the Slack user id.
	// This information should be sufficient to send a new message to a recipient.
	ID string
	// Kind is the recipient kind inferred from the Recipient Name. This is a messaging service concept, most common
	// values are "User" or "Channel".
	Kind string
	// Data allows MessagingBot to store required data for the recipient
	Data interface{}
}

Recipient is a generic representation of a message recipient. Its nature depends on the messaging service used. It can be a user, a public/private channel, or something else. A Recipient should contain enough information to identify uniquely where to send a message.

type RecipientSet

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

RecipientSet is a Set of Recipient. Recipient items are deduplicated based on Recipient.ID

func NewRecipientSet

func NewRecipientSet() RecipientSet

NewRecipientSet returns an initialized RecipientSet

func (*RecipientSet) Add

func (s *RecipientSet) Add(recipient Recipient)

Add adds an item to an existing RecipientSet. If an item with the same Recipient.ID already exists it is overridden.

func (*RecipientSet) Contains

func (s *RecipientSet) Contains(recipientID string) bool

Contains checks if the RecipientSet contains a Recipient for a given recipientID.

func (*RecipientSet) ToSlice

func (s *RecipientSet) ToSlice() []Recipient

ToSlice returns a Recipient slice from a RecipientSet. Items are copied but not deep-copied.

type StatusSink

type StatusSink interface {
	Emit(ctx context.Context, s types.PluginStatus) error
}

StatusSink defines a destination for PluginStatus

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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