Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jira: fix api token auth #2804

Merged
merged 1 commit into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .jira.d/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,25 @@
#
# See https:/go-jira/jira for documentation on how to use
# go-jira and edit these config files.
# You will need to put your login details in ~/.jira.d/config.yml.
#
# 1. Get an API key from here:
# https://jira.iohk.io/secure/ViewProfile.jspa?selectedTab=com.atlassian.pats.pats-plugin:jira-user-personal-access-tokens
#
# Then add your login details to ~/.jira.d/config.yml. You can't just
# paste your API key into this file. You need to select a password
# source, as per the go-jira docs.
#
# # ~/.jira.d/config.yml
# authentication-method: bearer-token
# login: [email protected]
# password-source: keyring
# password-name: jira.iohk.io
#
######################################################################

endpoint: https://jira.iohk.io
project: ADP
authentication-method: bearer-token

custom-commands:
- name: bugs
Expand Down
53 changes: 53 additions & 0 deletions nix/overlays/go-jira-api-token.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
diff --git a/jiracli/cli.go b/jiracli/cli.go
index d834520..920c0a8 100644
--- a/jiracli/cli.go
+++ b/jiracli/cli.go
@@ -173,7 +173,11 @@ func register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree) {
token := globals.GetPass()
authHeader := fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", globals.Login.Value, token))))
req.Header.Add("Authorization", authHeader)
- }
+ } else if globals.AuthMethod() == "bearer-token" {
+ token := globals.GetPass()
+ authHeader := fmt.Sprintf("Bearer %s", token)
+ req.Header.Add("Authorization", authHeader)
+ }
return req, nil
})

diff --git a/jiracmd/login.go b/jiracmd/login.go
index e74cb6f..b969e06 100644
--- a/jiracmd/login.go
+++ b/jiracmd/login.go
@@ -50,6 +50,10 @@ func CmdLogin(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.Comm
log.Noticef("No need to login when using api-token authentication method")
return nil
}
+ if globals.AuthMethod() == "bearer-token" {
+ log.Noticef("No need to login when using bearer-token authentication method")
+ return nil
+ }

ua := o.WithoutRedirect().WithRetries(0).WithoutCallbacks().WithPostCallback(authCallback)
for {
diff --git a/jiracmd/logout.go b/jiracmd/logout.go
index 1a534bc..6d909dd 100644
--- a/jiracmd/logout.go
+++ b/jiracmd/logout.go
@@ -30,13 +30,13 @@ func CmdLogoutRegistry() *jiracli.CommandRegistryEntry {

// CmdLogout will attempt to terminate an active Jira session
func CmdLogout(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.CommonOptions) error {
- if globals.AuthMethod() == "api-token" {
- log.Noticef("No need to logout when using api-token authentication method")
+ if (globals.AuthMethod() == "api-token" || globals.AuthMethod() == "bearer-token") {
+ log.Noticef("No need to logout when using api-token or bearer-token authentication method")
if globals.GetPass() != "" && terminal.IsTerminal(int(os.Stdin.Fd())) && terminal.IsTerminal(int(os.Stdout.Fd())) {
delete := false
err := survey.AskOne(
&survey.Confirm{
- Message: fmt.Sprintf("Delete api-token from password provider [%s]: ", globals.PasswordSource),
+ Message: fmt.Sprintf("Delete token from password provider [%s]: ", globals.PasswordSource),
Default: false,
},
&delete,
5 changes: 4 additions & 1 deletion nix/overlays/pkgs.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# our packages overlay
self: super: {

# Our jira installation needs API tokens to use Bearer authentication, not Basic.
go-jira = super.go-jira.overrideAttrs (oldAttrs: {
patches = (oldAttrs.patches or []) ++ [ ./go-jira-api-token.patch ];
});
}