fix: fix replication of multiple projects with numeric names (#21474)

Explicitly mark project names as strings

This keeps the server from parsing all-numeric project names as integer
values which it does not like.

Signed-off-by: Chris Girard <cgirard@mirantis.com>
Co-authored-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
Chris Girard 2025-03-18 05:06:35 -04:00 committed by GitHub
parent 6b2e6ba20c
commit c2098f2ba3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -160,12 +160,15 @@ func (a *Adapter) PrepareForPush(resources []*model.Resource) error {
}
}
// Create a list of the project names.
var ps []string
for p := range projects {
ps = append(ps, p)
// Surround name in 'quotes' to force the server to parse as a string.
// Handles the case where a project name consists entirely of numbers.
ps = append(ps, fmt.Sprintf("'%s'", p))
}
// query by project name, decorate the name as string to avoid parsed as int by server in case of pure numbers as project name
q := fmt.Sprintf("name={'%s'}", strings.Join(ps, " "))
// query by project names
q := fmt.Sprintf("name={%s}", strings.Join(ps, " "))
// get exist projects
queryProjects, err := a.Client.ListProjectsWithQuery(q, false)
if err != nil {