Skip to content

Commit 2ffcb5c

Browse files
authored
Allow domain_friendly_name to be used in name_prefix in development mode (#4173)
## Changes Allow domain_friendly_name to be used in name_prefix in development mode ## Why This is a valid name prefix so we should allow it ## Tests Added a unit test <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent 833cf5a commit 2ffcb5c

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
### CLI
88
* Skip non-exportable objects (e.g., `MLFLOW_EXPERIMENT`) during `workspace export-dir` instead of failing ([#4081](https://github.com/databricks/cli/issues/4081))
9+
* Allow domain_friendly_name to be used in name_prefix in development mode ([#4173](https://github.com/databricks/cli/pull/4173))
910

1011
### Bundles
1112
* Fix app deployment failure when app is in `DELETING` state ([#4176](https://github.com/databricks/cli/pull/4176))

bundle/config/mutator/resourcemutator/validate_target_mode.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func validateDevelopmentMode(b *bundle.Bundle) diag.Diagnostics {
6969
diags = diags.Extend(diag.Errorf("%s must start with '~/' or contain the current username to ensure uniqueness when using 'mode: development'", path))
7070
}
7171
}
72-
if p.NamePrefix != "" && !strings.Contains(p.NamePrefix, u.ShortName) && !strings.Contains(p.NamePrefix, u.UserName) {
72+
if p.NamePrefix != "" && !namePrefixContainsUserIdentifier(p.NamePrefix, u) {
7373
// Resources such as pipelines require a unique name, e.g. '[dev steve] my_pipeline'.
7474
// For this reason we require the name prefix to contain the current username;
7575
// it's a pitfall for users if they don't include it and later find out that
@@ -83,6 +83,21 @@ func validateDevelopmentMode(b *bundle.Bundle) diag.Diagnostics {
8383
return diags
8484
}
8585

86+
// namePrefixContainsUserIdentifier checks if the name prefix contains any user identifier
87+
// (username, short name, or domain friendly name) to ensure uniqueness.
88+
func namePrefixContainsUserIdentifier(prefix string, u *config.User) bool {
89+
if strings.Contains(prefix, u.UserName) {
90+
return true
91+
}
92+
if strings.Contains(prefix, u.ShortName) {
93+
return true
94+
}
95+
if u.DomainFriendlyName != "" && strings.Contains(prefix, u.DomainFriendlyName) {
96+
return true
97+
}
98+
return false
99+
}
100+
86101
// findNonUserPath finds the first workspace path such as root_path that doesn't
87102
// contain the current username or current user's shortname.
88103
func findNonUserPath(b *bundle.Bundle) string {

bundle/config/mutator/resourcemutator/validate_target_mode_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,23 @@ func TestValidateDevelopmentMode(t *testing.T) {
192192
b.Config.Workspace.ResourcePath = "/Users/[email protected]/.bundle/x/y/resources"
193193
diags = validateDevelopmentMode(b)
194194
require.NoError(t, diags.Error())
195+
196+
// Test with a bundle that has a prefix containing the domain_friendly_name
197+
b = mockBundle(config.Development)
198+
b.Config.Workspace.CurrentUser.DomainFriendlyName = "lennartfriendly"
199+
b.Config.Presets.NamePrefix = "[dev-lennartfriendly]"
200+
diags = validateDevelopmentMode(b)
201+
require.NoError(t, diags.Error())
202+
203+
// Test with a bundle that has a prefix containing the short_name
204+
b = mockBundle(config.Development)
205+
b.Config.Presets.NamePrefix = "[dev-lennart]"
206+
diags = validateDevelopmentMode(b)
207+
require.NoError(t, diags.Error())
208+
209+
// Test with a bundle that has a prefix containing the username
210+
b = mockBundle(config.Development)
211+
b.Config.Presets.NamePrefix = "[[email protected]]"
212+
diags = validateDevelopmentMode(b)
213+
require.NoError(t, diags.Error())
195214
}

0 commit comments

Comments
 (0)