Skip to content

Fix databricks CLI authentication on Windows#192

Merged
mgyucht merged 13 commits intomainfrom
fix-windows-databricks-cli-auth
Nov 24, 2023
Merged

Fix databricks CLI authentication on Windows#192
mgyucht merged 13 commits intomainfrom
fix-windows-databricks-cli-auth

Conversation

@mgyucht
Copy link
Copy Markdown
Contributor

@mgyucht mgyucht commented Nov 23, 2023

Changes

There are two problems with respect to the Java SDK's auth pathways:

  1. The logic to find the .databrickscfg file only works on *nix, as it hard-codes the path using forward-slashes. I've rewritten this to use Paths.get.
  2. The databricks binary on Windows is called databricks.exe, not databricks, so we need to search for the binary with OS-specific filename.

To make this change unit-testable, I introduce an Environment class to abstract over environment variables, the search path for the databricks CLI executable, and the operating system name. This is needed because there are both differences in the environment variable name (PATH in Linux/Mac vs Path in Windows) and in the path separator (: in Linux/Mac vs ; in Windows). The only system-independent way to get the path seems to be System.getenv("PATH") which works even on Windows. Note that System.getenv().get("PATH") doesn't work on Windows. Additionally, determining the OS depends on System.getProperty, so this can be initialized directly in DatabricksConfig and mocked in unit tests.

Tests

Manually tested on a Windows machine:

  1. Installed the Databricks CLI and ran .\datarbricks.exe auth login --host <HOST>.
  2. Added the Databricks CLI to the PATH system environment variable.
  3. Ran the CLIWorkspaceAuth example and was able to list clusters.

As a side note: when we make auth permutations test harnesses, we should have a Windows variant to catch these errors.

Copy link
Copy Markdown
Contributor

@tanmay-db tanmay-db left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. LGTM

LOG.debug("Found executable named '" + name + "' in PATH: " + pathStr);
return pathStr;
}
LOG.debug("Failed to find executable named '" + name + "' in PATH");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are mentioning failed in the message -- this probably should be LOG.warn

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is an indication that there is a problem though. The user may legitimately not have installed the CLI in their system (e.g. on a webserver).

*/
public static void main(String[] args) {
DatabricksConfig config = getConfig();
// DatabricksConfig config = getConfig();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove this comment from demo?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, thanks for the reminder, I was going to undo this change

@mgyucht mgyucht enabled auto-merge November 24, 2023 14:00
@mgyucht mgyucht force-pushed the fix-windows-databricks-cli-auth branch from 7bec2dc to e5fd5d9 Compare November 24, 2023 14:35
@mgyucht mgyucht added this pull request to the merge queue Nov 24, 2023
Merged via the queue into main with commit f814e5b Nov 24, 2023
@mgyucht mgyucht deleted the fix-windows-databricks-cli-auth branch November 24, 2023 14:39
mgyucht added a commit that referenced this pull request Nov 29, 2023
Bug fixes:

* Fix databricks CLI authentication on Windows ([#192](#192)).
* Fix SCIM pagination ([#193](#193)).

Other changes:

* Add more detailed error message on default credentials not found error ([#180](#180)).
* Support custom scopes and redirectUrl for U2M OAuth flow ([#190](#190)).

API Changes:

 * Removed `enableOptimization()` method for `workspaceClient.metastores()` service.
 * Added `pipelineId` field for `com.databricks.sdk.service.catalog.TableInfo`.
 * Added `enablePredictiveOptimization` field for `com.databricks.sdk.service.catalog.UpdateCatalog` and `com.databricks.sdk.service.catalog.UpdateSchema`.
 * Removed `com.databricks.sdk.service.catalog.UpdatePredictiveOptimization` and `com.databricks.sdk.service.catalog.UpdatePredictiveOptimizationResponse` class.
 * Added `description` field for `com.databricks.sdk.service.jobs.CreateJob` and `com.databricks.sdk.service.jobs.JobSettings`.
 * Added `listNetworkConnectivityConfigurations()` and `listPrivateEndpointRules()` methods for `accountClient.networkConnectivity()` service.
 * Added `com.databricks.sdk.service.settings.ListNccAzurePrivateEndpointRulesResponse`, `com.databricks.sdk.service.settings.ListNetworkConnectivityConfigurationsRequest`, `com.databricks.sdk.service.settings.ListNetworkConnectivityConfigurationsResponse`, and `com.databricks.sdk.service.settings.ListPrivateEndpointRulesRequest` classes.
 * Added `stringSharedAs` field for `com.databricks.sdk.service.sharing.SharedDataObject`.

OpenAPI SHA: 22f09783eb8a84d52026f856be3b2068f9498db3, Date: 2023-11-23

Dependency updates:

 * Bump API spec: 23 Nov 2023 ([#191](#191)).
@mgyucht mgyucht mentioned this pull request Nov 29, 2023
github-merge-queue bot pushed a commit that referenced this pull request Nov 29, 2023
Bug fixes:

* Fix databricks CLI authentication on Windows
([#192](#192)).
* Fix SCIM pagination
([#193](#193)).

Other changes:

* Add more detailed error message on default credentials not found error
([#180](#180)).
* Support custom scopes and redirectUrl for U2M OAuth flow
([#190](#190)).

API Changes:

* Removed `enableOptimization()` method for
`workspaceClient.metastores()` service.
* Added `pipelineId` field for
`com.databricks.sdk.service.catalog.TableInfo`.
* Added `enablePredictiveOptimization` field for
`com.databricks.sdk.service.catalog.UpdateCatalog` and
`com.databricks.sdk.service.catalog.UpdateSchema`.
* Removed
`com.databricks.sdk.service.catalog.UpdatePredictiveOptimization` and
`com.databricks.sdk.service.catalog.UpdatePredictiveOptimizationResponse`
class.
* Added `description` field for
`com.databricks.sdk.service.jobs.CreateJob` and
`com.databricks.sdk.service.jobs.JobSettings`.
* Added `listNetworkConnectivityConfigurations()` and
`listPrivateEndpointRules()` methods for
`accountClient.networkConnectivity()` service.
* Added
`com.databricks.sdk.service.settings.ListNccAzurePrivateEndpointRulesResponse`,
`com.databricks.sdk.service.settings.ListNetworkConnectivityConfigurationsRequest`,
`com.databricks.sdk.service.settings.ListNetworkConnectivityConfigurationsResponse`,
and
`com.databricks.sdk.service.settings.ListPrivateEndpointRulesRequest`
classes.
* Added `stringSharedAs` field for
`com.databricks.sdk.service.sharing.SharedDataObject`.

OpenAPI SHA: 22f09783eb8a84d52026f856be3b2068f9498db3, Date: 2023-11-23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants