mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-04-26 21:44:44 +00:00
added logging when login or hook fails. helps troubleshoot common issues
This commit is contained in:
parent
ab3df4bd65
commit
eda3cfbe4b
4 changed files with 50 additions and 21 deletions
|
@ -61,6 +61,9 @@ func (db *DB) GetBuildLast(repo string) (*common.Build, error) {
|
||||||
build := &common.Build{}
|
build := &common.Build{}
|
||||||
err := db.View(func(t *bolt.Tx) error {
|
err := db.View(func(t *bolt.Tx) error {
|
||||||
raw := t.Bucket(bucketBuildSeq).Get(key)
|
raw := t.Bucket(bucketBuildSeq).Get(key)
|
||||||
|
if raw == nil {
|
||||||
|
return ErrKeyNotFound
|
||||||
|
}
|
||||||
num := binary.LittleEndian.Uint32(raw)
|
num := binary.LittleEndian.Uint32(raw)
|
||||||
key = []byte(repo + "/" + strconv.FormatUint(uint64(num), 10))
|
key = []byte(repo + "/" + strconv.FormatUint(uint64(num), 10))
|
||||||
return get(t, bucketBuild, key, build)
|
return get(t, bucketBuild, key, build)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package server
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/drone/drone/common"
|
"github.com/drone/drone/common"
|
||||||
// "github.com/bradrydzewski/drone/worker"
|
// "github.com/bradrydzewski/drone/worker"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -19,6 +20,7 @@ func PostHook(c *gin.Context) {
|
||||||
|
|
||||||
hook, err := remote.Hook(c.Request)
|
hook, err := remote.Hook(c.Request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Errorf("failure to parse hook. %s", err)
|
||||||
c.Fail(400, err)
|
c.Fail(400, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -27,6 +29,7 @@ func PostHook(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if hook.Repo == nil {
|
if hook.Repo == nil {
|
||||||
|
log.Errorf("failure to ascertain repo from hook.")
|
||||||
c.Writer.WriteHeader(400)
|
c.Writer.WriteHeader(400)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -34,23 +37,36 @@ func PostHook(c *gin.Context) {
|
||||||
// a build may be skipped if the text [CI SKIP]
|
// a build may be skipped if the text [CI SKIP]
|
||||||
// is found inside the commit message
|
// is found inside the commit message
|
||||||
if hook.Commit != nil && strings.Contains(hook.Commit.Message, "[CI SKIP]") {
|
if hook.Commit != nil && strings.Contains(hook.Commit.Message, "[CI SKIP]") {
|
||||||
|
log.Infof("ignoring hook. [ci skip] found for %s")
|
||||||
c.Writer.WriteHeader(204)
|
c.Writer.WriteHeader(204)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := store.GetRepo(hook.Repo.FullName)
|
repo, err := store.GetRepo(hook.Repo.FullName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Errorf("failure to find repo %s from hook. %s", hook.Repo.FullName, err)
|
||||||
c.Fail(404, err)
|
c.Fail(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if repo.Disabled || repo.User == nil || (repo.DisablePR && hook.PullRequest != nil) {
|
switch {
|
||||||
|
case repo.Disabled:
|
||||||
|
log.Infof("ignoring hook. repo %s is disabled.", repo.FullName)
|
||||||
|
c.Writer.WriteHeader(204)
|
||||||
|
return
|
||||||
|
case repo.User == nil:
|
||||||
|
log.Warnf("ignoring hook. repo %s has no owner.", repo.FullName)
|
||||||
|
c.Writer.WriteHeader(204)
|
||||||
|
return
|
||||||
|
case repo.DisablePR && hook.PullRequest != nil:
|
||||||
|
log.Warnf("ignoring hook. repo %s is disabled for pull requests.", repo.FullName)
|
||||||
c.Writer.WriteHeader(204)
|
c.Writer.WriteHeader(204)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
user, err := store.GetUser(repo.User.Login)
|
user, err := store.GetUser(repo.User.Login)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Errorf("failure to find repo owner %s. %s", repo.User.Login, err)
|
||||||
c.Fail(500, err)
|
c.Fail(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -63,6 +79,7 @@ func PostHook(c *gin.Context) {
|
||||||
// featch the .drone.yml file from the database
|
// featch the .drone.yml file from the database
|
||||||
_, err = remote.Script(user, repo, build)
|
_, err = remote.Script(user, repo, build)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Errorf("failure to get .drone.yml for %s. %s", repo.FullName, err)
|
||||||
c.Fail(404, err)
|
c.Fail(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,11 @@ package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/drone/drone/common"
|
"github.com/drone/drone/common"
|
||||||
"github.com/drone/drone/common/gravatar"
|
"github.com/drone/drone/common/gravatar"
|
||||||
"github.com/drone/drone/common/httputil"
|
"github.com/drone/drone/common/httputil"
|
||||||
|
@ -52,15 +52,20 @@ func GetLogin(c *gin.Context) {
|
||||||
login := ToUser(c)
|
login := ToUser(c)
|
||||||
u, err := store.GetUser(login.Login)
|
u, err := store.GetUser(login.Login)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
count, err := store.GetUserCount()
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("cannot register %s. %s", login.Login, err)
|
||||||
|
c.Redirect(303, "/login#error=internal_error")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// if self-registration is disabled we should
|
// if self-registration is disabled we should
|
||||||
// return a notAuthorized error. the only exception
|
// return a notAuthorized error. the only exception
|
||||||
// is if no users exist yet in the system we'll proceed.
|
// is if no users exist yet in the system we'll proceed.
|
||||||
if !settings.Service.Open {
|
if !settings.Service.Open && count != 0 {
|
||||||
count, err := store.GetUserCount()
|
log.Errorf("cannot register %s. registration closed", login.Login)
|
||||||
if err != nil || count != 0 {
|
c.Redirect(303, "/login#error=access_denied")
|
||||||
c.String(400, "Unable to create account. Registration is closed")
|
return
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the user account
|
// create the user account
|
||||||
|
@ -74,15 +79,14 @@ func GetLogin(c *gin.Context) {
|
||||||
|
|
||||||
// insert the user into the database
|
// insert the user into the database
|
||||||
if err := store.InsertUser(u); err != nil {
|
if err := store.InsertUser(u); err != nil {
|
||||||
log.Println(err)
|
log.Errorf("cannot insert %s. %s", login.Login, err)
|
||||||
c.Fail(400, err)
|
c.Redirect(303, "/login#error=internal_error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// // if this is the first user, they
|
// if this is the first user, they
|
||||||
// // should be an admin.
|
// should be an admin.
|
||||||
//if u.ID == 1 {
|
if count == 0 {
|
||||||
if u.Login == "bradrydzewski" {
|
|
||||||
u.Admin = true
|
u.Admin = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,15 +100,15 @@ func GetLogin(c *gin.Context) {
|
||||||
u.Gravatar = gravatar.Generate(u.Email)
|
u.Gravatar = gravatar.Generate(u.Email)
|
||||||
|
|
||||||
if err := store.UpdateUser(u); err != nil {
|
if err := store.UpdateUser(u); err != nil {
|
||||||
log.Println(err)
|
log.Errorf("cannot update %s. %s", u.Login, err)
|
||||||
c.Fail(400, err)
|
c.Redirect(303, "/login#error=internal_error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
token, err := session.GenerateToken(c.Request, u)
|
token, err := session.GenerateToken(c.Request, u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Errorf("cannot create token for %s. %s", u.Login, err)
|
||||||
c.Fail(400, err)
|
c.Redirect(303, "/login#error=internal_error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.Redirect(303, "/#access_token="+token)
|
c.Redirect(303, "/#access_token="+token)
|
||||||
|
@ -130,6 +134,7 @@ func getLoginOauth2(c *gin.Context) {
|
||||||
var code = c.Request.FormValue("code")
|
var code = c.Request.FormValue("code")
|
||||||
//var state = c.Request.FormValue("state")
|
//var state = c.Request.FormValue("state")
|
||||||
if len(code) == 0 {
|
if len(code) == 0 {
|
||||||
|
// TODO this should be a random number, verified by a cookie
|
||||||
c.Redirect(303, config.AuthCodeURL("random"))
|
c.Redirect(303, config.AuthCodeURL("random"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -138,14 +143,16 @@ func getLoginOauth2(c *gin.Context) {
|
||||||
var trans = &oauth2.Transport{Config: config}
|
var trans = &oauth2.Transport{Config: config}
|
||||||
var token, err = trans.Exchange(code)
|
var token, err = trans.Exchange(code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(400, err)
|
log.Errorf("cannot get access_token. %s", err)
|
||||||
|
c.Redirect(303, "/login#error=token_exchange")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// get user account
|
// get user account
|
||||||
user, err := remote.Login(token.AccessToken, token.RefreshToken)
|
user, err := remote.Login(token.AccessToken, token.RefreshToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, err)
|
log.Errorf("cannot get user with access_token. %s", err)
|
||||||
|
c.Redirect(303, "/login#error=user_not_found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +179,8 @@ func getLoginBasic(c *gin.Context) {
|
||||||
// get user account
|
// get user account
|
||||||
user, err := remote.Login(username, password)
|
user, err := remote.Login(username, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, err)
|
log.Errorf("invalid username or password for %s. %s", username, err)
|
||||||
|
c.Redirect(303, "/login#error=invalid_credentials")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -212,6 +212,7 @@ func PostRepo(c *gin.Context) {
|
||||||
c.Fail(500, err)
|
c.Fail(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
println(link)
|
||||||
|
|
||||||
// persist the repository
|
// persist the repository
|
||||||
err = store.InsertRepo(user, r)
|
err = store.InsertRepo(user, r)
|
||||||
|
|
Loading…
Reference in a new issue