Documentation
¶
Index ¶
- Constants
- type ApplyResult
- type Clients
- type Config
- type DefaultSlackClient
- type DriftHttpWebhook
- type DriftProjectResult
- type DriftResult
- type DriftSender
- type DriftSlackWebhook
- type DriftWebhookSender
- type HttpClient
- type HttpWebhook
- type MultiWebhookSender
- type Sender
- type SlackClient
- type SlackWebhook
- type UnderlyingSlackClient
Constants ¶
const ApplyEvent = "apply"
const DriftEvent = "drift"
const HttpKind = "http"
const SlackKind = "slack"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ApplyResult ¶
type ApplyResult struct {
Workspace string
Repo models.Repo
Pull models.PullRequest
User models.User
Success bool
Directory string
ProjectName string
}
ApplyResult is the result of a terraform apply.
type Clients ¶ added in v0.33.0
type Clients struct {
Slack SlackClient
Http *HttpClient
}
type DefaultSlackClient ¶
type DefaultSlackClient struct {
Slack UnderlyingSlackClient
Token string
}
func (*DefaultSlackClient) AuthTest ¶
func (d *DefaultSlackClient) AuthTest() error
func (*DefaultSlackClient) PostDriftMessage ¶ added in v0.45.0
func (d *DefaultSlackClient) PostDriftMessage(channel string, driftResult DriftResult) error
func (*DefaultSlackClient) PostMessage ¶
func (d *DefaultSlackClient) PostMessage(channel string, applyResult ApplyResult) error
func (*DefaultSlackClient) TokenIsSet ¶
func (d *DefaultSlackClient) TokenIsSet() bool
type DriftHttpWebhook ¶ added in v0.45.0
type DriftHttpWebhook struct {
Client *HttpClient
URL string
}
DriftHttpWebhook sends drift notifications to an HTTP endpoint.
func (*DriftHttpWebhook) Send ¶ added in v0.45.0
func (h *DriftHttpWebhook) Send(_ logging.SimpleLogging, result DriftResult) error
Send sends the drift result to the configured HTTP endpoint.
type DriftProjectResult ¶ added in v0.45.0
type DriftProjectResult struct {
ProjectName string `json:"project_name"`
Path string `json:"path"`
Workspace string `json:"workspace"`
HasDrift bool `json:"has_drift"`
ToAdd int `json:"to_add"`
ToChange int `json:"to_change"`
ToDestroy int `json:"to_destroy"`
ToImport int `json:"to_import"`
ToForget int `json:"to_forget"`
Summary string `json:"summary"`
Error string `json:"error,omitempty"`
}
DriftProjectResult describes drift for a single project.
type DriftResult ¶ added in v0.45.0
type DriftResult struct {
Repository string `json:"repository"`
Ref string `json:"ref"`
DetectionID string `json:"detection_id"`
ProjectsWithDrift int `json:"projects_with_drift"`
TotalProjects int `json:"total_projects"`
Projects []DriftProjectResult `json:"projects"`
}
DriftResult is the payload sent to drift webhooks.
type DriftSender ¶ added in v0.45.0
type DriftSender interface {
Send(log logging.SimpleLogging, result DriftResult) error
}
DriftSender sends drift webhooks.
type DriftSlackWebhook ¶ added in v0.45.0
type DriftSlackWebhook struct {
Client SlackClient
Channel string
}
DriftSlackWebhook sends drift notifications to Slack.
func (*DriftSlackWebhook) Send ¶ added in v0.45.0
func (s *DriftSlackWebhook) Send(_ logging.SimpleLogging, result DriftResult) error
Send sends the drift result to Slack.
type DriftWebhookSender ¶ added in v0.45.0
type DriftWebhookSender struct {
Webhooks []DriftSender
}
DriftWebhookSender distributes drift notifications to all configured senders.
func NewDriftWebhookSender ¶ added in v0.45.0
func NewDriftWebhookSender(configs []Config, clients Clients) (*DriftWebhookSender, error)
NewDriftWebhookSender creates a DriftWebhookSender from webhook configs. It filters configs to only those with event: drift and validates kind/channel/url. Returns a sender with no webhooks (no-op) if no drift configs are found.
func (*DriftWebhookSender) Send ¶ added in v0.45.0
func (d *DriftWebhookSender) Send(log logging.SimpleLogging, result DriftResult) error
Send sends drift results to all configured webhook senders. Errors are logged but not propagated (fire-and-forget).
type HttpClient ¶ added in v0.33.0
HttpClient wraps http.Client allowing to add arbitrary Headers to a request.
type HttpWebhook ¶ added in v0.33.0
type HttpWebhook struct {
Client *HttpClient
WorkspaceRegex *regexp.Regexp
BranchRegex *regexp.Regexp
URL string
}
HttpWebhook sends webhooks to any HTTP destination.
func (*HttpWebhook) Send ¶ added in v0.33.0
func (h *HttpWebhook) Send(_ logging.SimpleLogging, applyResult ApplyResult) error
Send sends the webhook to URL if workspace and branch matches their respective regex.
type MultiWebhookSender ¶
type MultiWebhookSender struct {
Webhooks []Sender
}
MultiWebhookSender sends multiple webhooks for each one it's configured for.
func NewMultiWebhookSender ¶
func NewMultiWebhookSender(configs []Config, clients Clients) (*MultiWebhookSender, error)
func (*MultiWebhookSender) Send ¶
func (w *MultiWebhookSender) Send(log logging.SimpleLogging, result ApplyResult) error
Send sends the webhook using its Webhooks.
type Sender ¶
type Sender interface {
// Send sends the webhook (if the implementation thinks it should).
Send(log logging.SimpleLogging, applyResult ApplyResult) error
}
Sender sends webhooks.
type SlackClient ¶
type SlackClient interface {
AuthTest() error
TokenIsSet() bool
PostMessage(channel string, applyResult ApplyResult) error
PostDriftMessage(channel string, driftResult DriftResult) error
}
SlackClient handles making API calls to Slack.
func NewSlackClient ¶
func NewSlackClient(token string) SlackClient
type SlackWebhook ¶
type SlackWebhook struct {
Client SlackClient
WorkspaceRegex *regexp.Regexp
BranchRegex *regexp.Regexp
Channel string
}
SlackWebhook sends webhooks to Slack.
func NewSlack ¶
func NewSlack(wr *regexp.Regexp, br *regexp.Regexp, channel string, client SlackClient) (*SlackWebhook, error)
func (*SlackWebhook) Send ¶
func (s *SlackWebhook) Send(_ logging.SimpleLogging, applyResult ApplyResult) error
Send sends the webhook to Slack if workspace and branch matches their respective regex.
type UnderlyingSlackClient ¶
type UnderlyingSlackClient interface {
AuthTest() (response *slack.AuthTestResponse, error error)
GetConversations(conversationParams *slack.GetConversationsParameters) (channels []slack.Channel, nextCursor string, err error)
PostMessage(channelID string, options ...slack.MsgOption) (string, string, error)
}
UnderlyingSlackClient wraps the nlopes/slack.Client implementation so we can mock it during tests.