Skip to content

Commit 2aab03e

Browse files
authored
fix: keep cors config on project update (#408)
1 parent 315bb58 commit 2aab03e

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

cmd/cloudx/client/project.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,12 @@ func (h *CommandHelper) UpdateProject(ctx context.Context, id string, name strin
256256
}
257257
}
258258

259-
if _, found := interim["cors_admin"]; !found {
259+
_, corsAdminFound := interim["cors_admin"]
260+
if !corsAdminFound {
260261
interim["cors_admin"] = map[string]interface{}{}
261262
}
262-
if _, found := interim["cors_public"]; !found {
263+
_, corsPublicFound := interim["cors_public"]
264+
if !corsPublicFound {
263265
interim["cors_public"] = map[string]interface{}{}
264266
}
265267
if _, found := interim["name"]; !found {
@@ -278,15 +280,28 @@ func (h *CommandHelper) UpdateProject(ctx context.Context, id string, name strin
278280
if payload.Services.Identity == nil && payload.Services.Permission == nil && payload.Services.Oauth2 == nil {
279281
return nil, errors.Errorf("at least one of the keys `services.identity.config` and `services.permission.config` and `services.oauth2.config` is required and can not be empty")
280282
}
281-
282283
if name != "" {
283284
payload.Name = name
284-
} else if payload.Name == "" {
285+
}
286+
287+
// If either of the CORS keys is not set after the merge, we need to fetch it from the server
288+
// If the name is not set, and it was not provided, we need to fetch it from the server
289+
needsBackfill := !corsAdminFound || !corsPublicFound || payload.Name == ""
290+
291+
if needsBackfill {
285292
res, _, err := c.ProjectAPI.GetProject(ctx, id).Execute()
286293
if err != nil {
287294
return nil, errors.WithStack(err)
288295
}
289-
payload.Name = res.Name
296+
if payload.Name == "" {
297+
payload.Name = res.Name
298+
}
299+
if !corsAdminFound {
300+
payload.CorsAdmin = *res.CorsAdmin
301+
}
302+
if !corsPublicFound {
303+
payload.CorsPublic = *res.CorsPublic
304+
}
290305
}
291306

292307
res, _, err := c.ProjectAPI.SetProject(ctx, id).SetProject(payload).Execute()

0 commit comments

Comments
 (0)