-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (38 loc) · 1.09 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
package main
import (
"net/http"
"github.com/drone/drone-go/plugin/secret"
"github.com/kelseyhightower/envconfig"
log "github.com/sirupsen/logrus"
"github.com/bitsbeats/drone-vault-reposecrets/internal/config"
"github.com/bitsbeats/drone-vault-reposecrets/pkg/plugin"
)
func main() {
logger := log.StandardLogger()
cfg := &config.Config{}
err := envconfig.Process("", cfg)
if err != nil {
logger.WithError(err).Fatalf("unable to parse environment")
}
if cfg.Debug {
logger.SetLevel(log.DebugLevel)
logger.Debugf("enabled debug log")
}
p, err := plugin.New(
plugin.WithLogger(logger),
plugin.WithSecretPath(cfg.VaultSecretPath),
plugin.WithVaultAddr(cfg.VaultAddr),
plugin.WithVaultRoleID(cfg.VaultRoleID),
plugin.WithVaultSecretID(cfg.VaultSecretID),
)
if err != nil {
logger.WithError(err).Fatalf("unable to load plugin")
}
handler := secret.Handler(cfg.Secret, p, logger)
http.Handle("/", handler)
log.WithField("addr", cfg.Listen).Infof("listening")
err = http.ListenAndServe(cfg.Listen, nil)
if err != nil {
logger.WithError(err).Fatalf("unable to listen")
}
}