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

@@ -13,12 +13,14 @@ import (
type Gitlab struct {
url string
SkipVerify bool
Open bool
}
func New(url string, skipVerify bool) *Gitlab {
func New(url string, skipVerify, open bool) *Gitlab {
return &Gitlab{
url: url,
SkipVerify: skipVerify,
Open: open,
}
}
@@ -191,3 +193,7 @@ func (r *Gitlab) ParseHook(req *http.Request) (*model.Hook, error) {
return hook, nil
}
func (r *Gitlab) OpenRegistration() bool {
return r.Open
}

View File

@@ -14,7 +14,7 @@ func Test_Github(t *testing.T) {
var server = testdata.NewServer()
defer server.Close()
var gitlab = New(server.URL, false)
var gitlab = New(server.URL, false, false)
var user = model.User{
Access: "e3b0c44298fc1c149afbf4c8996fb",
}

View File

@@ -8,6 +8,7 @@ import (
var (
gitlabURL = config.String("gitlab-url", "")
gitlabSkipVerify = config.Bool("gitlab-skip-verify", false)
gitlabOpen = config.Bool("gitlab-open", false)
)
// Registers the Gitlab plugin using the default
@@ -21,6 +22,7 @@ func Register() {
New(
*gitlabURL,
*gitlabSkipVerify,
*gitlabOpen,
),
)
}