Skip to content
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

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

kai-zhu-sonatype
Copy link

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.

@andrewnester
Copy link
Contributor

@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.

@kai-zhu-sonatype
Copy link
Author

kai-zhu-sonatype commented Mar 28, 2024

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 kai-zhu-sonatype force-pushed the configure_use_databricks_config_file branch from 8d57f0c to 4886b9b Compare March 28, 2024 15:36
@kai-zhu-sonatype kai-zhu-sonatype force-pushed the configure_use_databricks_config_file branch from 4886b9b to 1f2dcd8 Compare March 28, 2024 15:51
@kai-zhu-sonatype kai-zhu-sonatype changed the title configure use DATABRICKS_CONFIG_FILE environment variable if exists as config file fix databricks configure to use DATABRICKS_CONFIG_FILE environment variable if exists as config file Mar 30, 2024
@kai-zhu-sonatype kai-zhu-sonatype changed the title fix databricks configure to use DATABRICKS_CONFIG_FILE environment variable if exists as config file Fix databricks configure to use DATABRICKS_CONFIG_FILE environment variable if exists as config file Mar 30, 2024
@codecov-commenter
Copy link

codecov-commenter commented Apr 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.06%. Comparing base (e22dd8a) to head (dc72e4b).
Report is 28 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1325      +/-   ##
==========================================
+ Coverage   52.25%   54.06%   +1.80%     
==========================================
  Files         317      327      +10     
  Lines       18004    14837    -3167     
==========================================
- Hits         9408     8021    -1387     
+ Misses       7903     6075    -1828     
- Partials      693      741      +48     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kai-zhu-sonatype
Copy link
Author

kai-zhu-sonatype commented Apr 12, 2024

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

@pietern
Copy link
Contributor

pietern commented Apr 18, 2024

@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.

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.

None yet

4 participants