Skip to content

Commit 8d914a9

Browse files
committed
Allow domain_friendly_name to be used in name_prefix in development mode
1 parent fe1b364 commit 8d914a9

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

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)