feat(codersdk): export name validators (#14551)

This commit is contained in:
Ethan
2024-09-04 08:34:39 +00:00
committed by GitHub
parent 01a904c133
commit 8f85464fe6
6 changed files with 59 additions and 135 deletions
+10 -3
View File
@@ -10,7 +10,6 @@ import (
"path/filepath"
"strings"
"time"
"unicode/utf8"
"github.com/briandowns/spinner"
"github.com/google/uuid"
@@ -57,8 +56,16 @@ func (r *RootCmd) templatePush() *serpent.Command {
return err
}
if utf8.RuneCountInString(name) > 32 {
return xerrors.Errorf("Template name must be no more than 32 characters")
err = codersdk.NameValid(name)
if err != nil {
return xerrors.Errorf("template name %q is invalid: %w", name, err)
}
if versionName != "" {
err = codersdk.TemplateVersionNameValid(versionName)
if err != nil {
return xerrors.Errorf("template version name %q is invalid: %w", versionName, err)
}
}
var createTemplate bool