From 0381400bfda16f910ca87b0258ddda1c1732fbc7 Mon Sep 17 00:00:00 2001 From: Amine Hilaly Date: Wed, 21 Aug 2019 14:24:48 +0200 Subject: [PATCH 1/7] commands: read token from stdin in bridge configuration bridge: improve bridge config validation --- bridge/github/config.go | 12 +++++++++++- bridge/gitlab/config.go | 13 +++++++++++-- bridge/launchpad/config.go | 8 +++++++- commands/bridge_configure.go | 22 +++++++++++----------- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/bridge/github/config.go b/bridge/github/config.go index 45c078f64c4a81c4763b29fe8606058de607211d..f55ea1b40d2fa4a05e853da5e9d16c886d9d2efb 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 1517287173430153f3d90d7ad1e679f38d8d94a6..d1d85030e3ff2960f157db8ff317c792091aec3c 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 1d6c8aba87fd3492702b69a8cd00246b5b081245..6669d0fa40deef5f07e8c7ebd00a9d4bcff9acda 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 } diff --git a/commands/bridge_configure.go b/commands/bridge_configure.go index 6bebc26245de7647fa997f07ef20414f1c490472..4cfe0ed5dedebeb4e4cce38e2c48f3217152ed67 100644 --- a/commands/bridge_configure.go +++ b/commands/bridge_configure.go @@ -6,10 +6,8 @@ import ( "os" "strconv" "strings" - "syscall" "github.com/spf13/cobra" - "golang.org/x/crypto/ssh/terminal" "github.com/MichaelMure/git-bug/bridge" "github.com/MichaelMure/git-bug/bridge/core" @@ -23,6 +21,7 @@ const ( ) var ( + tokenStdin bool bridgeConfigureName string bridgeConfigureTarget string bridgeParams core.BridgeParams @@ -36,15 +35,6 @@ func runBridgeConfigure(cmd *cobra.Command, args []string) error { defer backend.Close() interrupt.RegisterCleaner(backend.Close) - termState, err := terminal.GetState(int(syscall.Stdin)) - if err != nil { - return err - } - - interrupt.RegisterCleaner(func() error { - return terminal.Restore(int(syscall.Stdin), termState) - }) - if bridgeConfigureTarget == "" { bridgeConfigureTarget, err = promptTarget() if err != nil { @@ -64,6 +54,15 @@ func runBridgeConfigure(cmd *cobra.Command, args []string) error { return err } + if tokenStdin { + reader := bufio.NewReader(os.Stdin) + token, err := reader.ReadString('\n') + if err != nil { + return fmt.Errorf("reading from stdin: %v", err) + } + bridgeParams.Token = strings.TrimSuffix(token, "\n") + } + err = b.Configure(bridgeParams) if err != nil { return err @@ -192,6 +191,7 @@ func init() { bridgeConfigureCmd.Flags().StringVarP(&bridgeParams.URL, "url", "u", "", "The URL of the target repository") bridgeConfigureCmd.Flags().StringVarP(&bridgeParams.Owner, "owner", "o", "", "The owner of the target repository") bridgeConfigureCmd.Flags().StringVarP(&bridgeParams.Token, "token", "T", "", "The authentication token for the API") + bridgeConfigureCmd.Flags().BoolVar(&tokenStdin, "token-stdin", false, "Expect to receive token from stdin and ignore token flag.") bridgeConfigureCmd.Flags().StringVarP(&bridgeParams.Project, "project", "p", "", "The name of the target repository") bridgeConfigureCmd.Flags().SortFlags = false } From 65d7ce7c05a458beb306984c6fd3629839872845 Mon Sep 17 00:00:00 2001 From: Amine Date: Fri, 23 Aug 2019 11:09:03 +0200 Subject: [PATCH 2/7] commands: enhance flag description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bridge/github: improve configuration logic Co-Authored-By: Michael Muré --- bridge/github/config.go | 2 +- commands/bridge_configure.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bridge/github/config.go b/bridge/github/config.go index f55ea1b40d2fa4a05e853da5e9d16c886d9d2efb..954bf845ea798bbedd9c48143e701e6dc76e9711 100644 --- a/bridge/github/config.go +++ b/bridge/github/config.go @@ -45,7 +45,7 @@ func (g *Github) Configure(repo repository.RepoCommon, params core.BridgeParams) var project string if params.Token != "" && - !(params.URL != "" || (params.Project != "" && params.Owner != "")) { + (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") } diff --git a/commands/bridge_configure.go b/commands/bridge_configure.go index 4cfe0ed5dedebeb4e4cce38e2c48f3217152ed67..95cff1a2bccce8f47100c05fe03904b5cbdc0f23 100644 --- a/commands/bridge_configure.go +++ b/commands/bridge_configure.go @@ -191,7 +191,7 @@ func init() { bridgeConfigureCmd.Flags().StringVarP(&bridgeParams.URL, "url", "u", "", "The URL of the target repository") bridgeConfigureCmd.Flags().StringVarP(&bridgeParams.Owner, "owner", "o", "", "The owner of the target repository") bridgeConfigureCmd.Flags().StringVarP(&bridgeParams.Token, "token", "T", "", "The authentication token for the API") - bridgeConfigureCmd.Flags().BoolVar(&tokenStdin, "token-stdin", false, "Expect to receive token from stdin and ignore token flag.") + bridgeConfigureCmd.Flags().BoolVar(&tokenStdin, "token-stdin", false, "Will read the token from stdin and ignore --token") bridgeConfigureCmd.Flags().StringVarP(&bridgeParams.Project, "project", "p", "", "The name of the target repository") bridgeConfigureCmd.Flags().SortFlags = false } From 77e60aceeac60e02c253a24faba9603c76228e76 Mon Sep 17 00:00:00 2001 From: Amine Hilaly Date: Sat, 24 Aug 2019 13:11:58 +0200 Subject: [PATCH 3/7] commands: add bridge configure completion scripts --- doc/man/git-bug-bridge-configure.1 | 4 ++++ doc/md/git-bug_bridge_configure.md | 1 + misc/bash_completion/git-bug | 2 ++ misc/powershell_completion/git-bug | 1 + misc/zsh_completion/git-bug | 1 + 5 files changed, 9 insertions(+) diff --git a/doc/man/git-bug-bridge-configure.1 b/doc/man/git-bug-bridge-configure.1 index 5e103468a467ccbb269dc98a26d63687ef0481eb..00f57dfbf60d3374f952a69ee5ccafb956a92ada 100644 --- a/doc/man/git-bug-bridge-configure.1 +++ b/doc/man/git-bug-bridge-configure.1 @@ -47,6 +47,10 @@ Token configuration can be directly passed with the \-\-token flag or in the ter \fB\-T\fP, \fB\-\-token\fP="" The authentication token for the API +.PP +\fB\-\-token\-stdin\fP[=false] + Will read the token from stdin and ignore \-\-token + .PP \fB\-p\fP, \fB\-\-project\fP="" The name of the target repository diff --git a/doc/md/git-bug_bridge_configure.md b/doc/md/git-bug_bridge_configure.md index 0f6a10ebd558b06dbbb5eb366018aa072d142468..5181cd4320961d8eede1ac948e991cbb7e5ad152 100644 --- a/doc/md/git-bug_bridge_configure.md +++ b/doc/md/git-bug_bridge_configure.md @@ -68,6 +68,7 @@ git bug bridge configure \ -u, --url string The URL of the target repository -o, --owner string The owner of the target repository -T, --token string The authentication token for the API + --token-stdin Will read the token from stdin and ignore --token -p, --project string The name of the target repository -h, --help help for configure ``` diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug index 06032f1002d45757bc5ebc94bce2210e8cea2c3b..bbeb633516682d6184670895716a016f3204dbca 100644 --- a/misc/bash_completion/git-bug +++ b/misc/bash_completion/git-bug @@ -321,6 +321,8 @@ _git-bug_bridge_configure() two_word_flags+=("--token") two_word_flags+=("-T") local_nonpersistent_flags+=("--token=") + flags+=("--token-stdin") + local_nonpersistent_flags+=("--token-stdin") flags+=("--project=") two_word_flags+=("--project") two_word_flags+=("-p") diff --git a/misc/powershell_completion/git-bug b/misc/powershell_completion/git-bug index 3785c0ad2d2ef040f235e31416849cc2ad13b804..9e0805f36d53eae504c012f0ea1a8ca8da3572e6 100644 --- a/misc/powershell_completion/git-bug +++ b/misc/powershell_completion/git-bug @@ -65,6 +65,7 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock { [CompletionResult]::new('--owner', 'owner', [CompletionResultType]::ParameterName, 'The owner of the target repository') [CompletionResult]::new('-T', 'T', [CompletionResultType]::ParameterName, 'The authentication token for the API') [CompletionResult]::new('--token', 'token', [CompletionResultType]::ParameterName, 'The authentication token for the API') + [CompletionResult]::new('--token-stdin', 'token-stdin', [CompletionResultType]::ParameterName, 'Will read the token from stdin and ignore --token') [CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'The name of the target repository') [CompletionResult]::new('--project', 'project', [CompletionResultType]::ParameterName, 'The name of the target repository') break diff --git a/misc/zsh_completion/git-bug b/misc/zsh_completion/git-bug index fe1ca5a56998a7f4f3d22813f6793f8f636348cc..8eaaf694583139817f30841bb81bb1024f488b8d 100644 --- a/misc/zsh_completion/git-bug +++ b/misc/zsh_completion/git-bug @@ -146,6 +146,7 @@ function _git-bug_bridge_configure { '(-u --url)'{-u,--url}'[The URL of the target repository]:' \ '(-o --owner)'{-o,--owner}'[The owner of the target repository]:' \ '(-T --token)'{-T,--token}'[The authentication token for the API]:' \ + '--token-stdin[Will read the token from stdin and ignore --token]' \ '(-p --project)'{-p,--project}'[The name of the target repository]:' } From be94780315b85e51204e28c41fcad34e507d3d3c Mon Sep 17 00:00:00 2001 From: Amine Hilaly Date: Tue, 27 Aug 2019 00:32:30 +0200 Subject: [PATCH 4/7] bridge/github: recover terminal state in password prompts commands: error if a token is provide but not the bridge name and target --- bridge/github/config.go | 11 +++++++++++ commands/bridge_configure.go | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/bridge/github/config.go b/bridge/github/config.go index 954bf845ea798bbedd9c48143e701e6dc76e9711..d1b57e10a3e2b74634f8002c065b1fd148028851 100644 --- a/bridge/github/config.go +++ b/bridge/github/config.go @@ -21,6 +21,7 @@ import ( "github.com/MichaelMure/git-bug/bridge/core" "github.com/MichaelMure/git-bug/repository" + "github.com/MichaelMure/git-bug/util/interrupt" ) const ( @@ -236,6 +237,16 @@ func promptTokenOptions(owner, project string) (string, error) { return promptToken() } + // Register restore state cleaner before prompting passwords inputs + termState, err := terminal.GetState(int(syscall.Stdin)) + if err != nil { + return "", err + } + + interrupt.RegisterCleaner(func() error { + return terminal.Restore(int(syscall.Stdin), termState) + }) + return loginAndRequestToken(owner, project) } } diff --git a/commands/bridge_configure.go b/commands/bridge_configure.go index 95cff1a2bccce8f47100c05fe03904b5cbdc0f23..bb32c84e58dd6e0083b33a8942183004d82150fc 100644 --- a/commands/bridge_configure.go +++ b/commands/bridge_configure.go @@ -35,6 +35,10 @@ func runBridgeConfigure(cmd *cobra.Command, args []string) error { defer backend.Close() interrupt.RegisterCleaner(backend.Close) + if (tokenStdin || bridgeParams.Token != "") && (bridgeConfigureName == "" || bridgeConfigureTarget == "") { + return fmt.Errorf("you must bridge name and target to configure a bridge with a token") + } + if bridgeConfigureTarget == "" { bridgeConfigureTarget, err = promptTarget() if err != nil { From c5824ff1b44fe7005028a9e60161bf37ab658ecc Mon Sep 17 00:00:00 2001 From: Amine Hilaly Date: Tue, 27 Aug 2019 00:53:26 +0200 Subject: [PATCH 5/7] doc/man: update generated documentations --- doc/man/git-bug-bridge-configure.1 | 11 +++++++++-- doc/md/git-bug_bridge_configure.md | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/doc/man/git-bug-bridge-configure.1 b/doc/man/git-bug-bridge-configure.1 index 00f57dfbf60d3374f952a69ee5ccafb956a92ada..e93a9e6728b3595800adc04c460bafd72c1da290 100644 --- a/doc/man/git-bug-bridge-configure.1 +++ b/doc/man/git-bug-bridge-configure.1 @@ -95,7 +95,7 @@ Private: Enter token: 87cf5c03b64029f18ea5f9ca5679daa08ccbd700 Successfully configured bridge: default -# For Github +# For GitHub git bug bridge configure \\ \-\-name=default \\ \-\-target=github \\ @@ -107,7 +107,14 @@ git bug bridge configure \\ git bug bridge configure \\ \-\-name=default \\ \-\-target=launchpad\-preview \\ - \-\-url=https://bugs.launchpad.net/ubuntu/ + \-\-url=https://bugs.launchpad.net/ubuntu/ + +# For Gitlab +git bug bridge configure \\ + \-\-name=default \\ + \-\-target=github \\ + \-\-url=https://github.com/michaelmure/git\-bug \\ + \-\-token=$(TOKEN) .fi .RE diff --git a/doc/md/git-bug_bridge_configure.md b/doc/md/git-bug_bridge_configure.md index 5181cd4320961d8eede1ac948e991cbb7e5ad152..410183449e08c2f6be2562f4e5b6fc7b8f8f48bb 100644 --- a/doc/md/git-bug_bridge_configure.md +++ b/doc/md/git-bug_bridge_configure.md @@ -45,7 +45,7 @@ Private: Enter token: 87cf5c03b64029f18ea5f9ca5679daa08ccbd700 Successfully configured bridge: default -# For Github +# For GitHub git bug bridge configure \ --name=default \ --target=github \ @@ -57,7 +57,14 @@ git bug bridge configure \ git bug bridge configure \ --name=default \ --target=launchpad-preview \ - --url=https://bugs.launchpad.net/ubuntu/ + --url=https://bugs.launchpad.net/ubuntu/ + +# For Gitlab +git bug bridge configure \ + --name=default \ + --target=github \ + --url=https://github.com/michaelmure/git-bug \ + --token=$(TOKEN) ``` ### Options From 46f957344499863c97a20d34cf8ba078d3245c3a Mon Sep 17 00:00:00 2001 From: Amine Hilaly Date: Fri, 30 Aug 2019 23:20:46 +0200 Subject: [PATCH 6/7] bridge/github: move cleaners to where is called --- bridge/github/config.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/bridge/github/config.go b/bridge/github/config.go index d1b57e10a3e2b74634f8002c065b1fd148028851..bc4911e0c8a770ecf85200adfddccbddc5c52f4e 100644 --- a/bridge/github/config.go +++ b/bridge/github/config.go @@ -237,16 +237,6 @@ func promptTokenOptions(owner, project string) (string, error) { return promptToken() } - // Register restore state cleaner before prompting passwords inputs - termState, err := terminal.GetState(int(syscall.Stdin)) - if err != nil { - return "", err - } - - interrupt.RegisterCleaner(func() error { - return terminal.Restore(int(syscall.Stdin), termState) - }) - return loginAndRequestToken(owner, project) } } @@ -526,6 +516,16 @@ func validateProject(owner, project, token string) (bool, error) { } func promptPassword() (string, error) { + termState, err := terminal.GetState(int(syscall.Stdin)) + if err != nil { + return "", err + } + + cancel := interrupt.RegisterCleaner(func() error { + return terminal.Restore(int(syscall.Stdin), termState) + }) + defer cancel() + for { fmt.Print("password: ") @@ -547,6 +547,16 @@ func promptPassword() (string, error) { } func prompt2FA() (string, error) { + termState, err := terminal.GetState(int(syscall.Stdin)) + if err != nil { + return "", err + } + + cancel := interrupt.RegisterCleaner(func() error { + return terminal.Restore(int(syscall.Stdin), termState) + }) + defer cancel() + for { fmt.Print("two-factor authentication code: ") From f3d8da10750d58fce482042cff87455a1e6f36e0 Mon Sep 17 00:00:00 2001 From: Amine Hilaly Date: Mon, 2 Sep 2019 09:24:53 +0200 Subject: [PATCH 7/7] bridge/core: add tokenStdin field to bridgeParams commands: move tokenStdin handling logic to bridge.Configure --- bridge/core/bridge.go | 9 +++++---- bridge/github/config.go | 9 ++++++++- bridge/gitlab/config.go | 9 ++++++++- commands/bridge_configure.go | 16 +++------------- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/bridge/core/bridge.go b/bridge/core/bridge.go index 9161b4188cd9ce83099b2161106b8848004de40a..6fd28b03ca172a647a59b0797821e35b04347d38 100644 --- a/bridge/core/bridge.go +++ b/bridge/core/bridge.go @@ -31,10 +31,11 @@ var bridgeImpl map[string]reflect.Type // BridgeParams holds parameters to simplify the bridge configuration without // having to make terminal prompts. type BridgeParams struct { - Owner string - Project string - URL string - Token string + Owner string + Project string + URL string + Token string + TokenStdin bool } // Bridge is a wrapper around a BridgeImpl that will bind low-level diff --git a/bridge/github/config.go b/bridge/github/config.go index bc4911e0c8a770ecf85200adfddccbddc5c52f4e..16abfa09065f39cd82ce78dc8b060ff80a5ba26b 100644 --- a/bridge/github/config.go +++ b/bridge/github/config.go @@ -45,7 +45,7 @@ func (g *Github) Configure(repo repository.RepoCommon, params core.BridgeParams) var owner string var project string - if params.Token != "" && + if (params.Token != "" || params.TokenStdin) && (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") } @@ -91,6 +91,13 @@ func (g *Github) Configure(repo repository.RepoCommon, params core.BridgeParams) 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 = promptTokenOptions(owner, project) if err != nil { diff --git a/bridge/gitlab/config.go b/bridge/gitlab/config.go index d1d85030e3ff2960f157db8ff317c792091aec3c..a673af8ca701165caeb943ccb11a202b57933575 100644 --- a/bridge/gitlab/config.go +++ b/bridge/gitlab/config.go @@ -33,7 +33,7 @@ func (g *Gitlab) Configure(repo repository.RepoCommon, params core.BridgeParams) var url string var token string - if params.Token != "" && params.URL == "" { + if (params.Token != "" || params.TokenStdin) && params.URL == "" { return nil, fmt.Errorf("you must provide a project URL to configure this bridge with a token") } @@ -58,6 +58,13 @@ func (g *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 { diff --git a/commands/bridge_configure.go b/commands/bridge_configure.go index bb32c84e58dd6e0083b33a8942183004d82150fc..12cc35e351eb38e11efe8e3b30fb1ce63bdab827 100644 --- a/commands/bridge_configure.go +++ b/commands/bridge_configure.go @@ -21,7 +21,6 @@ const ( ) var ( - tokenStdin bool bridgeConfigureName string bridgeConfigureTarget string bridgeParams core.BridgeParams @@ -35,8 +34,8 @@ func runBridgeConfigure(cmd *cobra.Command, args []string) error { defer backend.Close() interrupt.RegisterCleaner(backend.Close) - if (tokenStdin || bridgeParams.Token != "") && (bridgeConfigureName == "" || bridgeConfigureTarget == "") { - return fmt.Errorf("you must bridge name and target to configure a bridge with a token") + if (bridgeParams.TokenStdin || bridgeParams.Token != "") && (bridgeConfigureName == "" || bridgeConfigureTarget == "") { + return fmt.Errorf("you must provide a bridge name and target to configure a bridge with a token") } if bridgeConfigureTarget == "" { @@ -58,15 +57,6 @@ func runBridgeConfigure(cmd *cobra.Command, args []string) error { return err } - if tokenStdin { - reader := bufio.NewReader(os.Stdin) - token, err := reader.ReadString('\n') - if err != nil { - return fmt.Errorf("reading from stdin: %v", err) - } - bridgeParams.Token = strings.TrimSuffix(token, "\n") - } - err = b.Configure(bridgeParams) if err != nil { return err @@ -195,7 +185,7 @@ func init() { bridgeConfigureCmd.Flags().StringVarP(&bridgeParams.URL, "url", "u", "", "The URL of the target repository") bridgeConfigureCmd.Flags().StringVarP(&bridgeParams.Owner, "owner", "o", "", "The owner of the target repository") bridgeConfigureCmd.Flags().StringVarP(&bridgeParams.Token, "token", "T", "", "The authentication token for the API") - bridgeConfigureCmd.Flags().BoolVar(&tokenStdin, "token-stdin", false, "Will read the token from stdin and ignore --token") + bridgeConfigureCmd.Flags().BoolVar(&bridgeParams.TokenStdin, "token-stdin", false, "Will read the token from stdin and ignore --token") bridgeConfigureCmd.Flags().StringVarP(&bridgeParams.Project, "project", "p", "", "The name of the target repository") bridgeConfigureCmd.Flags().SortFlags = false }