зеркало из https://github.com/Azure/ARO-RP.git
Add regex validation for resource names
This commit is contained in:
Родитель
bbf2c493b4
Коммит
c4e9812f77
|
@ -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 {
|
||||
|
|
Загрузка…
Ссылка в новой задаче