aboutsummaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
authorAmine Hilaly <hilalyamine@gmail.com>2019-08-21 14:24:48 +0200
committerAmine Hilaly <hilalyamine@gmail.com>2019-08-31 23:02:20 +0200
commit0381400bfda16f910ca87b0258ddda1c1732fbc7 (patch)
tree54a271f43bafbbc238e2fc26bb6fa67d6403c4af /bridge
parentc7792a5d1279a92c8d0caf67a0cf688cc9e32e09 (diff)
downloadgit-bug-0381400bfda16f910ca87b0258ddda1c1732fbc7.tar.gz
commands: read token from stdin in bridge configuration
bridge: improve bridge config validation
Diffstat (limited to 'bridge')
-rw-r--r--bridge/github/config.go12
-rw-r--r--bridge/gitlab/config.go13
-rw-r--r--bridge/launchpad/config.go8
3 files changed, 29 insertions, 4 deletions
diff --git a/bridge/github/config.go b/bridge/github/config.go
index 45c078f6..f55ea1b4 100644
--- a/bridge/github/config.go
+++ b/bridge/github/config.go
@@ -37,13 +37,18 @@ var (
ErrBadProjectURL = errors.New("bad project url")
)
-func (*Github) Configure(repo repository.RepoCommon, params core.BridgeParams) (core.Configuration, error) {
+func (g *Github) Configure(repo repository.RepoCommon, params core.BridgeParams) (core.Configuration, error) {
conf := make(core.Configuration)
var err error
var token string
var owner string
var project string
+ if params.Token != "" &&
+ !(params.URL != "" || (params.Project != "" && params.Owner != "")) {
+ return nil, fmt.Errorf("you must provide a project URL or Owner/Name to configure this bridge with a token")
+ }
+
// getting owner and project name
if params.Owner != "" && params.Project != "" {
// first try to use params if both or project and owner are provided
@@ -106,6 +111,11 @@ func (*Github) Configure(repo repository.RepoCommon, params core.BridgeParams) (
conf[keyOwner] = owner
conf[keyProject] = project
+ err = g.ValidateConfig(conf)
+ if err != nil {
+ return nil, err
+ }
+
return conf, nil
}
diff --git a/bridge/gitlab/config.go b/bridge/gitlab/config.go
index 15172871..d1d85030 100644
--- a/bridge/gitlab/config.go
+++ b/bridge/gitlab/config.go
@@ -20,7 +20,7 @@ var (
ErrBadProjectURL = errors.New("bad project url")
)
-func (*Gitlab) Configure(repo repository.RepoCommon, params core.BridgeParams) (core.Configuration, error) {
+func (g *Gitlab) Configure(repo repository.RepoCommon, params core.BridgeParams) (core.Configuration, error) {
if params.Project != "" {
fmt.Println("warning: --project is ineffective for a gitlab bridge")
}
@@ -33,6 +33,10 @@ func (*Gitlab) Configure(repo repository.RepoCommon, params core.BridgeParams) (
var url string
var token string
+ if params.Token != "" && params.URL == "" {
+ return nil, fmt.Errorf("you must provide a project URL to configure this bridge with a token")
+ }
+
// get project url
if params.URL != "" {
url = params.URL
@@ -71,10 +75,15 @@ func (*Gitlab) Configure(repo repository.RepoCommon, params core.BridgeParams) (
conf[keyToken] = token
conf[core.KeyTarget] = target
+ err = g.ValidateConfig(conf)
+ if err != nil {
+ return nil, err
+ }
+
return conf, nil
}
-func (*Gitlab) ValidateConfig(conf core.Configuration) error {
+func (g *Gitlab) ValidateConfig(conf core.Configuration) error {
if v, ok := conf[core.KeyTarget]; !ok {
return fmt.Errorf("missing %s key", core.KeyTarget)
} else if v != target {
diff --git a/bridge/launchpad/config.go b/bridge/launchpad/config.go
index 1d6c8aba..6669d0fa 100644
--- a/bridge/launchpad/config.go
+++ b/bridge/launchpad/config.go
@@ -22,7 +22,7 @@ const (
defaultTimeout = 60 * time.Second
)
-func (*Launchpad) Configure(repo repository.RepoCommon, params core.BridgeParams) (core.Configuration, error) {
+func (l *Launchpad) Configure(repo repository.RepoCommon, params core.BridgeParams) (core.Configuration, error) {
if params.Token != "" {
fmt.Println("warning: --token is ineffective for a Launchpad bridge")
}
@@ -63,6 +63,12 @@ func (*Launchpad) Configure(repo repository.RepoCommon, params core.BridgeParams
conf[keyProject] = project
conf[core.KeyTarget] = target
+
+ err = l.ValidateConfig(conf)
+ if err != nil {
+ return nil, err
+ }
+
return conf, nil
}