Add regex validation for resource names

This commit is contained in:
Christoph Blecker 2022-11-16 09:56:49 -08:00
Родитель bbf2c493b4
Коммит c4e9812f77
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B34A59A9D39F838B
2 изменённых файлов: 16 добавлений и 7 удалений

Просмотреть файл

@ -51,17 +51,20 @@ func (g *generator) populateParameters(n int, typ, friendlyName string) (s []int
}
if n > 2 {
temp := friendlyName
if contains(proxyResources, temp) {
temp = "OpenShift cluster"
}
s = append(s, Parameter{
resourceNameParameter := Parameter{
Name: "resourceName",
In: "path",
Description: "The name of the " + temp + " resource.",
Description: "The name of the " + friendlyName + " resource.",
Required: true,
Type: "string",
})
}
if contains(proxyResources, friendlyName) {
resourceNameParameter.Description = "The name of the OpenShift cluster resource."
resourceNameParameter.Pattern = resourceNamePattern
resourceNameParameter.MinLength = 1
resourceNameParameter.MaxLength = 63
}
s = append(s, resourceNameParameter)
}
// gross. this is really hacky :/
@ -75,6 +78,9 @@ func (g *generator) populateParameters(n int, typ, friendlyName string) (s []int
Description: "The name of the " + friendlyName + " resource.",
Required: true,
Type: "string",
Pattern: resourceNamePattern,
MinLength: 1,
MaxLength: 63,
})
}

Просмотреть файл

@ -25,6 +25,9 @@ var proxyResources = []string{
"OpenShiftVersion",
}
// resourceNamePattern is a regex pattern to validate resource names
const resourceNamePattern = `^[a-zA-Z0-9]$|^[a-zA-Z0-9][-_a-zA-Z0-9]*[a-zA-Z0-9]$`
func Run(api, outputDir string) error {
g, err := New(api)
if err != nil {