-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeputize.go
67 lines (53 loc) · 1.5 KB
/
deputize.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// deputize.go - main function
// Copyright 2024 F5 Inc.
// Licensed under the BSD 3-clause license; see LICENSE.md for more information.
package main
import (
"context"
"log"
"strings"
"github.com/aws/aws-lambda-go/lambda"
)
func main() {
lambda.Start(runLambda)
}
func runLambda(ctx context.Context, cfg *deputizeConfig) (string, error) {
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
err := validateConfig(cfg)
if err != nil {
return "", err
}
sec, err := buildSecrets(cfg)
if err != nil {
return "", err
}
oncallEmails, err := getPagerdutyInfo(ctx, cfg.Source.PagerDuty.WithOAuth, sec.PDAuthToken, cfg.Source.PagerDuty.OnCallSchedules)
if err != nil {
return "", err
}
log.Printf("Current On-Call Users: %s\n", strings.Join(oncallEmails, ", "))
if cfg.Sinks.LDAP.Enabled {
err := updateLDAP(cfg.Sinks.LDAP, oncallEmails, sec.LDAPModUserPassword)
if err != nil {
return "", err
}
}
if cfg.Sinks.Gitlab.Enabled {
gitlabApprovers, err := getPagerdutyInfo(ctx, cfg.Source.PagerDuty.WithOAuth, sec.PDAuthToken, []string{cfg.Sinks.Gitlab.ApproverSchedule})
if err != nil {
return "", err
}
log.Printf("Gitlab Approvers: %s\n", strings.Join(gitlabApprovers, ", "))
err = updateGitlab(cfg.Sinks.Gitlab, gitlabApprovers, sec.GitlabAuthToken)
if err != nil {
return "", err
}
}
if cfg.Sinks.Slack.Enabled {
err := updateSlack(cfg.Sinks.Slack, oncallEmails, sec.SlackAuthToken)
if err != nil {
return "", err
}
}
return strings.Join(oncallEmails, ", "), nil
}