woodpecker/pkg/remote/remote.go

94 lines
2.9 KiB
Go
Raw Normal View History

2015-04-08 22:00:27 +00:00
package remote
import (
"net/http"
2015-07-23 17:36:23 +00:00
"github.com/drone/drone/pkg/oauth2"
2015-08-06 15:54:47 +00:00
"github.com/drone/drone/pkg/types"
log "github.com/drone/drone/Godeps/_workspace/src/github.com/Sirupsen/logrus"
2015-04-08 22:00:27 +00:00
)
var drivers = make(map[string]DriverFunc)
// Register makes a remote driver available by the provided name.
// If Register is called twice with the same name or if driver is nil,
// it panics.
func Register(name string, driver DriverFunc) {
if driver == nil {
panic("remote: Register driver is nil")
}
if _, dup := drivers[name]; dup {
panic("remote: Register called twice for driver " + name)
}
drivers[name] = driver
}
// DriverFunc returns a new connection to the remote.
// Config is a struct, with base remote configuration.
2015-08-06 15:54:47 +00:00
type DriverFunc func(config string) (Remote, error)
// New creates a new remote connection.
2015-08-06 15:54:47 +00:00
func New(driver, config string) (Remote, error) {
fn, ok := drivers[driver]
if !ok {
2015-08-06 15:54:47 +00:00
log.Fatalf("remote: unknown driver %q", driver)
}
2015-08-06 22:53:39 +00:00
log.Infof("remote: loading driver %s", driver)
log.Infof("remote: loading config %s", config)
2015-08-06 15:54:47 +00:00
return fn(config)
}
2015-04-08 22:00:27 +00:00
type Remote interface {
// Login authenticates the session and returns the
// remote user details.
2015-08-06 15:54:47 +00:00
Login(token, secret string) (*types.User, error)
2015-04-08 22:00:27 +00:00
// Orgs fetches the organizations for the given user.
2015-08-06 15:54:47 +00:00
Orgs(u *types.User) ([]string, error)
2015-04-08 22:00:27 +00:00
// Repo fetches the named repository from the remote system.
2015-08-06 15:54:47 +00:00
Repo(u *types.User, owner, repo string) (*types.Repo, error)
2015-04-08 22:00:27 +00:00
// Perm fetches the named repository permissions from
// the remote system for the specified user.
2015-08-06 15:54:47 +00:00
Perm(u *types.User, owner, repo string) (*types.Perm, error)
2015-04-08 22:00:27 +00:00
// Script fetches the build script (.drone.yml) from the remote
// repository and returns in string format.
2015-08-06 15:54:47 +00:00
Script(u *types.User, r *types.Repo, b *types.Build) ([]byte, error)
2015-04-08 22:00:27 +00:00
// Status sends the commit status to the remote system.
// An example would be the GitHub pull request status.
2015-08-06 15:54:47 +00:00
Status(u *types.User, r *types.Repo, b *types.Build) error
2015-04-08 22:00:27 +00:00
2015-04-28 21:39:48 +00:00
// Netrc returns a .netrc file that can be used to clone
// private repositories from a remote system.
Netrc(u *types.User, r *types.Repo) (*types.Netrc, error)
2015-04-28 21:39:48 +00:00
2015-04-08 22:00:27 +00:00
// Activate activates a repository by creating the post-commit hook and
// adding the SSH deploy key, if applicable.
2015-08-06 15:54:47 +00:00
Activate(u *types.User, r *types.Repo, k *types.Keypair, link string) error
2015-04-08 22:00:27 +00:00
// Deactivate removes a repository by removing all the post-commit hooks
// which are equal to link and removing the SSH deploy key.
2015-08-06 15:54:47 +00:00
Deactivate(u *types.User, r *types.Repo, link string) error
2015-04-08 22:00:27 +00:00
// Hook parses the post-commit hook from the Request body
// and returns the required data in a standard format.
2015-08-06 15:54:47 +00:00
Hook(r *http.Request) (*types.Hook, error)
2015-07-23 17:36:23 +00:00
// Oauth2Transport
Oauth2Transport(r *http.Request) *oauth2.Transport
// GetOrgs returns all allowed organizations for remote.
GetOrgs() []string
// GetOpen returns boolean field with enabled or disabled
// registration.
GetOpen() bool
// Default scope for remote
Scope() string
2015-04-08 22:00:27 +00:00
}