1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-02 20:35:25 +02:00

feat(roles): add transactions support EE-5390 (#8878)

This commit is contained in:
andres-portainer 2023-05-02 19:05:18 -03:00 committed by GitHub
parent 757461d58b
commit 745bbb7d79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 89 additions and 9 deletions

View file

@ -8,10 +8,8 @@ import (
"github.com/rs/zerolog/log"
)
const (
// BucketName represents the name of the bucket where this service stores data.
BucketName = "roles"
)
// BucketName represents the name of the bucket where this service stores data.
const BucketName = "roles"
// Service represents a service for managing environment(endpoint) data.
type Service struct {
@ -34,6 +32,13 @@ func NewService(connection portainer.Connection) (*Service, error) {
}, nil
}
func (service *Service) Tx(tx portainer.Transaction) ServiceTx {
return ServiceTx{
service: service,
tx: tx,
}
}
// Role returns a Role by ID
func (service *Service) Role(ID portainer.RoleID) (*portainer.Role, error) {
var set portainer.Role
@ -47,7 +52,7 @@ func (service *Service) Role(ID portainer.RoleID) (*portainer.Role, error) {
return &set, nil
}
// Roles return an array containing all the sets.
// Roles returns an array containing all the sets.
func (service *Service) Roles() ([]portainer.Role, error) {
var sets = make([]portainer.Role, 0)
@ -58,7 +63,7 @@ func (service *Service) Roles() ([]portainer.Role, 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)
return nil, fmt.Errorf("failed to convert to Role object: %s", obj)
}
sets = append(sets, *set)