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",
|
2024-04-15 16:43:46 +00:00
|
|
|
Long: `Authentication related commands. For more information regarding how
|
|
|
|
authentication for the Databricks CLI and SDKs work please refer to the documentation
|
|
|
|
linked below.
|
|
|
|
|
2024-04-18 11:55:42 +00:00
|
|
|
AWS: https://docs.databricks.com/dev-tools/auth/index.html
|
|
|
|
Azure: https://learn.microsoft.com/azure/databricks/dev-tools/auth
|
|
|
|
GCP: https://docs.gcp.databricks.com/dev-tools/auth/index.html`,
|
2023-07-27 10:03:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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))
|
2024-04-03 08:14:04 +00:00
|
|
|
cmd.AddCommand(newDescribeCommand())
|
2023-07-27 10:03:08 +00:00
|
|
|
return cmd
|
|
|
|
}
|
2023-07-12 15:36:09 +00:00
|
|
|
|
|
|
|
func promptForHost(ctx context.Context) (string, error) {
|
|
|
|
prompt := cmdio.Prompt(ctx)
|
2024-04-15 17:31:00 +00:00
|
|
|
prompt.Label = "Databricks Host (e.g. https://<databricks-instance>.cloud.databricks.com)"
|
2023-07-12 15:36:09 +00:00
|
|
|
// 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
|
|
|
|
}
|