removed old, unused config package

This commit is contained in:
Brad Rydzewski 2015-09-08 18:55:03 -07:00
parent 2223e1d934
commit af82f7aa2c
7 changed files with 13 additions and 222 deletions

View file

@ -9,7 +9,6 @@ import (
"github.com/drone/drone/Godeps/_workspace/src/github.com/gin-gonic/gin"
"github.com/drone/drone/Godeps/_workspace/src/github.com/elazarl/go-bindata-assetfs"
"github.com/drone/drone/pkg/config"
"github.com/drone/drone/pkg/remote"
"github.com/drone/drone/pkg/server"
"github.com/drone/drone/pkg/server/session"
@ -89,12 +88,6 @@ func main() {
flag.String("config", "", "")
flag.Parse()
settings, err := config.Load()
if err != nil {
panic(err)
}
settings.Plugins = []string{conf.plugin.filter} // todo hack
store, err := store.New(conf.database.driver, conf.database.config)
if err != nil {
panic(err)
@ -123,7 +116,6 @@ func main() {
api.Use(server.SetDatastore(store))
api.Use(server.SetRemote(remote))
api.Use(server.SetQueue(queue_))
api.Use(server.SetSettings(settings))
api.Use(server.SetSession(session))
api.Use(server.SetUser(session))
api.Use(server.SetRunner(&runner_))
@ -207,7 +199,6 @@ func main() {
auth.Use(server.SetHeaders())
auth.Use(server.SetDatastore(store))
auth.Use(server.SetRemote(remote))
auth.Use(server.SetSettings(settings))
auth.Use(server.SetSession(session))
auth.GET("", server.GetLogin)
auth.POST("", server.GetLogin)

View file

@ -1,144 +0,0 @@
package config
import (
"fmt"
"os"
"path"
"strings"
log "github.com/drone/drone/Godeps/_workspace/src/github.com/Sirupsen/logrus"
"github.com/drone/drone/Godeps/_workspace/src/github.com/vrischmann/envconfig"
)
type Config struct {
Remote struct {
Driver string `envconfig:"optional"`
}
Auth struct {
Client string `envconfig:"optional"`
Secret string `envconfig:"optional"`
Authorize string `envconfig:"optional"`
AccessToken string `envconfig:"optional"`
RequestToken string `envconfig:"optional"`
Scope []string `envconfig:"optional"`
}
Server struct {
Base string `envconfig:"optional"`
Addr string `envconfig:"optional"`
Cert string `envconfig:"optional"`
Key string `envconfig:"optional"`
Scheme string `envconfig:"optional"`
Hostname string `envconfig:"optional"`
}
Session struct {
Secret string `envconfig:"optional"`
Expires int64 `envconfig:"optional"`
}
Agents struct {
Secret string `envconfig:"optional"`
}
Database struct {
Driver string `envconfig:"optional"`
Datasource string `envconfig:"optional"`
}
Docker struct {
Cert string `envconfig:"optional"`
Key string `envconfig:"optional"`
Addr string `envconfig:"optional"`
Swarm bool `envconfig:"optional"`
}
// Environment represents a set of global environment
// variable declarations that can be injected into
// build plugins. An example use case might be SMTP
// configuration.
Environment []string `envconfig:"optional"`
// Plugins represents a white-list of plugins
// that the system is authorized to load.
Plugins []string `envconfig:"optional"`
Github struct {
API string `envconfig:"optional"`
Host string `envconfig:"optional"`
Client string `envconfig:"optional"`
Secret string `envconfig:"optional"`
PrivateMode bool `envconfig:"optional"`
SkipVerify bool `envconfig:"optional"`
Open bool `envconfig:"optional"`
Orgs []string `envconfig:"optional"`
}
Bitbucket struct {
Client string `envconfig:"optional"`
Secret string `envconfig:"optional"`
Open bool `envconfig:"optional"`
Orgs []string `envconfig:"optional"`
}
Gitlab struct {
Host string `envconfig:"optional"`
Client string `envconfig:"optional"`
Secret string `envconfig:"optional"`
SkipVerify bool `envconfig:"optional"`
Open bool `envconfig:"optional"`
Orgs []string `envconfig:"optional"`
Search bool `envconfig:"optional"`
}
}
// Load loads the configuration from environment
// variables.
func Load() (*Config, error) {
conf := &Config{}
err := envconfig.Init(conf)
if err != nil {
return nil, err
}
return applyDefaults(conf), nil
}
func applyDefaults(c *Config) *Config {
// if no session token is provided we can
// instead use the client secret to sign
// our sessions and tokens.
if len(c.Session.Secret) == 0 {
c.Session.Secret = c.Auth.Secret
}
// Prevent crash on start, use sqlite3
// driver as default if DRONE_DATABASE_DRIVER and
// DRONE_DATABASE_DATASOURCE not specifed
if len(c.Database.Driver) == 0 && len(c.Database.Datasource) == 0 {
c.Database.Driver = "sqlite3"
pwd, err := os.Getwd()
if err != nil {
panic(err)
}
c.Database.Datasource = path.Join(pwd, "drone.sqlite3")
log.Warnf("Use default database settings, driver: %q, config: %q", c.Database.Driver, c.Database.Datasource)
}
// Set default settings for remotes
switch strings.ToLower(c.Remote.Driver) {
case "github":
if len(c.Github.API) == 0 && len(c.Github.Host) == 0 {
c.Github.API = "https://api.github.com/"
c.Github.Host = "https://github.com"
log.Warnf("Use default github settings, host: %q, api: %q", c.Github.Host, c.Github.API)
} else if len(c.Github.API) == 0 && len(c.Github.Host) != 0 {
c.Github.API = fmt.Sprintf("%s/api/v3/", c.Github.Host)
log.Warnf("Github API not specified, use: %q", c.Github.API)
}
}
return c
}

View file

@ -3,7 +3,9 @@ package server
import (
"fmt"
"io"
"os"
"strconv"
"strings"
"time"
"github.com/drone/drone/Godeps/_workspace/src/github.com/gin-gonic/gin"
@ -118,7 +120,6 @@ func RunBuild(c *gin.Context) {
store := ToDatastore(c)
queue_ := ToQueue(c)
repo := ToRepo(c)
conf := ToSettings(c)
num, err := strconv.Atoi(c.Params.ByName("number"))
if err != nil {
@ -189,8 +190,8 @@ func RunBuild(c *gin.Context) {
Secret: sec,
System: &common.System{
Link: httputil.GetURL(c.Request),
Plugins: conf.Plugins,
Globals: conf.Environment,
Plugins: strings.Split(os.Getenv("PLUGIN_FILTER"), " "),
Globals: strings.Split(os.Getenv("PLUGIN_PARAMS"), " "),
},
})
}

View file

@ -1,6 +1,7 @@
package server
import (
"os"
"strings"
log "github.com/drone/drone/Godeps/_workspace/src/github.com/Sirupsen/logrus"
@ -22,7 +23,6 @@ func PostHook(c *gin.Context) {
remote := ToRemote(c)
store := ToDatastore(c)
queue_ := ToQueue(c)
conf := ToSettings(c)
hook, err := remote.Hook(c.Request)
if err != nil {
@ -155,8 +155,8 @@ func PostHook(c *gin.Context) {
Secret: sec,
System: &common.System{
Link: httputil.GetURL(c.Request),
Plugins: conf.Plugins,
Globals: conf.Environment,
Plugins: strings.Split(os.Getenv("PLUGIN_FILTER"), " "),
Globals: strings.Split(os.Getenv("PLUGIN_PARAMS"), " "),
},
})
}

View file

@ -17,7 +17,6 @@ import (
// GET /authorize
//
func GetLogin(c *gin.Context) {
settings := ToSettings(c)
session := ToSession(c)
remote := ToRemote(c)
store := ToDatastore(c)
@ -27,18 +26,8 @@ func GetLogin(c *gin.Context) {
// rememver why, so need to revisit this line.
c.Writer.Header().Del("Content-Type")
// depending on the configuration a user may
// authenticate with OAuth1, OAuth2 or Basic
// Auth (username and password). This will delegate
// authorization accordingly.
switch {
// case settings.Auth == nil:
// getLoginBasic(c)
case settings.Auth.RequestToken != "":
getLoginOauth1(c)
default:
getLoginOauth2(c)
}
// TODO: move this back to the remote section
getLoginOauth2(c)
// exit if authorization fails
if c.Writer.Status() != 200 {

View file

@ -7,7 +7,6 @@ import (
"github.com/drone/drone/Godeps/_workspace/src/github.com/gin-gonic/gin"
"github.com/drone/drone/pkg/bus"
"github.com/drone/drone/pkg/config"
"github.com/drone/drone/pkg/queue"
"github.com/drone/drone/pkg/remote"
"github.com/drone/drone/pkg/runner"
@ -76,21 +75,6 @@ func SetRunner(r runner.Runner) gin.HandlerFunc {
}
}
func ToSettings(c *gin.Context) *config.Config {
v, ok := c.Get("config")
if !ok {
return nil
}
return v.(*config.Config)
}
func SetSettings(s *config.Config) gin.HandlerFunc {
return func(c *gin.Context) {
c.Set("config", s)
c.Next()
}
}
func ToPerm(c *gin.Context) *common.Perm {
v, ok := c.Get("perm")
if !ok {

View file

@ -1,9 +1,7 @@
package server
import (
"fmt"
"io"
"net/http"
"strconv"
"github.com/drone/drone/pkg/bus"
@ -51,7 +49,6 @@ func GetRepoEvents(c *gin.Context) {
}
func GetStream(c *gin.Context) {
conf := ToSettings(c)
store := ToDatastore(c)
repo := ToRepo(c)
runner := ToRunner(c)
@ -71,37 +68,10 @@ func GetStream(c *gin.Context) {
return
}
var rc io.ReadCloser
// if the commit is being executed by an agent
// we'll proxy the build output directly to the
// remote Docker client, through the agent.
if conf.Agents.Secret != "" {
addr, err := store.Agent(build)
if err != nil {
c.Fail(500, err)
return
}
url := fmt.Sprintf("http://%s/stream/%d?token=%s", addr, job.ID, conf.Agents.Secret)
resp, err := http.Get(url)
if err != nil {
c.Fail(500, err)
return
} else if resp.StatusCode != 200 {
resp.Body.Close()
c.AbortWithStatus(resp.StatusCode)
return
}
rc = resp.Body
} else {
// else if the commit is not being executed
// by the build agent we can use the local runner
rc, err = runner.Logs(job)
if err != nil {
c.Fail(404, err)
return
}
rc, err := runner.Logs(job)
if err != nil {
c.Fail(404, err)
return
}
defer func() {