databricks-cli/libs
shreyas-goenka 41a21af556
Refactor `bundle init` (#2074)
## Summary of changes
This PR introduces three new abstractions: 
1. `Resolver`: Resolves which reader and writer to use for a template.
2. `Writer`: Writes a template project to disk. Prompts the user if
necessary.
3. `Reader`: Reads a template specification from disk, built into the
CLI or from GitHub.

Introducing these abstractions helps decouple reading a template from
writing it. When I tried adding telemetry for the `bundle init` command,
I noticed that the code in `cmd/init.go` was getting convoluted and hard
to test. A future change could have accidentally logged PII when a user
initialised a custom template.

Hedging against that risk is important here because we use a generic
untyped `map<string, string>` representation in the backend to log
telemetry for the `databricks bundle init`. Otherwise, we risk
accidentally breaking our compliance with our centralization
requirements.

### Details

After this PR there are two classes of templates that can be
initialized:
1. A `databricks` template: This could be a builtin template or a
template outside the CLI like mlops-stacks, which is still owned and
managed by Databricks. These templates log their telemetry arguments and
template name.
2. A `custom` template: These are templates created by and managed by
the end user. In these templates we do not log the template name and
args. Instead a generic placeholder string of "custom" is logged in our
telemetry system.

NOTE: The functionality of the `databricks bundle init` command remains
the same after this PR. Only the internal abstractions used are changed.

## Tests
New unit tests. Existing golden and unit tests. Also a fair bit of
manual testing.
2025-01-20 12:09:28 +00:00
..
auth Enable perfsprint linter and apply autofix (#2071) 2025-01-07 10:49:23 +00:00
cmdgroup Add error checking in tests and enable errcheck there (#1980) 2024-12-09 13:56:41 +01:00
cmdio Refactor `bundle init` (#2074) 2025-01-20 12:09:28 +00:00
databrickscfg Refactor `bundle init` (#2074) 2025-01-20 12:09:28 +00:00
dbr Extract functionality to detect if the CLI is running on DBR (#1889) 2024-11-14 16:10:45 +00:00
diag Encourage the use of root_path in production to ensure single deployment (#1712) 2025-01-13 12:19:12 +00:00
dyn Enable linter 'unconvert' and fix the issues found (#2136) 2025-01-14 10:56:38 +00:00
env Add acceptance tests (#2081) 2025-01-08 12:41:08 +00:00
errs Enable perfsprint linter and apply autofix (#2071) 2025-01-07 10:49:23 +00:00
exec exec(test): Do not clear PATH; this breaks coverage on Windows (#2150) 2025-01-15 12:05:46 +01:00
fakefs Enable perfsprint linter and apply autofix (#2071) 2025-01-07 10:49:23 +00:00
filer Refactor `bundle init` (#2074) 2025-01-20 12:09:28 +00:00
fileset Enable testifylint and fix the issues (#2065) 2025-01-02 12:03:41 +01:00
flags Enable perfsprint linter and apply autofix (#2071) 2025-01-07 10:49:23 +00:00
folders Enable testifylint and fix the issues (#2065) 2025-01-02 12:03:41 +01:00
git Enable perfsprint linter and apply autofix (#2071) 2025-01-07 10:49:23 +00:00
iamutil Move utility functions dealing with IAM to libs/iamutil (#1820) 2024-10-10 13:02:25 +00:00
jsonschema Enable perfsprint linter and apply autofix (#2071) 2025-01-07 10:49:23 +00:00
locker Enable perfsprint linter and apply autofix (#2071) 2025-01-07 10:49:23 +00:00
log Enable gofumpt and goimports in golangci-lint (#1999) 2024-12-12 10:28:42 +01:00
notebook Format Python code with ruff (#2166) 2025-01-17 07:38:47 +00:00
process Enable perfsprint linter and apply autofix (#2071) 2025-01-07 10:49:23 +00:00
python Enable testifylint and fix the issues (#2065) 2025-01-02 12:03:41 +01:00
set Show actionable errors for collaborative deployment scenarios (#1386) 2024-10-10 11:18:23 +00:00
sync Format Python code with ruff (#2166) 2025-01-17 07:38:47 +00:00
tags Enable perfsprint linter and apply autofix (#2071) 2025-01-07 10:49:23 +00:00
template Refactor `bundle init` (#2074) 2025-01-20 12:09:28 +00:00
terraform Move to a single prompt during bundle destroy (#1583) 2024-07-24 13:02:19 +00:00
testdiff Fix incorrect TestingT.Errorf usage and enable linting for this (#2182) 2025-01-20 08:07:42 +00:00
testfile Refactor and cover edge cases in sync integration tests (#160) 2023-01-10 13:16:30 +01:00
textutil Enable gofumpt and goimports in golangci-lint (#1999) 2024-12-12 10:28:42 +01:00
vfs Enable testifylint and fix the issues (#2065) 2025-01-02 12:03:41 +01:00