2014-06-04 21:25:38 +00:00
|
|
|
package remote
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2014-07-13 02:01:58 +00:00
|
|
|
|
|
|
|
"github.com/drone/drone/shared/model"
|
2014-06-04 21:25:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Remote interface {
|
2014-09-02 07:18:17 +00:00
|
|
|
// 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)
|
2014-06-09 22:47:35 +00:00
|
|
|
|
2014-09-02 07:18:17 +00:00
|
|
|
// GetKind returns the kind of plugin
|
|
|
|
GetKind() string
|
2014-06-04 21:25:38 +00:00
|
|
|
|
2014-09-02 07:18:17 +00:00
|
|
|
// GetHost returns the hostname of the remote service.
|
|
|
|
GetHost() string
|
2014-06-04 21:25:38 +00:00
|
|
|
|
|
|
|
// GetRepos fetches all repositories that the specified
|
|
|
|
// user has access to in the remote system.
|
2014-09-02 07:18:17 +00:00
|
|
|
GetRepos(user *model.User) ([]*model.Repo, error)
|
2014-06-04 21:25:38 +00:00
|
|
|
|
|
|
|
// GetScript fetches the build script (.drone.yml) from the remote
|
|
|
|
// repository and returns in string format.
|
2014-09-02 07:18:17 +00:00
|
|
|
GetScript(user *model.User, repo *model.Repo, hook *model.Hook) ([]byte, error)
|
2014-06-04 21:25:38 +00:00
|
|
|
|
2014-09-02 07:18:17 +00:00
|
|
|
// 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
|
2014-06-04 21:25:38 +00:00
|
|
|
|
2014-09-02 07:18:17 +00:00
|
|
|
// 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)
|
2015-01-12 22:59:06 +00:00
|
|
|
|
|
|
|
// Registration returns true if open registration is allowed
|
|
|
|
OpenRegistration() bool
|
2015-01-26 23:32:42 +00:00
|
|
|
|
|
|
|
// Get token
|
|
|
|
GetToken(*model.User) (*model.Token, error)
|
2014-06-04 21:25:38 +00:00
|
|
|
}
|
|
|
|
|
2014-09-02 07:18:17 +00:00
|
|
|
// List of registered plugins.
|
|
|
|
var remotes []Remote
|
2014-06-04 21:25:38 +00:00
|
|
|
|
2014-09-02 07:18:17 +00:00
|
|
|
// 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)
|
2014-06-04 21:25:38 +00:00
|
|
|
}
|
|
|
|
|
2014-09-02 07:18:17 +00:00
|
|
|
// List Registered remote plugins
|
|
|
|
func Registered() []Remote {
|
|
|
|
return remotes
|
2014-06-04 21:25:38 +00:00
|
|
|
}
|
|
|
|
|
2014-09-02 07:18:17 +00:00
|
|
|
// 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
|
2014-06-04 21:25:38 +00:00
|
|
|
}
|