Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/azd/cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -852,9 +852,9 @@ func (e *envListAction) Run(ctx context.Context) (*actions.ActionResult, error)

if invalidCount > 0 {
warning := fmt.Sprintf(
"\n⚠ Warning: %d environment(s) have invalid names and may cause issues with azd commands. "+
"Valid names can only contain: a-z, A-Z, 0-9, -, (, ), _, . (max 64 chars)\n",
"\n⚠ Warning: %d environment(s) have invalid names and may cause issues with azd commands. %s\n",
invalidCount,
environment.EnvironmentNameValidationMessage,
)
fmt.Fprint(e.writer, warning)
}
Expand Down
3 changes: 3 additions & 0 deletions cli/azd/pkg/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ var EnvironmentNameRegexp = regexp.MustCompile(`^[a-zA-Z0-9-\(\)_\.]{1,64}$`)
// The maximum length of an environment name.
var EnvironmentNameMaxLength = 64

// EnvironmentNameValidationMessage is the message describing valid environment name constraints
const EnvironmentNameValidationMessage = "Valid names can only contain: a-z, A-Z, 0-9, -, (, ), _, . (max 64 chars)"

func IsValidEnvironmentName(name string) bool {
return EnvironmentNameRegexp.MatchString(name)
}
Expand Down
16 changes: 10 additions & 6 deletions cli/azd/pkg/environment/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,13 @@ func (m *manager) loadOrInitEnvironment(ctx context.Context, environmentName str
if environmentName != "" && !IsValidEnvironmentName(environmentName) {
fmt.Fprintf(
m.console.Handles().Stdout,
"environment name '%s' is invalid (it should contain only alphanumeric characters and hyphens)\n",
environmentName)
"environment name '%s' is invalid. %s\n",
environmentName,
EnvironmentNameValidationMessage)
return nil, false, fmt.Errorf(
"environment name '%s' is invalid (it should contain only alphanumeric characters and hyphens)",
environmentName)
"environment name '%s' is invalid. %s",
environmentName,
EnvironmentNameValidationMessage)
}

// No environment name, no default environment set.
Expand Down Expand Up @@ -409,8 +411,9 @@ func (m *manager) Get(ctx context.Context, name string) (*Environment, error) {
// Validate environment name
if !IsValidEnvironmentName(name) {
return nil, fmt.Errorf(
"environment name '%s' is invalid. Valid names can only contain: a-z, A-Z, 0-9, -, (, ), _, . (max 64 chars)",
"environment name '%s' is invalid. %s",
name,
EnvironmentNameValidationMessage,
)
}

Expand Down Expand Up @@ -580,7 +583,8 @@ func (m *manager) ensureValidEnvironmentName(ctx context.Context, spec *Spec) er

func invalidEnvironmentNameMsg(environmentName string) string {
return fmt.Sprintf(
"environment name '%s' is invalid (it should contain only alphanumeric characters and hyphens)\n",
"environment name '%s' is invalid. %s\n",
environmentName,
EnvironmentNameValidationMessage,
)
}
Loading