Skip to content

Commit

Permalink
Drop support for log in with user & password
Browse files Browse the repository at this point in the history
  • Loading branch information
joanlopez committed Aug 5, 2024
1 parent 913b280 commit 1ae078b
Showing 1 changed file with 7 additions and 45 deletions.
52 changes: 7 additions & 45 deletions cmd/cloud_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"encoding/json"
"errors"
"fmt"
"syscall"

Expand All @@ -13,7 +12,6 @@ import (

"go.k6.io/k6/cloudapi"
"go.k6.io/k6/cmd/state"
"go.k6.io/k6/lib/consts"
"go.k6.io/k6/ui"
)

Expand All @@ -30,7 +28,7 @@ func getCmdCloudLogin(gs *state.GlobalState) *cobra.Command {

// loginCloudCommand represents the 'cloud login' command
exampleText := getExampleText(gs, `
# Log in with an email/password
# Prompt for a Grafana Cloud k6 token
{{.}} cloud login
# Store a token in k6's persistent configuration
Expand Down Expand Up @@ -82,18 +80,6 @@ func (c *cmdCloudLogin) run(cmd *cobra.Command, _ []string) error {
}
}

// We want to use this fully consolidated config for things like
// host addresses, so users can overwrite them with env vars.
consolidatedCurrentConfig, warn, err := cloudapi.GetConsolidatedConfig(
currentJSONConfigRaw, c.globalState.Env, "", nil, nil)
if err != nil {
return err
}

if warn != "" {
c.globalState.Logger.Warn(warn)
}

// But we don't want to save them back to the JSON file, we only
// want to save what already existed there and the login details.
newCloudConf := currentJSONConfig
Expand All @@ -110,15 +96,13 @@ func (c *cmdCloudLogin) run(cmd *cobra.Command, _ []string) error {
newCloudConf.Token = token
default:
form := ui.Form{
Banner: "Please enter your Grafana Cloud k6 credentials",
Banner: "Enter your token to authenticate with Grafana Cloud k6.\n" +
"Please, consult the Grafana Cloud k6 documentation for instructions on how to generate one:\n" +
"https://grafana.com/docs/grafana-cloud/testing/k6/author-run/tokens-and-cli-authentication",
Fields: []ui.Field{
ui.StringField{
Key: "Email",
Label: "Email",
},
ui.PasswordField{
Key: "Password",
Label: "Password",
Key: "Token",
Label: "Token",
},
},
}
Expand All @@ -130,29 +114,7 @@ func (c *cmdCloudLogin) run(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
email := vals["Email"]
password := vals["Password"]

client := cloudapi.NewClient(
c.globalState.Logger,
"",
consolidatedCurrentConfig.Host.String,
consts.Version,
consolidatedCurrentConfig.Timeout.TimeDuration())

var res *cloudapi.LoginResponse
res, err = client.Login(email, password)
if err != nil {
return err
}

if res.Token == "" {
return errors.New("your account does not appear to have an active API token, please consult the " +
"Grafana Cloud k6 documentation for instructions on how to generate " +
"one: https://grafana.com/docs/grafana-cloud/testing/k6/author-run/tokens-and-cli-authentication")
}

newCloudConf.Token = null.StringFrom(res.Token)
newCloudConf.Token = null.StringFrom(vals["Token"])
}

if currentDiskConf.Collectors == nil {
Expand Down

0 comments on commit 1ae078b

Please sign in to comment.