2017-06-30 00:51:22 +02:00
|
|
|
package main
|
2017-05-03 23:25:33 +02:00
|
|
|
|
|
|
|
import (
|
2017-06-28 19:21:22 +02:00
|
|
|
"fmt"
|
|
|
|
|
2017-05-04 02:02:08 +02:00
|
|
|
"github.com/cncd/queue"
|
|
|
|
"github.com/drone/drone/model"
|
2017-05-07 18:47:06 +02:00
|
|
|
"github.com/drone/drone/plugins/registry"
|
|
|
|
"github.com/drone/drone/plugins/secrets"
|
2017-06-28 19:21:22 +02:00
|
|
|
"github.com/drone/drone/remote"
|
|
|
|
"github.com/drone/drone/remote/bitbucket"
|
|
|
|
"github.com/drone/drone/remote/bitbucketserver"
|
2017-07-22 11:12:09 +02:00
|
|
|
"github.com/drone/drone/remote/coding"
|
2017-06-28 19:21:22 +02:00
|
|
|
"github.com/drone/drone/remote/gitea"
|
|
|
|
"github.com/drone/drone/remote/github"
|
|
|
|
"github.com/drone/drone/remote/gitlab"
|
|
|
|
"github.com/drone/drone/remote/gogs"
|
2017-05-03 23:25:33 +02:00
|
|
|
"github.com/drone/drone/store"
|
|
|
|
"github.com/drone/drone/store/datastore"
|
|
|
|
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
func setupStore(c *cli.Context) store.Store {
|
|
|
|
return datastore.New(
|
|
|
|
c.String("driver"),
|
|
|
|
c.String("datasource"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-05-04 02:02:08 +02:00
|
|
|
func setupQueue(c *cli.Context, s store.Store) queue.Queue {
|
|
|
|
return model.WithTaskStore(queue.New(), s)
|
|
|
|
}
|
|
|
|
|
2017-05-07 18:47:06 +02:00
|
|
|
func setupSecretService(c *cli.Context, s store.Store) model.SecretService {
|
|
|
|
return secrets.New(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func setupRegistryService(c *cli.Context, s store.Store) model.RegistryService {
|
|
|
|
return registry.New(s)
|
|
|
|
}
|
|
|
|
|
2017-06-30 00:51:22 +02:00
|
|
|
func setupEnvironService(c *cli.Context, s store.Store) model.EnvironService {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-05-07 18:47:06 +02:00
|
|
|
func setupPubsub(c *cli.Context) {}
|
2017-06-30 00:51:22 +02:00
|
|
|
func setupStream(c *cli.Context) {}
|
|
|
|
func setupGatingService(c *cli.Context) {}
|
2017-06-28 19:21:22 +02:00
|
|
|
|
|
|
|
// helper function to setup the remote from the CLI arguments.
|
2017-06-30 00:51:22 +02:00
|
|
|
func SetupRemote(c *cli.Context) (remote.Remote, error) {
|
2017-06-28 19:21:22 +02:00
|
|
|
switch {
|
|
|
|
case c.Bool("github"):
|
|
|
|
return setupGithub(c)
|
|
|
|
case c.Bool("gitlab"):
|
|
|
|
return setupGitlab(c)
|
|
|
|
case c.Bool("bitbucket"):
|
|
|
|
return setupBitbucket(c)
|
|
|
|
case c.Bool("stash"):
|
|
|
|
return setupStash(c)
|
|
|
|
case c.Bool("gogs"):
|
|
|
|
return setupGogs(c)
|
|
|
|
case c.Bool("gitea"):
|
|
|
|
return setupGitea(c)
|
2017-07-22 11:12:09 +02:00
|
|
|
case c.Bool("coding"):
|
|
|
|
return setupCoding(c)
|
2017-06-28 19:21:22 +02:00
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("version control system not configured")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper function to setup the Bitbucket remote from the CLI arguments.
|
|
|
|
func setupBitbucket(c *cli.Context) (remote.Remote, error) {
|
|
|
|
return bitbucket.New(
|
|
|
|
c.String("bitbucket-client"),
|
|
|
|
c.String("bitbucket-secret"),
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper function to setup the Gogs remote from the CLI arguments.
|
|
|
|
func setupGogs(c *cli.Context) (remote.Remote, error) {
|
|
|
|
return gogs.New(gogs.Opts{
|
|
|
|
URL: c.String("gogs-server"),
|
|
|
|
Username: c.String("gogs-git-username"),
|
|
|
|
Password: c.String("gogs-git-password"),
|
|
|
|
PrivateMode: c.Bool("gogs-private-mode"),
|
|
|
|
SkipVerify: c.Bool("gogs-skip-verify"),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper function to setup the Gitea remote from the CLI arguments.
|
|
|
|
func setupGitea(c *cli.Context) (remote.Remote, error) {
|
|
|
|
return gitea.New(gitea.Opts{
|
|
|
|
URL: c.String("gitea-server"),
|
|
|
|
Username: c.String("gitea-git-username"),
|
|
|
|
Password: c.String("gitea-git-password"),
|
|
|
|
PrivateMode: c.Bool("gitea-private-mode"),
|
|
|
|
SkipVerify: c.Bool("gitea-skip-verify"),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper function to setup the Stash remote from the CLI arguments.
|
|
|
|
func setupStash(c *cli.Context) (remote.Remote, error) {
|
|
|
|
return bitbucketserver.New(bitbucketserver.Opts{
|
|
|
|
URL: c.String("stash-server"),
|
|
|
|
Username: c.String("stash-git-username"),
|
|
|
|
Password: c.String("stash-git-password"),
|
|
|
|
ConsumerKey: c.String("stash-consumer-key"),
|
|
|
|
ConsumerRSA: c.String("stash-consumer-rsa"),
|
|
|
|
ConsumerRSAString: c.String("stash-consumer-rsa-string"),
|
|
|
|
SkipVerify: c.Bool("stash-skip-verify"),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper function to setup the Gitlab remote from the CLI arguments.
|
|
|
|
func setupGitlab(c *cli.Context) (remote.Remote, error) {
|
|
|
|
return gitlab.New(gitlab.Opts{
|
|
|
|
URL: c.String("gitlab-server"),
|
|
|
|
Client: c.String("gitlab-client"),
|
|
|
|
Secret: c.String("gitlab-secret"),
|
|
|
|
Username: c.String("gitlab-git-username"),
|
|
|
|
Password: c.String("gitlab-git-password"),
|
|
|
|
PrivateMode: c.Bool("gitlab-private-mode"),
|
|
|
|
SkipVerify: c.Bool("gitlab-skip-verify"),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper function to setup the GitHub remote from the CLI arguments.
|
|
|
|
func setupGithub(c *cli.Context) (remote.Remote, error) {
|
|
|
|
return github.New(github.Opts{
|
|
|
|
URL: c.String("github-server"),
|
|
|
|
Context: c.String("github-context"),
|
|
|
|
Client: c.String("github-client"),
|
|
|
|
Secret: c.String("github-secret"),
|
|
|
|
Scopes: c.StringSlice("github-scope"),
|
|
|
|
Username: c.String("github-git-username"),
|
|
|
|
Password: c.String("github-git-password"),
|
|
|
|
PrivateMode: c.Bool("github-private-mode"),
|
|
|
|
SkipVerify: c.Bool("github-skip-verify"),
|
|
|
|
MergeRef: c.BoolT("github-merge-ref"),
|
|
|
|
})
|
|
|
|
}
|
2017-06-30 00:51:22 +02:00
|
|
|
|
2017-07-22 11:12:09 +02:00
|
|
|
// helper function to setup the Coding remote from the CLI arguments.
|
|
|
|
func setupCoding(c *cli.Context) (remote.Remote, error) {
|
|
|
|
return coding.New(coding.Opts{
|
|
|
|
URL: c.String("coding-server"),
|
|
|
|
Client: c.String("coding-client"),
|
|
|
|
Secret: c.String("coding-secret"),
|
|
|
|
Scopes: c.StringSlice("coding-scope"),
|
|
|
|
Machine: c.String("coding-git-machine"),
|
|
|
|
Username: c.String("coding-git-username"),
|
|
|
|
Password: c.String("coding-git-password"),
|
|
|
|
SkipVerify: c.Bool("coding-skip-verify"),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-06-30 00:51:22 +02:00
|
|
|
func before(c *cli.Context) error { return nil }
|