mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-03-21 09:24:55 +01:00
Move open registration setting into remote plugins
...so that it's possible to enable or disable open registration on a per-remote basis. For example, the `DRONE_REGISTRATION_OPEN` environment variable now becomes `DRONE_GITHUB_OPEN` when using GitHub as a remote. The default for open registration in this commit is `false` (disabled), which matches the existing behaviour. This is useful if you need to support both public and private remotes, e.g. GitHub.com and GitHub Enterprise, where you trust all of the private users and want to allow open registration for those but would not want all GitHub.com users to run builds on your server. Tested with GitHub and GitLab.
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
||||
|
||||
func TestBlobstore(t *testing.T) {
|
||||
caps := map[string]bool{}
|
||||
caps[Registration] = true
|
||||
|
||||
ctx := NewContext(context.Background(), caps)
|
||||
|
||||
@@ -17,7 +16,6 @@ func TestBlobstore(t *testing.T) {
|
||||
g.Describe("Capabilities", func() {
|
||||
|
||||
g.It("Should get capabilities from context", func() {
|
||||
g.Assert(Enabled(ctx, Registration)).Equal(true)
|
||||
g.Assert(Enabled(ctx, "Fake Key")).Equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/drone/drone/plugin/remote"
|
||||
"github.com/drone/drone/server/capability"
|
||||
"github.com/drone/drone/server/datastore"
|
||||
"github.com/drone/drone/server/session"
|
||||
"github.com/drone/drone/server/sync"
|
||||
@@ -49,7 +48,7 @@ func GetLogin(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||
// if self-registration is disabled we should
|
||||
// return a notAuthorized error. the only exception
|
||||
// is if no users exist yet in the system we'll proceed.
|
||||
if capability.Enabled(ctx, capability.Registration) == false {
|
||||
if remote.OpenRegistration() == false {
|
||||
users, err := datastore.GetUserList(ctx)
|
||||
if err != nil || len(users) != 0 {
|
||||
log.Println("Unable to create account. Registration is closed")
|
||||
|
||||
@@ -56,10 +56,6 @@ var (
|
||||
sslcrt = config.String("server-ssl-cert", "")
|
||||
sslkey = config.String("server-ssl-key", "")
|
||||
|
||||
// Enable self-registration. When false, the system admin
|
||||
// must grant user access.
|
||||
open = config.Bool("registration-open", false)
|
||||
|
||||
workers *pool.Pool
|
||||
worker *director.Director
|
||||
pub *pubsub.PubSub
|
||||
@@ -105,7 +101,6 @@ func main() {
|
||||
gogs.Register()
|
||||
|
||||
caps = map[string]bool{}
|
||||
caps[capability.Registration] = *open
|
||||
|
||||
// setup the database and cancel all pending
|
||||
// commits in the system.
|
||||
|
||||
Reference in New Issue
Block a user