diff --git a/b04061023c941d879460d81e6e4c6019621dbc16.patch b/b04061023c941d879460d81e6e4c6019621dbc16.patch new file mode 100644 index 0000000..3e429de --- /dev/null +++ b/b04061023c941d879460d81e6e4c6019621dbc16.patch @@ -0,0 +1,121 @@ +From b04061023c941d879460d81e6e4c6019621dbc16 Mon Sep 17 00:00:00 2001 +From: Augustin Husson +Date: Tue, 12 Nov 2024 10:42:49 +0100 +Subject: [PATCH] =?UTF-8?q?[BUGFIX]=C2=A0Fix=20login=20command=20avoiding?= + =?UTF-8?q?=20reusing=20previous=20config?= +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Signed-off-by: Augustin Husson +--- + .github/ISSUE_TEMPLATE/bug_report.yml | 2 +- + internal/cli/cmd/login/login.go | 29 +++++++++++++++------------ + internal/cli/config/config.go | 23 +++++++++++++++++++++ + 3 files changed, 40 insertions(+), 14 deletions(-) + +diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml +index f7fbce82d1..f27470fe29 100644 +--- a/.github/ISSUE_TEMPLATE/bug_report.yml ++++ b/.github/ISSUE_TEMPLATE/bug_report.yml +@@ -42,7 +42,7 @@ body: + - type: textarea + attributes: + label: Perses configuration file +- description: Insert relevant configuration here. Don't forget to remove secrets. ++ description: Insert relevant configuration here. Don't forget to remove secrets. You can use the CLI to get it (all secret will be hidden). percli config --online + render: yaml + - type: textarea + attributes: +diff --git a/internal/cli/cmd/login/login.go b/internal/cli/cmd/login/login.go +index b09b7a42b6..831daf2c6e 100644 +--- a/internal/cli/cmd/login/login.go ++++ b/internal/cli/cmd/login/login.go +@@ -90,20 +90,22 @@ func (o *option) Complete(args []string) error { + return fmt.Errorf("no URL has been provided neither found in the previous configuration") + } + +- // create a new apiClient +- o.restConfig = config.Global.RestClientConfig +- o.restConfig.URL = o.url +- if o.restConfig.TLSConfig == nil { +- o.restConfig.TLSConfig = &secret.TLSConfig{} ++ // Create a new apiClient from scratch. ++ // We shouldn't use the previous context as for the moment we have a single config. ++ // So, switching from a Perses instance to another one without restarting from scratch the context/ the Perses client doesn't make sense. ++ o.restConfig = clientConfig.RestConfigClient{ ++ URL: o.url, ++ TLSConfig: &secret.TLSConfig{ ++ InsecureSkipVerify: o.insecureTLS, ++ }, + } +- o.restConfig.TLSConfig.InsecureSkipVerify = o.insecureTLS + restClient, err := clientConfig.NewRESTClient(o.restConfig) + if err != nil { + return err + } + o.apiClient = api.NewWithClient(restClient) + +- // Finally get the API config, we will need for later ++ // Finally, get the API config; we will need it for later + cfg, err := o.apiClient.Config() + if err != nil { + return err +@@ -173,9 +175,10 @@ func (o *option) Execute() error { + o.accessToken = token.AccessToken + o.refreshToken = token.RefreshToken + } +- +- o.restConfig.Authorization = secret.NewBearerToken(o.accessToken) +- if writeErr := config.Write(&config.Config{ ++ if len(o.accessToken) > 0 { ++ o.restConfig.Authorization = secret.NewBearerToken(o.accessToken) ++ } ++ if writeErr := config.WriteFromScratch(&config.Config{ + RestClientConfig: o.restConfig, + RefreshToken: o.refreshToken, + }); writeErr != nil { +@@ -224,9 +227,9 @@ func (o *option) newLoginOption() (loginOption, error) { + + func (o *option) selectAndSetProvider() error { + providers := o.remoteConfig.Security.Authentication.Providers +- // The first step is to collect the different providers and store it into items + modifiers. +- // items will be the selection items to display to users. +- // modifiers will be the action to save the different user input into option struct. ++ // The first step is to collect the different providers and store it into options and modifiers. ++ // Options will be the selection items to display to users. ++ // Modifiers will be the action to save the different user input into option struct. + modifiers := map[string]func(){} + var options []huh.Option[string] + +diff --git a/internal/cli/config/config.go b/internal/cli/config/config.go +index e301642c79..645ce90a20 100644 +--- a/internal/cli/config/config.go ++++ b/internal/cli/config/config.go +@@ -220,3 +220,26 @@ func Write(cfg *Config) error { + + return os.WriteFile(filePath, data, 0600) + } ++ ++func WriteFromScratch(cfg *Config) error { ++ // this value has been set by the root command, and that will be the path where the config must be saved ++ filePath := Global.filePath ++ directory := filepath.Dir(filePath) ++ ++ if _, err := os.Stat(directory); os.IsNotExist(err) { ++ mkdirError := os.Mkdir(directory, 0700) ++ if mkdirError != nil { ++ return err ++ } ++ } else if err != nil { ++ return err ++ } ++ ++ data, err := json.Marshal(cfg) ++ ++ if err != nil { ++ return err ++ } ++ ++ return os.WriteFile(filePath, data, 0600) ++} diff --git a/perses-cli.changes b/perses-cli.changes index 5f2e25a..042a1bf 100644 --- a/perses-cli.changes +++ b/perses-cli.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Tue Dec 17 09:32:55 UTC 2024 - Johannes Kastl + +- backport patch b04061023c941d879460d81e6e4c6019621dbc16.patch to + fix failing logins + https://github.com/perses/perses/pull/2416 + ------------------------------------------------------------------- Tue Nov 12 06:52:05 UTC 2024 - opensuse_buildservice@ojkastl.de diff --git a/perses-cli.spec b/perses-cli.spec index a3d5dcb..a66d57b 100644 --- a/perses-cli.spec +++ b/perses-cli.spec @@ -26,6 +26,8 @@ License: Apache-2.0 URL: https://github.com/perses/perses Source: %{name}-%{version}.tar.gz Source1: vendor.tar.gz +# PATCH-FIX-UPSTREAM https://github.com/perses/perses/pull/2416 +Patch1: https://github.com/perses/perses/commit/b04061023c941d879460d81e6e4c6019621dbc16.patch BuildRequires: bash-completion BuildRequires: fish BuildRequires: go1.22 >= 1.22.5