Skip to content

Commit a67ba04

Browse files
committed
Show warning when both logged in and using api key
1 parent 9ffc814 commit a67ba04

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

internal/pkg/cli/command/logout/logout.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import (
44
"github.com/pinecone-io/cli/internal/pkg/utils/configuration/secrets"
55
"github.com/pinecone-io/cli/internal/pkg/utils/configuration/state"
66
"github.com/pinecone-io/cli/internal/pkg/utils/help"
7-
"github.com/pinecone-io/cli/internal/pkg/utils/pcio"
8-
"github.com/pinecone-io/cli/internal/pkg/utils/style"
7+
"github.com/pinecone-io/cli/internal/pkg/utils/msg"
98
"github.com/spf13/cobra"
109
)
1110

@@ -16,10 +15,10 @@ func NewLogoutCmd() *cobra.Command {
1615
GroupID: help.GROUP_START.ID,
1716
Run: func(cmd *cobra.Command, args []string) {
1817
secrets.ConfigFile.Clear()
19-
pcio.Println(style.SuccessMsg("Secrets cleared."))
18+
msg.SuccessMsg("API keys and user access tokens cleared.")
2019

2120
state.ConfigFile.Clear()
22-
pcio.Println(style.SuccessMsg("State cleared."))
21+
msg.SuccessMsg("State cleared.")
2322
},
2423
}
2524

internal/pkg/cli/command/target/target.go

-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ func postLoginSetTargetOrg(orgsResponse *dashboard.OrganizationsResponse) string
227227
orgName = orgsResponse.Organizations[0].Name
228228
log.Info().Msgf("Only 1 org present so target org set to %s", orgName)
229229
} else {
230-
pcio.Println()
231230
pcio.Println("Many API operations take place in the context of a specific org and project.")
232231
pcio.Println(pcio.Sprintf("This CLI maintains a piece of state called the %s so it knows which \n", style.Emphasis("target")) +
233232
"organization and project to use when calling the API on your behalf.")

internal/pkg/utils/sdk/client.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,19 @@ func newClientForUserFromTarget() *pinecone.Client {
4444
Msg("Loading target context")
4545

4646
apiKey := secrets.ApiKey.Get()
47+
oauth2Token := secrets.OAuth2Token.Get()
4748

4849
if apiKey != "" {
50+
if oauth2Token.AccessToken != "" {
51+
msg.WarnMsg("You are currently logged in and also have an API key set in your configuration. The API key (which is linked to a specific project) will be used in preference to any user authentication and target context that may be present.\n")
52+
}
53+
4954
log.Debug().Msg("Creating client for machine using stored API key")
5055
return NewClientForMachine(apiKey)
5156
}
5257

5358
log.Debug().Msg("No API key is stored in configuration, so attempting to create a client using user access token")
5459

55-
oauth2Token := secrets.OAuth2Token.Get()
56-
5760
if oauth2Token.AccessToken == "" {
5861
msg.FailMsg("Please set an API key with %s or login with %s before attempting this operation.", style.Code("pinecone config set-api-key"), style.Code("pinecone login"))
5962
exit.ErrorMsg("User is not logged in")

0 commit comments

Comments
 (0)