From 31b1ed1f48b4d7b3a5ffea62da9404e9e59ae0dd Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sun, 7 Sep 2014 11:26:16 -0700 Subject: [PATCH] added a private mode flag for github enterprise, defaulted to true --- README.md | 6 ++++++ debian/drone/etc/default/drone | 1 + plugin/remote/github/github.go | 25 +++++++++++++------------ plugin/remote/github/register.go | 10 ++++++---- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index b333dc7d..7895068f 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ client="" secret="" api="" url="" +private_mode=false [bitbucket] client="" @@ -64,6 +65,10 @@ pass="" Or you can use environment variables ```sh + +# enable users to self-register +export DRONE_REGISTRATION_OPEN=false + # github configuration export DRONE_GITHUB_CLIENT="" export DRONE_GITHUB_SECRET="" @@ -73,6 +78,7 @@ export DRONE_GITHUB_ENTERPRISE_CLIENT="" export DRONE_GITHUB_ENTERPRISE_SECRET="" export DRONE_GITHUB_ENTERPRISE_API="" export DRONE_GITHUB_ENTERPRISE_URL="" +export DRONE_GITHUB_ENTERPRISE_PRIVATE_MODE=false # bitbucket configuration export DRONE_BITBUCKET_CLIENT="" diff --git a/debian/drone/etc/default/drone b/debian/drone/etc/default/drone index 9c4b78c7..6109e5ca 100644 --- a/debian/drone/etc/default/drone +++ b/debian/drone/etc/default/drone @@ -25,6 +25,7 @@ #DRONE_GITHUB_ENTERPRISE_SECRET= #DRONE_GITHUB_ENTERPRISE_URL= #DRONE_GITHUB_ENTERPRISE_API= +#DRONE_GITHUB_ENTERPRISE_PRIVATE_MODE=false # GitLab configuration #DRONE_GITLAB_URL= diff --git a/plugin/remote/github/github.go b/plugin/remote/github/github.go index d8237429..b2b06f46 100644 --- a/plugin/remote/github/github.go +++ b/plugin/remote/github/github.go @@ -21,18 +21,20 @@ const ( ) type GitHub struct { - URL string - API string - Client string - Secret string + URL string + API string + Client string + Secret string + Private bool } -func New(url, api, client, secret string) *GitHub { +func New(url, api, client, secret string, private bool) *GitHub { var github = GitHub{ - URL: url, - API: api, - Client: client, - Secret: secret, + URL: url, + API: api, + Client: client, + Secret: secret, + Private: private, } // the API must have a trailing slash if !strings.HasSuffix(github.API, "/") { @@ -46,7 +48,7 @@ func New(url, api, client, secret string) *GitHub { } func NewDefault(client, secret string) *GitHub { - return New(DefaultURL, DefaultAPI, client, secret) + return New(DefaultURL, DefaultAPI, client, secret, false) } // Authorize handles GitHub API Authorization. @@ -134,7 +136,6 @@ func (r *GitHub) GetRepos(user *model.User) ([]*model.Repo, error) { var remote = r.GetKind() var hostname = r.GetHost() - var enterprise = r.IsEnterprise() for _, item := range list { var repo = model.Repo{ @@ -151,7 +152,7 @@ func (r *GitHub) GetRepos(user *model.User) ([]*model.Repo, error) { Role: &model.Perm{}, } - if enterprise || repo.Private { + if r.Private || repo.Private { repo.CloneURL = *item.SSHURL } diff --git a/plugin/remote/github/register.go b/plugin/remote/github/register.go index 91e10dc5..ae4e1e94 100644 --- a/plugin/remote/github/register.go +++ b/plugin/remote/github/register.go @@ -11,10 +11,11 @@ var ( githubSecret = config.String("github-secret", "") // 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", "") + 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) ) // Registers the GitHub plugins using the default @@ -49,6 +50,7 @@ func registerGitHubEnterprise() { *githubEnterpriseAPI, *githubEnterpriseClient, *githubEnterpriseSecret, + *githubEnterprisePrivate, ), ) }