mirror of
https://github.com/portainer/portainer.git
synced 2025-08-09 15:55:23 +02:00
migrate user dataservice
This commit is contained in:
parent
74615bff91
commit
cc1b8c05d4
15 changed files with 114 additions and 182 deletions
|
@ -73,10 +73,10 @@ func (service *Service) endpoints() ([]portainer.Endpoint, error) {
|
|||
var endpoints []portainer.Endpoint
|
||||
var err error
|
||||
|
||||
err = service.connection.ViewTx(func(tx portainer.Transaction) error {
|
||||
endpoints, err = service.Tx(tx).Endpoints()
|
||||
return err
|
||||
})
|
||||
// err = service.connection.ViewTx(func(tx portainer.Transaction) error {
|
||||
// endpoints, err = service.Tx(tx).Endpoints()
|
||||
// return err
|
||||
// })
|
||||
|
||||
return endpoints, err
|
||||
}
|
||||
|
|
|
@ -57,7 +57,6 @@ type (
|
|||
Create(customTemplate *portainer.CustomTemplate) error
|
||||
UpdateCustomTemplate(ID portainer.CustomTemplateID, customTemplate *portainer.CustomTemplate) error
|
||||
DeleteCustomTemplate(ID portainer.CustomTemplateID) error
|
||||
BucketName() string
|
||||
}
|
||||
|
||||
// EdgeGroupService represents a service to manage Edge groups
|
||||
|
@ -68,7 +67,6 @@ type (
|
|||
UpdateEdgeGroup(ID portainer.EdgeGroupID, group *portainer.EdgeGroup) error
|
||||
UpdateEdgeGroupFunc(ID portainer.EdgeGroupID, updateFunc func(group *portainer.EdgeGroup)) error
|
||||
DeleteEdgeGroup(ID portainer.EdgeGroupID) error
|
||||
BucketName() string
|
||||
}
|
||||
|
||||
// EdgeJobService represents a service to manage Edge jobs
|
||||
|
@ -79,7 +77,6 @@ type (
|
|||
UpdateEdgeJob(ID portainer.EdgeJobID, edgeJob *portainer.EdgeJob) error
|
||||
UpdateEdgeJobFunc(ID portainer.EdgeJobID, updateFunc func(edgeJob *portainer.EdgeJob)) error
|
||||
DeleteEdgeJob(ID portainer.EdgeJobID) error
|
||||
BucketName() string
|
||||
}
|
||||
|
||||
// EdgeStackService represents a service to manage Edge stacks
|
||||
|
@ -92,7 +89,6 @@ type (
|
|||
UpdateEdgeStack(ID portainer.EdgeStackID, edgeStack *portainer.EdgeStack) error
|
||||
UpdateEdgeStackFunc(ID portainer.EdgeStackID, updateFunc func(edgeStack *portainer.EdgeStack)) error
|
||||
DeleteEdgeStack(ID portainer.EdgeStackID) error
|
||||
BucketName() string
|
||||
}
|
||||
|
||||
// EndpointService represents a service for managing environment(endpoint) data
|
||||
|
@ -105,7 +101,6 @@ type (
|
|||
Create(endpoint *portainer.Endpoint) error
|
||||
UpdateEndpoint(ID portainer.EndpointID, endpoint *portainer.Endpoint) error
|
||||
DeleteEndpoint(ID portainer.EndpointID) error
|
||||
BucketName() string
|
||||
}
|
||||
|
||||
// EndpointGroupService represents a service for managing environment(endpoint) group data
|
||||
|
@ -115,7 +110,6 @@ type (
|
|||
Create(group *portainer.EndpointGroup) error
|
||||
UpdateEndpointGroup(ID portainer.EndpointGroupID, group *portainer.EndpointGroup) error
|
||||
DeleteEndpointGroup(ID portainer.EndpointGroupID) error
|
||||
BucketName() string
|
||||
}
|
||||
|
||||
// EndpointRelationService represents a service for managing environment(endpoint) relations data
|
||||
|
@ -125,7 +119,6 @@ type (
|
|||
Create(endpointRelation *portainer.EndpointRelation) error
|
||||
UpdateEndpointRelation(EndpointID portainer.EndpointID, endpointRelation *portainer.EndpointRelation) error
|
||||
DeleteEndpointRelation(EndpointID portainer.EndpointID) error
|
||||
BucketName() string
|
||||
}
|
||||
|
||||
// FDOProfileService represents a service to manage FDO Profiles
|
||||
|
@ -135,7 +128,6 @@ type (
|
|||
Create(FDOProfile *portainer.FDOProfile) error
|
||||
Update(ID portainer.FDOProfileID, FDOProfile *portainer.FDOProfile) error
|
||||
Delete(ID portainer.FDOProfileID) error
|
||||
BucketName() string
|
||||
}
|
||||
|
||||
// HelmUserRepositoryService represents a service to manage HelmUserRepositories
|
||||
|
@ -145,7 +137,6 @@ type (
|
|||
Create(record *portainer.HelmUserRepository) error
|
||||
UpdateHelmUserRepository(ID portainer.HelmUserRepositoryID, repository *portainer.HelmUserRepository) error
|
||||
DeleteHelmUserRepository(ID portainer.HelmUserRepositoryID) error
|
||||
BucketName() string
|
||||
}
|
||||
|
||||
// JWTService represents a service for managing JWT tokens
|
||||
|
@ -164,7 +155,6 @@ type (
|
|||
Create(registry *portainer.Registry) error
|
||||
UpdateRegistry(ID portainer.RegistryID, registry *portainer.Registry) error
|
||||
DeleteRegistry(ID portainer.RegistryID) error
|
||||
BucketName() string
|
||||
}
|
||||
|
||||
// ResourceControlService represents a service for managing resource control data
|
||||
|
@ -175,7 +165,6 @@ type (
|
|||
Create(rc *portainer.ResourceControl) error
|
||||
UpdateResourceControl(ID portainer.ResourceControlID, resourceControl *portainer.ResourceControl) error
|
||||
DeleteResourceControl(ID portainer.ResourceControlID) error
|
||||
BucketName() string
|
||||
}
|
||||
|
||||
// RoleService represents a service for managing user roles
|
||||
|
@ -184,7 +173,6 @@ type (
|
|||
Roles() ([]portainer.Role, error)
|
||||
Create(role *portainer.Role) error
|
||||
UpdateRole(ID portainer.RoleID, role *portainer.Role) error
|
||||
BucketName() string
|
||||
}
|
||||
|
||||
// APIKeyRepositoryService
|
||||
|
@ -201,7 +189,6 @@ type (
|
|||
SettingsService interface {
|
||||
Settings() (*portainer.Settings, error)
|
||||
UpdateSettings(settings *portainer.Settings) error
|
||||
BucketName() string
|
||||
}
|
||||
|
||||
SnapshotService interface {
|
||||
|
@ -210,14 +197,12 @@ type (
|
|||
UpdateSnapshot(snapshot *portainer.Snapshot) error
|
||||
DeleteSnapshot(endpointID portainer.EndpointID) error
|
||||
Create(snapshot *portainer.Snapshot) error
|
||||
BucketName() string
|
||||
}
|
||||
|
||||
// SSLSettingsService represents a service for managing application settings
|
||||
SSLSettingsService interface {
|
||||
Settings() (*portainer.SSLSettings, error)
|
||||
UpdateSettings(settings *portainer.SSLSettings) error
|
||||
BucketName() string
|
||||
}
|
||||
|
||||
// StackService represents a service for managing stack data
|
||||
|
@ -231,7 +216,6 @@ type (
|
|||
DeleteStack(ID portainer.StackID) error
|
||||
StackByWebhookID(ID string) (*portainer.Stack, error)
|
||||
RefreshableStacks() ([]portainer.Stack, error)
|
||||
BucketName() string
|
||||
}
|
||||
|
||||
// TagService represents a service for managing tag data
|
||||
|
@ -242,7 +226,6 @@ type (
|
|||
UpdateTag(ID portainer.TagID, tag *portainer.Tag) error
|
||||
UpdateTagFunc(ID portainer.TagID, updateFunc func(tag *portainer.Tag)) error
|
||||
DeleteTag(ID portainer.TagID) error
|
||||
BucketName() string
|
||||
}
|
||||
|
||||
// TeamService represents a service for managing user data
|
||||
|
@ -253,7 +236,6 @@ type (
|
|||
Create(team *portainer.Team) error
|
||||
UpdateTeam(ID portainer.TeamID, team *portainer.Team) error
|
||||
DeleteTeam(ID portainer.TeamID) error
|
||||
BucketName() string
|
||||
}
|
||||
|
||||
// TeamMembershipService represents a service for managing team membership data
|
||||
|
@ -267,7 +249,6 @@ type (
|
|||
DeleteTeamMembership(ID portainer.TeamMembershipID) error
|
||||
DeleteTeamMembershipByUserID(userID portainer.UserID) error
|
||||
DeleteTeamMembershipByTeamID(teamID portainer.TeamID) error
|
||||
BucketName() string
|
||||
DeleteTeamMembershipByTeamIDAndUserID(teamID portainer.TeamID, userID portainer.UserID) error
|
||||
}
|
||||
|
||||
|
@ -275,7 +256,6 @@ type (
|
|||
TunnelServerService interface {
|
||||
Info() (*portainer.TunnelServerInfo, error)
|
||||
UpdateInfo(info *portainer.TunnelServerInfo) error
|
||||
BucketName() string
|
||||
}
|
||||
|
||||
// UserService represents a service for managing user data
|
||||
|
@ -287,7 +267,6 @@ type (
|
|||
Create(user *portainer.User) error
|
||||
UpdateUser(ID portainer.UserID, user *portainer.User) error
|
||||
DeleteUser(ID portainer.UserID) error
|
||||
BucketName() string
|
||||
}
|
||||
|
||||
// VersionService represents a service for managing version data
|
||||
|
@ -310,7 +289,6 @@ type (
|
|||
WebhookByResourceID(resourceID string) (*portainer.Webhook, error)
|
||||
WebhookByToken(token string) (*portainer.Webhook, error)
|
||||
DeleteWebhook(ID portainer.WebhookID) error
|
||||
BucketName() string
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -19,12 +19,12 @@ func (service ServiceTx) BucketName() string {
|
|||
// Registry returns a registry by ID.
|
||||
func (service ServiceTx) Registry(ID portainer.RegistryID) (*portainer.Registry, error) {
|
||||
var registry portainer.Registry
|
||||
identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
// identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
|
||||
err := service.tx.GetObject(BucketName, identifier, ®istry)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// err := service.tx.GetObject(BucketName, identifier, ®istry)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
return ®istry, nil
|
||||
}
|
||||
|
@ -64,12 +64,14 @@ func (service ServiceTx) Create(registry *portainer.Registry) error {
|
|||
|
||||
// UpdateRegistry updates a registry.
|
||||
func (service ServiceTx) UpdateRegistry(ID portainer.RegistryID, registry *portainer.Registry) error {
|
||||
identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
return service.tx.UpdateObject(BucketName, identifier, registry)
|
||||
// identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
// return service.tx.UpdateObject(BucketName, identifier, registry)
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteRegistry deletes a registry.
|
||||
func (service ServiceTx) DeleteRegistry(ID portainer.RegistryID) error {
|
||||
identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
return service.tx.DeleteObject(BucketName, identifier)
|
||||
// identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
// return service.tx.DeleteObject(BucketName, identifier)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -21,12 +21,12 @@ func (service ServiceTx) BucketName() string {
|
|||
// ResourceControl returns a ResourceControl object by ID
|
||||
func (service ServiceTx) ResourceControl(ID portainer.ResourceControlID) (*portainer.ResourceControl, error) {
|
||||
var resourceControl portainer.ResourceControl
|
||||
identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
// identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
|
||||
err := service.tx.GetObject(BucketName, identifier, &resourceControl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// err := service.tx.GetObject(BucketName, identifier, &resourceControl)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
return &resourceControl, nil
|
||||
}
|
||||
|
@ -103,12 +103,14 @@ func (service ServiceTx) Create(resourceControl *portainer.ResourceControl) erro
|
|||
|
||||
// UpdateResourceControl saves a ResourceControl object.
|
||||
func (service ServiceTx) UpdateResourceControl(ID portainer.ResourceControlID, resourceControl *portainer.ResourceControl) error {
|
||||
identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
return service.tx.UpdateObject(BucketName, identifier, resourceControl)
|
||||
// identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
// return service.tx.UpdateObject(BucketName, identifier, resourceControl)
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteResourceControl deletes a ResourceControl object by ID
|
||||
func (service ServiceTx) DeleteResourceControl(ID portainer.ResourceControlID) error {
|
||||
identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
return service.tx.DeleteObject(BucketName, identifier)
|
||||
// identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
// return service.tx.DeleteObject(BucketName, identifier)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -21,12 +21,12 @@ func (service ServiceTx) BucketName() string {
|
|||
// Role returns a Role by ID
|
||||
func (service ServiceTx) Role(ID portainer.RoleID) (*portainer.Role, error) {
|
||||
var set portainer.Role
|
||||
identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
// identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
|
||||
err := service.tx.GetObject(BucketName, identifier, &set)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// err := service.tx.GetObject(BucketName, identifier, &set)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
return &set, nil
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ func (service ServiceTx) Create(role *portainer.Role) error {
|
|||
|
||||
// UpdateRole updates a role.
|
||||
func (service ServiceTx) UpdateRole(ID portainer.RoleID, role *portainer.Role) error {
|
||||
identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
return service.tx.UpdateObject(BucketName, identifier, role)
|
||||
// identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
// return service.tx.UpdateObject(BucketName, identifier, role)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -20,12 +20,12 @@ func (service ServiceTx) BucketName() string {
|
|||
// TeamMembership returns a TeamMembership object by ID
|
||||
func (service ServiceTx) TeamMembership(ID portainer.TeamMembershipID) (*portainer.TeamMembership, error) {
|
||||
var membership portainer.TeamMembership
|
||||
identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
// identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
|
||||
err := service.tx.GetObject(BucketName, identifier, &membership)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// err := service.tx.GetObject(BucketName, identifier, &membership)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
return &membership, nil
|
||||
}
|
||||
|
@ -102,8 +102,9 @@ func (service ServiceTx) TeamMembershipsByTeamID(teamID portainer.TeamID) ([]por
|
|||
|
||||
// UpdateTeamMembership saves a TeamMembership object.
|
||||
func (service ServiceTx) UpdateTeamMembership(ID portainer.TeamMembershipID, membership *portainer.TeamMembership) error {
|
||||
identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
return service.tx.UpdateObject(BucketName, identifier, membership)
|
||||
// identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
// return service.tx.UpdateObject(BucketName, identifier, membership)
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateTeamMembership creates a new TeamMembership object.
|
||||
|
@ -119,8 +120,9 @@ func (service ServiceTx) Create(membership *portainer.TeamMembership) error {
|
|||
|
||||
// DeleteTeamMembership deletes a TeamMembership object.
|
||||
func (service ServiceTx) DeleteTeamMembership(ID portainer.TeamMembershipID) error {
|
||||
identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
return service.tx.DeleteObject(BucketName, identifier)
|
||||
// identifier := service.service.connection.ConvertToKey(int(ID))
|
||||
// return service.tx.DeleteObject(BucketName, identifier)
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteTeamMembershipByUserID deletes all the TeamMembership object associated to a UserID.
|
||||
|
|
|
@ -2,11 +2,7 @@ package user
|
|||
|
||||
import (
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
)
|
||||
|
||||
const (
|
||||
// BucketName represents the name of the bucket where this service stores data.
|
||||
BucketName = "users"
|
||||
dserrors "github.com/portainer/portainer/api/dataservices/errors"
|
||||
)
|
||||
|
||||
// Service represents a service for managing environment(endpoint) data.
|
||||
|
@ -14,17 +10,8 @@ type Service struct {
|
|||
connection portainer.Connection
|
||||
}
|
||||
|
||||
func (service *Service) BucketName() string {
|
||||
return BucketName
|
||||
}
|
||||
|
||||
// NewService creates a new instance of a service.
|
||||
func NewService(connection portainer.Connection) (*Service, error) {
|
||||
// err := connection.SetServiceName(BucketName)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
return &Service{
|
||||
connection: connection,
|
||||
}, nil
|
||||
|
@ -32,70 +19,44 @@ func NewService(connection portainer.Connection) (*Service, error) {
|
|||
|
||||
// User returns a user by ID
|
||||
func (service *Service) User(ID portainer.UserID) (*portainer.User, error) {
|
||||
var user portainer.User
|
||||
// identifier := service.connection.ConvertToKey(int(ID))
|
||||
db := service.connection.GetDB()
|
||||
obj := portainer.User{}
|
||||
|
||||
// err := service.connection.GetObject(BucketName, identifier, &user)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
tx := db.First(&obj, `id = ?`, ID)
|
||||
if tx.Error != nil {
|
||||
return nil, tx.Error
|
||||
}
|
||||
|
||||
return &user, nil
|
||||
return &obj, nil
|
||||
}
|
||||
|
||||
// UserByUsername returns a user by username.
|
||||
func (service *Service) UserByUsername(username string) (*portainer.User, error) {
|
||||
// var u *portainer.User
|
||||
// stop := fmt.Errorf("ok")
|
||||
// err := service.connection.GetAll(
|
||||
// BucketName,
|
||||
// &portainer.User{},
|
||||
// func(obj interface{}) (interface{}, error) {
|
||||
// user, ok := obj.(*portainer.User)
|
||||
// if !ok {
|
||||
// log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to User object")
|
||||
u := portainer.User{}
|
||||
|
||||
// return nil, fmt.Errorf("Failed to convert to User object: %s", obj)
|
||||
// }
|
||||
db := service.connection.GetDB()
|
||||
tx := db.First(&u, `username = ?`, username)
|
||||
|
||||
// if strings.EqualFold(user.Username, username) {
|
||||
// u = user
|
||||
// return nil, stop
|
||||
// }
|
||||
if tx.Error != nil {
|
||||
return nil, tx.Error
|
||||
}
|
||||
|
||||
// return &portainer.User{}, nil
|
||||
// })
|
||||
if tx.Error == nil {
|
||||
return nil, dserrors.ErrObjectNotFound
|
||||
}
|
||||
|
||||
// if errors.Is(err, stop) {
|
||||
// return u, nil
|
||||
// }
|
||||
|
||||
// if err == nil {
|
||||
// return nil, dserrors.ErrObjectNotFound
|
||||
// }
|
||||
|
||||
return nil, nil
|
||||
return &u, nil
|
||||
}
|
||||
|
||||
// Users return an array containing all the users.
|
||||
func (service *Service) Users() ([]portainer.User, error) {
|
||||
var users = make([]portainer.User, 0)
|
||||
|
||||
// err := service.connection.GetAll(
|
||||
// BucketName,
|
||||
// &portainer.User{},
|
||||
// func(obj interface{}) (interface{}, error) {
|
||||
// user, ok := obj.(*portainer.User)
|
||||
// if !ok {
|
||||
// log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to User object")
|
||||
|
||||
// return nil, fmt.Errorf("Failed to convert to User object: %s", obj)
|
||||
// }
|
||||
|
||||
// users = append(users, *user)
|
||||
|
||||
// return &portainer.User{}, nil
|
||||
// })
|
||||
db := service.connection.GetDB()
|
||||
tx := db.Find(&users)
|
||||
if tx.Error != nil {
|
||||
return nil, tx.Error
|
||||
}
|
||||
|
||||
return users, nil
|
||||
}
|
||||
|
@ -104,53 +65,43 @@ func (service *Service) Users() ([]portainer.User, error) {
|
|||
func (service *Service) UsersByRole(role portainer.UserRole) ([]portainer.User, error) {
|
||||
var users = make([]portainer.User, 0)
|
||||
|
||||
// err := service.connection.GetAll(
|
||||
// BucketName,
|
||||
// &portainer.User{},
|
||||
// func(obj interface{}) (interface{}, error) {
|
||||
// user, ok := obj.(*portainer.User)
|
||||
// if !ok {
|
||||
// log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to User object")
|
||||
|
||||
// return nil, fmt.Errorf("Failed to convert to User object: %s", obj)
|
||||
// }
|
||||
|
||||
// if user.Role == role {
|
||||
// users = append(users, *user)
|
||||
// }
|
||||
|
||||
// return &portainer.User{}, nil
|
||||
// })
|
||||
db := service.connection.GetDB()
|
||||
tx := db.Find(&users, `role = ?`, role)
|
||||
if tx.Error != nil {
|
||||
return nil, tx.Error
|
||||
}
|
||||
|
||||
return users, nil
|
||||
}
|
||||
|
||||
// UpdateUser saves a user.
|
||||
func (service *Service) UpdateUser(ID portainer.UserID, user *portainer.User) error {
|
||||
// identifier := service.connection.ConvertToKey(int(ID))
|
||||
// user.Username = strings.ToLower(user.Username)
|
||||
// return service.connection.UpdateObject(BucketName, identifier, user)
|
||||
|
||||
db := service.connection.GetDB()
|
||||
tx := db.Model(&portainer.User{}).Where("id = ?", ID).UpdateColumns(&user)
|
||||
if tx.Error != nil {
|
||||
return tx.Error
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateUser creates a new user.
|
||||
func (service *Service) Create(user *portainer.User) error {
|
||||
// return service.connection.CreateObject(
|
||||
// BucketName,
|
||||
// func(id uint64) (int, interface{}) {
|
||||
// user.ID = portainer.UserID(id)
|
||||
// user.Username = strings.ToLower(user.Username)
|
||||
|
||||
// return int(user.ID), user
|
||||
// },
|
||||
// )
|
||||
db := service.connection.GetDB()
|
||||
tx := db.Model(&portainer.User{}).Create(&user)
|
||||
if tx.Error != nil {
|
||||
return tx.Error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteUser deletes a user.
|
||||
func (service *Service) DeleteUser(ID portainer.UserID) error {
|
||||
// identifier := service.connection.ConvertToKey(int(ID))
|
||||
// return service.connection.DeleteObject(BucketName, identifier)
|
||||
db := service.connection.GetDB()
|
||||
tx := db.Model(&portainer.User{}).Delete("id = ?", ID)
|
||||
if tx.Error != nil {
|
||||
return tx.Error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -29,10 +29,10 @@ func (handler *Handler) edgeStackCreate(w http.ResponseWriter, r *http.Request)
|
|||
if featureflags.IsEnabled(portainer.FeatureNoTx) {
|
||||
edgeStack, err = handler.createSwarmStack(handler.DataStore, method, dryrun, tokenData.ID, r)
|
||||
} else {
|
||||
err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error {
|
||||
edgeStack, err = handler.createSwarmStack(tx, method, dryrun, tokenData.ID, r)
|
||||
return err
|
||||
})
|
||||
// err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error {
|
||||
// edgeStack, err = handler.createSwarmStack(tx, method, dryrun, tokenData.ID, r)
|
||||
// return err
|
||||
// })
|
||||
}
|
||||
if err != nil {
|
||||
switch {
|
||||
|
|
|
@ -33,9 +33,9 @@ func (handler *Handler) edgeStackDelete(w http.ResponseWriter, r *http.Request)
|
|||
if featureflags.IsEnabled(portainer.FeatureNoTx) {
|
||||
err = handler.deleteEdgeStack(handler.DataStore, portainer.EdgeStackID(edgeStackID))
|
||||
} else {
|
||||
err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error {
|
||||
return handler.deleteEdgeStack(tx, portainer.EdgeStackID(edgeStackID))
|
||||
})
|
||||
// err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error {
|
||||
// return handler.deleteEdgeStack(tx, portainer.EdgeStackID(edgeStackID))
|
||||
// })
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -46,10 +46,10 @@ func (handler *Handler) edgeStackStatusDelete(w http.ResponseWriter, r *http.Req
|
|||
if featureflags.IsEnabled(portainer.FeatureNoTx) {
|
||||
stack, err = handler.deleteEdgeStackStatus(handler.DataStore, portainer.EdgeStackID(stackID), endpoint)
|
||||
} else {
|
||||
err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error {
|
||||
stack, err = handler.deleteEdgeStackStatus(tx, portainer.EdgeStackID(stackID), endpoint)
|
||||
return err
|
||||
})
|
||||
// err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error {
|
||||
// stack, err = handler.deleteEdgeStackStatus(tx, portainer.EdgeStackID(stackID), endpoint)
|
||||
// return err
|
||||
// })
|
||||
}
|
||||
if err != nil {
|
||||
var httpErr *httperror.HandlerError
|
||||
|
|
|
@ -65,10 +65,10 @@ func (handler *Handler) edgeStackStatusUpdate(w http.ResponseWriter, r *http.Req
|
|||
if featureflags.IsEnabled(portainer.FeatureNoTx) {
|
||||
stack, err = handler.updateEdgeStackStatus(handler.DataStore, r, portainer.EdgeStackID(stackID), payload)
|
||||
} else {
|
||||
err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error {
|
||||
stack, err = handler.updateEdgeStackStatus(tx, r, portainer.EdgeStackID(stackID), payload)
|
||||
return err
|
||||
})
|
||||
// err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error {
|
||||
// stack, err = handler.updateEdgeStackStatus(tx, r, portainer.EdgeStackID(stackID), payload)
|
||||
// return err
|
||||
// })
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -70,10 +70,10 @@ func (handler *Handler) edgeStackUpdate(w http.ResponseWriter, r *http.Request)
|
|||
if featureflags.IsEnabled(portainer.FeatureNoTx) {
|
||||
stack, err = handler.updateEdgeStack(handler.DataStore, portainer.EdgeStackID(stackID), payload)
|
||||
} else {
|
||||
err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error {
|
||||
stack, err = handler.updateEdgeStack(tx, portainer.EdgeStackID(stackID), payload)
|
||||
return err
|
||||
})
|
||||
// err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error {
|
||||
// stack, err = handler.updateEdgeStack(tx, portainer.EdgeStackID(stackID), payload)
|
||||
// return err
|
||||
// })
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -127,7 +127,7 @@ func DecorateCustomTemplates(templates []portainer.CustomTemplate, resourceContr
|
|||
|
||||
resourceControl := GetResourceControlByResourceIDAndType(strconv.Itoa(int(template.ID)), portainer.CustomTemplateResourceControl, resourceControls)
|
||||
if resourceControl != nil {
|
||||
templates[idx].ResourceControlID = resourceControl.ID
|
||||
templates[idx].ResourceControl = resourceControl
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ func FilterAuthorizedCustomTemplates(customTemplates []portainer.CustomTemplate,
|
|||
authorizedTemplates := make([]portainer.CustomTemplate, 0)
|
||||
|
||||
for _, customTemplate := range customTemplates {
|
||||
if customTemplate.CreatedByUserID == user.ID || (customTemplate.ResourceControlID == 0 && UserCanAccessResource(user.ID, userTeamIDs, customTemplate.ResourceControl)) {
|
||||
if customTemplate.CreatedByUserID == user.ID || (customTemplate.ResourceControl == nil && UserCanAccessResource(user.ID, userTeamIDs, customTemplate.ResourceControl)) {
|
||||
authorizedTemplates = append(authorizedTemplates, customTemplate)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,9 +78,7 @@ func createTLSSecuredEndpoint(flags *portainer.CLIFlags, dataStore dataservices.
|
|||
tlsConfiguration.TLS = true
|
||||
}
|
||||
|
||||
endpointID := dataStore.Endpoint().GetNextIdentifier()
|
||||
endpoint := &portainer.Endpoint{
|
||||
ID: portainer.EndpointID(endpointID),
|
||||
Name: "primary",
|
||||
URL: *flags.EndpointURL,
|
||||
GroupID: portainer.EndpointGroupID(1),
|
||||
|
@ -143,9 +141,7 @@ func createUnsecuredEndpoint(endpointURL string, dataStore dataservices.DataStor
|
|||
}
|
||||
}
|
||||
|
||||
endpointID := dataStore.Endpoint().GetNextIdentifier()
|
||||
endpoint := &portainer.Endpoint{
|
||||
ID: portainer.EndpointID(endpointID),
|
||||
Name: "primary",
|
||||
URL: endpointURL,
|
||||
GroupID: portainer.EndpointGroupID(1),
|
||||
|
|
|
@ -181,10 +181,10 @@ type (
|
|||
// * 1 - swarm
|
||||
// * 2 - compose
|
||||
// * 3 - kubernetes
|
||||
Type StackType `json:"Type" example:"1"`
|
||||
ResourceControlID ResourceControlID `json:"ResourceControl" gorm:"foreignKey"`
|
||||
Variables []CustomTemplateVariableDefinition `json:"Variables" gorm:"serialize:json"`
|
||||
GitConfig *gittypes.RepoConfig `json:"GitConfig" gorm:"serialize:json"`
|
||||
Type StackType `json:"Type" example:"1"`
|
||||
ResourceControl *ResourceControl `json:"ResourceControl" gorm:"foreignKey"`
|
||||
Variables []CustomTemplateVariableDefinition `json:"Variables" gorm:"serialize:json"`
|
||||
GitConfig *gittypes.RepoConfig `json:"GitConfig" gorm:"serialize:json"`
|
||||
// IsComposeFormat indicates if the Kubernetes template is created from a Docker Compose file
|
||||
IsComposeFormat bool `example:"false"`
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue