Documentation
¶
Overview ¶
Package notifications sends notifications for run state transitions and workspace events.
Index ¶
- Constants
- Variables
- type Config
- type CreateConfigOptions
- type Destination
- type Event
- type GenericPayload
- type Notifier
- type NotifierOptions
- type Options
- type Service
- func (s *Service) AddHandlers(r *mux.Router)
- func (s *Service) Create(ctx context.Context, workspaceID resource.TfeID, opts CreateConfigOptions) (*Config, error)
- func (s *Service) Delete(ctx context.Context, id resource.TfeID) error
- func (s *Service) Get(ctx context.Context, id resource.TfeID) (*Config, error)
- func (s *Service) List(ctx context.Context, workspaceID resource.TfeID) ([]*Config, error)
- func (s *Service) Update(ctx context.Context, id resource.TfeID, opts UpdateConfigOptions) (*Config, error)
- func (s *Service) Watch(ctx context.Context) (<-chan pubsub.Event[*Config], func())
- type TFEDeliveryResponse
- type TFENotificationConfiguration
- type TFENotificationConfigurationCreateOptions
- type TFENotificationConfigurationList
- type TFENotificationConfigurationUpdateOptions
- type TFENotificationDestinationType
- type TFENotificationTriggerType
- type Trigger
- type UpdateConfigOptions
Constants ¶
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" )
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
ID resource.TfeID `json:"notification_configuration_id" db:"notification_configuration_id"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
DestinationType Destination `json:"destination_type" db:"destination_type"`
Enabled bool
Name string
Triggers []Trigger
URL *string
WorkspaceID resource.TfeID `json:"workspace_id" db:"workspace_id"`
}
Config represents a Notification Configuration.
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 GenericPayload ¶
type GenericPayload struct {
PayloadVersion int
NotificationConfigurationID resource.TfeID
RunURL string
RunID resource.TfeID
RunMessage string
RunCreatedAt time.Time
RunCreatedBy string
WorkspaceID resource.TfeID
WorkspaceName string
OrganizationName organization.Name
Notifications []genericNotificationPayload
}
GenericPayload is the information sent in generic notifications, as documented here:
type Notifier ¶
Notifier relays run events onto interested parties
func NewNotifier ¶
func NewNotifier(opts NotifierOptions) *Notifier
type NotifierOptions ¶
type Service ¶
type Service struct {
logr.Logger
*authz.Authorizer
// contains filtered or unexported fields
}
func NewService ¶
func (*Service) AddHandlers ¶ added in v0.2.2
type TFEDeliveryResponse ¶ added in v0.3.17
type TFEDeliveryResponse struct {
Body string `jsonapi:"attribute" json:"body"`
Code string `jsonapi:"attribute" json:"code"`
Headers map[string][]string `jsonapi:"attribute" json:"headers"`
SentAt time.Time `jsonapi:"attribute" json:"sent-at"`
Successful string `jsonapi:"attribute" json:"successful"`
URL string `jsonapi:"attribute" json:"url"`
}
TFEDeliveryResponse represents a notification configuration delivery response.
type TFENotificationConfiguration ¶ added in v0.3.17
type TFENotificationConfiguration struct {
ID resource.TfeID `jsonapi:"primary,notification-configurations"`
CreatedAt time.Time `jsonapi:"attribute" json:"created-at"`
DeliveryResponses []*TFEDeliveryResponse `jsonapi:"attribute" json:"delivery-responses"`
DestinationType TFENotificationDestinationType `jsonapi:"attribute" json:"destination-type"`
Enabled bool `jsonapi:"attribute" json:"enabled"`
Name string `jsonapi:"attribute" json:"name"`
Token string `jsonapi:"attribute" json:"token"`
Triggers []string `jsonapi:"attribute" json:"triggers"`
UpdatedAt time.Time `jsonapi:"attribute" json:"updated-at"`
URL string `jsonapi:"attribute" json:"url"`
// EmailAddresses is only available for TFE users. It is not available in TFC.
EmailAddresses []string `jsonapi:"attribute" json:"email-addresses"`
// relationships
Subscribable *workspace.TFEWorkspace `jsonapi:"relationship" json:"subscribable"`
EmailUsers []*user.TFEUser `jsonapi:"relationship" json:"users"`
}
TFENotificationConfiguration represents a Notification Configuration.
type TFENotificationConfigurationCreateOptions ¶ added in v0.3.17
type TFENotificationConfigurationCreateOptions struct {
// Type is a public field utilized by JSON:API to
// set the resource type via the field tag.
// It is not a user-defined value and does not need to be set.
// https://jsonapi.org/format/#crud-creating
Type string `jsonapi:"primary,notification-configurations"`
// Required: The destination type of the notification configuration
DestinationType *TFENotificationDestinationType `jsonapi:"attribute" json:"destination-type"`
// Required: Whether the notification configuration should be enabled or not
Enabled *bool `jsonapi:"attribute" json:"enabled"`
// Required: The name of the notification configuration
Name *string `jsonapi:"attribute" json:"name"`
// Optional: The token of the notification configuration
Token *string `jsonapi:"attribute" json:"token,omitempty"`
// Optional: The list of run events that will trigger notifications.
Triggers []TFENotificationTriggerType `jsonapi:"attribute" json:"triggers,omitempty"`
// Optional: The url of the notification configuration
URL *string `jsonapi:"attribute" json:"url,omitempty"`
// Optional: The list of email addresses that will receive notification emails.
// EmailAddresses is only available for TFE users. It is not available in TFC.
EmailAddresses []string `jsonapi:"attribute" json:"email-addresses,omitempty"`
// Optional: The list of users belonging to the organization that will receive notification emails.
EmailUsers []*user.TFEUser `jsonapi:"relationship" json:"users,omitempty"`
}
TFENotificationConfigurationCreateOptions represents the options for creating a new notification configuration.
type TFENotificationConfigurationList ¶ added in v0.3.17
type TFENotificationConfigurationList struct {
*types.Pagination
Items []*TFENotificationConfiguration
}
TFENotificationConfigurationList represents a list of Notification Configurations.
type TFENotificationConfigurationUpdateOptions ¶ added in v0.3.17
type TFENotificationConfigurationUpdateOptions struct {
// Type is a public field utilized by JSON:API to
// set the resource type via the field tag.
// It is not a user-defined value and does not need to be set.
// https://jsonapi.org/format/#crud-creating
Type string `jsonapi:"primary,notification-configurations"`
// Optional: Whether the notification configuration should be enabled or not
Enabled *bool `jsonapi:"attribute" json:"enabled,omitempty"`
// Optional: The name of the notification configuration
Name *string `jsonapi:"attribute" json:"name,omitempty"`
// Optional: The token of the notification configuration
Token *string `jsonapi:"attribute" json:"token,omitempty"`
// Optional: The list of run events that will trigger notifications.
Triggers []TFENotificationTriggerType `jsonapi:"attribute" json:"triggers,omitempty"`
// Optional: The url of the notification configuration
URL *string `jsonapi:"attribute" json:"url,omitempty"`
// Optional: The list of email addresses that will receive notification emails.
// EmailAddresses is only available for TFE users. It is not available in TFC.
EmailAddresses []string `jsonapi:"attribute" json:"email-addresses,omitempty"`
// Optional: The list of users belonging to the organization that will receive notification emails.
EmailUsers []*user.TFEUser `jsonapi:"relationship" json:"users,omitempty"`
}
TFENotificationConfigurationUpdateOptions represents the options for updating a existing notification configuration.
type TFENotificationDestinationType ¶ added in v0.3.17
type TFENotificationDestinationType string
TFENotificationDestinationType represents the destination type of the notification configuration.
const ( NotificationDestinationTypeEmail TFENotificationDestinationType = "email" NotificationDestinationTypeGeneric TFENotificationDestinationType = "generic" NotificationDestinationTypeSlack TFENotificationDestinationType = "slack" NotificationDestinationTypeMicrosoftTeams TFENotificationDestinationType = "microsoft-teams" )
List of available notification destination types.
type TFENotificationTriggerType ¶ added in v0.3.17
type TFENotificationTriggerType string
TFENotificationTriggerType represents the different TFE notifications that can be sent as a run's progress transitions between different states
const ( NotificationTriggerCreated TFENotificationTriggerType = "run:created" NotificationTriggerPlanning TFENotificationTriggerType = "run:planning" NotificationTriggerNeedsAttention TFENotificationTriggerType = "run:needs_attention" NotificationTriggerApplying TFENotificationTriggerType = "run:applying" NotificationTriggerCompleted TFENotificationTriggerType = "run:completed" NotificationTriggerErrored TFENotificationTriggerType = "run:errored" NotificationTriggerAssessmentDrifted TFENotificationTriggerType = "assessment:drifted" NotificationTriggerAssessmentFailed TFENotificationTriggerType = "assessment:failed" NotificationTriggerAssessmentCheckFailed TFENotificationTriggerType = "assessment:check_failure" )
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.