notifications

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: MPL-2.0 Imports: 33 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

This section is empty.

Types

type Config

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

Config represents a Notification Configuration.

func NewConfig

func NewConfig(workspaceID resource.ID, 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 resource.ID
	RunURL                      string
	RunID                       resource.ID
	RunMessage                  string
	RunCreatedAt                time.Time
	RunCreatedBy                string
	WorkspaceID                 resource.ID
	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 Notifier

type Notifier struct {
	logr.Logger
	// 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 {
	RunClient          notifierRunClient
	WorkspaceClient    notifierWorkspaceClient
	NotificationClient notifierNotificationClient

	logr.Logger
	*internal.HostnameService
	*sql.DB
}

type Options

type Options struct {
	*sql.DB
	*sql.Listener
	*tfeapi.Responder
	logr.Logger

	Authorizer *authz.Authorizer
}

type Service

type Service struct {
	logr.Logger
	*authz.Authorizer
	// contains filtered or unexported fields
}

func NewService

func NewService(opts Options) *Service

func (*Service) AddHandlers added in v0.2.2

func (s *Service) AddHandlers(r *mux.Router)

func (*Service) Create added in v0.2.2

func (s *Service) Create(ctx context.Context, workspaceID resource.ID, opts CreateConfigOptions) (*Config, error)

func (*Service) Delete added in v0.2.2

func (s *Service) Delete(ctx context.Context, id resource.ID) error

func (*Service) Get added in v0.2.2

func (s *Service) Get(ctx context.Context, id resource.ID) (*Config, error)

func (*Service) List added in v0.2.2

func (s *Service) List(ctx context.Context, workspaceID resource.ID) ([]*Config, error)

func (*Service) Update added in v0.2.2

func (s *Service) Update(ctx context.Context, id resource.ID, opts UpdateConfigOptions) (*Config, error)

func (*Service) Watch added in v0.2.2

func (s *Service) Watch(ctx context.Context) (<-chan pubsub.Event[*Config], func())

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