diff options
author | cheshirekow <cheshirekow@users.noreply.github.com> | 2020-02-17 13:11:29 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-17 13:11:29 -0800 |
commit | 1e3d23c25bee76dcff83b47fbf848b7688b885d7 (patch) | |
tree | 5559678e01c9951d55a40b5268aed2a818fcb7dc /bridge/jira/jira.go | |
parent | 0bb9ed9b0e6a53fd668be0c60127af78ddd061b5 (diff) | |
parent | 01b0a931f737080c46373bee08bb4a21e932140a (diff) | |
download | git-bug-cheshirekow-jira.tar.gz git-bug-cheshirekow-jira.zip |
Merge pull request #329 from MichaelMure/jira-authcheshirekow-jira
jira: rework to use the credential system + adapt to refactors
Diffstat (limited to 'bridge/jira/jira.go')
-rw-r--r-- | bridge/jira/jira.go | 59 |
1 files changed, 47 insertions, 12 deletions
diff --git a/bridge/jira/jira.go b/bridge/jira/jira.go index 43a11c05..0ba27df3 100644 --- a/bridge/jira/jira.go +++ b/bridge/jira/jira.go @@ -2,27 +2,36 @@ package jira import ( + "context" + "fmt" "sort" "time" "github.com/MichaelMure/git-bug/bridge/core" + "github.com/MichaelMure/git-bug/bridge/core/auth" + "github.com/MichaelMure/git-bug/input" ) const ( target = "jira" - metaKeyJiraLogin = "jira-login" - - keyServer = "server" - keyProject = "project" - keyCredentialsType = "credentials-type" - keyCredentialsFile = "credentials-file" - keyUsername = "username" - keyPassword = "password" - keyIDMap = "bug-id-map" - keyIDRevMap = "bug-id-revmap" - keyCreateDefaults = "create-issue-defaults" - keyCreateGitBug = "create-issue-gitbug-id" + metaKeyJiraId = "jira-id" + metaKeyJiraOperationId = "jira-derived-id" + metaKeyJiraKey = "jira-key" + metaKeyJiraUser = "jira-user" + metaKeyJiraProject = "jira-project" + metaKeyJiraExportTime = "jira-export-time" + metaKeyJiraLogin = "jira-login" + + confKeyBaseUrl = "base-url" + confKeyProject = "project" + confKeyCredentialType = "credentials-type" // "SESSION" or "TOKEN" + confKeyIDMap = "bug-id-map" + confKeyIDRevMap = "bug-id-revmap" + // the issue type when exporting a new bug. Default is Story (10001) + confKeyCreateDefaults = "create-issue-defaults" + // if set, the bridge fill this JIRA field with the `git-bug` id when exporting + confKeyCreateGitBug = "create-issue-gitbug-id" defaultTimeout = 60 * time.Second ) @@ -51,6 +60,32 @@ func (*Jira) NewExporter() core.Exporter { return &jiraExporter{} } +func buildClient(ctx context.Context, baseURL string, credType string, cred auth.Credential) (*Client, error) { + client := NewClient(ctx, baseURL) + + var login, password string + + switch cred := cred.(type) { + case *auth.LoginPassword: + login = cred.Login + password = cred.Password + case *auth.Login: + login = cred.Login + p, err := input.PromptPassword(fmt.Sprintf("Password for %s", login), "password", input.Required) + if err != nil { + return nil, err + } + password = p + } + + err := client.Login(credType, login, password) + if err != nil { + return nil, err + } + + return client, nil +} + // stringInSlice returns true if needle is found in haystack func stringInSlice(needle string, haystack []string) bool { for _, match := range haystack { |