Add better documentation for the `auth login` command (#1366)

This PR improves the documentation for the `auth login` command,
accounting for the various ways this command can be used in.

---------

Co-authored-by: PaulCornellDB <paul.cornell@databricks.com>
Co-authored-by: Pieter Noordhuis <pieter.noordhuis@databricks.com>
This commit is contained in:
shreyas-goenka 2024-04-18 17:25:42 +05:30 committed by GitHub
parent 542156c30b
commit eb9665d2ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 49 additions and 4 deletions

View File

@ -16,9 +16,9 @@ func New() *cobra.Command {
authentication for the Databricks CLI and SDKs work please refer to the documentation authentication for the Databricks CLI and SDKs work please refer to the documentation
linked below. linked below.
AWS: https://docs.databricks.com/en/dev-tools/auth/index.html AWS: https://docs.databricks.com/dev-tools/auth/index.html
Azure: https://learn.microsoft.com/en-us/azure/databricks/dev-tools/auth Azure: https://learn.microsoft.com/azure/databricks/dev-tools/auth
GCP: https://docs.gcp.databricks.com/en/dev-tools/auth/index.html`, GCP: https://docs.gcp.databricks.com/dev-tools/auth/index.html`,
} }
var perisistentAuth auth.PersistentAuth var perisistentAuth auth.PersistentAuth

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"runtime"
"time" "time"
"github.com/databricks/cli/libs/auth" "github.com/databricks/cli/libs/auth"
@ -32,9 +33,53 @@ func configureHost(ctx context.Context, persistentAuth *auth.PersistentAuth, arg
const minimalDbConnectVersion = "13.1" const minimalDbConnectVersion = "13.1"
func newLoginCommand(persistentAuth *auth.PersistentAuth) *cobra.Command { func newLoginCommand(persistentAuth *auth.PersistentAuth) *cobra.Command {
defaultConfigPath := "~/.databrickscfg"
if runtime.GOOS == "windows" {
defaultConfigPath = "%USERPROFILE%\\.databrickscfg"
}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "login [HOST]", Use: "login [HOST]",
Short: "Authenticate this machine", Short: "Log into a Databricks workspace or account",
Long: fmt.Sprintf(`Log into a Databricks workspace or account.
This command logs you into the Databricks workspace or account and saves
the authentication configuration in a profile (in %s by default).
This profile can then be used to authenticate other Databricks CLI commands by
specifying the --profile flag. This profile can also be used to authenticate
other Databricks tooling that supports the Databricks Unified Authentication
Specification. This includes the Databricks Go, Python, and Java SDKs. For more information,
you can refer to the documentation linked below.
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
This command requires a Databricks Host URL (using --host or as a positional argument
or implicitly inferred from the specified profile name)
and a profile name (using --profile) to be specified. If you don't specify these
values, you'll be prompted for values at runtime.
While this command always logs you into the specified host, the runtime behaviour
depends on the existing profiles you have set in your configuration file
(at %s by default).
1. If a profile with the specified name exists and specifies a host, you'll
be logged into the host specified by the profile. The profile will be updated
to use "databricks-cli" as the auth type if that was not the case before.
2. If a profile with the specified name exists but does not specify a host,
you'll be prompted to specify a host. The profile will be updated to use the
specified host. The auth type will be updated to "databricks-cli" if that was
not the case before.
3. If a profile with the specified name exists and specifies a host, but you
specify a host using --host (or as the [HOST] positional arg), the profile will
be updated to use the newly specified host. The auth type will be updated to
"databricks-cli" if that was not the case before.
4. If a profile with the specified name does not exist, a new profile will be
created with the specified host. The auth type will be set to "databricks-cli".
`, defaultConfigPath, defaultConfigPath),
} }
var loginTimeout time.Duration var loginTimeout time.Duration