Merge pull request #16602 from chlins/release-2.5.0/fix-project-creation-validation

[cherry-pick] fix: validate project metadata public value
This commit is contained in:
Chenyu Zhang 2022-03-30 13:44:38 +08:00 committed by GitHub
commit f5866e5f15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -147,6 +147,13 @@ func (a *projectAPI) CreateProject(ctx context.Context, params operation.CreateP
req.Metadata.Public = strconv.FormatBool(false)
}
// validate metadata.public value, should only be "true" or "false"
if p := req.Metadata.Public; p != "" {
if p != "true" && p != "false" {
return a.SendError(ctx, errors.BadRequestError(nil).WithMessage(fmt.Sprintf("metadata.public should only be 'true' or 'false', but got: '%s'", p)))
}
}
// ignore enable_content_trust metadata for proxy cache project
// see https://github.com/goharbor/harbor/issues/12940 to get more info
if req.RegistryID != nil {