76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
// 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"
|
|
"time"
|
|
|
|
"git.entr0py.de/garionion/drone-yaml-server/plugin"
|
|
"github.com/drone/drone-go/plugin/config"
|
|
|
|
_ "github.com/joho/godotenv/autoload"
|
|
"github.com/kelseyhightower/envconfig"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// spec provides the plugin settings.
|
|
type spec struct {
|
|
Bind string `envconfig:"DRONE_BIND"`
|
|
Debug bool `envconfig:"DRONE_DEBUG"`
|
|
Secret string `envconfig:"DRONE_SECRET"`
|
|
|
|
Repo string `envconfig:"DRONE_YAML_REPO"`
|
|
Branch string `envconfig:"DRONE_BRANCH"`
|
|
Token string `envconfig:"DRONE_TOKEN"`
|
|
FetchFrequency time.Duration `envconfig:"DRONE_FETCH_FREQUENCY"`
|
|
}
|
|
|
|
func main() {
|
|
spec := new(spec)
|
|
err := envconfig.Process("", spec)
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
if spec.Debug {
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
}
|
|
if spec.Secret == "" {
|
|
logrus.Fatalln("missing secret key")
|
|
}
|
|
if spec.Bind == "" {
|
|
spec.Bind = ":3000"
|
|
}
|
|
|
|
if spec.Repo == "" {
|
|
logrus.Fatalln("missing repo")
|
|
}
|
|
|
|
if spec.Branch == "" {
|
|
spec.Branch = "main"
|
|
}
|
|
|
|
if spec.FetchFrequency == 0 {
|
|
spec.FetchFrequency = 10 * time.Minute
|
|
}
|
|
|
|
handler := config.Handler(
|
|
plugin.New(
|
|
spec.Repo,
|
|
spec.Branch,
|
|
spec.Token,
|
|
spec.FetchFrequency,
|
|
),
|
|
spec.Secret,
|
|
logrus.StandardLogger(),
|
|
)
|
|
|
|
logrus.Infof("server listening on address %s", spec.Bind)
|
|
|
|
http.Handle("/", handler)
|
|
logrus.Fatal(http.ListenAndServe(spec.Bind, nil))
|
|
}
|