mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 15:59:41 +02:00
feat(dataservices): unify access methods and abstract away redundant code [EE-5628] (#9115)
This commit is contained in:
parent
4c6bbe9a2f
commit
4cc96b4b30
171 changed files with 714 additions and 1590 deletions
|
@ -22,7 +22,7 @@ import (
|
|||
// @router /endpoints/agent_versions [get]
|
||||
|
||||
func (handler *Handler) agentVersions(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
||||
endpointGroups, err := handler.DataStore.EndpointGroup().EndpointGroups()
|
||||
endpointGroups, err := handler.DataStore.EndpointGroup().ReadAll()
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to retrieve environment groups from the database", err)
|
||||
}
|
||||
|
|
|
@ -222,12 +222,12 @@ func (handler *Handler) endpointCreate(w http.ResponseWriter, r *http.Request) *
|
|||
return endpointCreationError
|
||||
}
|
||||
|
||||
endpointGroup, err := handler.DataStore.EndpointGroup().EndpointGroup(endpoint.GroupID)
|
||||
endpointGroup, err := handler.DataStore.EndpointGroup().Read(endpoint.GroupID)
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to find an environment group inside the database", err)
|
||||
}
|
||||
|
||||
edgeGroups, err := handler.DataStore.EdgeGroup().EdgeGroups()
|
||||
edgeGroups, err := handler.DataStore.EdgeGroup().ReadAll()
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to retrieve edge groups from the database", err)
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ func (handler *Handler) endpointDelete(w http.ResponseWriter, r *http.Request) *
|
|||
}
|
||||
}
|
||||
|
||||
err = handler.DataStore.Snapshot().DeleteSnapshot(portainer.EndpointID(endpointID))
|
||||
err = handler.DataStore.Snapshot().Delete(portainer.EndpointID(endpointID))
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to remove the snapshot from the database", err)
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ func (handler *Handler) endpointDelete(w http.ResponseWriter, r *http.Request) *
|
|||
}
|
||||
}
|
||||
|
||||
edgeGroups, err := handler.DataStore.EdgeGroup().EdgeGroups()
|
||||
edgeGroups, err := handler.DataStore.EdgeGroup().ReadAll()
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to retrieve edge groups from the database", err)
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ func (handler *Handler) endpointDelete(w http.ResponseWriter, r *http.Request) *
|
|||
}
|
||||
}
|
||||
|
||||
registries, err := handler.DataStore.Registry().Registries()
|
||||
registries, err := handler.DataStore.Registry().ReadAll()
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to retrieve registries from the database", err)
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ func (handler *Handler) endpointDelete(w http.ResponseWriter, r *http.Request) *
|
|||
registry := ®istries[idx]
|
||||
if _, ok := registry.RegistryAccesses[endpoint.ID]; ok {
|
||||
delete(registry.RegistryAccesses, endpoint.ID)
|
||||
err = handler.DataStore.Registry().UpdateRegistry(registry.ID, registry)
|
||||
err = handler.DataStore.Registry().Update(registry.ID, registry)
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to update registry accesses", err)
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ func (handler *Handler) endpointDelete(w http.ResponseWriter, r *http.Request) *
|
|||
return response.Empty(w)
|
||||
}
|
||||
|
||||
edgeJobs, err := handler.DataStore.EdgeJob().EdgeJobs()
|
||||
edgeJobs, err := handler.DataStore.EdgeJob().ReadAll()
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to retrieve edge jobs from the database", err)
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ func TestEndpointDeleteEdgeGroupsConcurrently(t *testing.T) {
|
|||
|
||||
// Check that the edge group is consistent
|
||||
|
||||
edgeGroup, err := handler.DataStore.EdgeGroup().EdgeGroup(1)
|
||||
edgeGroup, err := handler.DataStore.EdgeGroup().Read(1)
|
||||
if err != nil {
|
||||
t.Fatal("could not retrieve the edge group:", err)
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ func (handler *Handler) endpointDockerhubStatus(w http.ResponseWriter, r *http.R
|
|||
if registryID == 0 {
|
||||
registry = &portainer.Registry{}
|
||||
} else {
|
||||
registry, err = handler.DataStore.Registry().Registry(portainer.RegistryID(registryID))
|
||||
registry, err = handler.DataStore.Registry().Read(portainer.RegistryID(registryID))
|
||||
if handler.DataStore.IsErrObjectNotFound(err) {
|
||||
return httperror.NotFound("Unable to find a registry with the specified identifier inside the database", err)
|
||||
} else if err != nil {
|
||||
|
|
|
@ -61,7 +61,7 @@ func (handler *Handler) endpointList(w http.ResponseWriter, r *http.Request) *ht
|
|||
sortField, _ := request.RetrieveQueryParameter(r, "sort", true)
|
||||
sortOrder, _ := request.RetrieveQueryParameter(r, "order", true)
|
||||
|
||||
endpointGroups, err := handler.DataStore.EndpointGroup().EndpointGroups()
|
||||
endpointGroups, err := handler.DataStore.EndpointGroup().ReadAll()
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to retrieve environment groups from the database", err)
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ func (handler *Handler) endpointRegistriesList(w http.ResponseWriter, r *http.Re
|
|||
return httperror.InternalServerError("Unable to retrieve info from request context", err)
|
||||
}
|
||||
|
||||
user, err := handler.DataStore.User().User(securityContext.UserID)
|
||||
user, err := handler.DataStore.User().Read(securityContext.UserID)
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to retrieve user from the database", err)
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ func (handler *Handler) endpointRegistriesList(w http.ResponseWriter, r *http.Re
|
|||
|
||||
isAdmin := securityContext.IsAdmin
|
||||
|
||||
registries, err := handler.DataStore.Registry().Registries()
|
||||
registries, err := handler.DataStore.Registry().ReadAll()
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to retrieve registries from the database", err)
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ func (handler *Handler) endpointRegistryAccess(w http.ResponseWriter, r *http.Re
|
|||
return httperror.Forbidden("User is not authorized", err)
|
||||
}
|
||||
|
||||
registry, err := handler.DataStore.Registry().Registry(portainer.RegistryID(registryID))
|
||||
registry, err := handler.DataStore.Registry().Read(portainer.RegistryID(registryID))
|
||||
if handler.DataStore.IsErrObjectNotFound(err) {
|
||||
return httperror.NotFound("Unable to find an environment with the specified identifier inside the database", err)
|
||||
} else if err != nil {
|
||||
|
@ -106,7 +106,7 @@ func (handler *Handler) endpointRegistryAccess(w http.ResponseWriter, r *http.Re
|
|||
|
||||
registry.RegistryAccesses[portainer.EndpointID(endpointID)] = registryAccess
|
||||
|
||||
handler.DataStore.Registry().UpdateRegistry(registry.ID, registry)
|
||||
handler.DataStore.Registry().Update(registry.ID, registry)
|
||||
|
||||
return response.Empty(w)
|
||||
}
|
||||
|
|
|
@ -176,7 +176,7 @@ func (handler *Handler) filterEndpointsByQuery(filteredEndpoints []portainer.End
|
|||
}
|
||||
|
||||
if query.search != "" {
|
||||
tags, err := handler.DataStore.Tag().Tags()
|
||||
tags, err := handler.DataStore.Tag().ReadAll()
|
||||
if err != nil {
|
||||
return nil, 0, errors.WithMessage(err, "Unable to retrieve tags from the database")
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ func filterEndpointsByEdgeStack(endpoints []portainer.Endpoint, edgeStackId port
|
|||
|
||||
envIds := make([]portainer.EndpointID, 0)
|
||||
for _, edgeGroupdId := range stack.EdgeGroups {
|
||||
edgeGroup, err := datastore.EdgeGroup().EdgeGroup(edgeGroupdId)
|
||||
edgeGroup, err := datastore.EdgeGroup().Read(edgeGroupdId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "Unable to retrieve edge group from the database")
|
||||
}
|
||||
|
|
|
@ -20,12 +20,12 @@ func (handler *Handler) updateEdgeRelations(tx dataservices.DataStoreTx, endpoin
|
|||
return errors.WithMessage(err, "Unable to find environment relation inside the database")
|
||||
}
|
||||
|
||||
endpointGroup, err := tx.EndpointGroup().EndpointGroup(endpoint.GroupID)
|
||||
endpointGroup, err := tx.EndpointGroup().Read(endpoint.GroupID)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "Unable to find environment group inside the database")
|
||||
}
|
||||
|
||||
edgeGroups, err := tx.EdgeGroup().EdgeGroups()
|
||||
edgeGroups, err := tx.EdgeGroup().ReadAll()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "Unable to retrieve edge groups from the database")
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
func updateEnvironmentEdgeGroups(tx dataservices.DataStoreTx, newEdgeGroups []portainer.EdgeGroupID, environmentID portainer.EndpointID) (bool, error) {
|
||||
edgeGroups, err := tx.EdgeGroup().EdgeGroups()
|
||||
edgeGroups, err := tx.EdgeGroup().ReadAll()
|
||||
if err != nil {
|
||||
return false, errors.WithMessage(err, "Unable to retrieve edge groups from the database")
|
||||
}
|
||||
|
@ -34,14 +34,14 @@ func updateEnvironmentEdgeGroups(tx dataservices.DataStoreTx, newEdgeGroups []po
|
|||
|
||||
updateSet := func(groupIDs set.Set[portainer.EdgeGroupID], updateItem func(*portainer.EdgeGroup)) error {
|
||||
for groupID := range groupIDs {
|
||||
group, err := tx.EdgeGroup().EdgeGroup(groupID)
|
||||
group, err := tx.EdgeGroup().Read(groupID)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "Unable to find a Edge group inside the database")
|
||||
}
|
||||
|
||||
updateItem(group)
|
||||
|
||||
err = tx.EdgeGroup().UpdateEdgeGroup(groupID, group)
|
||||
err = tx.EdgeGroup().Update(groupID, group)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "Unable to persist Edge group changes inside the database")
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ func Test_updateEdgeGroups(t *testing.T) {
|
|||
|
||||
checkGroups := func(store *datastore.Store, is *assert.Assertions, groupIDs []portainer.EdgeGroupID, endpointID portainer.EndpointID) {
|
||||
for _, groupID := range groupIDs {
|
||||
group, err := store.EdgeGroup().EdgeGroup(groupID)
|
||||
group, err := store.EdgeGroup().Read(groupID)
|
||||
is.NoError(err)
|
||||
|
||||
for _, endpoint := range group.Endpoints {
|
||||
|
@ -83,7 +83,7 @@ func Test_updateEdgeGroups(t *testing.T) {
|
|||
for _, group := range endpointGroups {
|
||||
group.Endpoints = append(group.Endpoints, testCase.endpoint.ID)
|
||||
|
||||
err = store.EdgeGroup().UpdateEdgeGroup(group.ID, &group)
|
||||
err = store.EdgeGroup().Update(group.ID, &group)
|
||||
is.NoError(err)
|
||||
}
|
||||
|
||||
|
|
|
@ -20,14 +20,14 @@ func updateEnvironmentTags(tx dataservices.DataStoreTx, newTags []portainer.TagI
|
|||
|
||||
updateSet := func(tagIDs set.Set[portainer.TagID], updateItem func(*portainer.Tag)) error {
|
||||
for tagID := range tagIDs {
|
||||
tag, err := tx.Tag().Tag(tagID)
|
||||
tag, err := tx.Tag().Read(tagID)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "Unable to find a tag inside the database")
|
||||
}
|
||||
|
||||
updateItem(tag)
|
||||
|
||||
err = tx.Tag().UpdateTag(tagID, tag)
|
||||
err = tx.Tag().Update(tagID, tag)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "Unable to persist tag changes inside the database")
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ func Test_updateTags(t *testing.T) {
|
|||
|
||||
checkTags := func(store *datastore.Store, is *assert.Assertions, tagIDs []portainer.TagID, endpointID portainer.EndpointID) {
|
||||
for _, tagID := range tagIDs {
|
||||
tag, err := store.Tag().Tag(tagID)
|
||||
tag, err := store.Tag().Read(tagID)
|
||||
is.NoError(err)
|
||||
|
||||
_, ok := tag.Endpoints[endpointID]
|
||||
|
@ -87,7 +87,7 @@ func Test_updateTags(t *testing.T) {
|
|||
for _, tag := range endpointTags {
|
||||
tag.Endpoints[testCase.endpoint.ID] = true
|
||||
|
||||
err = store.Tag().UpdateTag(tag.ID, &tag)
|
||||
err = store.Tag().Update(tag.ID, &tag)
|
||||
is.NoError(err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue