-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (48 loc) · 1.39 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
// Copyright 2019 the Drone Authors. All rights reserved.
// Use of this source code is governed by the Blue Oak Model License
// that can be found in the LICENSE file.
package main
import (
"net/http"
"github.com/drone/drone-go/plugin/secret"
"github.com/nuuday/drone-azure-key-vault/plugin"
_ "github.com/joho/godotenv/autoload"
"github.com/kelseyhightower/envconfig"
log "github.com/sirupsen/logrus"
)
// spec provides the plugin settings.
type Specification struct {
Bind string `envconfig:"DRONE_BIND"`
Debug bool `envconfig:"DRONE_DEBUG"`
Secret string `envconfig:"DRONE_SECRET"`
AzureClientID string `envconfig:"AZURE_CLIENT_ID" required:"true"`
AzureClientSecret string `envconfig:"AZURE_CLIENT_SECRET" required:"true"`
AzureTenantID string `envconfig:"AZURE_TENANT_ID" required:"true"`
AzureDebug bool `envconfig:"AZURE_DEBUG" default:"false"`
}
func main() {
spec := new(Specification)
err := envconfig.Process("", spec)
if err != nil {
log.Fatal(err)
}
if spec.Debug {
log.SetLevel(log.DebugLevel)
}
if spec.Secret == "" {
log.Fatalln("Missing secret key")
}
if spec.Bind == "" {
spec.Bind = ":3000"
}
handler := secret.Handler(
spec.Secret,
plugin.New(
spec.AzureDebug,
),
log.StandardLogger(),
)
log.Infof("server listening on address %s", spec.Bind)
http.Handle("/", handler)
log.Fatal(http.ListenAndServe(spec.Bind, nil))
}