notifications

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: MPL-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package notifications sends notifications for run state transitions and workspace events.

Index

Constants

View Source
const (
	DestinationGeneric   Destination = "generic"
	DestinationSlack     Destination = "slack"
	DestinationGCPPubSub Destination = "gcppubsub"
	// Email type is only accepted in order to pass the `go-tfe` API tests,
	// which create configs with this type. It otherwise is entirely
	// unfunctional; no emails are sent.
	DestinationEmail Destination = "email"

	TriggerCreated        Trigger = "run:created"
	TriggerPlanning       Trigger = "run:planning"
	TriggerNeedsAttention Trigger = "run:needs_attention"
	TriggerApplying       Trigger = "run:applying"
	TriggerCompleted      Trigger = "run:completed"
	TriggerErrored        Trigger = "run:errored"
)
View Source
const LockID int64 = 5577006791947779411

LockID guarantees only one notifier on a cluster is running at any time.

Variables

View Source
var (
	ErrInvalidGoogleProjectID    = errors.New("URL host must be a valid GCP project ID")
	ErrInvalidGooglePubSubTopic  = errors.New("URL path must be a valid GCP pubsub topic ID")
	ErrInvalidGooglePubSubScheme = errors.New("URL scheme must be: " + gcpPubSubScheme)
)
View Source
var (
	ErrUnsupportedDestination = errors.New("unsupported notification destination")
	ErrDestinationRequiresURL = errors.New("URL must be specified for this destination")
	ErrInvalidTrigger         = errors.New("invalid notification trigger")
)

Functions

func NewService

func NewService(opts Options) *service

Types

type Config

type Config struct {
	ID              string
	CreatedAt       time.Time
	UpdatedAt       time.Time
	DestinationType Destination
	Enabled         bool
	Name            string
	Token           string
	Triggers        []Trigger
	URL             *string
	WorkspaceID     string
}

Config represents a Notification Configuration.

func NewConfig

func NewConfig(workspaceID string, opts CreateConfigOptions) (*Config, error)

func (*Config) LogValue

func (c *Config) LogValue() slog.Value

type CreateConfigOptions

type CreateConfigOptions struct {
	// Required: The destination type of the notification configuration
	DestinationType Destination

	// Required: Whether the notification configuration should be enabled or not
	Enabled *bool

	// Required: The name of the notification configuration
	Name *string

	// Optional: The token of the notification configuration
	Token *string

	// Optional: The list of run events that will trigger notifications.
	Triggers []Trigger

	// Optional: The url of the notification configuration
	URL *string
}

type Destination

type Destination string

Destination is the destination platform for an event.

type GenericPayload

type GenericPayload struct {
	PayloadVersion              int
	NotificationConfigurationID string
	RunURL                      string
	RunID                       string
	RunMessage                  string
	RunCreatedAt                time.Time
	RunCreatedBy                string
	WorkspaceID                 string
	WorkspaceName               string
	OrganizationName            string
	Notifications               []genericNotificationPayload
}

GenericPayload is the information sent in generic notifications, as documented here:

https://developer.hashicorp.com/terraform/cloud-docs/api-docs/notification-configurations#run-notification-payload

type NotificationService

type NotificationService = Service

type Notifier

type Notifier struct {
	logr.Logger
	pubsub.Subscriber
	workspace.WorkspaceService // for retrieving workspace name
	internal.HostnameService   // for including a link in the notification
	// contains filtered or unexported fields
}

Notifier relays run events onto interested parties

func NewNotifier

func NewNotifier(opts NotifierOptions) *Notifier

func (*Notifier) Start

func (s *Notifier) Start(ctx context.Context) error

Start the notifier daemon. Should be started in a go-routine.

type NotifierOptions

type NotifierOptions struct {
	logr.Logger
	pubsub.Subscriber
	workspace.WorkspaceService // for retrieving workspace name
	internal.HostnameService   // for including a link in the notification
	*sql.DB
}

type Options

type Options struct {
	*sql.DB
	*pubsub.Broker
	logr.Logger
	WorkspaceAuthorizer internal.Authorizer
	workspace.WorkspaceService
	internal.HostnameService // for including a link in the notification
}

type Service

type Service interface {
	CreateNotificationConfiguration(ctx context.Context, workspaceID string, opts CreateConfigOptions) (*Config, error)
	UpdateNotificationConfiguration(ctx context.Context, id string, opts UpdateConfigOptions) (*Config, error)
	GetNotificationConfiguration(ctx context.Context, id string) (*Config, error)
	ListNotificationConfigurations(ctx context.Context, workspaceID string) ([]*Config, error)
	DeleteNotificationConfiguration(ctx context.Context, id string) error
}

type Trigger

type Trigger string

Trigger is the event triggering a notification

type UpdateConfigOptions

type UpdateConfigOptions struct {
	// Optional: Whether the notification configuration should be enabled or not
	Enabled *bool

	// Optional: The name of the notification configuration
	Name *string

	// Optional: The token of the notification configuration
	Token *string

	// Optional: The list of run events that will trigger notifications.
	Triggers []Trigger

	// Optional: The url of the notification configuration
	URL *string
}

UpdateConfigOptions represents the options for updating a existing notification configuration.

Jump to

Keyboard shortcuts

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