From 44ec2c3064b6888835e90dbd2740a6fe10b05794 Mon Sep 17 00:00:00 2001 From: Alexander Simonov Date: Sun, 12 Jul 2015 01:07:14 +0300 Subject: [PATCH 1/2] Fix database connection --- cmd/drone-server/drone.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/drone-server/drone.go b/cmd/drone-server/drone.go index a8099ff14..9f34453d5 100644 --- a/cmd/drone-server/drone.go +++ b/cmd/drone-server/drone.go @@ -4,7 +4,6 @@ import ( "flag" "html/template" "net/http" - "os" "github.com/drone/drone/Godeps/_workspace/src/github.com/gin-gonic/gin" @@ -45,7 +44,7 @@ func main() { panic(err) } - store, err := store.New(os.Getenv("DATABASE")) + store, err := store.New(settings.Database.Driver + "://" + settings.Database.Datasource) if err != nil { panic(err) } From 9652875129040067663f6857c49baf45be7dda63 Mon Sep 17 00:00:00 2001 From: Alexander Simonov Date: Sun, 12 Jul 2015 01:08:04 +0300 Subject: [PATCH 2/2] Fix logging into Github. Add setting default scope even if it not set in config file. --- pkg/remote/builtin/github/github.go | 5 +++++ pkg/remote/remote.go | 3 +++ pkg/server/login.go | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/remote/builtin/github/github.go b/pkg/remote/builtin/github/github.go index b7fb1f82a..1f50bf135 100644 --- a/pkg/remote/builtin/github/github.go +++ b/pkg/remote/builtin/github/github.go @@ -231,6 +231,11 @@ func (g *GitHub) Hook(r *http.Request) (*common.Hook, error) { } } +// return default scope for GitHub +func (g *GitHub) Scope() string { + return DefaultScope +} + // push parses a hook with event type `push` and returns // the commit data. func (g *GitHub) push(r *http.Request) (*common.Hook, error) { diff --git a/pkg/remote/remote.go b/pkg/remote/remote.go index a195f416d..8f95572ae 100644 --- a/pkg/remote/remote.go +++ b/pkg/remote/remote.go @@ -44,4 +44,7 @@ type Remote interface { // Hook parses the post-commit hook from the Request body // and returns the required data in a standard format. Hook(r *http.Request) (*common.Hook, error) + + // Default scope for remote + Scope() string } diff --git a/pkg/server/login.go b/pkg/server/login.go index 266f5ec60..5e73129e4 100644 --- a/pkg/server/login.go +++ b/pkg/server/login.go @@ -134,10 +134,14 @@ func getLoginOauth2(c *gin.Context) { var settings = ToSettings(c) var remote = ToRemote(c) + var scope = strings.Join(settings.Auth.Scope, ",") + if scope == "" { + scope = remote.Scope() + } var config = &oauth2.Config{ ClientId: settings.Auth.Client, ClientSecret: settings.Auth.Secret, - Scope: strings.Join(settings.Auth.Scope, ","), + Scope: scope, AuthURL: settings.Auth.Authorize, TokenURL: settings.Auth.AccessToken, RedirectURL: fmt.Sprintf("%s/authorize", httputil.GetURL(c.Request)),