From 3f4faf4d9cea50edf74602bad4d2623b2d1f3322 Mon Sep 17 00:00:00 2001 From: Harshjeet Patil Date: Thu, 1 Jan 2026 22:57:54 +0530 Subject: [PATCH 01/12] chnages added for the bug --- internal/wrappers/client.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/wrappers/client.go b/internal/wrappers/client.go index bf20407f2..50dd866b2 100644 --- a/internal/wrappers/client.go +++ b/internal/wrappers/client.go @@ -612,10 +612,10 @@ func configureClientCredentialsAndGetNewToken() (string, error) { return "", err } - if astAPIKey != "" { - accessToken, err = getNewToken(getAPIKeyPayload(astAPIKey), authURI) - } else { + if accessKeyID != "" { accessToken, err = getNewToken(getCredentialsPayload(accessKeyID, accessKeySecret), authURI) + } else { + accessToken, err = getNewToken(getAPIKeyPayload(astAPIKey), authURI) } if err != nil { @@ -874,6 +874,8 @@ func GetAuthURI() (string, error) { override := viper.GetBool(commonParams.ApikeyOverrideFlag) apiKey := viper.GetString(commonParams.AstAPIKey) + //accessKeyID := viper.GetString(commonParams.AccessKeyIDConfigKey) + if len(apiKey) > 0 { logger.PrintIfVerbose("Base Auth URI - Extract from API KEY") authURI, err = ExtractFromTokenClaims(apiKey, audienceClaimKey) From 1c3f1d93f3de98fe8269bed54afa34efe9f57064 Mon Sep 17 00:00:00 2001 From: Harshjeet Patil Date: Thu, 1 Jan 2026 23:05:48 +0530 Subject: [PATCH 02/12] some new chnages for bug --- internal/wrappers/client.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/wrappers/client.go b/internal/wrappers/client.go index 50dd866b2..3b8981160 100644 --- a/internal/wrappers/client.go +++ b/internal/wrappers/client.go @@ -980,4 +980,5 @@ func extractAZPFromToken(astToken string) (string, error) { return "ast-app", nil // default value in case of error } return azp, nil + } From fc453adaa23bc8efc92a3f113caa7e8909878c4d Mon Sep 17 00:00:00 2001 From: Harshjeet Patil Date: Thu, 1 Jan 2026 23:08:45 +0530 Subject: [PATCH 03/12] chnages restored --- internal/wrappers/client.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/wrappers/client.go b/internal/wrappers/client.go index 3b8981160..50dd866b2 100644 --- a/internal/wrappers/client.go +++ b/internal/wrappers/client.go @@ -980,5 +980,4 @@ func extractAZPFromToken(astToken string) (string, error) { return "ast-app", nil // default value in case of error } return azp, nil - } From f7d0138106f4f5bc8b164af89863105677327bed Mon Sep 17 00:00:00 2001 From: Harshjeet Patil Date: Thu, 1 Jan 2026 23:10:35 +0530 Subject: [PATCH 04/12] comment removed --- internal/wrappers/client.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/wrappers/client.go b/internal/wrappers/client.go index 50dd866b2..1699966bc 100644 --- a/internal/wrappers/client.go +++ b/internal/wrappers/client.go @@ -874,7 +874,6 @@ func GetAuthURI() (string, error) { override := viper.GetBool(commonParams.ApikeyOverrideFlag) apiKey := viper.GetString(commonParams.AstAPIKey) - //accessKeyID := viper.GetString(commonParams.AccessKeyIDConfigKey) if len(apiKey) > 0 { logger.PrintIfVerbose("Base Auth URI - Extract from API KEY") From 111d604635f24eeeb1cf2a5a49d7af6160650bb4 Mon Sep 17 00:00:00 2001 From: Harshjeet Patil Date: Thu, 1 Jan 2026 23:14:23 +0530 Subject: [PATCH 05/12] code matched to main --- internal/wrappers/client.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/wrappers/client.go b/internal/wrappers/client.go index 1699966bc..534a77ac9 100644 --- a/internal/wrappers/client.go +++ b/internal/wrappers/client.go @@ -874,7 +874,6 @@ func GetAuthURI() (string, error) { override := viper.GetBool(commonParams.ApikeyOverrideFlag) apiKey := viper.GetString(commonParams.AstAPIKey) - if len(apiKey) > 0 { logger.PrintIfVerbose("Base Auth URI - Extract from API KEY") authURI, err = ExtractFromTokenClaims(apiKey, audienceClaimKey) From cd90cd3f371e4d5b7bd36c6ed2d01090d26d7906 Mon Sep 17 00:00:00 2001 From: Harshjeet Patil Date: Fri, 2 Jan 2026 21:44:21 +0530 Subject: [PATCH 06/12] new changes for the bug --- internal/wrappers/client.go | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/internal/wrappers/client.go b/internal/wrappers/client.go index 534a77ac9..b7b15f71b 100644 --- a/internal/wrappers/client.go +++ b/internal/wrappers/client.go @@ -5,6 +5,7 @@ import ( "crypto/tls" "encoding/json" "fmt" + "github.com/spf13/cobra" "io" "io/ioutil" "net" @@ -595,10 +596,19 @@ func enrichWithPasswordCredentials( return nil } -func configureClientCredentialsAndGetNewToken() (string, error) { - accessKeyID := viper.GetString(commonParams.AccessKeyIDConfigKey) - accessKeySecret := viper.GetString(commonParams.AccessKeySecretConfigKey) - astAPIKey := viper.GetString(commonParams.AstAPIKey) +func configureClientCredentialsAndGetNewToken(cmd *cobra.Command) (string, error) { + // 🔹 Read CLI values first + accessKeyID, _ := cmd.Flags().GetString(commonParams.AccessKeyIDConfigKey) + accessKeySecret, _ := cmd.Flags().GetString(commonParams.AccessKeySecretConfigKey) + astAPIKey, _ := cmd.Flags().GetString(commonParams.AstAPIKey) + + // 🔹 If nothing passed via CLI, fall back to config + if accessKeyID == "" && accessKeySecret == "" && astAPIKey == "" { + accessKeyID = viper.GetString(commonParams.AccessKeyIDConfigKey) + accessKeySecret = viper.GetString(commonParams.AccessKeySecretConfigKey) + astAPIKey = viper.GetString(commonParams.AstAPIKey) + } + var accessToken string if accessKeyID == "" && astAPIKey == "" { @@ -613,9 +623,15 @@ func configureClientCredentialsAndGetNewToken() (string, error) { } if accessKeyID != "" { - accessToken, err = getNewToken(getCredentialsPayload(accessKeyID, accessKeySecret), authURI) + accessToken, err = getNewToken( + getCredentialsPayload(accessKeyID, accessKeySecret), + authURI, + ) } else { - accessToken, err = getNewToken(getAPIKeyPayload(astAPIKey), authURI) + accessToken, err = getNewToken( + getAPIKeyPayload(astAPIKey), + authURI, + ) } if err != nil { @@ -623,7 +639,6 @@ func configureClientCredentialsAndGetNewToken() (string, error) { } writeCredentialsToCache(accessToken) - return accessToken, nil } From f5daffa5ffe20312293516a713790f474cf2669b Mon Sep 17 00:00:00 2001 From: Harshjeet Patil Date: Fri, 2 Jan 2026 23:02:40 +0530 Subject: [PATCH 07/12] final code changes --- internal/commands/root.go | 7 +++++++ internal/wrappers/client.go | 23 +++++++---------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/internal/commands/root.go b/internal/commands/root.go index 453070073..03be18054 100644 --- a/internal/commands/root.go +++ b/internal/commands/root.go @@ -123,6 +123,13 @@ func NewAstCLI( if err != nil { return err } + if cmd.Flags().Changed(params.AccessKeyIDFlag) || cmd.Flags().Changed(params.AccessKeySecretFlag) { + viper.Set(params.AstAPIKey, "") + } + if cmd.Flags().Changed(params.AstAPIKeyFlag) { + viper.Set(params.AccessKeyIDConfigKey, "") + viper.Set(params.AccessKeySecretConfigKey, "") + } // Need to check the __complete command to allow correct behavior of the autocomplete if len(args) > 0 && cmd.Name() != params.Help && cmd.Name() != "__complete" { _ = cmd.Help() diff --git a/internal/wrappers/client.go b/internal/wrappers/client.go index b7b15f71b..cb2ccc750 100644 --- a/internal/wrappers/client.go +++ b/internal/wrappers/client.go @@ -5,7 +5,6 @@ import ( "crypto/tls" "encoding/json" "fmt" - "github.com/spf13/cobra" "io" "io/ioutil" "net" @@ -596,18 +595,10 @@ func enrichWithPasswordCredentials( return nil } -func configureClientCredentialsAndGetNewToken(cmd *cobra.Command) (string, error) { - // 🔹 Read CLI values first - accessKeyID, _ := cmd.Flags().GetString(commonParams.AccessKeyIDConfigKey) - accessKeySecret, _ := cmd.Flags().GetString(commonParams.AccessKeySecretConfigKey) - astAPIKey, _ := cmd.Flags().GetString(commonParams.AstAPIKey) - - // 🔹 If nothing passed via CLI, fall back to config - if accessKeyID == "" && accessKeySecret == "" && astAPIKey == "" { - accessKeyID = viper.GetString(commonParams.AccessKeyIDConfigKey) - accessKeySecret = viper.GetString(commonParams.AccessKeySecretConfigKey) - astAPIKey = viper.GetString(commonParams.AstAPIKey) - } +func configureClientCredentialsAndGetNewToken() (string, error) { + accessKeyID := viper.GetString(commonParams.AccessKeyIDConfigKey) + accessKeySecret := viper.GetString(commonParams.AccessKeySecretConfigKey) + astAPIKey := viper.GetString(commonParams.AstAPIKey) var accessToken string @@ -622,14 +613,14 @@ func configureClientCredentialsAndGetNewToken(cmd *cobra.Command) (string, error return "", err } - if accessKeyID != "" { + if astAPIKey != "" { accessToken, err = getNewToken( - getCredentialsPayload(accessKeyID, accessKeySecret), + getAPIKeyPayload(astAPIKey), authURI, ) } else { accessToken, err = getNewToken( - getAPIKeyPayload(astAPIKey), + getCredentialsPayload(accessKeyID, accessKeySecret), authURI, ) } From bd300695df5a7c90d2931cd76ce0d7b897daf2f1 Mon Sep 17 00:00:00 2001 From: Harshjeet Patil Date: Mon, 5 Jan 2026 14:20:35 +0530 Subject: [PATCH 08/12] new changes --- internal/commands/root.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/commands/root.go b/internal/commands/root.go index 03be18054..4cc5a7e2c 100644 --- a/internal/commands/root.go +++ b/internal/commands/root.go @@ -1,6 +1,7 @@ package commands import ( + "errors" "fmt" "io" "log" From cd45691b37add98427e2e61d85fc086ba5dd2e05 Mon Sep 17 00:00:00 2001 From: Harshjeet Patil Date: Mon, 5 Jan 2026 14:23:29 +0530 Subject: [PATCH 09/12] removed unused dependency --- internal/commands/root.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/commands/root.go b/internal/commands/root.go index 4cc5a7e2c..03be18054 100644 --- a/internal/commands/root.go +++ b/internal/commands/root.go @@ -1,7 +1,6 @@ package commands import ( - "errors" "fmt" "io" "log" From a2ec18fdf104fe062f079199f40e4d583ff1bd92 Mon Sep 17 00:00:00 2001 From: Harshjeet Patil Date: Mon, 5 Jan 2026 14:28:08 +0530 Subject: [PATCH 10/12] file restored --- internal/wrappers/client.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/internal/wrappers/client.go b/internal/wrappers/client.go index cb2ccc750..bf20407f2 100644 --- a/internal/wrappers/client.go +++ b/internal/wrappers/client.go @@ -599,7 +599,6 @@ func configureClientCredentialsAndGetNewToken() (string, error) { accessKeyID := viper.GetString(commonParams.AccessKeyIDConfigKey) accessKeySecret := viper.GetString(commonParams.AccessKeySecretConfigKey) astAPIKey := viper.GetString(commonParams.AstAPIKey) - var accessToken string if accessKeyID == "" && astAPIKey == "" { @@ -614,15 +613,9 @@ func configureClientCredentialsAndGetNewToken() (string, error) { } if astAPIKey != "" { - accessToken, err = getNewToken( - getAPIKeyPayload(astAPIKey), - authURI, - ) + accessToken, err = getNewToken(getAPIKeyPayload(astAPIKey), authURI) } else { - accessToken, err = getNewToken( - getCredentialsPayload(accessKeyID, accessKeySecret), - authURI, - ) + accessToken, err = getNewToken(getCredentialsPayload(accessKeyID, accessKeySecret), authURI) } if err != nil { @@ -630,6 +623,7 @@ func configureClientCredentialsAndGetNewToken() (string, error) { } writeCredentialsToCache(accessToken) + return accessToken, nil } From d8811b10ea27ed8afb62cc084c5b62e2c8fc3554 Mon Sep 17 00:00:00 2001 From: Harshjeet Patil Date: Mon, 5 Jan 2026 15:30:58 +0530 Subject: [PATCH 11/12] commit --- internal/wrappers/client.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/wrappers/client.go b/internal/wrappers/client.go index bf20407f2..bcb5d594a 100644 --- a/internal/wrappers/client.go +++ b/internal/wrappers/client.go @@ -978,4 +978,5 @@ func extractAZPFromToken(astToken string) (string, error) { return "ast-app", nil // default value in case of error } return azp, nil + } From eeb676551bf62ae8b46e2ab99eadfb1c0de18f20 Mon Sep 17 00:00:00 2001 From: Harshjeet Patil Date: Mon, 5 Jan 2026 15:32:03 +0530 Subject: [PATCH 12/12] file restored --- internal/wrappers/client.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/wrappers/client.go b/internal/wrappers/client.go index bcb5d594a..bf20407f2 100644 --- a/internal/wrappers/client.go +++ b/internal/wrappers/client.go @@ -978,5 +978,4 @@ func extractAZPFromToken(astToken string) (string, error) { return "ast-app", nil // default value in case of error } return azp, nil - }