mirror of
https://github.com/portainer/portainer.git
synced 2025-08-05 05:45:22 +02:00
feat(dataservices): abstract away some redundant code EE-5620 (#9110)
This commit is contained in:
parent
7dc6a1559f
commit
716c196682
33 changed files with 315 additions and 824 deletions
|
@ -1,11 +1,8 @@
|
|||
package role
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/portainer/portainer/api/dataservices"
|
||||
)
|
||||
|
||||
// BucketName represents the name of the bucket where this service stores data.
|
||||
|
@ -56,22 +53,11 @@ func (service *Service) Role(ID portainer.RoleID) (*portainer.Role, error) {
|
|||
func (service *Service) Roles() ([]portainer.Role, error) {
|
||||
var sets = make([]portainer.Role, 0)
|
||||
|
||||
err := service.connection.GetAll(
|
||||
return sets, service.connection.GetAll(
|
||||
BucketName,
|
||||
&portainer.Role{},
|
||||
func(obj interface{}) (interface{}, error) {
|
||||
set, ok := obj.(*portainer.Role)
|
||||
if !ok {
|
||||
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to Role object")
|
||||
return nil, fmt.Errorf("failed to convert to Role object: %s", obj)
|
||||
}
|
||||
|
||||
sets = append(sets, *set)
|
||||
|
||||
return &portainer.Role{}, nil
|
||||
})
|
||||
|
||||
return sets, err
|
||||
dataservices.AppendFn(&sets),
|
||||
)
|
||||
}
|
||||
|
||||
// CreateRole creates a new Role.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue