databricks-cli/libs/template
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
..
templates Add experimental-jobs-as-code template (#2177) 2025-01-20 10:15:11 +00:00
testdata Add the `bundle_uuid` helper function for templates (#1947) 2024-12-02 10:29:29 +00:00
builtin.go Refactor `bundle init` (#2074) 2025-01-20 12:09:28 +00:00
builtin_test.go Refactor `bundle init` (#2074) 2025-01-20 12:09:28 +00:00
config.go Enable perfsprint linter and apply autofix (#2071) 2025-01-07 10:49:23 +00:00
config_test.go Enable testifylint and fix the issues (#2065) 2025-01-02 12:03:41 +01:00
file.go Use `filer.Filer` to write template instantiation (#1911) 2024-11-20 11:11:31 +01:00
file_test.go Set the write bit for files written during template initialization (#2068) 2025-01-08 13:18:28 +00:00
helpers.go Enable gofumpt and goimports in golangci-lint (#1999) 2024-12-12 10:28:42 +01:00
helpers_test.go Enable testifylint and fix the issues (#2065) 2025-01-02 12:03:41 +01:00
reader.go Refactor `bundle init` (#2074) 2025-01-20 12:09:28 +00:00
reader_test.go Refactor `bundle init` (#2074) 2025-01-20 12:09:28 +00:00
renderer.go Set the write bit for files written during template initialization (#2068) 2025-01-08 13:18:28 +00:00
renderer_test.go Set the write bit for files written during template initialization (#2068) 2025-01-08 13:18:28 +00:00
resolver.go Refactor `bundle init` (#2074) 2025-01-20 12:09:28 +00:00
resolver_test.go Refactor `bundle init` (#2074) 2025-01-20 12:09:28 +00:00
template.go Refactor `bundle init` (#2074) 2025-01-20 12:09:28 +00:00
template_test.go Refactor `bundle init` (#2074) 2025-01-20 12:09:28 +00:00
writer.go Refactor `bundle init` (#2074) 2025-01-20 12:09:28 +00:00
writer_test.go Refactor `bundle init` (#2074) 2025-01-20 12:09:28 +00:00