-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
69 lines (59 loc) · 2.14 KB
/
main.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
68
69
package main
import (
"context"
"fmt"
"math/rand"
"os"
"time"
"helm-rollback-web/internal/webserver"
logger "github.com/apsdehal/go-logger"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)
var log *logger.Logger
var buildDate string
func main() {
tracer.Start()
defer tracer.Stop()
err := error(nil)
log, err = logger.New("hrw-webserver", 1, os.Stderr)
if err != nil {
panic(err) // Check for error
}
log.Infof("Starting helm-rollback-web server build %s", buildDate)
rand.Seed(time.Now().UnixNano())
port := "8080"
// Auth / OpenID Connect configuration
oidcIssuer := os.Getenv("HELM_ROLLBACK_WEB_OIDC_ISSUER")
if oidcIssuer == "" {
log.Warning("Tip: To use Google Accounts, set the issuer value 'https://accounts.google.com'")
log.Fatal("Missing required env var HELM_ROLLBACK_WEB_OIDC_ISSUER")
}
clientId := os.Getenv("HELM_ROLLBACK_WEB_OIDC_CLIENT_ID")
if clientId == "" {
log.Fatal("Missing required env var HELM_ROLLBACK_WEB_OIDC_CLIENT_ID")
}
clientSecret := os.Getenv("HELM_ROLLBACK_WEB_OIDC_CLIENT_SECRET")
if clientSecret == "" {
log.Fatal("Missing required env var HELM_ROLLBACK_WEB_OIDC_CLIENT_SECRET")
}
callbackURL := os.Getenv("HELM_ROLLBACK_WEB_CALLBACK_URL")
if callbackURL == "" {
callbackURL = fmt.Sprintf("http://localhost:%s/callback-gl", port)
log.Warningf("Missing env var HELM_ROLLBACK_WEB_CALLBACK_URL. Assuming `%s` - This only works locally!", callbackURL)
}
// This function fetches the configuration from the issuer
if err := webserver.ConfigureOidc(context.Background(), oidcIssuer, clientId, clientSecret, callbackURL); err != nil {
log.Fatalf("OpenID Connect auto-configuration failed: %s", err.Error())
}
if os.Getenv("SLACK_APP_HELM_OAUTH_TOKEN") == "" {
log.Fatal("Missing required env var SLACK_APP_HELM_OAUTH_TOKEN")
}
if os.Getenv("HELM_ROLLBACK_WEB_NOTIFICATION_CHANNEL") == "" {
log.Fatal("Missing required env var HELM_ROLLBACK_WEB_NOTIFICATION_CHANNEL")
}
if os.Getenv("HELM_ROLLBACK_WEB_HELM_COMMAND") == "" {
log.Info("Missing required env var HELM_ROLLBACK_WEB_HELM_COMMAND assuming `helm`")
}
log.Infof("Starting webserver on port %s", port)
webserver.HandleHTTP(port)
}