cli icon indicating copy to clipboard operation
cli copied to clipboard

Fix `databricks configure` to use DATABRICKS_CONFIG_FILE environment variable if exists as config file

Open kai-zhu-sonatype opened this issue 10 months ago • 5 comments

Changes

added ConfigFile: cfg.ConfigFile for databrickscfg.SaveToProfile in cmd/configure/configure.go to save the file in a specified path when the value is not empty

Tests

TestConfigFileFromEnvNoInteractive in cmd/configure/configure_test.go sets a different config file path by DATABRICKS_CONFIG_FILE, after execution, the overwrite config file is generated, and the default path has no file.

kai-zhu-sonatype avatar Mar 28 '24 09:03 kai-zhu-sonatype

@kai-zhu-sonatype thanks for the contribution! could you please clarify what are you trying to achieve with this change? current behaviour is if DATABRICKS_CONFIG_FILE is provided, cfg.ConfigFile should be set to this value as well and databrickscfg.SaveToProfile should save to DATABRICKS_CONFIG_FILE which effectively means that the pass of the file is going to be written in the profile.

andrewnester avatar Mar 28 '24 14:03 andrewnester

Thanks @andrewnester for your response. currently trying to use databrick configure with DATABRICKS_CONFIG_FILE, it seems not used to change config file location. if looking the test TestConfigFileFromEnvNoInteractive in cmd/configure/configure_test.go, because the setup(t) is set HOME to tempHomeDir, then cfgPath still is the default path {HOME}/.databrickscfg, the test hasn't covered the case if the config file set a different path, for example: changing .databrickscfg to any other name .databrickscfg-test, the test will fail.

cfgPath := filepath.Join(tempHomeDir, ".databrickscfg-test")
t.Setenv("DATABRICKS_CONFIG_FILE", cfgPath)

adding to pass cfg.ConfigFile to databrickscfg.SaveToProfile, DATABRICKS_CONFIG_FILE is used. debug log shows before and after the change before: should save in /tmp/.databrickscfg-test, but still /home/ubuntu/.databrickscfg

❯ DATABRICKS_CONFIG_FILE=/tmp/.databrickscfg-test DATABRICKS_HOST=https://test DATABRICKS_TOKEN=TEST databricks configure --profile jenkins --debug
10:36:05  INFO start pid=7725 version=0.216.0 args="databricks, configure, --profile, jenkins, --debug"tabricks configure --profile jenkins --debug
10:36:05  INFO Backing up in /home/ubuntu/.databrickscfg.bak pid=7725
10:36:05  INFO Overwriting /home/ubuntu/.databrickscfg pid=7725
10:36:05  INFO completed execution pid=7725 exit_code=0

after: change to the specified location /tmp/.databrickscfg-test

❯ DATABRICKS_CONFIG_FILE=/tmp/.databrickscfg-test DATABRICKS_HOST=https://test DATABRICKS_TOKEN=TEST ./cli configure --profile jenkins --debug
10:35:31  INFO start pid=7675 version=0.0.0-dev+b0529cdd16c7 args="./cli, configure, --profile, jenkins, --debug"ure --profile jenkins --debug 
10:35:31  INFO Saving /tmp/.databrickscfg-test pid=7675
10:35:31  INFO completed execution pid=7675 exit_code=0

kai-zhu-sonatype avatar Mar 28 '24 14:03 kai-zhu-sonatype

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 53.77%. Comparing base (e22dd8a) to head (278c2e7). Report is 160 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1325      +/-   ##
==========================================
+ Coverage   52.25%   53.77%   +1.52%     
==========================================
  Files         317      353      +36     
  Lines       18004    20480    +2476     
==========================================
+ Hits         9408    11014    +1606     
- Misses       7903     8661     +758     
- Partials      693      805     +112     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Apr 02 '24 09:04 codecov-commenter

Hi @pietern, when you have time please have a look if this is the right way to fix databricks configure currently does not use DATABRICKS_CONFIG_FILE, the fix will help us to run cli on Jenkins easier. currently, we change HOME as a workaround. Thanks

kai-zhu-sonatype avatar Apr 12 '24 03:04 kai-zhu-sonatype

@kai-zhu-sonatype Thanks for the contribution!

Because of licensing reasons we're required to get a CLA signed before we can merge it. We don't have a smooth process for this setup quite yet, but I'll send an email to see if this is possible out of band.

Thanks for your patience.

pietern avatar Apr 18 '24 11:04 pietern

Fixes #1473

andrewnester avatar Jun 17 '24 09:06 andrewnester

@kai-zhu-sonatype could you please update the PR to latest base branch? It will retrigger the test as well and if everything passes we're ready to merge it

andrewnester avatar Jun 17 '24 10:06 andrewnester

Thanks @andrewnester for your approval, have merged the latest main to the branch

kai-zhu-sonatype avatar Jun 17 '24 16:06 kai-zhu-sonatype