2023-01-06 15:15:57 +00:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
2023-07-12 15:36:09 +00:00
|
|
|
"context"
|
2024-08-14 13:01:00 +00:00
|
|
|
"fmt"
|
2023-07-12 15:36:09 +00:00
|
|
|
|
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) {
|
2024-08-14 13:01:00 +00:00
|
|
|
if !cmdio.IsInTTY(ctx) {
|
|
|
|
return "", fmt.Errorf("the command is being run in a non-interactive environment, please specify a host using --host")
|
2023-07-12 15:36:09 +00:00
|
|
|
}
|
2024-08-14 13:01:00 +00:00
|
|
|
|
|
|
|
prompt := cmdio.Prompt(ctx)
|
|
|
|
prompt.Label = "Databricks host (e.g. https://<databricks-instance>.cloud.databricks.com)"
|
|
|
|
return prompt.Run()
|
2023-07-12 15:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func promptForAccountID(ctx context.Context) (string, error) {
|
2024-08-14 13:01:00 +00:00
|
|
|
if !cmdio.IsInTTY(ctx) {
|
|
|
|
return "", fmt.Errorf("the command is being run in a non-interactive environment, please specify an account ID using --account-id")
|
|
|
|
}
|
|
|
|
|
2023-07-12 15:36:09 +00:00
|
|
|
prompt := cmdio.Prompt(ctx)
|
2024-08-14 13:01:00 +00:00
|
|
|
prompt.Label = "Databricks account ID"
|
2023-07-12 15:36:09 +00:00
|
|
|
prompt.Default = ""
|
|
|
|
prompt.AllowEdit = true
|
2024-08-14 13:01:00 +00:00
|
|
|
return prompt.Run()
|
2023-07-12 15:36:09 +00:00
|
|
|
}
|