Commit Graph

413 Commits

Author SHA1 Message Date
Shreyas Goenka 736730c38a
- 2023-06-19 18:38:11 +02:00
Shreyas Goenka 404652b95a
some more tests 2023-06-19 18:32:29 +02:00
Shreyas Goenka 32786e009a
- 2023-06-19 18:26:15 +02:00
Shreyas Goenka eb4710f3a9
Merge remote-tracking branch 'origin' into fix-windows-root-filer 2023-06-19 18:05:14 +02:00
Shreyas Goenka 84a904a355
- 2023-06-19 16:32:18 +02:00
Shreyas Goenka 2e85bd3bb1
- 2023-06-19 16:00:59 +02:00
shreyas-goenka 5d036ab6b8
Fix locker unlock for destroy (#492)
## Changes
Adds ability for allowing unlock to succeed even if the deploy file is
missing.
 
## Tests
Using integration tests and manually
2023-06-19 15:57:25 +02:00
Shreyas Goenka 7529c8a4ca
- 2023-06-19 14:37:29 +02:00
shreyas-goenka 4a03265dc2
Fix force flag not working for bundle destroy (#434)
## Changes
`--force` flag did not exist for `bundle destroy`. This PR adds that in.

## Tests
manually tested. Now adding the `--force` flag hijacks the deploy lock
on the target directory.
2023-06-19 12:31:07 +02:00
Shreyas Goenka cf04ef8550
- 2023-06-19 01:46:18 +02:00
Shreyas Goenka ec19fe21dc
- 2023-06-19 01:39:36 +02:00
Shreyas Goenka 90b80eb91b
proper fix 2023-06-19 01:37:01 +02:00
Shreyas Goenka 5368972172
Merge remote-tracking branch 'origin' into fix-windows-root-filer 2023-06-19 00:52:31 +02:00
shreyas-goenka bb32067a80
Add fs cp command (#463)
## Tests
Tested using integration tests
2023-06-16 17:09:08 +02:00
Pieter Noordhuis b72742a129
Update README to reflect public preview status (#491) 2023-06-16 14:37:10 +00:00
shreyas-goenka de47cf19f1
Use better error assertions and clean up locker API (#490)
## Changes
Some cleanup work

## Tests
Locker integration test passes
2023-06-16 16:29:04 +02:00
Andrew Nester fb25baf100
Do not use white color as string output (#489)
## Changes
Do not use white color as string output
2023-06-16 13:55:22 +00:00
Andrew Nester 9cf0e0db24
Correctly set ExactArgs if generated command has positional arguments (#488)
## Changes
Some of the command such as `databricks alerts create` require
positional arguments which are not primitive.

Since these arguments are required, we should correctly set ExactArgs
for such commands

Fixes #367 

## Tests
Running `databricks alerts create`

Before
```
andrew.nester@HFW9Y94129 cli % ./cli alerts create                     
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/databricks/bricks/cmd/workspace/alerts.glob..func1(0x22a1280?, {0x2321638, 0x0, 0x0?})
	github.com/databricks/bricks/cmd/workspace/alerts/alerts.go:57 +0x355
github.com/spf13/cobra.(*Command).execute(0x22a1280, {0x2321638, 0x0, 0x0})
	github.com/spf13/cobra@v1.7.0/command.go:940 +0x862
github.com/spf13/cobra.(*Command).ExecuteC(0x22a0700)
	github.com/spf13/cobra@v1.7.0/command.go:1068 +0x3bd
github.com/spf13/cobra.(*Command).ExecuteContextC(...)
	github.com/spf13/cobra@v1.7.0/command.go:1001
github.com/databricks/bricks/cmd/root.Execute()
	github.com/databricks/bricks/cmd/root/root.go:80 +0x6a
main.main()
	github.com/databricks/bricks/main.go:18 +0x17                                           

```

After
```
andrew.nester@HFW9Y94129 cli % ./cli alerts create                                                                
Error: provide command input in JSON format by specifying --json option
```
Acceptance test
```
=== RUN   TestAccAlertsCreateErrWhenNoArguments
    alerts_test.go:10: gcp
    helpers.go:147: Error running command: provide command input in JSON format by specifying --json option
--- PASS: TestAccAlertsCreateErrWhenNoArguments (1.99s)
PASS
```
2023-06-16 12:15:25 +00:00
Shreyas Goenka 95f37b1d96
added unit test for this 2023-06-16 00:54:00 +02:00
Shreyas Goenka 0947b61bab
Merge remote-tracking branch 'origin' into fix-windows-root-filer 2023-06-15 19:40:05 +02:00
Shreyas Goenka c66793c02b
- 2023-06-15 19:36:22 +02:00
Shreyas Goenka e101f92016
add windows fix 2023-06-15 19:32:56 +02:00
Pieter Noordhuis 18e1d93218
Release v0.100.4 (#486)
## Changes

CLI:
* Add workspace import-dir command
([#456](https://github.com/databricks/cli/pull/456)).
* Annotate generated commands with OpenAPI package name
([#466](https://github.com/databricks/cli/pull/466)).
* Associate generated commands with command groups
([#475](https://github.com/databricks/cli/pull/475)).
* Disable shell completions for generated commands
([#483](https://github.com/databricks/cli/pull/483)).
* Include [DEFAULT] section header when writing ~/.databrickscfg
([#464](https://github.com/databricks/cli/pull/464)).
* Pass through proxy related environment variables
([#465](https://github.com/databricks/cli/pull/465)).
* Restore flags to original values on test completion
([#470](https://github.com/databricks/cli/pull/470)).
* Update configure command
([#482](https://github.com/databricks/cli/pull/482)).

Dependencies:
* Bump SDK to latest
([#473](https://github.com/databricks/cli/pull/473)).
2023-06-15 15:04:11 +00:00
Pieter Noordhuis dd92b3f989
Disable shell completions for generated commands (#483)
## Changes

Disable shell completions for generated commands.

Default completion behavior completes local files which never makes
sense.

Automatic contextual completion of required arguments would be super
powerful but a lot of work to get right. Until then, we could do manual
completion functions in `overrides.go` as needed.

This fixes #374.

## Tests

Confirmed manually that commands no longer complete local files.
2023-06-15 14:56:36 +00:00
Pieter Noordhuis c080fc67c9
Associate generated commands with command groups (#475)
## Changes

With this change related commands show up next to each other in help
output.

The ordered list of groups is hard-coded until it can be derived from
the specification.

## Tests

Manually confirmed that the help output of the root command and the
account command list commands by their groups.
2023-06-15 14:47:24 +00:00
Pieter Noordhuis b9406efd27
Update configure command (#482)
## Changes

This now uses:
* libs/cmdio to determine interactivity and perform prompting
* libs/databrickscfg to persist the profile

It loads a config.Config structure from the environment just like we do
for unified authentication. It is therefore possible to specify both the
host and token with environment variables.

## Tests

```
pieter.noordhuis@L4GHXDT29P /tmp % export DATABRICKS_CONFIG_FILE=.databrickscfg
pieter.noordhuis@L4GHXDT29P /tmp % databricks configure
Databricks Host: https://foo.bar
Personal Access Token: *****
pieter.noordhuis@L4GHXDT29P /tmp % cat .databrickscfg
[DEFAULT]
host  = https://foo.bar
token = token
pieter.noordhuis@L4GHXDT29P /tmp % echo token | databricks configure
Error: host must be set in non-interactive mode
pieter.noordhuis@L4GHXDT29P /tmp % echo token | databricks configure --host foo
Error: must start with https://
pieter.noordhuis@L4GHXDT29P /tmp % echo token | databricks configure --host https://foo
pieter.noordhuis@L4GHXDT29P /tmp % cat .databrickscfg
[DEFAULT]
host  = https://foo
token = token
pieter.noordhuis@L4GHXDT29P /tmp % cat .databrickscfg
pieter.noordhuis@L4GHXDT29P /tmp % databricks configure --host https://foo
Personal Access Token: ******
pieter.noordhuis@L4GHXDT29P /tmp % cat .databrickscfg
[DEFAULT]
host  = https://foo
token = token2
```
2023-06-15 12:50:19 +00:00
Pieter Noordhuis becf4d9c31
Fix deprecation notice for io/ioutil (#477)
## Changes

"io/ioutil" has been deprecated since Go 1.16: As of Go 1.16, the same
functionality is now provided by package io or package os, and those
implementations should be preferred in new code. See the specific
function documentation for details.

## Tests

n/a
2023-06-15 10:38:30 +00:00
Pieter Noordhuis faeddfae68
Update short name for bundle command (#476) 2023-06-14 22:44:18 +02:00
Pieter Noordhuis 1875908b59
Pass through proxy related environment variables (#465)
## Changes

If set on the host, we must pass them through to Terraform.

## Tests

Unit tests pass.
2023-06-14 21:58:26 +02:00
Pieter Noordhuis 30e9cf048c
Bump SDK to latest (#473)
## Changes

This pulls in the Files API work from
https://github.com/databricks/databricks-sdk-go/pull/423.

## Tests

Integration tests pass.
2023-06-14 18:27:29 +00:00
Serge Smertin 6b1b3dfa87
Create NOTICE (#468) 2023-06-14 20:05:08 +02:00
Pieter Noordhuis 96643fd746
Hide commands under preview from help output (#469)
## Changes

TSIA

Depends on https://github.com/databricks/databricks-sdk-go/pull/497.

## Tests

Manually looked at the help output and no longer see the hidden commands.
2023-06-14 14:59:57 +00:00
Serge Smertin 63437a6a98
Create LICENSE (#467)
Adding Databricks License v2
2023-06-14 14:38:52 +00:00
shreyas-goenka 968489d7c4
Restore flags to original values on test completion (#470)
## Changes

This is necessary to avoid test interference.

## Tests

Manually.

---------

Co-authored-by: Pieter Noordhuis <pieter.noordhuis@databricks.com>
2023-06-14 14:53:27 +02:00
shreyas-goenka 3d03df8844
Add mode default as a valid set value for progress-format flag (#472)
Manually tested `progress-format` works fine for all three modes
2023-06-14 13:26:56 +02:00
Pieter Noordhuis a17876480a
Include [DEFAULT] section header when writing ~/.databrickscfg (#464)
## Changes

The ini library omits the default section header and in doing so breaks
compatibility with Python's config parser. It raises:

```
Error: MissingSectionHeaderError: File contains no section headers.
```

This commit makes sure the DEFAULT section header is included.

If the config file doesn't include a DEFAULT section itself, we include
a comment describing its purpose.

## Tests

New tests pass. Manually confirmed the DEFAULT section header is
included.

---------

Co-authored-by: PaulCornellDB <paul.cornell@databricks.com>
2023-06-13 16:41:56 +00:00
Pieter Noordhuis f219a0da5a
Annotate generated commands with OpenAPI package name (#466)
Co-authored-by: Serge Smertin <259697+nfx@users.noreply.github.com>
2023-06-13 17:20:42 +02:00
shreyas-goenka d38649088c
Add workspace import-dir command (#456)
## Tests
Testing using integration tests and manually
2023-06-12 21:03:46 +02:00
Pieter Noordhuis 35dd56c716
Release v0.100.3 (#461)
## Changes

CLI:
* Add directory tracking to sync
([#425](https://github.com/databricks/cli/pull/425)).
* Add fs cat command for dbfs files
([#430](https://github.com/databricks/cli/pull/430)).
* Add fs ls command for dbfs
([#429](https://github.com/databricks/cli/pull/429)).
* Add fs mkdirs command for dbfs
([#432](https://github.com/databricks/cli/pull/432)).
* Add fs rm command for dbfs
([#433](https://github.com/databricks/cli/pull/433)).
* Add installation instructions
([#458](https://github.com/databricks/cli/pull/458)).
* Add new line to cmdio JSON rendering
([#443](https://github.com/databricks/cli/pull/443)).
* Add profile on `databricks auth login`
([#423](https://github.com/databricks/cli/pull/423)).
* Add readable console logger
([#370](https://github.com/databricks/cli/pull/370)).
* Add workspace export-dir command
([#449](https://github.com/databricks/cli/pull/449)).
* Added secrets input prompt for secrets put-secret command
([#413](https://github.com/databricks/cli/pull/413)).
* Added spinner when loading command prompts
([#420](https://github.com/databricks/cli/pull/420)).
* Better error message if can not load prompts
([#437](https://github.com/databricks/cli/pull/437)).
* Changed service template to correctly handle required positional
arguments ([#405](https://github.com/databricks/cli/pull/405)).
* Do not generate prompts for certain commands
([#438](https://github.com/databricks/cli/pull/438)).
* Do not prompt for List methods
([#411](https://github.com/databricks/cli/pull/411)).
* Do not use FgWhite and FgBlack for terminal output
([#435](https://github.com/databricks/cli/pull/435)).
* Skip path translation of job task for jobs with a Git source
([#404](https://github.com/databricks/cli/pull/404)).
* Tweak profile prompt
([#454](https://github.com/databricks/cli/pull/454)).
* Update with the latest Go SDK
([#457](https://github.com/databricks/cli/pull/457)).
* Use cmdio in version command for `--output` flag
([#419](https://github.com/databricks/cli/pull/419)).

Bundles:
* Check for nil environment before accessing it
([#453](https://github.com/databricks/cli/pull/453)).

Dependencies:
* Bump github.com/hashicorp/terraform-json from 0.16.0 to 0.17.0
([#459](https://github.com/databricks/cli/pull/459)).
* Bump github.com/mattn/go-isatty from 0.0.18 to 0.0.19
([#412](https://github.com/databricks/cli/pull/412)).

Internal:
* Add Mkdir and ReadDir functions to filer.Filer interface
([#414](https://github.com/databricks/cli/pull/414)).
* Add Stat function to filer.Filer interface
([#421](https://github.com/databricks/cli/pull/421)).
* Add check for path is a directory in filer.ReadDir
([#426](https://github.com/databricks/cli/pull/426)).
* Add fs.FS adapter for the filer interface
([#422](https://github.com/databricks/cli/pull/422)).
* Add implementation of filer.Filer for local filesystem
([#460](https://github.com/databricks/cli/pull/460)).
* Allow equivalence checking of filer errors to fs errors
([#416](https://github.com/databricks/cli/pull/416)).
* Fix locker integration test
([#417](https://github.com/databricks/cli/pull/417)).
* Implement DBFS filer
([#139](https://github.com/databricks/cli/pull/139)).
* Include recursive deletion in filer interface
([#442](https://github.com/databricks/cli/pull/442)).
* Make filer.Filer return fs.DirEntry from ReadDir
([#415](https://github.com/databricks/cli/pull/415)).
* Speed up sync integration tests
([#428](https://github.com/databricks/cli/pull/428)).
2023-06-12 17:08:00 +02:00
Lennart Kats (databricks) 03964537b2
Add installation instructions (#458)
## Changes

Add installation instructions to the README.
2023-06-12 16:31:22 +02:00
dependabot[bot] 2c2b8655a6
Bump github.com/hashicorp/terraform-json from 0.16.0 to 0.17.0 (#459) 2023-06-12 14:09:41 +00:00
Pieter Noordhuis 960ce2e18e
Add implementation of filer.Filer for local filesystem (#460)
## Changes

Local file reads on Windows require the file handle to be closed after
using it. This commit includes an interface change to return an
`io.ReadCloser` from `Read` to accommodate this.

## Tests

The existing integration tests for the filer interface all pass.
2023-06-12 15:53:58 +02:00
Serge Smertin 2aa61a7c1b
Update with the latest Go SDK (#457)
## Changes
- removed deprecated methods
- regenerated with the latest OpenAPI spec
- picked up the latest go SDK version

## Tests
`make test`
2023-06-12 14:23:21 +02:00
shreyas-goenka cd99fce2a5
Add fs mkdirs command for dbfs (#432)
## Changes
TSIA

## Tests
Integration tests
2023-06-12 14:05:56 +02:00
Pieter Noordhuis 16bb224108
Add directory tracking to sync (#425)
## Changes

This change replaces usage of the `repofiles` package with the `filer`
package to consolidate WSFS code paths.

The `repofiles` package implemented the following behavior. If a file at
`foo/bar.txt` was created and removed, the directory `foo` was kept
around because we do not perform directory tracking. If subsequently, a
file at `foo` was created, it resulted in an `fs.ErrExist` because it is
impossible to overwrite a directory. It would then perform a recursive
delete of the path if this happened and retry the file write.

To make this use case work without resorting to a recursive delete on
conflict, we need to implement directory tracking as part of sync. The
approach in this commit is as follows:

1. Maintain set of directories needed for current set of files. Compare
to previous set of files. This results in mkdir of added directories and
rmdir of removed directories.
2. Creation of new directories should happen prior to writing files.
Otherwise, many file writes may race to create the same parent
directories, resulting in additional API calls. Removal of existing
directories should happen after removing files.
3. Making new directories can be deduped across common prefixes where
only the longest prefix is created recursively.
4. Removing existing directories must happen sequentially, starting with
the longest prefix.
5. Removal of directories is a best effort. It fails only if the
directory is not empty, and if this happens we know something placed a
file or directory manually, outside of sync.

## Tests

* Existing integration tests pass (modified where it used to assert
directories weren't cleaned up)
* New integration test to confirm the inability to remove a directory
doesn't fail the sync run
2023-06-12 11:44:00 +00:00
Pieter Noordhuis e4415bfbcf
Tweak profile prompt (#454)
## Changes

This includes the following changes:
* Move profile loading code to libs/databrickscfg and add tests
* Update prompt label to reflect workspace/account profiles
* Start prompt in search mode by default
* Custom error if `~/.databrickscfg` doesn't exist
* Custom error if `~/.databrickscfg` doesn't contain profiles
* Use stderr for prompt so that stdout redirection works (e.g. with `jq` or `jless`)

## Tests

* New unit tests pass
* Manual tests for both workspace and account commands
* Search-by-default is really nice if you have many profiles
2023-06-09 13:56:35 +02:00
Pieter Noordhuis 894d25e434
Check for nil environment before accessing it (#453) 2023-06-08 20:55:49 +00:00
shreyas-goenka 4818541062
Add workspace export-dir command (#449)
## Changes
This PR:
1. Adds the export-dir command
2. Changes filer.Read to return an error if a user tries to read a
directory
3. Adds returning internal file structures from filer.Stat().Sys()

## Tests
Integration tests and manually
2023-06-08 18:15:12 +02:00
shreyas-goenka 53164ae880
Add new line to cmdio JSON rendering (#443)
## Changes
This PR adds a new line break to JSON rendering using cmdio. This is
useful when we call `cmdio.Render` multiple times

## Tests
Manually

Co-authored-by: Pieter Noordhuis <pieter.noordhuis@databricks.com>
2023-06-08 15:48:51 +02:00
stikkireddy 402fcdd62c
Skip path translation of job task for jobs with a Git source (#404)
## Changes

Added skipping of translating paths for notebook path in notebook tasks
and python file path in spark python tasks if the git source is not null.

Resolves: #402

## Tests

There is a unit test and also tested with a sample bundle:

```
resources:
  jobs:
    demo:
      git_source:
        git_branch: master
        git_provider: github
        git_url: https://github.com/test/dummy
   ....
```

---------

Co-authored-by: Pieter Noordhuis <pieter.noordhuis@databricks.com>
2023-06-07 12:34:59 +02:00