diff options
Diffstat (limited to 'bridge')
-rw-r--r-- | bridge/core/bridge.go | 4 | ||||
-rw-r--r-- | bridge/core/interfaces.go | 4 | ||||
-rw-r--r-- | bridge/github/config.go | 12 | ||||
-rw-r--r-- | bridge/gitlab/config.go | 14 | ||||
-rw-r--r-- | bridge/jira/config.go | 49 | ||||
-rw-r--r-- | bridge/launchpad/config.go | 5 |
6 files changed, 65 insertions, 23 deletions
diff --git a/bridge/core/bridge.go b/bridge/core/bridge.go index 8c1f9714..b410b470 100644 --- a/bridge/core/bridge.go +++ b/bridge/core/bridge.go @@ -202,10 +202,10 @@ func RemoveBridge(repo repository.RepoConfig, name string) error { } // Configure run the target specific configuration process -func (b *Bridge) Configure(params BridgeParams) error { +func (b *Bridge) Configure(params BridgeParams, interactive bool) error { validateParams(params, b.impl) - conf, err := b.impl.Configure(b.repo, params) + conf, err := b.impl.Configure(b.repo, params, interactive) if err != nil { return err } diff --git a/bridge/core/interfaces.go b/bridge/core/interfaces.go index 47dbd63b..3d212f29 100644 --- a/bridge/core/interfaces.go +++ b/bridge/core/interfaces.go @@ -20,8 +20,8 @@ type BridgeImpl interface { NewExporter() Exporter // Configure handle the user interaction and return a key/value configuration - // for future use - Configure(repo *cache.RepoCache, params BridgeParams) (Configuration, error) + // for future use. + Configure(repo *cache.RepoCache, params BridgeParams, interactive bool) (Configuration, error) // The set of the BridgeParams fields supported ValidParams() map[string]interface{} diff --git a/bridge/github/config.go b/bridge/github/config.go index 55a09c53..9889f403 100644 --- a/bridge/github/config.go +++ b/bridge/github/config.go @@ -40,7 +40,7 @@ func (g *Github) ValidParams() map[string]interface{} { } } -func (g *Github) Configure(repo *cache.RepoCache, params core.BridgeParams) (core.Configuration, error) { +func (g *Github) Configure(repo *cache.RepoCache, params core.BridgeParams, interactive bool) (core.Configuration, error) { var err error var owner string var project string @@ -60,6 +60,9 @@ func (g *Github) Configure(repo *cache.RepoCache, params core.BridgeParams) (cor } default: // terminal prompt + if !interactive { + return nil, fmt.Errorf("Non-interactive-mode is active. Please specify the remote repository with --owner and --project, or via --url option.") + } owner, project, err = promptURL(repo) if err != nil { return nil, err @@ -99,6 +102,9 @@ func (g *Github) Configure(repo *cache.RepoCache, params core.BridgeParams) (cor cred = token default: if params.Login == "" { + if !interactive { + return nil, fmt.Errorf("Non-interactive-mode is active. Please specify a login via the --login option.") + } login, err = promptLogin() } else { // validate login and override with the correct case @@ -110,6 +116,10 @@ func (g *Github) Configure(repo *cache.RepoCache, params core.BridgeParams) (cor if err != nil { return nil, err } + + if !interactive { + return nil, fmt.Errorf("Non-interactive-mode is active. Please specify a access token via the --token option.") + } cred, err = promptTokenOptions(repo, login, owner, project) if err != nil { return nil, err diff --git a/bridge/gitlab/config.go b/bridge/gitlab/config.go index dfac4c54..3496b4a3 100644 --- a/bridge/gitlab/config.go +++ b/bridge/gitlab/config.go @@ -32,7 +32,7 @@ func (g *Gitlab) ValidParams() map[string]interface{} { } } -func (g *Gitlab) Configure(repo *cache.RepoCache, params core.BridgeParams) (core.Configuration, error) { +func (g *Gitlab) Configure(repo *cache.RepoCache, params core.BridgeParams, interactive bool) (core.Configuration, error) { var err error var baseUrl string @@ -40,6 +40,9 @@ func (g *Gitlab) Configure(repo *cache.RepoCache, params core.BridgeParams) (cor case params.BaseURL != "": baseUrl = params.BaseURL default: + if !interactive { + return nil, fmt.Errorf("Non-interactive-mode is active. Please specify the gitlab instance URL via the --base-url option.") + } baseUrl, err = input.PromptDefault("Gitlab server URL", "URL", defaultBaseURL, input.Required, input.IsURL) if err != nil { return nil, errors.Wrap(err, "base url prompt") @@ -54,6 +57,9 @@ func (g *Gitlab) Configure(repo *cache.RepoCache, params core.BridgeParams) (cor projectURL = params.URL default: // terminal prompt + if !interactive { + return nil, fmt.Errorf("Non-interactive-mode is active. Please specify the gitlab project URL via the --url option.") + } projectURL, err = promptProjectURL(repo, baseUrl) if err != nil { return nil, errors.Wrap(err, "url prompt") @@ -89,6 +95,9 @@ func (g *Gitlab) Configure(repo *cache.RepoCache, params core.BridgeParams) (cor cred = token default: if params.Login == "" { + if !interactive { + return nil, fmt.Errorf("Non-interactive-mode is active. Please specify the login name via the --login option.") + } // TODO: validate username login, err = input.Prompt("Gitlab login", "login", input.Required) } else { @@ -98,6 +107,9 @@ func (g *Gitlab) Configure(repo *cache.RepoCache, params core.BridgeParams) (cor if err != nil { return nil, err } + if !interactive { + return nil, fmt.Errorf("Non-interactive-mode is active. Please specify the access token via the --token option.") + } cred, err = promptTokenOptions(repo, login, baseUrl) if err != nil { return nil, err diff --git a/bridge/jira/config.go b/bridge/jira/config.go index 717046e2..3ce6ad9a 100644 --- a/bridge/jira/config.go +++ b/bridge/jira/config.go @@ -33,15 +33,19 @@ func (*Jira) ValidParams() map[string]interface{} { "Login": nil, "CredPrefix": nil, "Project": nil, + "TokenRaw": nil, } } // Configure sets up the bridge configuration -func (j *Jira) Configure(repo *cache.RepoCache, params core.BridgeParams) (core.Configuration, error) { +func (j *Jira) Configure(repo *cache.RepoCache, params core.BridgeParams, interactive bool) (core.Configuration, error) { var err error baseURL := params.BaseURL if baseURL == "" { + if !interactive { + return nil, fmt.Errorf("Non-interactive-mode is active. Please specify the JIRA server URL via the --base-url option.") + } // terminal prompt baseURL, err = input.Prompt("JIRA server URL", "URL", input.Required, input.IsURL) if err != nil { @@ -51,20 +55,17 @@ func (j *Jira) Configure(repo *cache.RepoCache, params core.BridgeParams) (core. project := params.Project if project == "" { + if !interactive { + return nil, fmt.Errorf("Non-interactive-mode is active. Please specify the JIRA project key via the --project option.") + } project, err = input.Prompt("JIRA project key", "project", input.Required) if err != nil { return nil, err } } - fmt.Println(credTypeText) - credTypeInput, err := input.PromptChoice("Authentication mechanism", []string{"SESSION", "TOKEN"}) - if err != nil { - return nil, err - } - credType := []string{"SESSION", "TOKEN"}[credTypeInput] - var login string + var credType string var cred auth.Credential switch { @@ -80,18 +81,34 @@ func (j *Jira) Configure(repo *cache.RepoCache, params core.BridgeParams) (core. login = l default: if params.Login == "" { - // TODO: validate username + if !interactive { + return nil, fmt.Errorf("Non-interactive-mode is active. Please specify the login name via the --login option.") + } login, err = input.Prompt("JIRA login", "login", input.Required) + if err != nil { + return nil, err + } } else { - // TODO: validate username login = params.Login } - if err != nil { - return nil, err - } - cred, err = promptCredOptions(repo, login, baseURL) - if err != nil { - return nil, err + // TODO: validate username + + if params.TokenRaw == "" { + if !interactive { + return nil, fmt.Errorf("Non-interactive-mode is active. Please specify the access token via the --token option.") + } + fmt.Println(credTypeText) + credTypeInput, err := input.PromptChoice("Authentication mechanism", []string{"SESSION", "TOKEN"}) + if err != nil { + return nil, err + } + credType = []string{"SESSION", "TOKEN"}[credTypeInput] + cred, err = promptCredOptions(repo, login, baseURL) + if err != nil { + return nil, err + } + } else { + credType = "TOKEN" } } diff --git a/bridge/launchpad/config.go b/bridge/launchpad/config.go index e2eb86da..f97714bd 100644 --- a/bridge/launchpad/config.go +++ b/bridge/launchpad/config.go @@ -20,7 +20,7 @@ func (Launchpad) ValidParams() map[string]interface{} { } } -func (l *Launchpad) Configure(repo *cache.RepoCache, params core.BridgeParams) (core.Configuration, error) { +func (l *Launchpad) Configure(repo *cache.RepoCache, params core.BridgeParams, interactive bool) (core.Configuration, error) { var err error var project string @@ -31,6 +31,9 @@ func (l *Launchpad) Configure(repo *cache.RepoCache, params core.BridgeParams) ( // get project name from url project, err = splitURL(params.URL) default: + if !interactive { + return nil, fmt.Errorf("Non-interactive-mode is active. Please specify the project name with the --project option.") + } // get project name from terminal prompt project, err = input.Prompt("Launchpad project name", "project name", input.Required) } |