woodpecker/plugin/remote/github/register.go
Matt Bostock 307aed12bc 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.
2015-01-16 22:04:24 +00:00

64 lines
1.9 KiB
Go

package github
import (
"github.com/drone/config"
"github.com/drone/drone/plugin/remote"
)
var (
// GitHub cloud configuration details
githubClient = config.String("github-client", "")
githubSecret = config.String("github-secret", "")
githubOrgs = config.Strings("github-orgs")
githubOpen = config.Bool("github-open", false)
// GitHub Enterprise configuration details
githubEnterpriseURL = config.String("github-enterprise-url", "")
githubEnterpriseAPI = config.String("github-enterprise-api", "")
githubEnterpriseClient = config.String("github-enterprise-client", "")
githubEnterpriseSecret = config.String("github-enterprise-secret", "")
githubEnterprisePrivate = config.Bool("github-enterprise-private-mode", true)
githubEnterpriseSkipVerify = config.Bool("github-enterprise-skip-verify", false)
githubEnterpriseOrgs = config.Strings("github-enterprise-orgs")
githubEnterpriseOpen = config.Bool("github-enterprise-open", false)
)
// Registers the GitHub plugins using the default
// settings from the config file or environment
// variables.
func Register() {
registerGitHub()
registerGitHubEnterprise()
}
// registers the GitHub (github.com) plugin
func registerGitHub() {
if len(*githubClient) == 0 || len(*githubSecret) == 0 {
return
}
remote.Register(
NewDefault(*githubClient, *githubSecret, *githubOrgs, *githubOpen),
)
}
// registers the GitHub Enterprise plugin
func registerGitHubEnterprise() {
if len(*githubEnterpriseURL) == 0 ||
len(*githubEnterpriseAPI) == 0 ||
len(*githubEnterpriseClient) == 0 ||
len(*githubEnterpriseSecret) == 0 {
return
}
remote.Register(
New(
*githubEnterpriseURL,
*githubEnterpriseAPI,
*githubEnterpriseClient,
*githubEnterpriseSecret,
*githubEnterprisePrivate,
*githubEnterpriseSkipVerify,
*githubEnterpriseOrgs,
*githubEnterpriseOpen,
),
)
}