2023-01-06 15:15:57 +00:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
2023-07-12 15:36:09 +00:00
|
|
|
"context"
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/libs/auth"
|
2023-07-12 15:36:09 +00:00
|
|
|
"github.com/databricks/cli/libs/cmdio"
|
2023-01-06 15:15:57 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2023-07-27 10:03:08 +00:00
|
|
|
func New() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "auth",
|
|
|
|
Short: "Authentication related commands",
|
|
|
|
}
|
|
|
|
|
|
|
|
var perisistentAuth auth.PersistentAuth
|
|
|
|
cmd.PersistentFlags().StringVar(&perisistentAuth.Host, "host", perisistentAuth.Host, "Databricks Host")
|
|
|
|
cmd.PersistentFlags().StringVar(&perisistentAuth.AccountID, "account-id", perisistentAuth.AccountID, "Databricks Account ID")
|
2023-01-06 15:15:57 +00:00
|
|
|
|
2023-07-27 10:03:08 +00:00
|
|
|
cmd.AddCommand(newEnvCommand())
|
|
|
|
cmd.AddCommand(newLoginCommand(&perisistentAuth))
|
|
|
|
cmd.AddCommand(newProfilesCommand())
|
|
|
|
cmd.AddCommand(newTokenCommand(&perisistentAuth))
|
|
|
|
return cmd
|
|
|
|
}
|
2023-07-12 15:36:09 +00:00
|
|
|
|
|
|
|
func promptForHost(ctx context.Context) (string, error) {
|
|
|
|
prompt := cmdio.Prompt(ctx)
|
|
|
|
prompt.Label = "Databricks Host"
|
|
|
|
prompt.Default = "https://"
|
|
|
|
prompt.AllowEdit = true
|
|
|
|
// Validate?
|
|
|
|
host, err := prompt.Run()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return host, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func promptForAccountID(ctx context.Context) (string, error) {
|
|
|
|
prompt := cmdio.Prompt(ctx)
|
|
|
|
prompt.Label = "Databricks Account ID"
|
|
|
|
prompt.Default = ""
|
|
|
|
prompt.AllowEdit = true
|
|
|
|
// Validate?
|
|
|
|
accountId, err := prompt.Run()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return accountId, nil
|
|
|
|
}
|