From 9dfac98a26a590fad346396699469ffb14c3bb98 Mon Sep 17 00:00:00 2001 From: andres-portainer <91705312+andres-portainer@users.noreply.github.com> Date: Thu, 24 Nov 2022 14:16:04 -0300 Subject: [PATCH] fix(tags): add missing error handling EE-4622 (#8102) --- api/dataservices/tag/tag.go | 4 +--- api/http/handler/endpointgroups/endpointgroup_create.go | 2 +- api/http/handler/endpointgroups/endpointgroup_delete.go | 2 +- api/http/handler/endpointgroups/endpointgroup_update.go | 4 ++-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/api/dataservices/tag/tag.go b/api/dataservices/tag/tag.go index 7641afc37..1c4bd456c 100644 --- a/api/dataservices/tag/tag.go +++ b/api/dataservices/tag/tag.go @@ -91,11 +91,9 @@ func (service *Service) UpdateTagFunc(ID portainer.TagID, updateFunc func(tag *p id := service.connection.ConvertToKey(int(ID)) tag := &portainer.Tag{} - service.connection.UpdateObjectFunc(BucketName, id, tag, func() { + return service.connection.UpdateObjectFunc(BucketName, id, tag, func() { updateFunc(tag) }) - - return nil } // DeleteTag deletes a tag. diff --git a/api/http/handler/endpointgroups/endpointgroup_create.go b/api/http/handler/endpointgroups/endpointgroup_create.go index 3a9096433..939868fea 100644 --- a/api/http/handler/endpointgroups/endpointgroup_create.go +++ b/api/http/handler/endpointgroups/endpointgroup_create.go @@ -91,7 +91,7 @@ func (handler *Handler) endpointGroupCreate(w http.ResponseWriter, r *http.Reque } for _, tagID := range endpointGroup.TagIDs { - handler.DataStore.Tag().UpdateTagFunc(tagID, func(tag *portainer.Tag) { + err = handler.DataStore.Tag().UpdateTagFunc(tagID, func(tag *portainer.Tag) { tag.EndpointGroups[endpointGroup.ID] = true }) diff --git a/api/http/handler/endpointgroups/endpointgroup_delete.go b/api/http/handler/endpointgroups/endpointgroup_delete.go index a96bd7278..c82eee7fb 100644 --- a/api/http/handler/endpointgroups/endpointgroup_delete.go +++ b/api/http/handler/endpointgroups/endpointgroup_delete.go @@ -66,7 +66,7 @@ func (handler *Handler) endpointGroupDelete(w http.ResponseWriter, r *http.Reque } for _, tagID := range endpointGroup.TagIDs { - handler.DataStore.Tag().UpdateTagFunc(tagID, func(tag *portainer.Tag) { + err = handler.DataStore.Tag().UpdateTagFunc(tagID, func(tag *portainer.Tag) { delete(tag.EndpointGroups, endpointGroup.ID) }) diff --git a/api/http/handler/endpointgroups/endpointgroup_update.go b/api/http/handler/endpointgroups/endpointgroup_update.go index fbbd3384a..ee0c40fce 100644 --- a/api/http/handler/endpointgroups/endpointgroup_update.go +++ b/api/http/handler/endpointgroups/endpointgroup_update.go @@ -81,7 +81,7 @@ func (handler *Handler) endpointGroupUpdate(w http.ResponseWriter, r *http.Reque removeTags := tag.Difference(endpointGroupTagSet, payloadTagSet) for tagID := range removeTags { - handler.DataStore.Tag().UpdateTagFunc(tagID, func(tag *portainer.Tag) { + err = handler.DataStore.Tag().UpdateTagFunc(tagID, func(tag *portainer.Tag) { delete(tag.EndpointGroups, endpointGroup.ID) }) @@ -94,7 +94,7 @@ func (handler *Handler) endpointGroupUpdate(w http.ResponseWriter, r *http.Reque endpointGroup.TagIDs = payload.TagIDs for _, tagID := range payload.TagIDs { - handler.DataStore.Tag().UpdateTagFunc(tagID, func(tag *portainer.Tag) { + err = handler.DataStore.Tag().UpdateTagFunc(tagID, func(tag *portainer.Tag) { tag.EndpointGroups[endpointGroup.ID] = true })