aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/gitlab/config.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-09-02 11:34:47 +0200
committerGitHub <noreply@github.com>2019-09-02 11:34:47 +0200
commit16af70894c0348ec90dfee69274f7d44ef2eb079 (patch)
tree5018a7356afa8ade6a69eb8767aa7a3439aa01da /bridge/gitlab/config.go
parentc7792a5d1279a92c8d0caf67a0cf688cc9e32e09 (diff)
parentf3d8da10750d58fce482042cff87455a1e6f36e0 (diff)
downloadgit-bug-16af70894c0348ec90dfee69274f7d44ef2eb079.tar.gz
Merge pull request #200 from MichaelMure/bridge-token-stdin
bridge: support --token-stdin
Diffstat (limited to 'bridge/gitlab/config.go')
-rw-r--r--bridge/gitlab/config.go20
1 files changed, 18 insertions, 2 deletions
diff --git a/bridge/gitlab/config.go b/bridge/gitlab/config.go
index 15172871..a673af8c 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.TokenStdin) && 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
@@ -54,6 +58,13 @@ func (*Gitlab) Configure(repo repository.RepoCommon, params core.BridgeParams) (
// get user token
if params.Token != "" {
token = params.Token
+ } else if params.TokenStdin {
+ reader := bufio.NewReader(os.Stdin)
+ token, err = reader.ReadString('\n')
+ if err != nil {
+ return nil, fmt.Errorf("reading from stdin: %v", err)
+ }
+ token = strings.TrimSuffix(token, "\n")
} else {
token, err = promptToken()
if err != nil {
@@ -71,10 +82,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 {