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:
Matt Bostock
2015-01-12 22:59:06 +00:00
parent f79762177c
commit 307aed12bc
14 changed files with 52 additions and 34 deletions

View File

@@ -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")