mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-03-16 17:54:07 +01:00
Do not use oauth client without token (#1803)
Closes https://github.com/woodpecker-ci/woodpecker/issues/1370
This commit is contained in:
@@ -15,9 +15,15 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||
"github.com/woodpecker-ci/woodpecker/server/store"
|
||||
)
|
||||
|
||||
func ExtractHostFromCloneURL(cloneURL string) (string, error) {
|
||||
@@ -37,3 +43,24 @@ func ExtractHostFromCloneURL(cloneURL string) (string, error) {
|
||||
|
||||
return host, nil
|
||||
}
|
||||
|
||||
func UserToken(ctx context.Context, r *model.Repo, u *model.User) string {
|
||||
if u != nil {
|
||||
return u.Token
|
||||
}
|
||||
|
||||
_store, ok := store.TryFromContext(ctx)
|
||||
if !ok {
|
||||
log.Error().Msg("could not get store from context")
|
||||
return ""
|
||||
}
|
||||
if r == nil {
|
||||
log.Error().Msg("can not get user token by empty repo")
|
||||
return ""
|
||||
}
|
||||
user, err := _store.GetUser(r.UserID)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return user.Token
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user