-
Notifications
You must be signed in to change notification settings - Fork 145
Respect BROWSER environment variable in "auth login" command
#3659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e8e5742
d1c8e54
648197b
103a911
f0d2ca1
4643a4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| This script fetches a URL. | ||
| It follows redirects if applicable. | ||
|
|
||
| Usage: browser.py <url> | ||
| """ | ||
|
|
||
| import urllib.request | ||
| import sys | ||
|
|
||
| if len(sys.argv) < 2: | ||
| sys.stderr.write("Usage: browser.py <url>\n") | ||
| sys.exit(1) | ||
|
|
||
| url = sys.argv[1] | ||
| try: | ||
| response = urllib.request.urlopen(url) | ||
| if response.status != 200: | ||
| sys.stderr.write(f"Failed to fetch URL: {url} (status {response.status})\n") | ||
| sys.exit(1) | ||
| except Exception as e: | ||
| sys.stderr.write(f"Failed to fetch URL: {url} ({e})\n") | ||
| sys.exit(1) | ||
|
|
||
| sys.exit(0) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| ; The profile defined in the DEFAULT section is to be used as a fallback when no profile is explicitly specified. | ||
| [DEFAULT] | ||
|
|
||
| [test] | ||
| host = [DATABRICKS_URL] | ||
| auth_type = databricks-cli |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
|
|
||
| >>> [CLI] auth login --host [DATABRICKS_URL] --profile test | ||
| Profile test was successfully saved | ||
|
|
||
| >>> [CLI] auth profiles | ||
| Name Host Valid | ||
| test [DATABRICKS_URL] YES |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| sethome "./home" | ||
|
|
||
| # Use a fake browser that performs a GET on the authorization URL | ||
| # and follows the redirect back to localhost. | ||
| export BROWSER="browser.py" | ||
|
|
||
| trace $CLI auth login --host $DATABRICKS_HOST --profile test | ||
| trace $CLI auth profiles | ||
|
|
||
| # Track the .databrickscfg file that was created to surface changes. | ||
| mv "./home/.databrickscfg" "./out.databrickscfg" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Ignore = [ | ||
| "home" | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,3 +97,14 @@ envsubst() { | |
| print_telemetry_bool_values() { | ||
| jq -r 'select(.path? == "/telemetry-ext") | (.body.protoLogs // [])[] | fromjson | ( (.entry // .) | (.databricks_cli_log.bundle_deploy_event.experimental.bool_values // []) ) | map("\(.key) \(.value)") | .[]' out.requests.txt | sort | ||
| } | ||
|
|
||
| sethome() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why add it here if it's only used in one test?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I spent a few iterations figuring out why something was failing on Windows only to find out that the wrong $HOME-equivalent environment variable was set. With a helper it is more likely that the right thing is copy/pasted into other acceptance tests. |
||
| local home="$1" | ||
| mkdir -p "$home" | ||
|
|
||
| # For macOS and Linux, use HOME. | ||
| export HOME="$home" | ||
|
|
||
| # For Windows, use USERPROFILE. | ||
| export USERPROFILE="$home" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package testserver | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "net/url" | ||
| ) | ||
|
|
||
| // FakeOidc holds OAuth state for acceptance tests. | ||
| type FakeOidc struct { | ||
| url string | ||
| } | ||
|
|
||
| func (s *FakeOidc) OidcEndpoints() Response { | ||
| return Response{ | ||
| Body: map[string]string{ | ||
| "authorization_endpoint": s.url + "/oidc/v1/authorize", | ||
| "token_endpoint": s.url + "/oidc/v1/token", | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (s *FakeOidc) OidcAuthorize(req Request) Response { | ||
| redirectURI, err := url.Parse(req.URL.Query().Get("redirect_uri")) | ||
| if err != nil { | ||
| return Response{ | ||
| StatusCode: http.StatusBadRequest, | ||
| Body: err.Error(), | ||
| } | ||
| } | ||
|
|
||
| // Compile query parameters for the redirect URL. | ||
| q := make(url.Values) | ||
|
|
||
| // Include an opaque authorization code that will be used to exchange for a token. | ||
| q.Set("code", "oauth-code") | ||
|
|
||
| // Include the state parameter from the original request. | ||
| q.Set("state", req.URL.Query().Get("state")) | ||
|
|
||
| // Update the redirect URI with the new query parameters. | ||
| redirectURI.RawQuery = q.Encode() | ||
|
|
||
| return Response{ | ||
| StatusCode: http.StatusMovedPermanently, | ||
| Headers: map[string][]string{ | ||
| "Location": {redirectURI.String()}, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (s *FakeOidc) OidcToken(req Request) Response { | ||
| return Response{ | ||
| Body: map[string]string{ | ||
| "access_token": "oauth-token", | ||
| "expires_in": "3600", | ||
| "scope": "all-apis", | ||
| "token_type": "Bearer", | ||
| }, | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: not needed.