63 lines
1.4 KiB
Go
63 lines
1.4 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"
|
||
|
|
||
|
"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"`
|
||
|
|
||
|
// TODO replace or remove these configuration
|
||
|
// parameters. They are for demo purposes only.
|
||
|
Param1 string `envconfig:"DRONE_PARAM_1"`
|
||
|
Param2 string `envconfig:"DRONE_PARAM_2"`
|
||
|
}
|
||
|
|
||
|
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"
|
||
|
}
|
||
|
|
||
|
handler := config.Handler(
|
||
|
plugin.New(
|
||
|
// TODO replace or remove these configuration
|
||
|
// parameters. They are for demo purposes only.
|
||
|
spec.Param1,
|
||
|
spec.Param2,
|
||
|
),
|
||
|
spec.Secret,
|
||
|
logrus.StandardLogger(),
|
||
|
)
|
||
|
|
||
|
logrus.Infof("server listening on address %s", spec.Bind)
|
||
|
|
||
|
http.Handle("/", handler)
|
||
|
logrus.Fatal(http.ListenAndServe(spec.Bind, nil))
|
||
|
}
|