woodpecker/plugin/remote/remote.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

66 lines
1.8 KiB
Go

package remote
import (
"net/http"
"github.com/drone/drone/shared/model"
)
type Remote interface {
// Authorize handles authentication with thrid party remote systems,
// such as github or bitbucket, and returns user data.
Authorize(w http.ResponseWriter, r *http.Request) (*model.Login, error)
// GetKind returns the kind of plugin
GetKind() string
// GetHost returns the hostname of the remote service.
GetHost() string
// GetRepos fetches all repositories that the specified
// user has access to in the remote system.
GetRepos(user *model.User) ([]*model.Repo, error)
// GetScript fetches the build script (.drone.yml) from the remote
// repository and returns in string format.
GetScript(user *model.User, repo *model.Repo, hook *model.Hook) ([]byte, error)
// Activate activates a repository by creating the post-commit hook and
// adding the SSH deploy key, if applicable.
Activate(user *model.User, repo *model.Repo, link string) error
// ParseHook parses the post-commit hook from the Request body
// and returns the required data in a standard format.
ParseHook(r *http.Request) (*model.Hook, error)
// Registration returns true if open registration is allowed
OpenRegistration() bool
}
// List of registered plugins.
var remotes []Remote
// Register registers a plugin by name.
//
// All plugins must be registered when the application
// initializes. This should not be invoked while the application
// is running, and is not thread safe.
func Register(remote Remote) {
remotes = append(remotes, remote)
}
// List Registered remote plugins
func Registered() []Remote {
return remotes
}
// Lookup gets a plugin by name.
func Lookup(name string) Remote {
for _, remote := range remotes {
if remote.GetKind() == name ||
remote.GetHost() == name {
return remote
}
}
return nil
}