8000 fix(api): avoid worker model name with space (#4690) · ovh/cds@ef9c54a · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit ef9c54a

Browse files
yesnaultfsamin
authored andcommitted
fix(api): avoid worker model name with space (#4690)
close #4602 Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
1 parent e698292 commit ef9c54a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

sdk/error.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ var (
197197
ErrIntegrationtNotFound = Error{ID: 180, Status: http.StatusBadRequest}
198198
ErrBadBrokerConfiguration = Error{ID: 181, Status: http.StatusBadRequest}
199199
ErrInvalidJobRequirementNetworkAccess = Error{ID: 182, Status: http.StatusBadRequest}
200+
ErrInvalidWorkerModelNamePattern = Error{ID: 183, Status: http.StatusBadRequest}
200201
)
201202

202203
var errorsAmericanEnglish = map[int]string{
@@ -236,6 +237,7 @@ var errorsAmericanEnglish = map[int]string{
236237
ErrNotEnoughAdmin.ID: "not enough group admin left",
237238
ErrInvalidProjectName.ID: "project name must not be empty",
238239
ErrInvalidApplicationPattern.ID: "application name must respect '^[a-zA-Z0-9.-_-]{1,}$'",
240+
ErrInvalidWorkerModelNamePattern.ID: "worker model name must respect '^[a-zA-Z0-9.-_-]{1,}$'",
239241
ErrInvalidPipelinePattern.ID: "pipeline name must respect '^[a-zA-Z0-9.-_-]{1,}$'",
240242
ErrNotFound.ID: "resource not found",
241243
ErrNoWorkerModelCapa.ID: "capability not found",
@@ -415,6 +417,7 @@ var errorsFrench = map[int]string{
415417
ErrNotEnoughAdmin.ID: "pas assez d'admin restant",
416418
ErrInvalidProjectName.ID: "nom de project vide non autorisé",
417419
ErrInvalidApplicationPattern.ID: "nom de l'application invalide '^[a-zA-Z0-9.-_-]{1,}$'",
420+
ErrInvalidWorkerModelNamePattern.ID: "nom du worker model invalide '^[a-zA-Z0-9.-_-]{1,}$'",
418421
ErrInvalidPipelinePattern.ID: "nom du pipeline invalide '^[a-zA-Z0-9.-_-]{1,}$'",
419422
ErrNotFound.ID: "la ressource n'existe pas",
420423
ErrNoWorkerModelCapa.ID: "la capacité n'existe pas",

sdk/worker_model.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,10 @@ func (m *Model) Update(data Model) {
108108

109109
// IsValid returns error if the model is not valid.
110110
func (m Model) IsValid() error {
111-
if m.Name == "" {
112-
return WrapError(ErrWrongRequest, "invalid worker model name")
111+
if !NamePatternRegex.MatchString(m.Name) {
112+
return WrapError(ErrInvalidWorkerModelNamePattern, "worker model name %s does not respect pattern %s", m.Name, NamePattern)
113113
}
114+
114115
if m.GroupID == 0 {
115116
return WrapError(ErrWrongRequest, "missing worker model group data")
116117
}

0 commit comments

Comments
 (0)
0