feat(api): introduce new datastore interface (#3802)

* feat(api): introduce new datastore interface

* refactor(api): refactor http and main layers

* refactor(api): refactor http and bolt layers
2.0
Anthony Lapenna 2020-05-20 17:23:15 +12:00 committed by Anthony Lapenna
parent 493de20540
commit 25103f08f9
151 changed files with 792 additions and 1004 deletions

View File

@ -3,34 +3,13 @@ package portainer
// AuthorizationService represents a service used to // AuthorizationService represents a service used to
// update authorizations associated to a user or team. // update authorizations associated to a user or team.
type AuthorizationService struct { type AuthorizationService struct {
endpointService EndpointService dataStore DataStore
endpointGroupService EndpointGroupService
registryService RegistryService
roleService RoleService
teamMembershipService TeamMembershipService
userService UserService
}
// AuthorizationServiceParameters are the required parameters
// used to create a new AuthorizationService.
type AuthorizationServiceParameters struct {
EndpointService EndpointService
EndpointGroupService EndpointGroupService
RegistryService RegistryService
RoleService RoleService
TeamMembershipService TeamMembershipService
UserService UserService
} }
// NewAuthorizationService returns a point to a new AuthorizationService instance. // NewAuthorizationService returns a point to a new AuthorizationService instance.
func NewAuthorizationService(parameters *AuthorizationServiceParameters) *AuthorizationService { func NewAuthorizationService(dataStore DataStore) *AuthorizationService {
return &AuthorizationService{ return &AuthorizationService{
endpointService: parameters.EndpointService, dataStore: dataStore,
endpointGroupService: parameters.EndpointGroupService,
registryService: parameters.RegistryService,
roleService: parameters.RoleService,
teamMembershipService: parameters.TeamMembershipService,
userService: parameters.UserService,
} }
} }
@ -449,7 +428,7 @@ func DefaultPortainerAuthorizations() Authorizations {
// the authorizations will be dropped for the each role. If removeAuthorizations is set to false, the authorizations // the authorizations will be dropped for the each role. If removeAuthorizations is set to false, the authorizations
// will be reset based for each role. // will be reset based for each role.
func (service AuthorizationService) UpdateVolumeBrowsingAuthorizations(remove bool) error { func (service AuthorizationService) UpdateVolumeBrowsingAuthorizations(remove bool) error {
roles, err := service.roleService.Roles() roles, err := service.dataStore.Role().Roles()
if err != nil { if err != nil {
return err return err
} }
@ -459,7 +438,7 @@ func (service AuthorizationService) UpdateVolumeBrowsingAuthorizations(remove bo
if role.ID != RoleID(1) { if role.ID != RoleID(1) {
updateRoleVolumeBrowsingAuthorizations(&role, remove) updateRoleVolumeBrowsingAuthorizations(&role, remove)
err := service.roleService.UpdateRole(role.ID, &role) err := service.dataStore.Role().UpdateRole(role.ID, &role)
if err != nil { if err != nil {
return err return err
} }
@ -492,7 +471,7 @@ func updateRoleVolumeBrowsingAuthorizations(role *Role, removeAuthorizations boo
// RemoveTeamAccessPolicies will remove all existing access policies associated to the specified team // RemoveTeamAccessPolicies will remove all existing access policies associated to the specified team
func (service *AuthorizationService) RemoveTeamAccessPolicies(teamID TeamID) error { func (service *AuthorizationService) RemoveTeamAccessPolicies(teamID TeamID) error {
endpoints, err := service.endpointService.Endpoints() endpoints, err := service.dataStore.Endpoint().Endpoints()
if err != nil { if err != nil {
return err return err
} }
@ -502,7 +481,7 @@ func (service *AuthorizationService) RemoveTeamAccessPolicies(teamID TeamID) err
if policyTeamID == teamID { if policyTeamID == teamID {
delete(endpoint.TeamAccessPolicies, policyTeamID) delete(endpoint.TeamAccessPolicies, policyTeamID)
err := service.endpointService.UpdateEndpoint(endpoint.ID, &endpoint) err := service.dataStore.Endpoint().UpdateEndpoint(endpoint.ID, &endpoint)
if err != nil { if err != nil {
return err return err
} }
@ -512,7 +491,7 @@ func (service *AuthorizationService) RemoveTeamAccessPolicies(teamID TeamID) err
} }
} }
endpointGroups, err := service.endpointGroupService.EndpointGroups() endpointGroups, err := service.dataStore.EndpointGroup().EndpointGroups()
if err != nil { if err != nil {
return err return err
} }
@ -522,7 +501,7 @@ func (service *AuthorizationService) RemoveTeamAccessPolicies(teamID TeamID) err
if policyTeamID == teamID { if policyTeamID == teamID {
delete(endpointGroup.TeamAccessPolicies, policyTeamID) delete(endpointGroup.TeamAccessPolicies, policyTeamID)
err := service.endpointGroupService.UpdateEndpointGroup(endpointGroup.ID, &endpointGroup) err := service.dataStore.EndpointGroup().UpdateEndpointGroup(endpointGroup.ID, &endpointGroup)
if err != nil { if err != nil {
return err return err
} }
@ -532,7 +511,7 @@ func (service *AuthorizationService) RemoveTeamAccessPolicies(teamID TeamID) err
} }
} }
registries, err := service.registryService.Registries() registries, err := service.dataStore.Registry().Registries()
if err != nil { if err != nil {
return err return err
} }
@ -542,7 +521,7 @@ func (service *AuthorizationService) RemoveTeamAccessPolicies(teamID TeamID) err
if policyTeamID == teamID { if policyTeamID == teamID {
delete(registry.TeamAccessPolicies, policyTeamID) delete(registry.TeamAccessPolicies, policyTeamID)
err := service.registryService.UpdateRegistry(registry.ID, &registry) err := service.dataStore.Registry().UpdateRegistry(registry.ID, &registry)
if err != nil { if err != nil {
return err return err
} }
@ -557,7 +536,7 @@ func (service *AuthorizationService) RemoveTeamAccessPolicies(teamID TeamID) err
// RemoveUserAccessPolicies will remove all existing access policies associated to the specified user // RemoveUserAccessPolicies will remove all existing access policies associated to the specified user
func (service *AuthorizationService) RemoveUserAccessPolicies(userID UserID) error { func (service *AuthorizationService) RemoveUserAccessPolicies(userID UserID) error {
endpoints, err := service.endpointService.Endpoints() endpoints, err := service.dataStore.Endpoint().Endpoints()
if err != nil { if err != nil {
return err return err
} }
@ -567,7 +546,7 @@ func (service *AuthorizationService) RemoveUserAccessPolicies(userID UserID) err
if policyUserID == userID { if policyUserID == userID {
delete(endpoint.UserAccessPolicies, policyUserID) delete(endpoint.UserAccessPolicies, policyUserID)
err := service.endpointService.UpdateEndpoint(endpoint.ID, &endpoint) err := service.dataStore.Endpoint().UpdateEndpoint(endpoint.ID, &endpoint)
if err != nil { if err != nil {
return err return err
} }
@ -577,7 +556,7 @@ func (service *AuthorizationService) RemoveUserAccessPolicies(userID UserID) err
} }
} }
endpointGroups, err := service.endpointGroupService.EndpointGroups() endpointGroups, err := service.dataStore.EndpointGroup().EndpointGroups()
if err != nil { if err != nil {
return err return err
} }
@ -587,7 +566,7 @@ func (service *AuthorizationService) RemoveUserAccessPolicies(userID UserID) err
if policyUserID == userID { if policyUserID == userID {
delete(endpointGroup.UserAccessPolicies, policyUserID) delete(endpointGroup.UserAccessPolicies, policyUserID)
err := service.endpointGroupService.UpdateEndpointGroup(endpointGroup.ID, &endpointGroup) err := service.dataStore.EndpointGroup().UpdateEndpointGroup(endpointGroup.ID, &endpointGroup)
if err != nil { if err != nil {
return err return err
} }
@ -597,7 +576,7 @@ func (service *AuthorizationService) RemoveUserAccessPolicies(userID UserID) err
} }
} }
registries, err := service.registryService.Registries() registries, err := service.dataStore.Registry().Registries()
if err != nil { if err != nil {
return err return err
} }
@ -607,7 +586,7 @@ func (service *AuthorizationService) RemoveUserAccessPolicies(userID UserID) err
if policyUserID == userID { if policyUserID == userID {
delete(registry.UserAccessPolicies, policyUserID) delete(registry.UserAccessPolicies, policyUserID)
err := service.registryService.UpdateRegistry(registry.ID, &registry) err := service.dataStore.Registry().UpdateRegistry(registry.ID, &registry)
if err != nil { if err != nil {
return err return err
} }
@ -622,7 +601,7 @@ func (service *AuthorizationService) RemoveUserAccessPolicies(userID UserID) err
// UpdateUsersAuthorizations will trigger an update of the authorizations for all the users. // UpdateUsersAuthorizations will trigger an update of the authorizations for all the users.
func (service *AuthorizationService) UpdateUsersAuthorizations() error { func (service *AuthorizationService) UpdateUsersAuthorizations() error {
users, err := service.userService.Users() users, err := service.dataStore.User().Users()
if err != nil { if err != nil {
return err return err
} }
@ -638,7 +617,7 @@ func (service *AuthorizationService) UpdateUsersAuthorizations() error {
} }
func (service *AuthorizationService) updateUserAuthorizations(userID UserID) error { func (service *AuthorizationService) updateUserAuthorizations(userID UserID) error {
user, err := service.userService.User(userID) user, err := service.dataStore.User().User(userID)
if err != nil { if err != nil {
return err return err
} }
@ -650,7 +629,7 @@ func (service *AuthorizationService) updateUserAuthorizations(userID UserID) err
user.EndpointAuthorizations = endpointAuthorizations user.EndpointAuthorizations = endpointAuthorizations
return service.userService.UpdateUser(userID, user) return service.dataStore.User().UpdateUser(userID, user)
} }
func (service *AuthorizationService) getAuthorizations(user *User) (EndpointAuthorizations, error) { func (service *AuthorizationService) getAuthorizations(user *User) (EndpointAuthorizations, error) {
@ -659,22 +638,22 @@ func (service *AuthorizationService) getAuthorizations(user *User) (EndpointAuth
return endpointAuthorizations, nil return endpointAuthorizations, nil
} }
userMemberships, err := service.teamMembershipService.TeamMembershipsByUserID(user.ID) userMemberships, err := service.dataStore.TeamMembership().TeamMembershipsByUserID(user.ID)
if err != nil { if err != nil {
return endpointAuthorizations, err return endpointAuthorizations, err
} }
endpoints, err := service.endpointService.Endpoints() endpoints, err := service.dataStore.Endpoint().Endpoints()
if err != nil { if err != nil {
return endpointAuthorizations, err return endpointAuthorizations, err
} }
endpointGroups, err := service.endpointGroupService.EndpointGroups() endpointGroups, err := service.dataStore.EndpointGroup().EndpointGroups()
if err != nil { if err != nil {
return endpointAuthorizations, err return endpointAuthorizations, err
} }
roles, err := service.roleService.Roles() roles, err := service.dataStore.Role().Roles()
if err != nil { if err != nil {
return endpointAuthorizations, err return endpointAuthorizations, err
} }

View File

@ -41,7 +41,6 @@ type Store struct {
db *bolt.DB db *bolt.DB
isNew bool isNew bool
fileService portainer.FileService fileService portainer.FileService
RoleService *role.Service
DockerHubService *dockerhub.Service DockerHubService *dockerhub.Service
EdgeGroupService *edgegroup.Service EdgeGroupService *edgegroup.Service
EdgeStackService *edgestack.Service EdgeStackService *edgestack.Service
@ -51,6 +50,8 @@ type Store struct {
ExtensionService *extension.Service ExtensionService *extension.Service
RegistryService *registry.Service RegistryService *registry.Service
ResourceControlService *resourcecontrol.Service ResourceControlService *resourcecontrol.Service
RoleService *role.Service
ScheduleService *schedule.Service
SettingsService *settings.Service SettingsService *settings.Service
StackService *stack.Service StackService *stack.Service
TagService *tag.Service TagService *tag.Service
@ -60,7 +61,6 @@ type Store struct {
UserService *user.Service UserService *user.Service
VersionService *version.Service VersionService *version.Service
WebhookService *webhook.Service WebhookService *webhook.Service
ScheduleService *schedule.Service
} }
// NewStore initializes a new Store and the associated services // NewStore initializes a new Store and the associated services
@ -143,6 +143,7 @@ func (store *Store) MigrateData() error {
UserService: store.UserService, UserService: store.UserService,
VersionService: store.VersionService, VersionService: store.VersionService,
FileService: store.fileService, FileService: store.fileService,
AuthorizationService: portainer.NewAuthorizationService(store),
} }
migrator := migrator.NewMigrator(migratorParams) migrator := migrator.NewMigrator(migratorParams)
@ -280,3 +281,103 @@ func (store *Store) initServices() error {
return nil return nil
} }
// DockerHub gives access to the DockerHub data management layer
func (store *Store) DockerHub() portainer.DockerHubService {
return store.DockerHubService
}
// EdgeGroup gives access to the EdgeGroup data management layer
func (store *Store) EdgeGroup() portainer.EdgeGroupService {
return store.EdgeGroupService
}
// EdgeStack gives access to the EdgeStack data management layer
func (store *Store) EdgeStack() portainer.EdgeStackService {
return store.EdgeStackService
}
// Endpoint gives access to the Endpoint data management layer
func (store *Store) Endpoint() portainer.EndpointService {
return store.EndpointService
}
// EndpointGroup gives access to the EndpointGroup data management layer
func (store *Store) EndpointGroup() portainer.EndpointGroupService {
return store.EndpointGroupService
}
// EndpointRelation gives access to the EndpointRelation data management layer
func (store *Store) EndpointRelation() portainer.EndpointRelationService {
return store.EndpointRelationService
}
// Extension gives access to the Extension data management layer
func (store *Store) Extension() portainer.ExtensionService {
return store.ExtensionService
}
// Registry gives access to the Registry data management layer
func (store *Store) Registry() portainer.RegistryService {
return store.RegistryService
}
// ResourceControl gives access to the ResourceControl data management layer
func (store *Store) ResourceControl() portainer.ResourceControlService {
return store.ResourceControlService
}
// Role gives access to the Role data management layer
func (store *Store) Role() portainer.RoleService {
return store.RoleService
}
// Schedule gives access to the Schedule data management layer
func (store *Store) Schedule() portainer.ScheduleService {
return store.ScheduleService
}
// Settings gives access to the Settings data management layer
func (store *Store) Settings() portainer.SettingsService {
return store.SettingsService
}
// Stack gives access to the Stack data management layer
func (store *Store) Stack() portainer.StackService {
return store.StackService
}
// Tag gives access to the Tag data management layer
func (store *Store) Tag() portainer.TagService {
return store.TagService
}
// TeamMembership gives access to the TeamMembership data management layer
func (store *Store) TeamMembership() portainer.TeamMembershipService {
return store.TeamMembershipService
}
// Team gives access to the Team data management layer
func (store *Store) Team() portainer.TeamService {
return store.TeamService
}
// TunnelServer gives access to the TunnelServer data management layer
func (store *Store) TunnelServer() portainer.TunnelServerService {
return store.TunnelServerService
}
// User gives access to the User data management layer
func (store *Store) User() portainer.UserService {
return store.UserService
}
// Version gives access to the Version data management layer
func (store *Store) Version() portainer.VersionService {
return store.VersionService
}
// Webhook gives access to the Webhook data management layer
func (store *Store) Webhook() portainer.WebhookService {
return store.WebhookService
}

View File

@ -7,17 +7,7 @@ import (
) )
func (m *Migrator) updateUsersToDBVersion20() error { func (m *Migrator) updateUsersToDBVersion20() error {
authorizationServiceParameters := &portainer.AuthorizationServiceParameters{ return m.authorizationService.UpdateUsersAuthorizations()
EndpointService: m.endpointService,
EndpointGroupService: m.endpointGroupService,
RegistryService: m.registryService,
RoleService: m.roleService,
TeamMembershipService: m.teamMembershipService,
UserService: m.userService,
}
authorizationService := portainer.NewAuthorizationService(authorizationServiceParameters)
return authorizationService.UpdateUsersAuthorizations()
} }
func (m *Migrator) updateSettingsToDBVersion20() error { func (m *Migrator) updateSettingsToDBVersion20() error {

View File

@ -74,16 +74,9 @@ func (m *Migrator) updateUsersAndRolesToDBVersion22() error {
readOnlyUserRole.Authorizations = portainer.DefaultEndpointAuthorizationsForReadOnlyUserRole(settings.AllowVolumeBrowserForRegularUsers) readOnlyUserRole.Authorizations = portainer.DefaultEndpointAuthorizationsForReadOnlyUserRole(settings.AllowVolumeBrowserForRegularUsers)
err = m.roleService.UpdateRole(readOnlyUserRole.ID, readOnlyUserRole) err = m.roleService.UpdateRole(readOnlyUserRole.ID, readOnlyUserRole)
if err != nil {
authorizationServiceParameters := &portainer.AuthorizationServiceParameters{ return err
EndpointService: m.endpointService,
EndpointGroupService: m.endpointGroupService,
RegistryService: m.registryService,
RoleService: m.roleService,
TeamMembershipService: m.teamMembershipService,
UserService: m.userService,
} }
authorizationService := portainer.NewAuthorizationService(authorizationServiceParameters) return m.authorizationService.UpdateUsersAuthorizations()
return authorizationService.UpdateUsersAuthorizations()
} }

View File

@ -39,6 +39,7 @@ type (
userService *user.Service userService *user.Service
versionService *version.Service versionService *version.Service
fileService portainer.FileService fileService portainer.FileService
authorizationService *portainer.AuthorizationService
} }
// Parameters represents the required parameters to create a new Migrator instance. // Parameters represents the required parameters to create a new Migrator instance.
@ -60,6 +61,7 @@ type (
UserService *user.Service UserService *user.Service
VersionService *version.Service VersionService *version.Service
FileService portainer.FileService FileService portainer.FileService
AuthorizationService *portainer.AuthorizationService
} }
) )
@ -83,12 +85,12 @@ func NewMigrator(parameters *Parameters) *Migrator {
userService: parameters.UserService, userService: parameters.UserService,
versionService: parameters.VersionService, versionService: parameters.VersionService,
fileService: parameters.FileService, fileService: parameters.FileService,
authorizationService: parameters.AuthorizationService,
} }
} }
// Migrate checks the database version and migrate the existing data to the most recent data model. // Migrate checks the database version and migrate the existing data to the most recent data model.
func (m *Migrator) Migrate() error { func (m *Migrator) Migrate() error {
// Portainer < 1.12 // Portainer < 1.12
if m.currentDBVersion < 1 { if m.currentDBVersion < 1 {
err := m.updateAdminUserToDBVersion1() err := m.updateAdminUserToDBVersion1()

View File

@ -24,21 +24,19 @@ const (
// It is used to start a reverse tunnel server and to manage the connection status of each tunnel // It is used to start a reverse tunnel server and to manage the connection status of each tunnel
// connected to the tunnel server. // connected to the tunnel server.
type Service struct { type Service struct {
serverFingerprint string serverFingerprint string
serverPort string serverPort string
tunnelDetailsMap cmap.ConcurrentMap tunnelDetailsMap cmap.ConcurrentMap
endpointService portainer.EndpointService dataStore portainer.DataStore
tunnelServerService portainer.TunnelServerService snapshotter portainer.Snapshotter
snapshotter portainer.Snapshotter chiselServer *chserver.Server
chiselServer *chserver.Server
} }
// NewService returns a pointer to a new instance of Service // NewService returns a pointer to a new instance of Service
func NewService(endpointService portainer.EndpointService, tunnelServerService portainer.TunnelServerService) *Service { func NewService(dataStore portainer.DataStore) *Service {
return &Service{ return &Service{
tunnelDetailsMap: cmap.New(), tunnelDetailsMap: cmap.New(),
endpointService: endpointService, dataStore: dataStore,
tunnelServerService: tunnelServerService,
} }
} }
@ -89,7 +87,7 @@ func (service *Service) StartTunnelServer(addr, port string, snapshotter portain
func (service *Service) retrievePrivateKeySeed() (string, error) { func (service *Service) retrievePrivateKeySeed() (string, error) {
var serverInfo *portainer.TunnelServerInfo var serverInfo *portainer.TunnelServerInfo
serverInfo, err := service.tunnelServerService.Info() serverInfo, err := service.dataStore.TunnelServer().Info()
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
keySeed := uniuri.NewLen(16) keySeed := uniuri.NewLen(16)
@ -97,7 +95,7 @@ func (service *Service) retrievePrivateKeySeed() (string, error) {
PrivateKeySeed: keySeed, PrivateKeySeed: keySeed,
} }
err := service.tunnelServerService.UpdateInfo(serverInfo) err := service.dataStore.TunnelServer().UpdateInfo(serverInfo)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -173,7 +171,7 @@ func (service *Service) checkTunnels() {
} }
func (service *Service) snapshotEnvironment(endpointID portainer.EndpointID, tunnelPort int) error { func (service *Service) snapshotEnvironment(endpointID portainer.EndpointID, tunnelPort int) error {
endpoint, err := service.endpointService.Endpoint(portainer.EndpointID(endpointID)) endpoint, err := service.dataStore.Endpoint().Endpoint(endpointID)
if err != nil { if err != nil {
return err return err
} }
@ -187,5 +185,5 @@ func (service *Service) snapshotEnvironment(endpointID portainer.EndpointID, tun
endpoint.Snapshots = []portainer.Snapshot{*snapshot} endpoint.Snapshots = []portainer.Snapshot{*snapshot}
endpoint.URL = endpointURL endpoint.URL = endpointURL
return service.endpointService.UpdateEndpoint(endpoint.ID, endpoint) return service.dataStore.Endpoint().UpdateEndpoint(endpoint.ID, endpoint)
} }

View File

@ -97,7 +97,7 @@ func (service *Service) SetTunnelStatusToRequired(endpointID portainer.EndpointI
tunnel := service.GetTunnelDetails(endpointID) tunnel := service.GetTunnelDetails(endpointID)
if tunnel.Port == 0 { if tunnel.Port == 0 {
endpoint, err := service.endpointService.Endpoint(endpointID) endpoint, err := service.dataStore.Endpoint().Endpoint(endpointID)
if err != nil { if err != nil {
return err return err
} }

View File

@ -25,13 +25,13 @@ import (
) )
func initCLI() *portainer.CLIFlags { func initCLI() *portainer.CLIFlags {
var cli portainer.CLIService = &cli.Service{} var cliService portainer.CLIService = &cli.Service{}
flags, err := cli.ParseFlags(portainer.APIVersion) flags, err := cliService.ParseFlags(portainer.APIVersion)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
err = cli.ValidateFlags(flags) err = cliService.ValidateFlags(flags)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -46,7 +46,7 @@ func initFileService(dataStorePath string) portainer.FileService {
return fileService return fileService
} }
func initStore(dataStorePath string, fileService portainer.FileService) *bolt.Store { func initDataStore(dataStorePath string, fileService portainer.FileService) portainer.DataStore {
store, err := bolt.NewStore(dataStorePath, fileService) store, err := bolt.NewStore(dataStorePath, fileService)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -116,13 +116,13 @@ func initJobScheduler() portainer.JobScheduler {
return cron.NewJobScheduler() return cron.NewJobScheduler()
} }
func loadSnapshotSystemSchedule(jobScheduler portainer.JobScheduler, snapshotter portainer.Snapshotter, scheduleService portainer.ScheduleService, endpointService portainer.EndpointService, settingsService portainer.SettingsService) error { func loadSnapshotSystemSchedule(jobScheduler portainer.JobScheduler, snapshotter portainer.Snapshotter, dataStore portainer.DataStore) error {
settings, err := settingsService.Settings() settings, err := dataStore.Settings().Settings()
if err != nil { if err != nil {
return err return err
} }
schedules, err := scheduleService.SchedulesByJobType(portainer.SnapshotJobType) schedules, err := dataStore.Schedule().SchedulesByJobType(portainer.SnapshotJobType)
if err != nil { if err != nil {
return err return err
} }
@ -131,7 +131,7 @@ func loadSnapshotSystemSchedule(jobScheduler portainer.JobScheduler, snapshotter
if len(schedules) == 0 { if len(schedules) == 0 {
snapshotJob := &portainer.SnapshotJob{} snapshotJob := &portainer.SnapshotJob{}
snapshotSchedule = &portainer.Schedule{ snapshotSchedule = &portainer.Schedule{
ID: portainer.ScheduleID(scheduleService.GetNextIdentifier()), ID: portainer.ScheduleID(dataStore.Schedule().GetNextIdentifier()),
Name: "system_snapshot", Name: "system_snapshot",
CronExpression: "@every " + settings.SnapshotInterval, CronExpression: "@every " + settings.SnapshotInterval,
Recurring: true, Recurring: true,
@ -143,7 +143,7 @@ func loadSnapshotSystemSchedule(jobScheduler portainer.JobScheduler, snapshotter
snapshotSchedule = &schedules[0] snapshotSchedule = &schedules[0]
} }
snapshotJobContext := cron.NewSnapshotJobContext(endpointService, snapshotter) snapshotJobContext := cron.NewSnapshotJobContext(dataStore, snapshotter)
snapshotJobRunner := cron.NewSnapshotJobRunner(snapshotSchedule, snapshotJobContext) snapshotJobRunner := cron.NewSnapshotJobRunner(snapshotSchedule, snapshotJobContext)
err = jobScheduler.ScheduleJob(snapshotJobRunner) err = jobScheduler.ScheduleJob(snapshotJobRunner)
@ -152,13 +152,13 @@ func loadSnapshotSystemSchedule(jobScheduler portainer.JobScheduler, snapshotter
} }
if len(schedules) == 0 { if len(schedules) == 0 {
return scheduleService.CreateSchedule(snapshotSchedule) return dataStore.Schedule().CreateSchedule(snapshotSchedule)
} }
return nil return nil
} }
func loadSchedulesFromDatabase(jobScheduler portainer.JobScheduler, jobService portainer.JobService, scheduleService portainer.ScheduleService, endpointService portainer.EndpointService, fileService portainer.FileService, reverseTunnelService portainer.ReverseTunnelService) error { func loadSchedulesFromDatabase(jobScheduler portainer.JobScheduler, jobService portainer.JobService, dataStore portainer.DataStore, fileService portainer.FileService, reverseTunnelService portainer.ReverseTunnelService) error {
schedules, err := scheduleService.Schedules() schedules, err := dataStore.Schedule().Schedules()
if err != nil { if err != nil {
return err return err
} }
@ -166,7 +166,7 @@ func loadSchedulesFromDatabase(jobScheduler portainer.JobScheduler, jobService p
for _, schedule := range schedules { for _, schedule := range schedules {
if schedule.JobType == portainer.ScriptExecutionJobType { if schedule.JobType == portainer.ScriptExecutionJobType {
jobContext := cron.NewScriptExecutionJobContext(jobService, endpointService, fileService) jobContext := cron.NewScriptExecutionJobContext(jobService, dataStore, fileService)
jobRunner := cron.NewScriptExecutionJobRunner(&schedule, jobContext) jobRunner := cron.NewScriptExecutionJobRunner(&schedule, jobContext)
err = jobScheduler.ScheduleJob(jobRunner) err = jobScheduler.ScheduleJob(jobRunner)
@ -194,8 +194,8 @@ func initStatus(flags *portainer.CLIFlags) *portainer.Status {
} }
} }
func updateSettingsFromFlags(settingsService portainer.SettingsService, flags *portainer.CLIFlags) error { func updateSettingsFromFlags(dataStore portainer.DataStore, flags *portainer.CLIFlags) error {
settings, err := settingsService.Settings() settings, err := dataStore.Settings().Settings()
if err != nil { if err != nil {
return err return err
} }
@ -211,7 +211,7 @@ func updateSettingsFromFlags(settingsService portainer.SettingsService, flags *p
settings.BlackListedLabels = *flags.Labels settings.BlackListedLabels = *flags.Labels
} }
return settingsService.UpdateSettings(settings) return dataStore.Settings().UpdateSettings(settings)
} }
func loadAndParseKeyPair(fileService portainer.FileService, signatureService portainer.DigitalSignatureService) error { func loadAndParseKeyPair(fileService portainer.FileService, signatureService portainer.DigitalSignatureService) error {
@ -243,7 +243,7 @@ func initKeyPair(fileService portainer.FileService, signatureService portainer.D
return generateAndStoreKeyPair(fileService, signatureService) return generateAndStoreKeyPair(fileService, signatureService)
} }
func createTLSSecuredEndpoint(flags *portainer.CLIFlags, endpointService portainer.EndpointService, snapshotter portainer.Snapshotter) error { func createTLSSecuredEndpoint(flags *portainer.CLIFlags, dataStore portainer.DataStore, snapshotter portainer.Snapshotter) error {
tlsConfiguration := portainer.TLSConfiguration{ tlsConfiguration := portainer.TLSConfiguration{
TLS: *flags.TLS, TLS: *flags.TLS,
TLSSkipVerify: *flags.TLSSkipVerify, TLSSkipVerify: *flags.TLSSkipVerify,
@ -257,7 +257,7 @@ func createTLSSecuredEndpoint(flags *portainer.CLIFlags, endpointService portain
tlsConfiguration.TLS = true tlsConfiguration.TLS = true
} }
endpointID := endpointService.GetNextIdentifier() endpointID := dataStore.Endpoint().GetNextIdentifier()
endpoint := &portainer.Endpoint{ endpoint := &portainer.Endpoint{
ID: portainer.EndpointID(endpointID), ID: portainer.EndpointID(endpointID),
Name: "primary", Name: "primary",
@ -289,10 +289,10 @@ func createTLSSecuredEndpoint(flags *portainer.CLIFlags, endpointService portain
} }
} }
return snapshotAndPersistEndpoint(endpoint, endpointService, snapshotter) return snapshotAndPersistEndpoint(endpoint, dataStore, snapshotter)
} }
func createUnsecuredEndpoint(endpointURL string, endpointService portainer.EndpointService, snapshotter portainer.Snapshotter) error { func createUnsecuredEndpoint(endpointURL string, dataStore portainer.DataStore, snapshotter portainer.Snapshotter) error {
if strings.HasPrefix(endpointURL, "tcp://") { if strings.HasPrefix(endpointURL, "tcp://") {
_, err := client.ExecutePingOperation(endpointURL, nil) _, err := client.ExecutePingOperation(endpointURL, nil)
if err != nil { if err != nil {
@ -300,7 +300,7 @@ func createUnsecuredEndpoint(endpointURL string, endpointService portainer.Endpo
} }
} }
endpointID := endpointService.GetNextIdentifier() endpointID := dataStore.Endpoint().GetNextIdentifier()
endpoint := &portainer.Endpoint{ endpoint := &portainer.Endpoint{
ID: portainer.EndpointID(endpointID), ID: portainer.EndpointID(endpointID),
Name: "primary", Name: "primary",
@ -316,10 +316,10 @@ func createUnsecuredEndpoint(endpointURL string, endpointService portainer.Endpo
Snapshots: []portainer.Snapshot{}, Snapshots: []portainer.Snapshot{},
} }
return snapshotAndPersistEndpoint(endpoint, endpointService, snapshotter) return snapshotAndPersistEndpoint(endpoint, dataStore, snapshotter)
} }
func snapshotAndPersistEndpoint(endpoint *portainer.Endpoint, endpointService portainer.EndpointService, snapshotter portainer.Snapshotter) error { func snapshotAndPersistEndpoint(endpoint *portainer.Endpoint, dataStore portainer.DataStore, snapshotter portainer.Snapshotter) error {
snapshot, err := snapshotter.CreateSnapshot(endpoint) snapshot, err := snapshotter.CreateSnapshot(endpoint)
endpoint.Status = portainer.EndpointStatusUp endpoint.Status = portainer.EndpointStatusUp
if err != nil { if err != nil {
@ -330,15 +330,15 @@ func snapshotAndPersistEndpoint(endpoint *portainer.Endpoint, endpointService po
endpoint.Snapshots = []portainer.Snapshot{*snapshot} endpoint.Snapshots = []portainer.Snapshot{*snapshot}
} }
return endpointService.CreateEndpoint(endpoint) return dataStore.Endpoint().CreateEndpoint(endpoint)
} }
func initEndpoint(flags *portainer.CLIFlags, endpointService portainer.EndpointService, snapshotter portainer.Snapshotter) error { func initEndpoint(flags *portainer.CLIFlags, dataStore portainer.DataStore, snapshotter portainer.Snapshotter) error {
if *flags.EndpointURL == "" { if *flags.EndpointURL == "" {
return nil return nil
} }
endpoints, err := endpointService.Endpoints() endpoints, err := dataStore.Endpoint().Endpoints()
if err != nil { if err != nil {
return err return err
} }
@ -349,17 +349,17 @@ func initEndpoint(flags *portainer.CLIFlags, endpointService portainer.EndpointS
} }
if *flags.TLS || *flags.TLSSkipVerify { if *flags.TLS || *flags.TLSSkipVerify {
return createTLSSecuredEndpoint(flags, endpointService, snapshotter) return createTLSSecuredEndpoint(flags, dataStore, snapshotter)
} }
return createUnsecuredEndpoint(*flags.EndpointURL, endpointService, snapshotter) return createUnsecuredEndpoint(*flags.EndpointURL, dataStore, snapshotter)
} }
func initJobService(dockerClientFactory *docker.ClientFactory) portainer.JobService { func initJobService(dockerClientFactory *docker.ClientFactory) portainer.JobService {
return docker.NewJobService(dockerClientFactory) return docker.NewJobService(dockerClientFactory)
} }
func initExtensionManager(fileService portainer.FileService, extensionService portainer.ExtensionService) (portainer.ExtensionManager, error) { func initExtensionManager(fileService portainer.FileService, dataStore portainer.DataStore) (portainer.ExtensionManager, error) {
extensionManager := exec.NewExtensionManager(fileService, extensionService) extensionManager := exec.NewExtensionManager(fileService, dataStore)
err := extensionManager.StartExtensions() err := extensionManager.StartExtensions()
if err != nil { if err != nil {
@ -369,11 +369,11 @@ func initExtensionManager(fileService portainer.FileService, extensionService po
return extensionManager, nil return extensionManager, nil
} }
func terminateIfNoAdminCreated(userService portainer.UserService) { func terminateIfNoAdminCreated(dataStore portainer.DataStore) {
timer1 := time.NewTimer(5 * time.Minute) timer1 := time.NewTimer(5 * time.Minute)
<-timer1.C <-timer1.C
users, err := userService.UsersByRole(portainer.AdministratorRole) users, err := dataStore.User().UsersByRole(portainer.AdministratorRole)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -389,8 +389,8 @@ func main() {
fileService := initFileService(*flags.Data) fileService := initFileService(*flags.Data)
store := initStore(*flags.Data, fileService) dataStore := initDataStore(*flags.Data, fileService)
defer store.Close() defer dataStore.Close()
jwtService := initJWTService(!*flags.NoAuth) jwtService := initJWTService(!*flags.NoAuth)
@ -407,12 +407,12 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
extensionManager, err := initExtensionManager(fileService, store.ExtensionService) extensionManager, err := initExtensionManager(fileService, dataStore)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
reverseTunnelService := chisel.NewService(store.EndpointService, store.TunnelServerService) reverseTunnelService := chisel.NewService(dataStore)
clientFactory := initClientFactory(digitalSignatureService, reverseTunnelService) clientFactory := initClientFactory(digitalSignatureService, reverseTunnelService)
@ -427,8 +427,8 @@ func main() {
composeStackManager := initComposeStackManager(*flags.Data, reverseTunnelService) composeStackManager := initComposeStackManager(*flags.Data, reverseTunnelService)
if store.IsNew() { if dataStore.IsNew() {
err = updateSettingsFromFlags(store.SettingsService, flags) err = updateSettingsFromFlags(dataStore, flags)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -436,12 +436,12 @@ func main() {
jobScheduler := initJobScheduler() jobScheduler := initJobScheduler()
err = loadSchedulesFromDatabase(jobScheduler, jobService, store.ScheduleService, store.EndpointService, fileService, reverseTunnelService) err = loadSchedulesFromDatabase(jobScheduler, jobService, dataStore, fileService, reverseTunnelService)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
err = loadSnapshotSystemSchedule(jobScheduler, snapshotter, store.ScheduleService, store.EndpointService, store.SettingsService) err = loadSnapshotSystemSchedule(jobScheduler, snapshotter, dataStore)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -450,7 +450,7 @@ func main() {
applicationStatus := initStatus(flags) applicationStatus := initStatus(flags)
err = initEndpoint(flags, store.EndpointService, snapshotter) err = initEndpoint(flags, dataStore, snapshotter)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -470,7 +470,7 @@ func main() {
} }
if adminPasswordHash != "" { if adminPasswordHash != "" {
users, err := store.UserService.UsersByRole(portainer.AdministratorRole) users, err := dataStore.User().UsersByRole(portainer.AdministratorRole)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -483,7 +483,7 @@ func main() {
Password: adminPasswordHash, Password: adminPasswordHash,
PortainerAuthorizations: portainer.DefaultPortainerAuthorizations(), PortainerAuthorizations: portainer.DefaultPortainerAuthorizations(),
} }
err := store.UserService.CreateUser(user) err := dataStore.User().CreateUser(user)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -493,7 +493,7 @@ func main() {
} }
if !*flags.NoAuth { if !*flags.NoAuth {
go terminateIfNoAdminCreated(store.UserService) go terminateIfNoAdminCreated(dataStore)
} }
err = reverseTunnelService.StartTunnelServer(*flags.TunnelAddr, *flags.TunnelPort, snapshotter) err = reverseTunnelService.StartTunnelServer(*flags.TunnelAddr, *flags.TunnelPort, snapshotter)
@ -502,45 +502,28 @@ func main() {
} }
var server portainer.Server = &http.Server{ var server portainer.Server = &http.Server{
ReverseTunnelService: reverseTunnelService, ReverseTunnelService: reverseTunnelService,
Status: applicationStatus, Status: applicationStatus,
BindAddress: *flags.Addr, BindAddress: *flags.Addr,
AssetsPath: *flags.Assets, AssetsPath: *flags.Assets,
AuthDisabled: *flags.NoAuth, AuthDisabled: *flags.NoAuth,
RoleService: store.RoleService, DataStore: dataStore,
UserService: store.UserService, SwarmStackManager: swarmStackManager,
TeamService: store.TeamService, ComposeStackManager: composeStackManager,
TeamMembershipService: store.TeamMembershipService, ExtensionManager: extensionManager,
EdgeGroupService: store.EdgeGroupService, CryptoService: cryptoService,
EdgeStackService: store.EdgeStackService, JWTService: jwtService,
EndpointService: store.EndpointService, FileService: fileService,
EndpointGroupService: store.EndpointGroupService, LDAPService: ldapService,
EndpointRelationService: store.EndpointRelationService, GitService: gitService,
ExtensionService: store.ExtensionService, SignatureService: digitalSignatureService,
ResourceControlService: store.ResourceControlService, JobScheduler: jobScheduler,
SettingsService: store.SettingsService, Snapshotter: snapshotter,
RegistryService: store.RegistryService, SSL: *flags.SSL,
DockerHubService: store.DockerHubService, SSLCert: *flags.SSLCert,
StackService: store.StackService, SSLKey: *flags.SSLKey,
ScheduleService: store.ScheduleService, DockerClientFactory: clientFactory,
TagService: store.TagService, JobService: jobService,
WebhookService: store.WebhookService,
SwarmStackManager: swarmStackManager,
ComposeStackManager: composeStackManager,
ExtensionManager: extensionManager,
CryptoService: cryptoService,
JWTService: jwtService,
FileService: fileService,
LDAPService: ldapService,
GitService: gitService,
SignatureService: digitalSignatureService,
JobScheduler: jobScheduler,
Snapshotter: snapshotter,
SSL: *flags.SSL,
SSLCert: *flags.SSLCert,
SSLKey: *flags.SSLKey,
DockerClientFactory: clientFactory,
JobService: jobService,
} }
log.Printf("Starting Portainer %s on %s", portainer.APIVersion, *flags.Addr) log.Printf("Starting Portainer %s on %s", portainer.APIVersion, *flags.Addr)

View File

@ -16,17 +16,17 @@ type ScriptExecutionJobRunner struct {
// ScriptExecutionJobContext represents the context of execution of a ScriptExecutionJob // ScriptExecutionJobContext represents the context of execution of a ScriptExecutionJob
type ScriptExecutionJobContext struct { type ScriptExecutionJobContext struct {
jobService portainer.JobService dataStore portainer.DataStore
endpointService portainer.EndpointService jobService portainer.JobService
fileService portainer.FileService fileService portainer.FileService
} }
// NewScriptExecutionJobContext returns a new context that can be used to execute a ScriptExecutionJob // NewScriptExecutionJobContext returns a new context that can be used to execute a ScriptExecutionJob
func NewScriptExecutionJobContext(jobService portainer.JobService, endpointService portainer.EndpointService, fileService portainer.FileService) *ScriptExecutionJobContext { func NewScriptExecutionJobContext(jobService portainer.JobService, dataStore portainer.DataStore, fileService portainer.FileService) *ScriptExecutionJobContext {
return &ScriptExecutionJobContext{ return &ScriptExecutionJobContext{
jobService: jobService, jobService: jobService,
endpointService: endpointService, dataStore: dataStore,
fileService: fileService, fileService: fileService,
} }
} }
@ -56,7 +56,7 @@ func (runner *ScriptExecutionJobRunner) Run() {
targets := make([]*portainer.Endpoint, 0) targets := make([]*portainer.Endpoint, 0)
for _, endpointID := range runner.schedule.ScriptExecutionJob.Endpoints { for _, endpointID := range runner.schedule.ScriptExecutionJob.Endpoints {
endpoint, err := runner.context.endpointService.Endpoint(endpointID) endpoint, err := runner.context.dataStore.Endpoint().Endpoint(endpointID)
if err != nil { if err != nil {
log.Printf("scheduled job error (script execution). Unable to retrieve information about endpoint (id=%d) (err=%s)\n", endpointID, err) log.Printf("scheduled job error (script execution). Unable to retrieve information about endpoint (id=%d) (err=%s)\n", endpointID, err)
return return

View File

@ -14,15 +14,15 @@ type SnapshotJobRunner struct {
// SnapshotJobContext represents the context of execution of a SnapshotJob // SnapshotJobContext represents the context of execution of a SnapshotJob
type SnapshotJobContext struct { type SnapshotJobContext struct {
endpointService portainer.EndpointService dataStore portainer.DataStore
snapshotter portainer.Snapshotter snapshotter portainer.Snapshotter
} }
// NewSnapshotJobContext returns a new context that can be used to execute a SnapshotJob // NewSnapshotJobContext returns a new context that can be used to execute a SnapshotJob
func NewSnapshotJobContext(endpointService portainer.EndpointService, snapshotter portainer.Snapshotter) *SnapshotJobContext { func NewSnapshotJobContext(dataStore portainer.DataStore, snapshotter portainer.Snapshotter) *SnapshotJobContext {
return &SnapshotJobContext{ return &SnapshotJobContext{
endpointService: endpointService, dataStore: dataStore,
snapshotter: snapshotter, snapshotter: snapshotter,
} }
} }
@ -46,7 +46,7 @@ func (runner *SnapshotJobRunner) GetSchedule() *portainer.Schedule {
// retrieve the latest version of the endpoint right after a snapshot. // retrieve the latest version of the endpoint right after a snapshot.
func (runner *SnapshotJobRunner) Run() { func (runner *SnapshotJobRunner) Run() {
go func() { go func() {
endpoints, err := runner.context.endpointService.Endpoints() endpoints, err := runner.context.dataStore.Endpoint().Endpoints()
if err != nil { if err != nil {
log.Printf("background schedule error (endpoint snapshot). Unable to retrieve endpoint list (err=%s)\n", err) log.Printf("background schedule error (endpoint snapshot). Unable to retrieve endpoint list (err=%s)\n", err)
return return
@ -59,7 +59,7 @@ func (runner *SnapshotJobRunner) Run() {
snapshot, snapshotError := runner.context.snapshotter.CreateSnapshot(&endpoint) snapshot, snapshotError := runner.context.snapshotter.CreateSnapshot(&endpoint)
latestEndpointReference, err := runner.context.endpointService.Endpoint(endpoint.ID) latestEndpointReference, err := runner.context.dataStore.Endpoint().Endpoint(endpoint.ID)
if latestEndpointReference == nil { if latestEndpointReference == nil {
log.Printf("background schedule error (endpoint snapshot). Endpoint not found inside the database anymore (endpoint=%s, URL=%s) (err=%s)\n", endpoint.Name, endpoint.URL, err) log.Printf("background schedule error (endpoint snapshot). Endpoint not found inside the database anymore (endpoint=%s, URL=%s) (err=%s)\n", endpoint.Name, endpoint.URL, err)
continue continue
@ -75,7 +75,7 @@ func (runner *SnapshotJobRunner) Run() {
latestEndpointReference.Snapshots = []portainer.Snapshot{*snapshot} latestEndpointReference.Snapshots = []portainer.Snapshot{*snapshot}
} }
err = runner.context.endpointService.UpdateEndpoint(latestEndpointReference.ID, latestEndpointReference) err = runner.context.dataStore.Endpoint().UpdateEndpoint(latestEndpointReference.ID, latestEndpointReference)
if err != nil { if err != nil {
log.Printf("background schedule error (endpoint snapshot). Unable to update endpoint (endpoint=%s, URL=%s) (err=%s)\n", endpoint.Name, endpoint.URL, err) log.Printf("background schedule error (endpoint snapshot). Unable to update endpoint (endpoint=%s, URL=%s) (err=%s)\n", endpoint.Name, endpoint.URL, err)
return return

View File

@ -34,17 +34,17 @@ var extensionBinaryMap = map[portainer.ExtensionID]string{
// ExtensionManager represents a service used to // ExtensionManager represents a service used to
// manage extension processes. // manage extension processes.
type ExtensionManager struct { type ExtensionManager struct {
processes cmap.ConcurrentMap processes cmap.ConcurrentMap
fileService portainer.FileService fileService portainer.FileService
extensionService portainer.ExtensionService dataStore portainer.DataStore
} }
// NewExtensionManager returns a pointer to an ExtensionManager // NewExtensionManager returns a pointer to an ExtensionManager
func NewExtensionManager(fileService portainer.FileService, extensionService portainer.ExtensionService) *ExtensionManager { func NewExtensionManager(fileService portainer.FileService, dataStore portainer.DataStore) *ExtensionManager {
return &ExtensionManager{ return &ExtensionManager{
processes: cmap.New(), processes: cmap.New(),
fileService: fileService, fileService: fileService,
extensionService: extensionService, dataStore: dataStore,
} }
} }
@ -188,7 +188,7 @@ func (manager *ExtensionManager) DisableExtension(extension *portainer.Extension
// The purpose of this function is to be ran at startup, as such most of the error handling won't block the program execution // The purpose of this function is to be ran at startup, as such most of the error handling won't block the program execution
// and will log warning messages instead. // and will log warning messages instead.
func (manager *ExtensionManager) StartExtensions() error { func (manager *ExtensionManager) StartExtensions() error {
extensions, err := manager.extensionService.Extensions() extensions, err := manager.dataStore.Extension().Extensions()
if err != nil { if err != nil {
return err return err
} }
@ -224,7 +224,7 @@ func (manager *ExtensionManager) updateAndStartExtensions(extensions []portainer
} }
} }
err := manager.extensionService.Persist(&extension) err := manager.dataStore.Extension().Persist(&extension)
if err != nil { if err != nil {
return err return err
} }

View File

@ -42,12 +42,12 @@ func (handler *Handler) authenticate(w http.ResponseWriter, r *http.Request) *ht
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
} }
settings, err := handler.SettingsService.Settings() settings, err := handler.DataStore.Settings().Settings()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve settings from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve settings from the database", err}
} }
u, err := handler.UserService.UserByUsername(payload.Username) u, err := handler.DataStore.User().UserByUsername(payload.Username)
if err != nil && err != portainer.ErrObjectNotFound { if err != nil && err != portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve a user with the specified username from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve a user with the specified username from the database", err}
} }
@ -108,7 +108,7 @@ func (handler *Handler) authenticateLDAPAndCreateUser(w http.ResponseWriter, use
PortainerAuthorizations: portainer.DefaultPortainerAuthorizations(), PortainerAuthorizations: portainer.DefaultPortainerAuthorizations(),
} }
err = handler.UserService.CreateUser(user) err = handler.DataStore.User().CreateUser(user)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist user inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist user inside the database", err}
} }
@ -146,7 +146,7 @@ func (handler *Handler) persistAndWriteToken(w http.ResponseWriter, tokenData *p
} }
func (handler *Handler) addUserIntoTeams(user *portainer.User, settings *portainer.LDAPSettings) error { func (handler *Handler) addUserIntoTeams(user *portainer.User, settings *portainer.LDAPSettings) error {
teams, err := handler.TeamService.Teams() teams, err := handler.DataStore.Team().Teams()
if err != nil { if err != nil {
return err return err
} }
@ -156,7 +156,7 @@ func (handler *Handler) addUserIntoTeams(user *portainer.User, settings *portain
return err return err
} }
userMemberships, err := handler.TeamMembershipService.TeamMembershipsByUserID(user.ID) userMemberships, err := handler.DataStore.TeamMembership().TeamMembershipsByUserID(user.ID)
if err != nil { if err != nil {
return err return err
} }
@ -174,7 +174,7 @@ func (handler *Handler) addUserIntoTeams(user *portainer.User, settings *portain
Role: portainer.TeamMember, Role: portainer.TeamMember,
} }
err := handler.TeamMembershipService.CreateTeamMembership(membership) err := handler.DataStore.TeamMembership().CreateTeamMembership(membership)
if err != nil { if err != nil {
return err return err
} }

View File

@ -78,7 +78,7 @@ func (handler *Handler) validateOAuth(w http.ResponseWriter, r *http.Request) *h
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
} }
settings, err := handler.SettingsService.Settings() settings, err := handler.DataStore.Settings().Settings()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve settings from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve settings from the database", err}
} }
@ -87,7 +87,7 @@ func (handler *Handler) validateOAuth(w http.ResponseWriter, r *http.Request) *h
return &httperror.HandlerError{http.StatusForbidden, "OAuth authentication is not enabled", portainer.Error("OAuth authentication is not enabled")} return &httperror.HandlerError{http.StatusForbidden, "OAuth authentication is not enabled", portainer.Error("OAuth authentication is not enabled")}
} }
extension, err := handler.ExtensionService.Extension(portainer.OAuthAuthenticationExtension) extension, err := handler.DataStore.Extension().Extension(portainer.OAuthAuthenticationExtension)
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Oauth authentication extension is not enabled", err} return &httperror.HandlerError{http.StatusNotFound, "Oauth authentication extension is not enabled", err}
} else if err != nil { } else if err != nil {
@ -100,7 +100,7 @@ func (handler *Handler) validateOAuth(w http.ResponseWriter, r *http.Request) *h
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to authenticate through OAuth", portainer.ErrUnauthorized} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to authenticate through OAuth", portainer.ErrUnauthorized}
} }
user, err := handler.UserService.UserByUsername(username) user, err := handler.DataStore.User().UserByUsername(username)
if err != nil && err != portainer.ErrObjectNotFound { if err != nil && err != portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve a user with the specified username from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve a user with the specified username from the database", err}
} }
@ -116,7 +116,7 @@ func (handler *Handler) validateOAuth(w http.ResponseWriter, r *http.Request) *h
PortainerAuthorizations: portainer.DefaultPortainerAuthorizations(), PortainerAuthorizations: portainer.DefaultPortainerAuthorizations(),
} }
err = handler.UserService.CreateUser(user) err = handler.DataStore.User().CreateUser(user)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist user inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist user inside the database", err}
} }
@ -128,7 +128,7 @@ func (handler *Handler) validateOAuth(w http.ResponseWriter, r *http.Request) *h
Role: portainer.TeamMember, Role: portainer.TeamMember,
} }
err = handler.TeamMembershipService.CreateTeamMembership(membership) err = handler.DataStore.TeamMembership().CreateTeamMembership(membership)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist team membership inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist team membership inside the database", err}
} }

View File

@ -11,8 +11,6 @@ import (
) )
const ( const (
// ErrInvalidCredentials is an error raised when credentials for a user are invalid
ErrInvalidCredentials = portainer.Error("Invalid credentials")
// ErrAuthDisabled is an error raised when trying to access the authentication endpoints // ErrAuthDisabled is an error raised when trying to access the authentication endpoints
// when the server has been started with the --no-auth flag // when the server has been started with the --no-auth flag
ErrAuthDisabled = portainer.Error("Authentication is disabled") ErrAuthDisabled = portainer.Error("Authentication is disabled")
@ -21,20 +19,13 @@ const (
// Handler is the HTTP handler used to handle authentication operations. // Handler is the HTTP handler used to handle authentication operations.
type Handler struct { type Handler struct {
*mux.Router *mux.Router
authDisabled bool authDisabled bool
UserService portainer.UserService DataStore portainer.DataStore
CryptoService portainer.CryptoService CryptoService portainer.CryptoService
JWTService portainer.JWTService JWTService portainer.JWTService
LDAPService portainer.LDAPService LDAPService portainer.LDAPService
SettingsService portainer.SettingsService ProxyManager *proxy.Manager
TeamService portainer.TeamService AuthorizationService *portainer.AuthorizationService
TeamMembershipService portainer.TeamMembershipService
ExtensionService portainer.ExtensionService
EndpointService portainer.EndpointService
EndpointGroupService portainer.EndpointGroupService
RoleService portainer.RoleService
ProxyManager *proxy.Manager
AuthorizationService *portainer.AuthorizationService
} }
// NewHandler creates a handler to manage authentication operations. // NewHandler creates a handler to manage authentication operations.

View File

@ -9,7 +9,7 @@ import (
// GET request on /api/dockerhub // GET request on /api/dockerhub
func (handler *Handler) dockerhubInspect(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { func (handler *Handler) dockerhubInspect(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
dockerhub, err := handler.DockerHubService.DockerHub() dockerhub, err := handler.DataStore.DockerHub().DockerHub()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve DockerHub details from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve DockerHub details from the database", err}
} }

View File

@ -43,7 +43,7 @@ func (handler *Handler) dockerhubUpdate(w http.ResponseWriter, r *http.Request)
dockerhub.Password = payload.Password dockerhub.Password = payload.Password
} }
err = handler.DockerHubService.UpdateDockerHub(dockerhub) err = handler.DataStore.DockerHub().UpdateDockerHub(dockerhub)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the Dockerhub changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the Dockerhub changes inside the database", err}
} }

View File

@ -16,7 +16,7 @@ func hideFields(dockerHub *portainer.DockerHub) {
// Handler is the HTTP handler used to handle DockerHub operations. // Handler is the HTTP handler used to handle DockerHub operations.
type Handler struct { type Handler struct {
*mux.Router *mux.Router
DockerHubService portainer.DockerHubService DataStore portainer.DataStore
} }
// NewHandler creates a handler to manage Dockerhub operations. // NewHandler creates a handler to manage Dockerhub operations.

View File

@ -11,7 +11,7 @@ func (handler *Handler) getEndpointsByTags(tagIDs []portainer.TagID, partialMatc
return []portainer.EndpointID{}, nil return []portainer.EndpointID{}, nil
} }
endpoints, err := handler.EndpointService.Endpoints() endpoints, err := handler.DataStore.Endpoint().Endpoints()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -20,7 +20,7 @@ func (handler *Handler) getEndpointsByTags(tagIDs []portainer.TagID, partialMatc
tags := []portainer.Tag{} tags := []portainer.Tag{}
for _, tagID := range tagIDs { for _, tagID := range tagIDs {
tag, err := handler.TagService.Tag(tagID) tag, err := handler.DataStore.Tag().Tag(tagID)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -38,7 +38,7 @@ func (handler *Handler) edgeGroupCreate(w http.ResponseWriter, r *http.Request)
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
} }
edgeGroups, err := handler.EdgeGroupService.EdgeGroups() edgeGroups, err := handler.DataStore.EdgeGroup().EdgeGroups()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve Edge groups from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve Edge groups from the database", err}
} }
@ -62,7 +62,7 @@ func (handler *Handler) edgeGroupCreate(w http.ResponseWriter, r *http.Request)
} else { } else {
endpointIDs := []portainer.EndpointID{} endpointIDs := []portainer.EndpointID{}
for _, endpointID := range payload.Endpoints { for _, endpointID := range payload.Endpoints {
endpoint, err := handler.EndpointService.Endpoint(endpointID) endpoint, err := handler.DataStore.Endpoint().Endpoint(endpointID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoint from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoint from the database", err}
} }
@ -74,7 +74,7 @@ func (handler *Handler) edgeGroupCreate(w http.ResponseWriter, r *http.Request)
edgeGroup.Endpoints = endpointIDs edgeGroup.Endpoints = endpointIDs
} }
err = handler.EdgeGroupService.CreateEdgeGroup(edgeGroup) err = handler.DataStore.EdgeGroup().CreateEdgeGroup(edgeGroup)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the Edge group inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the Edge group inside the database", err}
} }

View File

@ -15,14 +15,14 @@ func (handler *Handler) edgeGroupDelete(w http.ResponseWriter, r *http.Request)
return &httperror.HandlerError{http.StatusBadRequest, "Invalid Edge group identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid Edge group identifier route variable", err}
} }
_, err = handler.EdgeGroupService.EdgeGroup(portainer.EdgeGroupID(edgeGroupID)) _, err = handler.DataStore.EdgeGroup().EdgeGroup(portainer.EdgeGroupID(edgeGroupID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an Edge group with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an Edge group with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find an Edge group with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find an Edge group with the specified identifier inside the database", err}
} }
edgeStacks, err := handler.EdgeStackService.EdgeStacks() edgeStacks, err := handler.DataStore.EdgeStack().EdgeStacks()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve Edge stacks from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve Edge stacks from the database", err}
} }
@ -35,7 +35,7 @@ func (handler *Handler) edgeGroupDelete(w http.ResponseWriter, r *http.Request)
} }
} }
err = handler.EdgeGroupService.DeleteEdgeGroup(portainer.EdgeGroupID(edgeGroupID)) err = handler.DataStore.EdgeGroup().DeleteEdgeGroup(portainer.EdgeGroupID(edgeGroupID))
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove the Edge group from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove the Edge group from the database", err}
} }

View File

@ -15,7 +15,7 @@ func (handler *Handler) edgeGroupInspect(w http.ResponseWriter, r *http.Request)
return &httperror.HandlerError{http.StatusBadRequest, "Invalid Edge group identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid Edge group identifier route variable", err}
} }
edgeGroup, err := handler.EdgeGroupService.EdgeGroup(portainer.EdgeGroupID(edgeGroupID)) edgeGroup, err := handler.DataStore.EdgeGroup().EdgeGroup(portainer.EdgeGroupID(edgeGroupID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an Edge group with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an Edge group with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {

View File

@ -14,12 +14,12 @@ type decoratedEdgeGroup struct {
} }
func (handler *Handler) edgeGroupList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { func (handler *Handler) edgeGroupList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
edgeGroups, err := handler.EdgeGroupService.EdgeGroups() edgeGroups, err := handler.DataStore.EdgeGroup().EdgeGroups()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve Edge groups from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve Edge groups from the database", err}
} }
edgeStacks, err := handler.EdgeStackService.EdgeStacks() edgeStacks, err := handler.DataStore.EdgeStack().EdgeStacks()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve Edge stacks from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve Edge stacks from the database", err}
} }

View File

@ -43,7 +43,7 @@ func (handler *Handler) edgeGroupUpdate(w http.ResponseWriter, r *http.Request)
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
} }
edgeGroup, err := handler.EdgeGroupService.EdgeGroup(portainer.EdgeGroupID(edgeGroupID)) edgeGroup, err := handler.DataStore.EdgeGroup().EdgeGroup(portainer.EdgeGroupID(edgeGroupID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an Edge group with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an Edge group with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -51,7 +51,7 @@ func (handler *Handler) edgeGroupUpdate(w http.ResponseWriter, r *http.Request)
} }
if payload.Name != "" { if payload.Name != "" {
edgeGroups, err := handler.EdgeGroupService.EdgeGroups() edgeGroups, err := handler.DataStore.EdgeGroup().EdgeGroups()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve Edge groups from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve Edge groups from the database", err}
} }
@ -63,12 +63,12 @@ func (handler *Handler) edgeGroupUpdate(w http.ResponseWriter, r *http.Request)
edgeGroup.Name = payload.Name edgeGroup.Name = payload.Name
} }
endpoints, err := handler.EndpointService.Endpoints() endpoints, err := handler.DataStore.Endpoint().Endpoints()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoints from database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoints from database", err}
} }
endpointGroups, err := handler.EndpointGroupService.EndpointGroups() endpointGroups, err := handler.DataStore.EndpointGroup().EndpointGroups()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoint groups from database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoint groups from database", err}
} }
@ -81,7 +81,7 @@ func (handler *Handler) edgeGroupUpdate(w http.ResponseWriter, r *http.Request)
} else { } else {
endpointIDs := []portainer.EndpointID{} endpointIDs := []portainer.EndpointID{}
for _, endpointID := range payload.Endpoints { for _, endpointID := range payload.Endpoints {
endpoint, err := handler.EndpointService.Endpoint(endpointID) endpoint, err := handler.DataStore.Endpoint().Endpoint(endpointID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoint from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoint from the database", err}
} }
@ -97,7 +97,7 @@ func (handler *Handler) edgeGroupUpdate(w http.ResponseWriter, r *http.Request)
edgeGroup.PartialMatch = *payload.PartialMatch edgeGroup.PartialMatch = *payload.PartialMatch
} }
err = handler.EdgeGroupService.UpdateEdgeGroup(edgeGroup.ID, edgeGroup) err = handler.DataStore.EdgeGroup().UpdateEdgeGroup(edgeGroup.ID, edgeGroup)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist Edge group changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist Edge group changes inside the database", err}
} }
@ -116,27 +116,27 @@ func (handler *Handler) edgeGroupUpdate(w http.ResponseWriter, r *http.Request)
} }
func (handler *Handler) updateEndpoint(endpointID portainer.EndpointID) error { func (handler *Handler) updateEndpoint(endpointID portainer.EndpointID) error {
relation, err := handler.EndpointRelationService.EndpointRelation(endpointID) relation, err := handler.DataStore.EndpointRelation().EndpointRelation(endpointID)
if err != nil { if err != nil {
return err return err
} }
endpoint, err := handler.EndpointService.Endpoint(endpointID) endpoint, err := handler.DataStore.Endpoint().Endpoint(endpointID)
if err != nil { if err != nil {
return err return err
} }
endpointGroup, err := handler.EndpointGroupService.EndpointGroup(endpoint.GroupID) endpointGroup, err := handler.DataStore.EndpointGroup().EndpointGroup(endpoint.GroupID)
if err != nil { if err != nil {
return err return err
} }
edgeGroups, err := handler.EdgeGroupService.EdgeGroups() edgeGroups, err := handler.DataStore.EdgeGroup().EdgeGroups()
if err != nil { if err != nil {
return err return err
} }
edgeStacks, err := handler.EdgeStackService.EdgeStacks() edgeStacks, err := handler.DataStore.EdgeStack().EdgeStacks()
if err != nil { if err != nil {
return err return err
} }
@ -150,5 +150,5 @@ func (handler *Handler) updateEndpoint(endpointID portainer.EndpointID) error {
relation.EdgeStacks = edgeStackSet relation.EdgeStacks = edgeStackSet
return handler.EndpointRelationService.UpdateEndpointRelation(endpoint.ID, relation) return handler.DataStore.EndpointRelation().UpdateEndpointRelation(endpoint.ID, relation)
} }

View File

@ -12,12 +12,7 @@ import (
// Handler is the HTTP handler used to handle endpoint group operations. // Handler is the HTTP handler used to handle endpoint group operations.
type Handler struct { type Handler struct {
*mux.Router *mux.Router
EdgeGroupService portainer.EdgeGroupService DataStore portainer.DataStore
EdgeStackService portainer.EdgeStackService
EndpointService portainer.EndpointService
EndpointGroupService portainer.EndpointGroupService
EndpointRelationService portainer.EndpointRelationService
TagService portainer.TagService
} }
// NewHandler creates a handler to manage endpoint group operations. // NewHandler creates a handler to manage endpoint group operations.

View File

@ -27,17 +27,17 @@ func (handler *Handler) edgeStackCreate(w http.ResponseWriter, r *http.Request)
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to create Edge stack", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to create Edge stack", err}
} }
endpoints, err := handler.EndpointService.Endpoints() endpoints, err := handler.DataStore.Endpoint().Endpoints()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoints from database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoints from database", err}
} }
endpointGroups, err := handler.EndpointGroupService.EndpointGroups() endpointGroups, err := handler.DataStore.EndpointGroup().EndpointGroups()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoint groups from database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoint groups from database", err}
} }
edgeGroups, err := handler.EdgeGroupService.EdgeGroups() edgeGroups, err := handler.DataStore.EdgeGroup().EdgeGroups()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge groups from database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge groups from database", err}
} }
@ -45,14 +45,14 @@ func (handler *Handler) edgeStackCreate(w http.ResponseWriter, r *http.Request)
relatedEndpoints, err := portainer.EdgeStackRelatedEndpoints(edgeStack.EdgeGroups, endpoints, endpointGroups, edgeGroups) relatedEndpoints, err := portainer.EdgeStackRelatedEndpoints(edgeStack.EdgeGroups, endpoints, endpointGroups, edgeGroups)
for _, endpointID := range relatedEndpoints { for _, endpointID := range relatedEndpoints {
relation, err := handler.EndpointRelationService.EndpointRelation(endpointID) relation, err := handler.DataStore.EndpointRelation().EndpointRelation(endpointID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find endpoint relation in database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find endpoint relation in database", err}
} }
relation.EdgeStacks[edgeStack.ID] = true relation.EdgeStacks[edgeStack.ID] = true
err = handler.EndpointRelationService.UpdateEndpointRelation(endpointID, relation) err = handler.DataStore.EndpointRelation().UpdateEndpointRelation(endpointID, relation)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint relation in database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint relation in database", err}
} }
@ -104,7 +104,7 @@ func (handler *Handler) createSwarmStackFromFileContent(r *http.Request) (*porta
return nil, err return nil, err
} }
stackID := handler.EdgeStackService.GetNextIdentifier() stackID := handler.DataStore.EdgeStack().GetNextIdentifier()
stack := &portainer.EdgeStack{ stack := &portainer.EdgeStack{
ID: portainer.EdgeStackID(stackID), ID: portainer.EdgeStackID(stackID),
Name: payload.Name, Name: payload.Name,
@ -122,7 +122,7 @@ func (handler *Handler) createSwarmStackFromFileContent(r *http.Request) (*porta
} }
stack.ProjectPath = projectPath stack.ProjectPath = projectPath
err = handler.EdgeStackService.CreateEdgeStack(stack) err = handler.DataStore.EdgeStack().CreateEdgeStack(stack)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -172,7 +172,7 @@ func (handler *Handler) createSwarmStackFromGitRepository(r *http.Request) (*por
return nil, err return nil, err
} }
stackID := handler.EdgeStackService.GetNextIdentifier() stackID := handler.DataStore.EdgeStack().GetNextIdentifier()
stack := &portainer.EdgeStack{ stack := &portainer.EdgeStack{
ID: portainer.EdgeStackID(stackID), ID: portainer.EdgeStackID(stackID),
Name: payload.Name, Name: payload.Name,
@ -200,7 +200,7 @@ func (handler *Handler) createSwarmStackFromGitRepository(r *http.Request) (*por
return nil, err return nil, err
} }
err = handler.EdgeStackService.CreateEdgeStack(stack) err = handler.DataStore.EdgeStack().CreateEdgeStack(stack)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -248,7 +248,7 @@ func (handler *Handler) createSwarmStackFromFileUpload(r *http.Request) (*portai
return nil, err return nil, err
} }
stackID := handler.EdgeStackService.GetNextIdentifier() stackID := handler.DataStore.EdgeStack().GetNextIdentifier()
stack := &portainer.EdgeStack{ stack := &portainer.EdgeStack{
ID: portainer.EdgeStackID(stackID), ID: portainer.EdgeStackID(stackID),
Name: payload.Name, Name: payload.Name,
@ -266,7 +266,7 @@ func (handler *Handler) createSwarmStackFromFileUpload(r *http.Request) (*portai
} }
stack.ProjectPath = projectPath stack.ProjectPath = projectPath
err = handler.EdgeStackService.CreateEdgeStack(stack) err = handler.DataStore.EdgeStack().CreateEdgeStack(stack)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -275,7 +275,7 @@ func (handler *Handler) createSwarmStackFromFileUpload(r *http.Request) (*portai
} }
func (handler *Handler) validateUniqueName(name string) error { func (handler *Handler) validateUniqueName(name string) error {
edgeStacks, err := handler.EdgeStackService.EdgeStacks() edgeStacks, err := handler.DataStore.EdgeStack().EdgeStacks()
if err != nil { if err != nil {
return err return err
} }

View File

@ -15,29 +15,29 @@ func (handler *Handler) edgeStackDelete(w http.ResponseWriter, r *http.Request)
return &httperror.HandlerError{http.StatusBadRequest, "Invalid edge stack identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid edge stack identifier route variable", err}
} }
edgeStack, err := handler.EdgeStackService.EdgeStack(portainer.EdgeStackID(edgeStackID)) edgeStack, err := handler.DataStore.EdgeStack().EdgeStack(portainer.EdgeStackID(edgeStackID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an edge stack with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an edge stack with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find an edge stack with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find an edge stack with the specified identifier inside the database", err}
} }
err = handler.EdgeStackService.DeleteEdgeStack(portainer.EdgeStackID(edgeStackID)) err = handler.DataStore.EdgeStack().DeleteEdgeStack(portainer.EdgeStackID(edgeStackID))
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove the edge stack from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove the edge stack from the database", err}
} }
endpoints, err := handler.EndpointService.Endpoints() endpoints, err := handler.DataStore.Endpoint().Endpoints()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoints from database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoints from database", err}
} }
endpointGroups, err := handler.EndpointGroupService.EndpointGroups() endpointGroups, err := handler.DataStore.EndpointGroup().EndpointGroups()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoint groups from database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoint groups from database", err}
} }
edgeGroups, err := handler.EdgeGroupService.EdgeGroups() edgeGroups, err := handler.DataStore.EdgeGroup().EdgeGroups()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge groups from database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge groups from database", err}
} }
@ -45,14 +45,14 @@ func (handler *Handler) edgeStackDelete(w http.ResponseWriter, r *http.Request)
relatedEndpoints, err := portainer.EdgeStackRelatedEndpoints(edgeStack.EdgeGroups, endpoints, endpointGroups, edgeGroups) relatedEndpoints, err := portainer.EdgeStackRelatedEndpoints(edgeStack.EdgeGroups, endpoints, endpointGroups, edgeGroups)
for _, endpointID := range relatedEndpoints { for _, endpointID := range relatedEndpoints {
relation, err := handler.EndpointRelationService.EndpointRelation(endpointID) relation, err := handler.DataStore.EndpointRelation().EndpointRelation(endpointID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find endpoint relation in database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find endpoint relation in database", err}
} }
delete(relation.EdgeStacks, edgeStack.ID) delete(relation.EdgeStacks, edgeStack.ID)
err = handler.EndpointRelationService.UpdateEndpointRelation(endpointID, relation) err = handler.DataStore.EndpointRelation().UpdateEndpointRelation(endpointID, relation)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint relation in database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint relation in database", err}
} }

View File

@ -21,7 +21,7 @@ func (handler *Handler) edgeStackFile(w http.ResponseWriter, r *http.Request) *h
return &httperror.HandlerError{http.StatusBadRequest, "Invalid edge stack identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid edge stack identifier route variable", err}
} }
stack, err := handler.EdgeStackService.EdgeStack(portainer.EdgeStackID(stackID)) stack, err := handler.DataStore.EdgeStack().EdgeStack(portainer.EdgeStackID(stackID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an edge stack with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an edge stack with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {

View File

@ -15,7 +15,7 @@ func (handler *Handler) edgeStackInspect(w http.ResponseWriter, r *http.Request)
return &httperror.HandlerError{http.StatusBadRequest, "Invalid edge stack identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid edge stack identifier route variable", err}
} }
edgeStack, err := handler.EdgeStackService.EdgeStack(portainer.EdgeStackID(edgeStackID)) edgeStack, err := handler.DataStore.EdgeStack().EdgeStack(portainer.EdgeStackID(edgeStackID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an edge stack with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an edge stack with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {

View File

@ -8,7 +8,7 @@ import (
) )
func (handler *Handler) edgeStackList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { func (handler *Handler) edgeStackList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
edgeStacks, err := handler.EdgeStackService.EdgeStacks() edgeStacks, err := handler.DataStore.EdgeStack().EdgeStacks()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge stacks from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge stacks from the database", err}
} }

View File

@ -35,7 +35,7 @@ func (handler *Handler) edgeStackStatusUpdate(w http.ResponseWriter, r *http.Req
return &httperror.HandlerError{http.StatusBadRequest, "Invalid stack identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid stack identifier route variable", err}
} }
stack, err := handler.EdgeStackService.EdgeStack(portainer.EdgeStackID(stackID)) stack, err := handler.DataStore.EdgeStack().EdgeStack(portainer.EdgeStackID(stackID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a stack with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find a stack with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -48,7 +48,7 @@ func (handler *Handler) edgeStackStatusUpdate(w http.ResponseWriter, r *http.Req
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
} }
endpoint, err := handler.EndpointService.Endpoint(portainer.EndpointID(*payload.EndpointID)) endpoint, err := handler.DataStore.Endpoint().Endpoint(portainer.EndpointID(*payload.EndpointID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -66,7 +66,7 @@ func (handler *Handler) edgeStackStatusUpdate(w http.ResponseWriter, r *http.Req
EndpointID: *payload.EndpointID, EndpointID: *payload.EndpointID,
} }
err = handler.EdgeStackService.UpdateEdgeStack(stack.ID, stack) err = handler.DataStore.EdgeStack().UpdateEdgeStack(stack.ID, stack)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the stack changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the stack changes inside the database", err}
} }

View File

@ -34,7 +34,7 @@ func (handler *Handler) edgeStackUpdate(w http.ResponseWriter, r *http.Request)
return &httperror.HandlerError{http.StatusBadRequest, "Invalid stack identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid stack identifier route variable", err}
} }
stack, err := handler.EdgeStackService.EdgeStack(portainer.EdgeStackID(stackID)) stack, err := handler.DataStore.EdgeStack().EdgeStack(portainer.EdgeStackID(stackID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a stack with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find a stack with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -48,17 +48,17 @@ func (handler *Handler) edgeStackUpdate(w http.ResponseWriter, r *http.Request)
} }
if payload.EdgeGroups != nil { if payload.EdgeGroups != nil {
endpoints, err := handler.EndpointService.Endpoints() endpoints, err := handler.DataStore.Endpoint().Endpoints()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoints from database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoints from database", err}
} }
endpointGroups, err := handler.EndpointGroupService.EndpointGroups() endpointGroups, err := handler.DataStore.EndpointGroup().EndpointGroups()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoint groups from database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoint groups from database", err}
} }
edgeGroups, err := handler.EdgeGroupService.EdgeGroups() edgeGroups, err := handler.DataStore.EdgeGroup().EdgeGroups()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge groups from database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge groups from database", err}
} }
@ -84,14 +84,14 @@ func (handler *Handler) edgeStackUpdate(w http.ResponseWriter, r *http.Request)
} }
for endpointID := range endpointsToRemove { for endpointID := range endpointsToRemove {
relation, err := handler.EndpointRelationService.EndpointRelation(endpointID) relation, err := handler.DataStore.EndpointRelation().EndpointRelation(endpointID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find endpoint relation in database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find endpoint relation in database", err}
} }
delete(relation.EdgeStacks, stack.ID) delete(relation.EdgeStacks, stack.ID)
err = handler.EndpointRelationService.UpdateEndpointRelation(endpointID, relation) err = handler.DataStore.EndpointRelation().UpdateEndpointRelation(endpointID, relation)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint relation in database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint relation in database", err}
} }
@ -105,14 +105,14 @@ func (handler *Handler) edgeStackUpdate(w http.ResponseWriter, r *http.Request)
} }
for endpointID := range endpointsToAdd { for endpointID := range endpointsToAdd {
relation, err := handler.EndpointRelationService.EndpointRelation(endpointID) relation, err := handler.DataStore.EndpointRelation().EndpointRelation(endpointID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find endpoint relation in database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find endpoint relation in database", err}
} }
relation.EdgeStacks[stack.ID] = true relation.EdgeStacks[stack.ID] = true
err = handler.EndpointRelationService.UpdateEndpointRelation(endpointID, relation) err = handler.DataStore.EndpointRelation().UpdateEndpointRelation(endpointID, relation)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint relation in database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint relation in database", err}
} }
@ -137,7 +137,7 @@ func (handler *Handler) edgeStackUpdate(w http.ResponseWriter, r *http.Request)
stack.Status = map[portainer.EndpointID]portainer.EdgeStackStatus{} stack.Status = map[portainer.EndpointID]portainer.EdgeStackStatus{}
} }
err = handler.EdgeStackService.UpdateEdgeStack(stack.ID, stack) err = handler.DataStore.EdgeStack().UpdateEdgeStack(stack.ID, stack)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the stack changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the stack changes inside the database", err}
} }

View File

@ -12,14 +12,10 @@ import (
// Handler is the HTTP handler used to handle endpoint group operations. // Handler is the HTTP handler used to handle endpoint group operations.
type Handler struct { type Handler struct {
*mux.Router *mux.Router
requestBouncer *security.RequestBouncer requestBouncer *security.RequestBouncer
EdgeGroupService portainer.EdgeGroupService DataStore portainer.DataStore
EdgeStackService portainer.EdgeStackService FileService portainer.FileService
EndpointService portainer.EndpointService GitService portainer.GitService
EndpointGroupService portainer.EndpointGroupService
EndpointRelationService portainer.EndpointRelationService
FileService portainer.FileService
GitService portainer.GitService
} }
// NewHandler creates a handler to manage endpoint group operations. // NewHandler creates a handler to manage endpoint group operations.

View File

@ -17,7 +17,7 @@ type templateFileFormat struct {
// GET request on /api/edgetemplates // GET request on /api/edgetemplates
func (handler *Handler) edgeTemplateList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { func (handler *Handler) edgeTemplateList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
settings, err := handler.SettingsService.Settings() settings, err := handler.DataStore.Settings().Settings()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve settings from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve settings from the database", err}
} }

View File

@ -13,8 +13,8 @@ import (
// Handler is the HTTP handler used to handle edge endpoint operations. // Handler is the HTTP handler used to handle edge endpoint operations.
type Handler struct { type Handler struct {
*mux.Router *mux.Router
requestBouncer *security.RequestBouncer requestBouncer *security.RequestBouncer
SettingsService portainer.SettingsService DataStore portainer.DataStore
} }
// NewHandler creates a handler to manage endpoint operations. // NewHandler creates a handler to manage endpoint operations.

View File

@ -23,7 +23,7 @@ func (handler *Handler) endpointEdgeStackInspect(w http.ResponseWriter, r *http.
return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err}
} }
endpoint, err := handler.EndpointService.Endpoint(portainer.EndpointID(endpointID)) endpoint, err := handler.DataStore.Endpoint().Endpoint(portainer.EndpointID(endpointID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -40,7 +40,7 @@ func (handler *Handler) endpointEdgeStackInspect(w http.ResponseWriter, r *http.
return &httperror.HandlerError{http.StatusBadRequest, "Invalid edge stack identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid edge stack identifier route variable", err}
} }
edgeStack, err := handler.EdgeStackService.EdgeStack(portainer.EdgeStackID(edgeStackID)) edgeStack, err := handler.DataStore.EdgeStack().EdgeStack(portainer.EdgeStackID(edgeStackID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an edge stack with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an edge stack with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {

View File

@ -13,10 +13,9 @@ import (
// Handler is the HTTP handler used to handle edge endpoint operations. // Handler is the HTTP handler used to handle edge endpoint operations.
type Handler struct { type Handler struct {
*mux.Router *mux.Router
requestBouncer *security.RequestBouncer requestBouncer *security.RequestBouncer
EndpointService portainer.EndpointService DataStore portainer.DataStore
EdgeStackService portainer.EdgeStackService FileService portainer.FileService
FileService portainer.FileService
} }
// NewHandler creates a handler to manage endpoint operations. // NewHandler creates a handler to manage endpoint operations.

View File

@ -43,12 +43,12 @@ func (handler *Handler) endpointGroupCreate(w http.ResponseWriter, r *http.Reque
TagIDs: payload.TagIDs, TagIDs: payload.TagIDs,
} }
err = handler.EndpointGroupService.CreateEndpointGroup(endpointGroup) err = handler.DataStore.EndpointGroup().CreateEndpointGroup(endpointGroup)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the endpoint group inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the endpoint group inside the database", err}
} }
endpoints, err := handler.EndpointService.Endpoints() endpoints, err := handler.DataStore.Endpoint().Endpoints()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoints from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoints from the database", err}
} }
@ -58,7 +58,7 @@ func (handler *Handler) endpointGroupCreate(w http.ResponseWriter, r *http.Reque
if endpoint.ID == id { if endpoint.ID == id {
endpoint.GroupID = endpointGroup.ID endpoint.GroupID = endpointGroup.ID
err := handler.EndpointService.UpdateEndpoint(endpoint.ID, &endpoint) err := handler.DataStore.Endpoint().UpdateEndpoint(endpoint.ID, &endpoint)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to update endpoint", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to update endpoint", err}
} }
@ -74,14 +74,14 @@ func (handler *Handler) endpointGroupCreate(w http.ResponseWriter, r *http.Reque
} }
for _, tagID := range endpointGroup.TagIDs { for _, tagID := range endpointGroup.TagIDs {
tag, err := handler.TagService.Tag(tagID) tag, err := handler.DataStore.Tag().Tag(tagID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve tag from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve tag from the database", err}
} }
tag.EndpointGroups[endpointGroup.ID] = true tag.EndpointGroups[endpointGroup.ID] = true
err = handler.TagService.UpdateTag(tagID, tag) err = handler.DataStore.Tag().UpdateTag(tagID, tag)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist tag changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist tag changes inside the database", err}
} }

View File

@ -20,19 +20,19 @@ func (handler *Handler) endpointGroupDelete(w http.ResponseWriter, r *http.Reque
return &httperror.HandlerError{http.StatusForbidden, "Unable to remove the default 'Unassigned' group", portainer.ErrCannotRemoveDefaultGroup} return &httperror.HandlerError{http.StatusForbidden, "Unable to remove the default 'Unassigned' group", portainer.ErrCannotRemoveDefaultGroup}
} }
endpointGroup, err := handler.EndpointGroupService.EndpointGroup(portainer.EndpointGroupID(endpointGroupID)) endpointGroup, err := handler.DataStore.EndpointGroup().EndpointGroup(portainer.EndpointGroupID(endpointGroupID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint group with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint group with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find an endpoint group with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find an endpoint group with the specified identifier inside the database", err}
} }
err = handler.EndpointGroupService.DeleteEndpointGroup(portainer.EndpointGroupID(endpointGroupID)) err = handler.DataStore.EndpointGroup().DeleteEndpointGroup(portainer.EndpointGroupID(endpointGroupID))
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove the endpoint group from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove the endpoint group from the database", err}
} }
endpoints, err := handler.EndpointService.Endpoints() endpoints, err := handler.DataStore.Endpoint().Endpoints()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoints from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoints from the database", err}
} }
@ -42,7 +42,7 @@ func (handler *Handler) endpointGroupDelete(w http.ResponseWriter, r *http.Reque
if endpoint.GroupID == portainer.EndpointGroupID(endpointGroupID) { if endpoint.GroupID == portainer.EndpointGroupID(endpointGroupID) {
updateAuthorizations = true updateAuthorizations = true
endpoint.GroupID = portainer.EndpointGroupID(1) endpoint.GroupID = portainer.EndpointGroupID(1)
err = handler.EndpointService.UpdateEndpoint(endpoint.ID, &endpoint) err = handler.DataStore.Endpoint().UpdateEndpoint(endpoint.ID, &endpoint)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to update endpoint", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to update endpoint", err}
} }
@ -62,14 +62,14 @@ func (handler *Handler) endpointGroupDelete(w http.ResponseWriter, r *http.Reque
} }
for _, tagID := range endpointGroup.TagIDs { for _, tagID := range endpointGroup.TagIDs {
tag, err := handler.TagService.Tag(tagID) tag, err := handler.DataStore.Tag().Tag(tagID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve tag from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve tag from the database", err}
} }
delete(tag.EndpointGroups, endpointGroup.ID) delete(tag.EndpointGroups, endpointGroup.ID)
err = handler.TagService.UpdateTag(tagID, tag) err = handler.DataStore.Tag().UpdateTag(tagID, tag)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist tag changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist tag changes inside the database", err}
} }

View File

@ -21,14 +21,14 @@ func (handler *Handler) endpointGroupAddEndpoint(w http.ResponseWriter, r *http.
return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err}
} }
endpointGroup, err := handler.EndpointGroupService.EndpointGroup(portainer.EndpointGroupID(endpointGroupID)) endpointGroup, err := handler.DataStore.EndpointGroup().EndpointGroup(portainer.EndpointGroupID(endpointGroupID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint group with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint group with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find an endpoint group with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find an endpoint group with the specified identifier inside the database", err}
} }
endpoint, err := handler.EndpointService.Endpoint(portainer.EndpointID(endpointID)) endpoint, err := handler.DataStore.Endpoint().Endpoint(portainer.EndpointID(endpointID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -37,7 +37,7 @@ func (handler *Handler) endpointGroupAddEndpoint(w http.ResponseWriter, r *http.
endpoint.GroupID = endpointGroup.ID endpoint.GroupID = endpointGroup.ID
err = handler.EndpointService.UpdateEndpoint(endpoint.ID, endpoint) err = handler.DataStore.Endpoint().UpdateEndpoint(endpoint.ID, endpoint)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint changes inside the database", err}
} }

View File

@ -21,14 +21,14 @@ func (handler *Handler) endpointGroupDeleteEndpoint(w http.ResponseWriter, r *ht
return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err}
} }
_, err = handler.EndpointGroupService.EndpointGroup(portainer.EndpointGroupID(endpointGroupID)) _, err = handler.DataStore.EndpointGroup().EndpointGroup(portainer.EndpointGroupID(endpointGroupID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint group with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint group with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find an endpoint group with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find an endpoint group with the specified identifier inside the database", err}
} }
endpoint, err := handler.EndpointService.Endpoint(portainer.EndpointID(endpointID)) endpoint, err := handler.DataStore.Endpoint().Endpoint(portainer.EndpointID(endpointID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -37,7 +37,7 @@ func (handler *Handler) endpointGroupDeleteEndpoint(w http.ResponseWriter, r *ht
endpoint.GroupID = portainer.EndpointGroupID(1) endpoint.GroupID = portainer.EndpointGroupID(1)
err = handler.EndpointService.UpdateEndpoint(endpoint.ID, endpoint) err = handler.DataStore.Endpoint().UpdateEndpoint(endpoint.ID, endpoint)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint changes inside the database", err}
} }

View File

@ -16,7 +16,7 @@ func (handler *Handler) endpointGroupInspect(w http.ResponseWriter, r *http.Requ
return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint group identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint group identifier route variable", err}
} }
endpointGroup, err := handler.EndpointGroupService.EndpointGroup(portainer.EndpointGroupID(endpointGroupID)) endpointGroup, err := handler.DataStore.EndpointGroup().EndpointGroup(portainer.EndpointGroupID(endpointGroupID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint group with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint group with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {

View File

@ -10,7 +10,7 @@ import (
// GET request on /api/endpoint_groups // GET request on /api/endpoint_groups
func (handler *Handler) endpointGroupList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { func (handler *Handler) endpointGroupList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
endpointGroups, err := handler.EndpointGroupService.EndpointGroups() endpointGroups, err := handler.DataStore.EndpointGroup().EndpointGroups()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoint groups from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoint groups from the database", err}
} }

View File

@ -35,7 +35,7 @@ func (handler *Handler) endpointGroupUpdate(w http.ResponseWriter, r *http.Reque
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
} }
endpointGroup, err := handler.EndpointGroupService.EndpointGroup(portainer.EndpointGroupID(endpointGroupID)) endpointGroup, err := handler.DataStore.EndpointGroup().EndpointGroup(portainer.EndpointGroupID(endpointGroupID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint group with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint group with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -62,12 +62,12 @@ func (handler *Handler) endpointGroupUpdate(w http.ResponseWriter, r *http.Reque
removeTags := portainer.TagDifference(endpointGroupTagSet, payloadTagSet) removeTags := portainer.TagDifference(endpointGroupTagSet, payloadTagSet)
for tagID := range removeTags { for tagID := range removeTags {
tag, err := handler.TagService.Tag(tagID) tag, err := handler.DataStore.Tag().Tag(tagID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a tag inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a tag inside the database", err}
} }
delete(tag.EndpointGroups, endpointGroup.ID) delete(tag.EndpointGroups, endpointGroup.ID)
err = handler.TagService.UpdateTag(tag.ID, tag) err = handler.DataStore.Tag().UpdateTag(tag.ID, tag)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist tag changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist tag changes inside the database", err}
} }
@ -75,14 +75,14 @@ func (handler *Handler) endpointGroupUpdate(w http.ResponseWriter, r *http.Reque
endpointGroup.TagIDs = payload.TagIDs endpointGroup.TagIDs = payload.TagIDs
for _, tagID := range payload.TagIDs { for _, tagID := range payload.TagIDs {
tag, err := handler.TagService.Tag(tagID) tag, err := handler.DataStore.Tag().Tag(tagID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a tag inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a tag inside the database", err}
} }
tag.EndpointGroups[endpointGroup.ID] = true tag.EndpointGroups[endpointGroup.ID] = true
err = handler.TagService.UpdateTag(tag.ID, tag) err = handler.DataStore.Tag().UpdateTag(tag.ID, tag)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist tag changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist tag changes inside the database", err}
} }
@ -101,7 +101,7 @@ func (handler *Handler) endpointGroupUpdate(w http.ResponseWriter, r *http.Reque
updateAuthorizations = true updateAuthorizations = true
} }
err = handler.EndpointGroupService.UpdateEndpointGroup(endpointGroup.ID, endpointGroup) err = handler.DataStore.EndpointGroup().UpdateEndpointGroup(endpointGroup.ID, endpointGroup)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint group changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint group changes inside the database", err}
} }
@ -114,7 +114,7 @@ func (handler *Handler) endpointGroupUpdate(w http.ResponseWriter, r *http.Reque
} }
if tagsChanged { if tagsChanged {
endpoints, err := handler.EndpointService.Endpoints() endpoints, err := handler.DataStore.Endpoint().Endpoints()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoints from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoints from the database", err}

View File

@ -8,7 +8,7 @@ func (handler *Handler) updateEndpointRelations(endpoint *portainer.Endpoint, en
} }
if endpointGroup == nil { if endpointGroup == nil {
unassignedGroup, err := handler.EndpointGroupService.EndpointGroup(portainer.EndpointGroupID(1)) unassignedGroup, err := handler.DataStore.EndpointGroup().EndpointGroup(portainer.EndpointGroupID(1))
if err != nil { if err != nil {
return err return err
} }
@ -16,17 +16,17 @@ func (handler *Handler) updateEndpointRelations(endpoint *portainer.Endpoint, en
endpointGroup = unassignedGroup endpointGroup = unassignedGroup
} }
endpointRelation, err := handler.EndpointRelationService.EndpointRelation(endpoint.ID) endpointRelation, err := handler.DataStore.EndpointRelation().EndpointRelation(endpoint.ID)
if err != nil { if err != nil {
return err return err
} }
edgeGroups, err := handler.EdgeGroupService.EdgeGroups() edgeGroups, err := handler.DataStore.EdgeGroup().EdgeGroups()
if err != nil { if err != nil {
return err return err
} }
edgeStacks, err := handler.EdgeStackService.EdgeStacks() edgeStacks, err := handler.DataStore.EdgeStack().EdgeStacks()
if err != nil { if err != nil {
return err return err
} }
@ -38,5 +38,5 @@ func (handler *Handler) updateEndpointRelations(endpoint *portainer.Endpoint, en
} }
endpointRelation.EdgeStacks = stacksSet endpointRelation.EdgeStacks = stacksSet
return handler.EndpointRelationService.UpdateEndpointRelation(endpoint.ID, endpointRelation) return handler.DataStore.EndpointRelation().UpdateEndpointRelation(endpoint.ID, endpointRelation)
} }

View File

@ -12,13 +12,8 @@ import (
// Handler is the HTTP handler used to handle endpoint group operations. // Handler is the HTTP handler used to handle endpoint group operations.
type Handler struct { type Handler struct {
*mux.Router *mux.Router
AuthorizationService *portainer.AuthorizationService DataStore portainer.DataStore
EdgeGroupService portainer.EdgeGroupService AuthorizationService *portainer.AuthorizationService
EdgeStackService portainer.EdgeStackService
EndpointService portainer.EndpointService
EndpointGroupService portainer.EndpointGroupService
EndpointRelationService portainer.EndpointRelationService
TagService portainer.TagService
} }
// NewHandler creates a handler to manage endpoint group operations. // NewHandler creates a handler to manage endpoint group operations.

View File

@ -11,9 +11,8 @@ import (
// Handler is the HTTP handler used to proxy requests to external APIs. // Handler is the HTTP handler used to proxy requests to external APIs.
type Handler struct { type Handler struct {
*mux.Router *mux.Router
DataStore portainer.DataStore
requestBouncer *security.RequestBouncer requestBouncer *security.RequestBouncer
EndpointService portainer.EndpointService
SettingsService portainer.SettingsService
ProxyManager *proxy.Manager ProxyManager *proxy.Manager
ReverseTunnelService portainer.ReverseTunnelService ReverseTunnelService portainer.ReverseTunnelService
} }

View File

@ -18,7 +18,7 @@ func (handler *Handler) proxyRequestsToDockerAPI(w http.ResponseWriter, r *http.
return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err}
} }
endpoint, err := handler.EndpointService.Endpoint(portainer.EndpointID(endpointID)) endpoint, err := handler.DataStore.Endpoint().Endpoint(portainer.EndpointID(endpointID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -44,7 +44,7 @@ func (handler *Handler) proxyRequestsToDockerAPI(w http.ResponseWriter, r *http.
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to update tunnel status", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to update tunnel status", err}
} }
settings, err := handler.SettingsService.Settings() settings, err := handler.DataStore.Settings().Settings()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve settings from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve settings from the database", err}
} }

View File

@ -18,7 +18,7 @@ func (handler *Handler) proxyRequestsToStoridgeAPI(w http.ResponseWriter, r *htt
return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err}
} }
endpoint, err := handler.EndpointService.Endpoint(portainer.EndpointID(endpointID)) endpoint, err := handler.DataStore.Endpoint().Endpoint(portainer.EndpointID(endpointID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {

View File

@ -118,17 +118,17 @@ func (handler *Handler) endpointCreate(w http.ResponseWriter, r *http.Request) *
return endpointCreationError return endpointCreationError
} }
endpointGroup, err := handler.EndpointGroupService.EndpointGroup(endpoint.GroupID) endpointGroup, err := handler.DataStore.EndpointGroup().EndpointGroup(endpoint.GroupID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find an endpoint group inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find an endpoint group inside the database", err}
} }
edgeGroups, err := handler.EdgeGroupService.EdgeGroups() edgeGroups, err := handler.DataStore.EdgeGroup().EdgeGroups()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge groups from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge groups from the database", err}
} }
edgeStacks, err := handler.EdgeStackService.EdgeStacks() edgeStacks, err := handler.DataStore.EdgeStack().EdgeStacks()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge stacks from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge stacks from the database", err}
} }
@ -145,7 +145,7 @@ func (handler *Handler) endpointCreate(w http.ResponseWriter, r *http.Request) *
} }
} }
err = handler.EndpointRelationService.CreateEndpointRelation(relationObject) err = handler.DataStore.EndpointRelation().CreateEndpointRelation(relationObject)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the relation object inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the relation object inside the database", err}
} }
@ -166,7 +166,7 @@ func (handler *Handler) createEndpoint(payload *endpointCreatePayload) (*portain
func (handler *Handler) createEdgeAgentEndpoint(payload *endpointCreatePayload) (*portainer.Endpoint, *httperror.HandlerError) { func (handler *Handler) createEdgeAgentEndpoint(payload *endpointCreatePayload) (*portainer.Endpoint, *httperror.HandlerError) {
endpointType := portainer.EdgeAgentEnvironment endpointType := portainer.EdgeAgentEnvironment
endpointID := handler.EndpointService.GetNextIdentifier() endpointID := handler.DataStore.Endpoint().GetNextIdentifier()
portainerURL, err := url.Parse(payload.URL) portainerURL, err := url.Parse(payload.URL)
if err != nil { if err != nil {
@ -228,7 +228,7 @@ func (handler *Handler) createUnsecuredEndpoint(payload *endpointCreatePayload)
} }
} }
endpointID := handler.EndpointService.GetNextIdentifier() endpointID := handler.DataStore.Endpoint().GetNextIdentifier()
endpoint := &portainer.Endpoint{ endpoint := &portainer.Endpoint{
ID: portainer.EndpointID(endpointID), ID: portainer.EndpointID(endpointID),
Name: payload.Name, Name: payload.Name,
@ -271,7 +271,7 @@ func (handler *Handler) createTLSSecuredEndpoint(payload *endpointCreatePayload)
endpointType = portainer.AgentOnDockerEnvironment endpointType = portainer.AgentOnDockerEnvironment
} }
endpointID := handler.EndpointService.GetNextIdentifier() endpointID := handler.DataStore.Endpoint().GetNextIdentifier()
endpoint := &portainer.Endpoint{ endpoint := &portainer.Endpoint{
ID: portainer.EndpointID(endpointID), ID: portainer.EndpointID(endpointID),
Name: payload.Name, Name: payload.Name,
@ -327,12 +327,12 @@ func (handler *Handler) snapshotAndPersistEndpoint(endpoint *portainer.Endpoint)
} }
func (handler *Handler) saveEndpointAndUpdateAuthorizations(endpoint *portainer.Endpoint) error { func (handler *Handler) saveEndpointAndUpdateAuthorizations(endpoint *portainer.Endpoint) error {
err := handler.EndpointService.CreateEndpoint(endpoint) err := handler.DataStore.Endpoint().CreateEndpoint(endpoint)
if err != nil { if err != nil {
return err return err
} }
group, err := handler.EndpointGroupService.EndpointGroup(endpoint.GroupID) group, err := handler.DataStore.EndpointGroup().EndpointGroup(endpoint.GroupID)
if err != nil { if err != nil {
return err return err
} }
@ -342,14 +342,14 @@ func (handler *Handler) saveEndpointAndUpdateAuthorizations(endpoint *portainer.
} }
for _, tagID := range endpoint.TagIDs { for _, tagID := range endpoint.TagIDs {
tag, err := handler.TagService.Tag(tagID) tag, err := handler.DataStore.Tag().Tag(tagID)
if err != nil { if err != nil {
return err return err
} }
tag.Endpoints[endpoint.ID] = true tag.Endpoints[endpoint.ID] = true
err = handler.TagService.UpdateTag(tagID, tag) err = handler.DataStore.Tag().UpdateTag(tagID, tag)
if err != nil { if err != nil {
return err return err
} }

View File

@ -17,7 +17,7 @@ func (handler *Handler) endpointDelete(w http.ResponseWriter, r *http.Request) *
return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err}
} }
endpoint, err := handler.EndpointService.Endpoint(portainer.EndpointID(endpointID)) endpoint, err := handler.DataStore.Endpoint().Endpoint(portainer.EndpointID(endpointID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -32,7 +32,7 @@ func (handler *Handler) endpointDelete(w http.ResponseWriter, r *http.Request) *
} }
} }
err = handler.EndpointService.DeleteEndpoint(portainer.EndpointID(endpointID)) err = handler.DataStore.Endpoint().DeleteEndpoint(portainer.EndpointID(endpointID))
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove endpoint from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove endpoint from the database", err}
} }
@ -46,26 +46,26 @@ func (handler *Handler) endpointDelete(w http.ResponseWriter, r *http.Request) *
} }
} }
err = handler.EndpointRelationService.DeleteEndpointRelation(endpoint.ID) err = handler.DataStore.EndpointRelation().DeleteEndpointRelation(endpoint.ID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove endpoint relation from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove endpoint relation from the database", err}
} }
for _, tagID := range endpoint.TagIDs { for _, tagID := range endpoint.TagIDs {
tag, err := handler.TagService.Tag(tagID) tag, err := handler.DataStore.Tag().Tag(tagID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find tag inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find tag inside the database", err}
} }
delete(tag.Endpoints, endpoint.ID) delete(tag.Endpoints, endpoint.ID)
err = handler.TagService.UpdateTag(tagID, tag) err = handler.DataStore.Tag().UpdateTag(tagID, tag)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist tag relation inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist tag relation inside the database", err}
} }
} }
edgeGroups, err := handler.EdgeGroupService.EdgeGroups() edgeGroups, err := handler.DataStore.EdgeGroup().EdgeGroups()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge groups from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge groups from the database", err}
} }
@ -75,14 +75,14 @@ func (handler *Handler) endpointDelete(w http.ResponseWriter, r *http.Request) *
endpointIdx := findEndpointIndex(edgeGroup.Endpoints, endpoint.ID) endpointIdx := findEndpointIndex(edgeGroup.Endpoints, endpoint.ID)
if endpointIdx != -1 { if endpointIdx != -1 {
edgeGroup.Endpoints = removeElement(edgeGroup.Endpoints, endpointIdx) edgeGroup.Endpoints = removeElement(edgeGroup.Endpoints, endpointIdx)
err = handler.EdgeGroupService.UpdateEdgeGroup(edgeGroup.ID, edgeGroup) err = handler.DataStore.EdgeGroup().UpdateEdgeGroup(edgeGroup.ID, edgeGroup)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to update edge group", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to update edge group", err}
} }
} }
} }
edgeStacks, err := handler.EdgeStackService.EdgeStacks() edgeStacks, err := handler.DataStore.EdgeStack().EdgeStacks()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge stacks from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge stacks from the database", err}
} }
@ -91,7 +91,7 @@ func (handler *Handler) endpointDelete(w http.ResponseWriter, r *http.Request) *
edgeStack := &edgeStacks[idx] edgeStack := &edgeStacks[idx]
if _, ok := edgeStack.Status[endpoint.ID]; ok { if _, ok := edgeStack.Status[endpoint.ID]; ok {
delete(edgeStack.Status, endpoint.ID) delete(edgeStack.Status, endpoint.ID)
err = handler.EdgeStackService.UpdateEdgeStack(edgeStack.ID, edgeStack) err = handler.DataStore.EdgeStack().UpdateEdgeStack(edgeStack.ID, edgeStack)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to update edge stack", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to update edge stack", err}
} }

View File

@ -34,7 +34,7 @@ func (handler *Handler) endpointExtensionAdd(w http.ResponseWriter, r *http.Requ
return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err}
} }
endpoint, err := handler.EndpointService.Endpoint(portainer.EndpointID(endpointID)) endpoint, err := handler.DataStore.Endpoint().Endpoint(portainer.EndpointID(endpointID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -66,7 +66,7 @@ func (handler *Handler) endpointExtensionAdd(w http.ResponseWriter, r *http.Requ
endpoint.Extensions = append(endpoint.Extensions, *extension) endpoint.Extensions = append(endpoint.Extensions, *extension)
} }
err = handler.EndpointService.UpdateEndpoint(endpoint.ID, endpoint) err = handler.DataStore.Endpoint().UpdateEndpoint(endpoint.ID, endpoint)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint changes inside the database", err}
} }

View File

@ -18,7 +18,7 @@ func (handler *Handler) endpointExtensionRemove(w http.ResponseWriter, r *http.R
return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err}
} }
endpoint, err := handler.EndpointService.Endpoint(portainer.EndpointID(endpointID)) endpoint, err := handler.DataStore.Endpoint().Endpoint(portainer.EndpointID(endpointID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -36,7 +36,7 @@ func (handler *Handler) endpointExtensionRemove(w http.ResponseWriter, r *http.R
} }
} }
err = handler.EndpointService.UpdateEndpoint(endpoint.ID, endpoint) err = handler.DataStore.Endpoint().UpdateEndpoint(endpoint.ID, endpoint)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint changes inside the database", err}
} }

View File

@ -16,7 +16,7 @@ func (handler *Handler) endpointInspect(w http.ResponseWriter, r *http.Request)
return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err}
} }
endpoint, err := handler.EndpointService.Endpoint(portainer.EndpointID(endpointID)) endpoint, err := handler.DataStore.Endpoint().Endpoint(portainer.EndpointID(endpointID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {

View File

@ -63,7 +63,7 @@ func (handler *Handler) endpointJob(w http.ResponseWriter, r *http.Request) *htt
nodeName, _ := request.RetrieveQueryParameter(r, "nodeName", true) nodeName, _ := request.RetrieveQueryParameter(r, "nodeName", true)
endpoint, err := handler.EndpointService.Endpoint(portainer.EndpointID(endpointID)) endpoint, err := handler.DataStore.Endpoint().Endpoint(portainer.EndpointID(endpointID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {

View File

@ -38,12 +38,12 @@ func (handler *Handler) endpointList(w http.ResponseWriter, r *http.Request) *ht
var endpointIDs []portainer.EndpointID var endpointIDs []portainer.EndpointID
request.RetrieveJSONQueryParameter(r, "endpointIds", &endpointIDs, true) request.RetrieveJSONQueryParameter(r, "endpointIds", &endpointIDs, true)
endpointGroups, err := handler.EndpointGroupService.EndpointGroups() endpointGroups, err := handler.DataStore.EndpointGroup().EndpointGroups()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoint groups from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoint groups from the database", err}
} }
endpoints, err := handler.EndpointService.Endpoints() endpoints, err := handler.DataStore.Endpoint().Endpoints()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoints from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoints from the database", err}
} }
@ -64,7 +64,7 @@ func (handler *Handler) endpointList(w http.ResponseWriter, r *http.Request) *ht
} }
if search != "" { if search != "" {
tags, err := handler.TagService.Tags() tags, err := handler.DataStore.Tag().Tags()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve tags from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve tags from the database", err}
} }

View File

@ -16,7 +16,7 @@ func (handler *Handler) endpointSnapshot(w http.ResponseWriter, r *http.Request)
return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err}
} }
endpoint, err := handler.EndpointService.Endpoint(portainer.EndpointID(endpointID)) endpoint, err := handler.DataStore.Endpoint().Endpoint(portainer.EndpointID(endpointID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -25,7 +25,7 @@ func (handler *Handler) endpointSnapshot(w http.ResponseWriter, r *http.Request)
snapshot, snapshotError := handler.Snapshotter.CreateSnapshot(endpoint) snapshot, snapshotError := handler.Snapshotter.CreateSnapshot(endpoint)
latestEndpointReference, err := handler.EndpointService.Endpoint(endpoint.ID) latestEndpointReference, err := handler.DataStore.Endpoint().Endpoint(endpoint.ID)
if latestEndpointReference == nil { if latestEndpointReference == nil {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
} }
@ -39,7 +39,7 @@ func (handler *Handler) endpointSnapshot(w http.ResponseWriter, r *http.Request)
latestEndpointReference.Snapshots = []portainer.Snapshot{*snapshot} latestEndpointReference.Snapshots = []portainer.Snapshot{*snapshot}
} }
err = handler.EndpointService.UpdateEndpoint(latestEndpointReference.ID, latestEndpointReference) err = handler.DataStore.Endpoint().UpdateEndpoint(latestEndpointReference.ID, latestEndpointReference)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint changes inside the database", err}
} }

View File

@ -11,7 +11,7 @@ import (
// POST request on /api/endpoints/snapshot // POST request on /api/endpoints/snapshot
func (handler *Handler) endpointSnapshots(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { func (handler *Handler) endpointSnapshots(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
endpoints, err := handler.EndpointService.Endpoints() endpoints, err := handler.DataStore.Endpoint().Endpoints()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoints from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoints from the database", err}
} }
@ -19,7 +19,7 @@ func (handler *Handler) endpointSnapshots(w http.ResponseWriter, r *http.Request
for _, endpoint := range endpoints { for _, endpoint := range endpoints {
snapshot, snapshotError := handler.Snapshotter.CreateSnapshot(&endpoint) snapshot, snapshotError := handler.Snapshotter.CreateSnapshot(&endpoint)
latestEndpointReference, err := handler.EndpointService.Endpoint(endpoint.ID) latestEndpointReference, err := handler.DataStore.Endpoint().Endpoint(endpoint.ID)
if latestEndpointReference == nil { if latestEndpointReference == nil {
log.Printf("background schedule error (endpoint snapshot). Endpoint not found inside the database anymore (endpoint=%s, URL=%s) (err=%s)\n", endpoint.Name, endpoint.URL, err) log.Printf("background schedule error (endpoint snapshot). Endpoint not found inside the database anymore (endpoint=%s, URL=%s) (err=%s)\n", endpoint.Name, endpoint.URL, err)
continue continue
@ -35,7 +35,7 @@ func (handler *Handler) endpointSnapshots(w http.ResponseWriter, r *http.Request
latestEndpointReference.Snapshots = []portainer.Snapshot{*snapshot} latestEndpointReference.Snapshots = []portainer.Snapshot{*snapshot}
} }
err = handler.EndpointService.UpdateEndpoint(latestEndpointReference.ID, latestEndpointReference) err = handler.DataStore.Endpoint().UpdateEndpoint(latestEndpointReference.ID, latestEndpointReference)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint changes inside the database", err}
} }

View File

@ -30,7 +30,7 @@ func (handler *Handler) endpointStatusInspect(w http.ResponseWriter, r *http.Req
return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err}
} }
endpoint, err := handler.EndpointService.Endpoint(portainer.EndpointID(endpointID)) endpoint, err := handler.DataStore.Endpoint().Endpoint(portainer.EndpointID(endpointID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -47,13 +47,13 @@ func (handler *Handler) endpointStatusInspect(w http.ResponseWriter, r *http.Req
endpoint.EdgeID = edgeIdentifier endpoint.EdgeID = edgeIdentifier
err := handler.EndpointService.UpdateEndpoint(endpoint.ID, endpoint) err := handler.DataStore.Endpoint().UpdateEndpoint(endpoint.ID, endpoint)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to Unable to persist endpoint changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to Unable to persist endpoint changes inside the database", err}
} }
} }
settings, err := handler.SettingsService.Settings() settings, err := handler.DataStore.Settings().Settings()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve settings from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve settings from the database", err}
} }
@ -72,14 +72,14 @@ func (handler *Handler) endpointStatusInspect(w http.ResponseWriter, r *http.Req
handler.ReverseTunnelService.SetTunnelStatusToActive(endpoint.ID) handler.ReverseTunnelService.SetTunnelStatusToActive(endpoint.ID)
} }
relation, err := handler.EndpointRelationService.EndpointRelation(endpoint.ID) relation, err := handler.DataStore.EndpointRelation().EndpointRelation(endpoint.ID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve relation object from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve relation object from the database", err}
} }
edgeStacksStatus := []stackStatusResponse{} edgeStacksStatus := []stackStatusResponse{}
for stackID := range relation.EdgeStacks { for stackID := range relation.EdgeStacks {
stack, err := handler.EdgeStackService.EdgeStack(stackID) stack, err := handler.DataStore.EdgeStack().EdgeStack(stackID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge stack from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge stack from the database", err}
} }

View File

@ -42,7 +42,7 @@ func (handler *Handler) endpointUpdate(w http.ResponseWriter, r *http.Request) *
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
} }
endpoint, err := handler.EndpointService.Endpoint(portainer.EndpointID(endpointID)) endpoint, err := handler.DataStore.Endpoint().Endpoint(portainer.EndpointID(endpointID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -80,13 +80,13 @@ func (handler *Handler) endpointUpdate(w http.ResponseWriter, r *http.Request) *
removeTags := portainer.TagDifference(endpointTagSet, payloadTagSet) removeTags := portainer.TagDifference(endpointTagSet, payloadTagSet)
for tagID := range removeTags { for tagID := range removeTags {
tag, err := handler.TagService.Tag(tagID) tag, err := handler.DataStore.Tag().Tag(tagID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a tag inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a tag inside the database", err}
} }
delete(tag.Endpoints, endpoint.ID) delete(tag.Endpoints, endpoint.ID)
err = handler.TagService.UpdateTag(tag.ID, tag) err = handler.DataStore.Tag().UpdateTag(tag.ID, tag)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist tag changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist tag changes inside the database", err}
} }
@ -94,14 +94,14 @@ func (handler *Handler) endpointUpdate(w http.ResponseWriter, r *http.Request) *
endpoint.TagIDs = payload.TagIDs endpoint.TagIDs = payload.TagIDs
for _, tagID := range payload.TagIDs { for _, tagID := range payload.TagIDs {
tag, err := handler.TagService.Tag(tagID) tag, err := handler.DataStore.Tag().Tag(tagID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a tag inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a tag inside the database", err}
} }
tag.Endpoints[endpoint.ID] = true tag.Endpoints[endpoint.ID] = true
err = handler.TagService.UpdateTag(tag.ID, tag) err = handler.DataStore.Tag().UpdateTag(tag.ID, tag)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist tag changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist tag changes inside the database", err}
} }
@ -184,7 +184,7 @@ func (handler *Handler) endpointUpdate(w http.ResponseWriter, r *http.Request) *
} }
} }
err = handler.EndpointService.UpdateEndpoint(endpoint.ID, endpoint) err = handler.DataStore.Endpoint().UpdateEndpoint(endpoint.ID, endpoint)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint changes inside the database", err}
} }
@ -197,22 +197,22 @@ func (handler *Handler) endpointUpdate(w http.ResponseWriter, r *http.Request) *
} }
if endpoint.Type == portainer.EdgeAgentEnvironment && (groupIDChanged || tagsChanged) { if endpoint.Type == portainer.EdgeAgentEnvironment && (groupIDChanged || tagsChanged) {
relation, err := handler.EndpointRelationService.EndpointRelation(endpoint.ID) relation, err := handler.DataStore.EndpointRelation().EndpointRelation(endpoint.ID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find endpoint relation inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find endpoint relation inside the database", err}
} }
endpointGroup, err := handler.EndpointGroupService.EndpointGroup(endpoint.GroupID) endpointGroup, err := handler.DataStore.EndpointGroup().EndpointGroup(endpoint.GroupID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find endpoint group inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find endpoint group inside the database", err}
} }
edgeGroups, err := handler.EdgeGroupService.EdgeGroups() edgeGroups, err := handler.DataStore.EdgeGroup().EdgeGroups()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge groups from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge groups from the database", err}
} }
edgeStacks, err := handler.EdgeStackService.EdgeStacks() edgeStacks, err := handler.DataStore.EdgeStack().EdgeStacks()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge stacks from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge stacks from the database", err}
} }
@ -226,7 +226,7 @@ func (handler *Handler) endpointUpdate(w http.ResponseWriter, r *http.Request) *
relation.EdgeStacks = edgeStackSet relation.EdgeStacks = edgeStackSet
err = handler.EndpointRelationService.UpdateEndpointRelation(endpoint.ID, relation) err = handler.DataStore.EndpointRelation().UpdateEndpointRelation(endpoint.ID, relation)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint relation changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist endpoint relation changes inside the database", err}
} }

View File

@ -20,27 +20,21 @@ func hideFields(endpoint *portainer.Endpoint) {
// Handler is the HTTP handler used to handle endpoint operations. // Handler is the HTTP handler used to handle endpoint operations.
type Handler struct { type Handler struct {
*mux.Router *mux.Router
requestBouncer *security.RequestBouncer requestBouncer *security.RequestBouncer
AuthorizationService *portainer.AuthorizationService DataStore portainer.DataStore
EdgeGroupService portainer.EdgeGroupService AuthorizationService *portainer.AuthorizationService
EdgeStackService portainer.EdgeStackService FileService portainer.FileService
EndpointService portainer.EndpointService JobService portainer.JobService
EndpointGroupService portainer.EndpointGroupService ProxyManager *proxy.Manager
EndpointRelationService portainer.EndpointRelationService ReverseTunnelService portainer.ReverseTunnelService
FileService portainer.FileService Snapshotter portainer.Snapshotter
JobService portainer.JobService
ProxyManager *proxy.Manager
ReverseTunnelService portainer.ReverseTunnelService
SettingsService portainer.SettingsService
Snapshotter portainer.Snapshotter
TagService portainer.TagService
} }
// NewHandler creates a handler to manage endpoint operations. // NewHandler creates a handler to manage endpoint operations.
func NewHandler(bouncer *security.RequestBouncer) *Handler { func NewHandler(bouncer *security.RequestBouncer) *Handler {
h := &Handler{ h := &Handler{
Router: mux.NewRouter(), Router: mux.NewRouter(),
requestBouncer: bouncer, requestBouncer: bouncer,
} }
h.Handle("/endpoints", h.Handle("/endpoints",

View File

@ -17,7 +17,7 @@ func updateTeamAccessPolicyToReadOnlyRole(policies portainer.TeamAccessPolicies,
} }
func (handler *Handler) upgradeRBACData() error { func (handler *Handler) upgradeRBACData() error {
endpointGroups, err := handler.EndpointGroupService.EndpointGroups() endpointGroups, err := handler.DataStore.EndpointGroup().EndpointGroups()
if err != nil { if err != nil {
return err return err
} }
@ -31,13 +31,13 @@ func (handler *Handler) upgradeRBACData() error {
updateTeamAccessPolicyToReadOnlyRole(endpointGroup.TeamAccessPolicies, key) updateTeamAccessPolicyToReadOnlyRole(endpointGroup.TeamAccessPolicies, key)
} }
err := handler.EndpointGroupService.UpdateEndpointGroup(endpointGroup.ID, &endpointGroup) err := handler.DataStore.EndpointGroup().UpdateEndpointGroup(endpointGroup.ID, &endpointGroup)
if err != nil { if err != nil {
return err return err
} }
} }
endpoints, err := handler.EndpointService.Endpoints() endpoints, err := handler.DataStore.Endpoint().Endpoints()
if err != nil { if err != nil {
return err return err
} }
@ -51,7 +51,7 @@ func (handler *Handler) upgradeRBACData() error {
updateTeamAccessPolicyToReadOnlyRole(endpoint.TeamAccessPolicies, key) updateTeamAccessPolicyToReadOnlyRole(endpoint.TeamAccessPolicies, key)
} }
err := handler.EndpointService.UpdateEndpoint(endpoint.ID, &endpoint) err := handler.DataStore.Endpoint().UpdateEndpoint(endpoint.ID, &endpoint)
if err != nil { if err != nil {
return err return err
} }
@ -73,7 +73,7 @@ func updateTeamAccessPolicyToNoRole(policies portainer.TeamAccessPolicies, key p
} }
func (handler *Handler) downgradeRBACData() error { func (handler *Handler) downgradeRBACData() error {
endpointGroups, err := handler.EndpointGroupService.EndpointGroups() endpointGroups, err := handler.DataStore.EndpointGroup().EndpointGroups()
if err != nil { if err != nil {
return err return err
} }
@ -87,13 +87,13 @@ func (handler *Handler) downgradeRBACData() error {
updateTeamAccessPolicyToNoRole(endpointGroup.TeamAccessPolicies, key) updateTeamAccessPolicyToNoRole(endpointGroup.TeamAccessPolicies, key)
} }
err := handler.EndpointGroupService.UpdateEndpointGroup(endpointGroup.ID, &endpointGroup) err := handler.DataStore.EndpointGroup().UpdateEndpointGroup(endpointGroup.ID, &endpointGroup)
if err != nil { if err != nil {
return err return err
} }
} }
endpoints, err := handler.EndpointService.Endpoints() endpoints, err := handler.DataStore.Endpoint().Endpoints()
if err != nil { if err != nil {
return err return err
} }
@ -107,7 +107,7 @@ func (handler *Handler) downgradeRBACData() error {
updateTeamAccessPolicyToNoRole(endpoint.TeamAccessPolicies, key) updateTeamAccessPolicyToNoRole(endpoint.TeamAccessPolicies, key)
} }
err := handler.EndpointService.UpdateEndpoint(endpoint.ID, &endpoint) err := handler.DataStore.Endpoint().UpdateEndpoint(endpoint.ID, &endpoint)
if err != nil { if err != nil {
return err return err
} }

View File

@ -36,7 +36,7 @@ func (handler *Handler) extensionCreate(w http.ResponseWriter, r *http.Request)
} }
extensionID := portainer.ExtensionID(extensionIdentifier) extensionID := portainer.ExtensionID(extensionIdentifier)
extensions, err := handler.ExtensionService.Extensions() extensions, err := handler.DataStore.Extension().Extensions()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve extensions status from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve extensions status from the database", err}
} }
@ -77,7 +77,7 @@ func (handler *Handler) extensionCreate(w http.ResponseWriter, r *http.Request)
} }
} }
err = handler.ExtensionService.Persist(extension) err = handler.DataStore.Extension().Persist(extension)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist extension status inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist extension status inside the database", err}
} }

View File

@ -17,7 +17,7 @@ func (handler *Handler) extensionDelete(w http.ResponseWriter, r *http.Request)
} }
extensionID := portainer.ExtensionID(extensionIdentifier) extensionID := portainer.ExtensionID(extensionIdentifier)
extension, err := handler.ExtensionService.Extension(extensionID) extension, err := handler.DataStore.Extension().Extension(extensionID)
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a extension with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find a extension with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -36,7 +36,7 @@ func (handler *Handler) extensionDelete(w http.ResponseWriter, r *http.Request)
} }
} }
err = handler.ExtensionService.DeleteExtension(extensionID) err = handler.DataStore.Extension().DeleteExtension(extensionID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to delete the extension from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to delete the extension from the database", err}
} }

View File

@ -25,7 +25,7 @@ func (handler *Handler) extensionInspect(w http.ResponseWriter, r *http.Request)
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve extensions informations", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve extensions informations", err}
} }
localExtension, err := handler.ExtensionService.Extension(extensionID) localExtension, err := handler.DataStore.Extension().Extension(extensionID)
if err != nil && err != portainer.ErrObjectNotFound { if err != nil && err != portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve extension information from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve extension information from the database", err}
} }

View File

@ -12,7 +12,7 @@ import (
func (handler *Handler) extensionList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { func (handler *Handler) extensionList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
fetchManifestInformation, _ := request.RetrieveBooleanQueryParameter(r, "store", true) fetchManifestInformation, _ := request.RetrieveBooleanQueryParameter(r, "store", true)
extensions, err := handler.ExtensionService.Extensions() extensions, err := handler.DataStore.Extension().Extensions()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve extensions from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve extensions from the database", err}
} }

View File

@ -35,7 +35,7 @@ func (handler *Handler) extensionUpdate(w http.ResponseWriter, r *http.Request)
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
} }
extension, err := handler.ExtensionService.Extension(extensionID) extension, err := handler.DataStore.Extension().Extension(extensionID)
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a extension with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find a extension with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -47,7 +47,7 @@ func (handler *Handler) extensionUpdate(w http.ResponseWriter, r *http.Request)
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to update extension", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to update extension", err}
} }
err = handler.ExtensionService.Persist(extension) err = handler.DataStore.Extension().Persist(extension)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist extension status inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist extension status inside the database", err}
} }

View File

@ -66,7 +66,7 @@ func (handler *Handler) extensionUpload(w http.ResponseWriter, r *http.Request)
} }
} }
err = handler.ExtensionService.Persist(extension) err = handler.DataStore.Extension().Persist(extension)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist extension status inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist extension status inside the database", err}
} }

View File

@ -14,11 +14,8 @@ import (
// Handler is the HTTP handler used to handle extension operations. // Handler is the HTTP handler used to handle extension operations.
type Handler struct { type Handler struct {
*mux.Router *mux.Router
ExtensionService portainer.ExtensionService DataStore portainer.DataStore
ExtensionManager portainer.ExtensionManager ExtensionManager portainer.ExtensionManager
EndpointGroupService portainer.EndpointGroupService
EndpointService portainer.EndpointService
RegistryService portainer.RegistryService
AuthorizationService *portainer.AuthorizationService AuthorizationService *portainer.AuthorizationService
} }

View File

@ -18,11 +18,10 @@ func hideFields(registry *portainer.Registry) {
// Handler is the HTTP handler used to handle registry operations. // Handler is the HTTP handler used to handle registry operations.
type Handler struct { type Handler struct {
*mux.Router *mux.Router
requestBouncer *security.RequestBouncer requestBouncer *security.RequestBouncer
RegistryService portainer.RegistryService DataStore portainer.DataStore
ExtensionService portainer.ExtensionService FileService portainer.FileService
FileService portainer.FileService ProxyManager *proxy.Manager
ProxyManager *proxy.Manager
} }
// NewHandler creates a handler to manage registry operations. // NewHandler creates a handler to manage registry operations.

View File

@ -17,7 +17,7 @@ func (handler *Handler) proxyRequestsToRegistryAPI(w http.ResponseWriter, r *htt
return &httperror.HandlerError{http.StatusBadRequest, "Invalid registry identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid registry identifier route variable", err}
} }
registry, err := handler.RegistryService.Registry(portainer.RegistryID(registryID)) registry, err := handler.DataStore.Registry().Registry(portainer.RegistryID(registryID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a registry with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find a registry with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -29,7 +29,7 @@ func (handler *Handler) proxyRequestsToRegistryAPI(w http.ResponseWriter, r *htt
return &httperror.HandlerError{http.StatusForbidden, "Permission denied to access registry", portainer.ErrEndpointAccessDenied} return &httperror.HandlerError{http.StatusForbidden, "Permission denied to access registry", portainer.ErrEndpointAccessDenied}
} }
extension, err := handler.ExtensionService.Extension(portainer.RegistryManagementExtension) extension, err := handler.DataStore.Extension().Extension(portainer.RegistryManagementExtension)
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Registry management extension is not enabled", err} return &httperror.HandlerError{http.StatusNotFound, "Registry management extension is not enabled", err}
} else if err != nil { } else if err != nil {

View File

@ -17,7 +17,7 @@ func (handler *Handler) proxyRequestsToGitlabAPIWithRegistry(w http.ResponseWrit
return &httperror.HandlerError{http.StatusBadRequest, "Invalid registry identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid registry identifier route variable", err}
} }
registry, err := handler.RegistryService.Registry(portainer.RegistryID(registryID)) registry, err := handler.DataStore.Registry().Registry(portainer.RegistryID(registryID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a registry with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find a registry with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -29,7 +29,7 @@ func (handler *Handler) proxyRequestsToGitlabAPIWithRegistry(w http.ResponseWrit
return &httperror.HandlerError{http.StatusForbidden, "Permission denied to access registry", portainer.ErrEndpointAccessDenied} return &httperror.HandlerError{http.StatusForbidden, "Permission denied to access registry", portainer.ErrEndpointAccessDenied}
} }
extension, err := handler.ExtensionService.Extension(portainer.RegistryManagementExtension) extension, err := handler.DataStore.Extension().Extension(portainer.RegistryManagementExtension)
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Registry management extension is not enabled", err} return &httperror.HandlerError{http.StatusNotFound, "Registry management extension is not enabled", err}
} else if err != nil { } else if err != nil {

View File

@ -78,7 +78,7 @@ func (handler *Handler) registryConfigure(w http.ResponseWriter, r *http.Request
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
} }
registry, err := handler.RegistryService.Registry(portainer.RegistryID(registryID)) registry, err := handler.DataStore.Registry().Registry(portainer.RegistryID(registryID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a registry with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find a registry with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -128,7 +128,7 @@ func (handler *Handler) registryConfigure(w http.ResponseWriter, r *http.Request
} }
} }
err = handler.RegistryService.UpdateRegistry(registry.ID, registry) err = handler.DataStore.Registry().UpdateRegistry(registry.ID, registry)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist registry changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist registry changes inside the database", err}
} }

View File

@ -55,7 +55,7 @@ func (handler *Handler) registryCreate(w http.ResponseWriter, r *http.Request) *
Gitlab: payload.Gitlab, Gitlab: payload.Gitlab,
} }
err = handler.RegistryService.CreateRegistry(registry) err = handler.DataStore.Registry().CreateRegistry(registry)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the registry inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the registry inside the database", err}
} }

View File

@ -16,14 +16,14 @@ func (handler *Handler) registryDelete(w http.ResponseWriter, r *http.Request) *
return &httperror.HandlerError{http.StatusBadRequest, "Invalid registry identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid registry identifier route variable", err}
} }
_, err = handler.RegistryService.Registry(portainer.RegistryID(registryID)) _, err = handler.DataStore.Registry().Registry(portainer.RegistryID(registryID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a registry with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find a registry with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a registry with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a registry with the specified identifier inside the database", err}
} }
err = handler.RegistryService.DeleteRegistry(portainer.RegistryID(registryID)) err = handler.DataStore.Registry().DeleteRegistry(portainer.RegistryID(registryID))
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove the registry from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove the registry from the database", err}
} }

View File

@ -16,7 +16,7 @@ func (handler *Handler) registryInspect(w http.ResponseWriter, r *http.Request)
return &httperror.HandlerError{http.StatusBadRequest, "Invalid registry identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid registry identifier route variable", err}
} }
registry, err := handler.RegistryService.Registry(portainer.RegistryID(registryID)) registry, err := handler.DataStore.Registry().Registry(portainer.RegistryID(registryID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a registry with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find a registry with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {

View File

@ -10,7 +10,7 @@ import (
// GET request on /api/registries // GET request on /api/registries
func (handler *Handler) registryList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { func (handler *Handler) registryList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
registries, err := handler.RegistryService.Registries() registries, err := handler.DataStore.Registry().Registries()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve registries from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve registries from the database", err}
} }

View File

@ -36,7 +36,7 @@ func (handler *Handler) registryUpdate(w http.ResponseWriter, r *http.Request) *
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
} }
registry, err := handler.RegistryService.Registry(portainer.RegistryID(registryID)) registry, err := handler.DataStore.Registry().Registry(portainer.RegistryID(registryID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a registry with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find a registry with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -48,7 +48,7 @@ func (handler *Handler) registryUpdate(w http.ResponseWriter, r *http.Request) *
} }
if payload.URL != nil { if payload.URL != nil {
registries, err := handler.RegistryService.Registries() registries, err := handler.DataStore.Registry().Registries()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve registries from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve registries from the database", err}
} }
@ -88,7 +88,7 @@ func (handler *Handler) registryUpdate(w http.ResponseWriter, r *http.Request) *
registry.TeamAccessPolicies = payload.TeamAccessPolicies registry.TeamAccessPolicies = payload.TeamAccessPolicies
} }
err = handler.RegistryService.UpdateRegistry(registry.ID, registry) err = handler.DataStore.Registry().UpdateRegistry(registry.ID, registry)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist registry changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist registry changes inside the database", err}
} }

View File

@ -12,7 +12,7 @@ import (
// Handler is the HTTP handler used to handle resource control operations. // Handler is the HTTP handler used to handle resource control operations.
type Handler struct { type Handler struct {
*mux.Router *mux.Router
ResourceControlService portainer.ResourceControlService DataStore portainer.DataStore
} }
// NewHandler creates a handler to manage resource control operations. // NewHandler creates a handler to manage resource control operations.

View File

@ -68,7 +68,7 @@ func (handler *Handler) resourceControlCreate(w http.ResponseWriter, r *http.Req
return &httperror.HandlerError{http.StatusBadRequest, "Invalid type value. Value must be one of: container, service, volume, network, secret, stack or config", portainer.ErrInvalidResourceControlType} return &httperror.HandlerError{http.StatusBadRequest, "Invalid type value. Value must be one of: container, service, volume, network, secret, stack or config", portainer.ErrInvalidResourceControlType}
} }
rc, err := handler.ResourceControlService.ResourceControlByResourceIDAndType(payload.ResourceID, resourceControlType) rc, err := handler.DataStore.ResourceControl().ResourceControlByResourceIDAndType(payload.ResourceID, resourceControlType)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve resource controls from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve resource controls from the database", err}
} }
@ -104,7 +104,7 @@ func (handler *Handler) resourceControlCreate(w http.ResponseWriter, r *http.Req
TeamAccesses: teamAccesses, TeamAccesses: teamAccesses,
} }
err = handler.ResourceControlService.CreateResourceControl(&resourceControl) err = handler.DataStore.ResourceControl().CreateResourceControl(&resourceControl)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the resource control inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the resource control inside the database", err}
} }

View File

@ -16,14 +16,14 @@ func (handler *Handler) resourceControlDelete(w http.ResponseWriter, r *http.Req
return &httperror.HandlerError{http.StatusBadRequest, "Invalid resource control identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid resource control identifier route variable", err}
} }
_, err = handler.ResourceControlService.ResourceControl(portainer.ResourceControlID(resourceControlID)) _, err = handler.DataStore.ResourceControl().ResourceControl(portainer.ResourceControlID(resourceControlID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a resource control with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find a resource control with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a resource control with with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a resource control with with the specified identifier inside the database", err}
} }
err = handler.ResourceControlService.DeleteResourceControl(portainer.ResourceControlID(resourceControlID)) err = handler.DataStore.ResourceControl().DeleteResourceControl(portainer.ResourceControlID(resourceControlID))
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove the resource control from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove the resource control from the database", err}
} }

View File

@ -42,7 +42,7 @@ func (handler *Handler) resourceControlUpdate(w http.ResponseWriter, r *http.Req
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
} }
resourceControl, err := handler.ResourceControlService.ResourceControl(portainer.ResourceControlID(resourceControlID)) resourceControl, err := handler.DataStore.ResourceControl().ResourceControl(portainer.ResourceControlID(resourceControlID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a resource control with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find a resource control with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -85,7 +85,7 @@ func (handler *Handler) resourceControlUpdate(w http.ResponseWriter, r *http.Req
return &httperror.HandlerError{http.StatusForbidden, "Permission denied to update the resource control", portainer.ErrResourceAccessDenied} return &httperror.HandlerError{http.StatusForbidden, "Permission denied to update the resource control", portainer.ErrResourceAccessDenied}
} }
err = handler.ResourceControlService.UpdateResourceControl(resourceControl.ID, resourceControl) err = handler.DataStore.ResourceControl().UpdateResourceControl(resourceControl.ID, resourceControl)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist resource control changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist resource control changes inside the database", err}
} }

View File

@ -12,7 +12,7 @@ import (
// Handler is the HTTP handler used to handle role operations. // Handler is the HTTP handler used to handle role operations.
type Handler struct { type Handler struct {
*mux.Router *mux.Router
RoleService portainer.RoleService DataStore portainer.DataStore
} }
// NewHandler creates a handler to manage role operations. // NewHandler creates a handler to manage role operations.

View File

@ -9,7 +9,7 @@ import (
// GET request on /api/Role // GET request on /api/Role
func (handler *Handler) roleList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { func (handler *Handler) roleList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
roles, err := handler.RoleService.Roles() roles, err := handler.DataStore.Role().Roles()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve authorization sets from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve authorization sets from the database", err}
} }

View File

@ -12,9 +12,7 @@ import (
// Handler is the HTTP handler used to handle schedule operations. // Handler is the HTTP handler used to handle schedule operations.
type Handler struct { type Handler struct {
*mux.Router *mux.Router
ScheduleService portainer.ScheduleService DataStore portainer.DataStore
EndpointService portainer.EndpointService
SettingsService portainer.SettingsService
FileService portainer.FileService FileService portainer.FileService
JobService portainer.JobService JobService portainer.JobService
JobScheduler portainer.JobScheduler JobScheduler portainer.JobScheduler

View File

@ -117,7 +117,7 @@ func (payload *scheduleCreateFromFileContentPayload) Validate(r *http.Request) e
// POST /api/schedules?method=file|string // POST /api/schedules?method=file|string
func (handler *Handler) scheduleCreate(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { func (handler *Handler) scheduleCreate(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
settings, err := handler.SettingsService.Settings() settings, err := handler.DataStore.Settings().Settings()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusServiceUnavailable, "Unable to retrieve settings", err} return &httperror.HandlerError{http.StatusServiceUnavailable, "Unable to retrieve settings", err}
} }
@ -175,7 +175,7 @@ func (handler *Handler) createScheduleFromFile(w http.ResponseWriter, r *http.Re
} }
func (handler *Handler) createScheduleObjectFromFilePayload(payload *scheduleCreateFromFilePayload) *portainer.Schedule { func (handler *Handler) createScheduleObjectFromFilePayload(payload *scheduleCreateFromFilePayload) *portainer.Schedule {
scheduleIdentifier := portainer.ScheduleID(handler.ScheduleService.GetNextIdentifier()) scheduleIdentifier := portainer.ScheduleID(handler.DataStore.Schedule().GetNextIdentifier())
job := &portainer.ScriptExecutionJob{ job := &portainer.ScriptExecutionJob{
Endpoints: payload.Endpoints, Endpoints: payload.Endpoints,
@ -198,7 +198,7 @@ func (handler *Handler) createScheduleObjectFromFilePayload(payload *scheduleCre
} }
func (handler *Handler) createScheduleObjectFromFileContentPayload(payload *scheduleCreateFromFileContentPayload) *portainer.Schedule { func (handler *Handler) createScheduleObjectFromFileContentPayload(payload *scheduleCreateFromFileContentPayload) *portainer.Schedule {
scheduleIdentifier := portainer.ScheduleID(handler.ScheduleService.GetNextIdentifier()) scheduleIdentifier := portainer.ScheduleID(handler.DataStore.Schedule().GetNextIdentifier())
job := &portainer.ScriptExecutionJob{ job := &portainer.ScriptExecutionJob{
Endpoints: payload.Endpoints, Endpoints: payload.Endpoints,
@ -231,7 +231,7 @@ func (handler *Handler) addAndPersistSchedule(schedule *portainer.Schedule, file
for _, ID := range schedule.ScriptExecutionJob.Endpoints { for _, ID := range schedule.ScriptExecutionJob.Endpoints {
endpoint, err := handler.EndpointService.Endpoint(ID) endpoint, err := handler.DataStore.Endpoint().Endpoint(ID)
if err != nil { if err != nil {
return err return err
} }
@ -268,7 +268,7 @@ func (handler *Handler) addAndPersistSchedule(schedule *portainer.Schedule, file
schedule.ScriptExecutionJob.ScriptPath = scriptPath schedule.ScriptExecutionJob.ScriptPath = scriptPath
jobContext := cron.NewScriptExecutionJobContext(handler.JobService, handler.EndpointService, handler.FileService) jobContext := cron.NewScriptExecutionJobContext(handler.JobService, handler.DataStore, handler.FileService)
jobRunner := cron.NewScriptExecutionJobRunner(schedule, jobContext) jobRunner := cron.NewScriptExecutionJobRunner(schedule, jobContext)
err = handler.JobScheduler.ScheduleJob(jobRunner) err = handler.JobScheduler.ScheduleJob(jobRunner)
@ -276,5 +276,5 @@ func (handler *Handler) addAndPersistSchedule(schedule *portainer.Schedule, file
return err return err
} }
return handler.ScheduleService.CreateSchedule(schedule) return handler.DataStore.Schedule().CreateSchedule(schedule)
} }

View File

@ -12,7 +12,7 @@ import (
) )
func (handler *Handler) scheduleDelete(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { func (handler *Handler) scheduleDelete(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
settings, err := handler.SettingsService.Settings() settings, err := handler.DataStore.Settings().Settings()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusServiceUnavailable, "Unable to retrieve settings", err} return &httperror.HandlerError{http.StatusServiceUnavailable, "Unable to retrieve settings", err}
} }
@ -25,7 +25,7 @@ func (handler *Handler) scheduleDelete(w http.ResponseWriter, r *http.Request) *
return &httperror.HandlerError{http.StatusBadRequest, "Invalid schedule identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid schedule identifier route variable", err}
} }
schedule, err := handler.ScheduleService.Schedule(portainer.ScheduleID(scheduleID)) schedule, err := handler.DataStore.Schedule().Schedule(portainer.ScheduleID(scheduleID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a schedule with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find a schedule with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -46,7 +46,7 @@ func (handler *Handler) scheduleDelete(w http.ResponseWriter, r *http.Request) *
handler.JobScheduler.UnscheduleJob(schedule.ID) handler.JobScheduler.UnscheduleJob(schedule.ID)
err = handler.ScheduleService.DeleteSchedule(portainer.ScheduleID(scheduleID)) err = handler.DataStore.Schedule().DeleteSchedule(portainer.ScheduleID(scheduleID))
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove the schedule from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove the schedule from the database", err}
} }

View File

@ -16,7 +16,7 @@ type scheduleFileResponse struct {
// GET request on /api/schedules/:id/file // GET request on /api/schedules/:id/file
func (handler *Handler) scheduleFile(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { func (handler *Handler) scheduleFile(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
settings, err := handler.SettingsService.Settings() settings, err := handler.DataStore.Settings().Settings()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusServiceUnavailable, "Unable to retrieve settings", err} return &httperror.HandlerError{http.StatusServiceUnavailable, "Unable to retrieve settings", err}
} }
@ -29,7 +29,7 @@ func (handler *Handler) scheduleFile(w http.ResponseWriter, r *http.Request) *ht
return &httperror.HandlerError{http.StatusBadRequest, "Invalid schedule identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid schedule identifier route variable", err}
} }
schedule, err := handler.ScheduleService.Schedule(portainer.ScheduleID(scheduleID)) schedule, err := handler.DataStore.Schedule().Schedule(portainer.ScheduleID(scheduleID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a schedule with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find a schedule with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {

View File

@ -11,7 +11,7 @@ import (
) )
func (handler *Handler) scheduleInspect(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { func (handler *Handler) scheduleInspect(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
settings, err := handler.SettingsService.Settings() settings, err := handler.DataStore.Settings().Settings()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusServiceUnavailable, "Unable to retrieve settings", err} return &httperror.HandlerError{http.StatusServiceUnavailable, "Unable to retrieve settings", err}
} }
@ -24,7 +24,7 @@ func (handler *Handler) scheduleInspect(w http.ResponseWriter, r *http.Request)
return &httperror.HandlerError{http.StatusBadRequest, "Invalid schedule identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid schedule identifier route variable", err}
} }
schedule, err := handler.ScheduleService.Schedule(portainer.ScheduleID(scheduleID)) schedule, err := handler.DataStore.Schedule().Schedule(portainer.ScheduleID(scheduleID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a schedule with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find a schedule with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {

View File

@ -10,7 +10,7 @@ import (
// GET request on /api/schedules // GET request on /api/schedules
func (handler *Handler) scheduleList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { func (handler *Handler) scheduleList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
settings, err := handler.SettingsService.Settings() settings, err := handler.DataStore.Settings().Settings()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusServiceUnavailable, "Unable to retrieve settings", err} return &httperror.HandlerError{http.StatusServiceUnavailable, "Unable to retrieve settings", err}
} }
@ -18,7 +18,7 @@ func (handler *Handler) scheduleList(w http.ResponseWriter, r *http.Request) *ht
return &httperror.HandlerError{http.StatusServiceUnavailable, "Host management features are disabled", portainer.ErrHostManagementFeaturesDisabled} return &httperror.HandlerError{http.StatusServiceUnavailable, "Host management features are disabled", portainer.ErrHostManagementFeaturesDisabled}
} }
schedules, err := handler.ScheduleService.Schedules() schedules, err := handler.DataStore.Schedule().Schedules()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve schedules from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve schedules from the database", err}
} }

View File

@ -24,7 +24,7 @@ type taskContainer struct {
// GET request on /api/schedules/:id/tasks // GET request on /api/schedules/:id/tasks
func (handler *Handler) scheduleTasks(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { func (handler *Handler) scheduleTasks(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
settings, err := handler.SettingsService.Settings() settings, err := handler.DataStore.Settings().Settings()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusServiceUnavailable, "Unable to retrieve settings", err} return &httperror.HandlerError{http.StatusServiceUnavailable, "Unable to retrieve settings", err}
} }
@ -37,7 +37,7 @@ func (handler *Handler) scheduleTasks(w http.ResponseWriter, r *http.Request) *h
return &httperror.HandlerError{http.StatusBadRequest, "Invalid schedule identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid schedule identifier route variable", err}
} }
schedule, err := handler.ScheduleService.Schedule(portainer.ScheduleID(scheduleID)) schedule, err := handler.DataStore.Schedule().Schedule(portainer.ScheduleID(scheduleID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a schedule with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find a schedule with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -51,7 +51,7 @@ func (handler *Handler) scheduleTasks(w http.ResponseWriter, r *http.Request) *h
tasks := make([]taskContainer, 0) tasks := make([]taskContainer, 0)
for _, endpointID := range schedule.ScriptExecutionJob.Endpoints { for _, endpointID := range schedule.ScriptExecutionJob.Endpoints {
endpoint, err := handler.EndpointService.Endpoint(endpointID) endpoint, err := handler.DataStore.Endpoint().Endpoint(endpointID)
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
continue continue
} else if err != nil { } else if err != nil {

View File

@ -33,7 +33,7 @@ func (payload *scheduleUpdatePayload) Validate(r *http.Request) error {
} }
func (handler *Handler) scheduleUpdate(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { func (handler *Handler) scheduleUpdate(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
settings, err := handler.SettingsService.Settings() settings, err := handler.DataStore.Settings().Settings()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusServiceUnavailable, "Unable to retrieve settings", err} return &httperror.HandlerError{http.StatusServiceUnavailable, "Unable to retrieve settings", err}
} }
@ -52,7 +52,7 @@ func (handler *Handler) scheduleUpdate(w http.ResponseWriter, r *http.Request) *
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
} }
schedule, err := handler.ScheduleService.Schedule(portainer.ScheduleID(scheduleID)) schedule, err := handler.DataStore.Schedule().Schedule(portainer.ScheduleID(scheduleID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a schedule with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find a schedule with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -78,7 +78,7 @@ func (handler *Handler) scheduleUpdate(w http.ResponseWriter, r *http.Request) *
} }
if updateJobSchedule { if updateJobSchedule {
jobContext := cron.NewScriptExecutionJobContext(handler.JobService, handler.EndpointService, handler.FileService) jobContext := cron.NewScriptExecutionJobContext(handler.JobService, handler.DataStore, handler.FileService)
jobRunner := cron.NewScriptExecutionJobRunner(schedule, jobContext) jobRunner := cron.NewScriptExecutionJobRunner(schedule, jobContext)
err := handler.JobScheduler.UpdateJobSchedule(jobRunner) err := handler.JobScheduler.UpdateJobSchedule(jobRunner)
if err != nil { if err != nil {
@ -86,7 +86,7 @@ func (handler *Handler) scheduleUpdate(w http.ResponseWriter, r *http.Request) *
} }
} }
err = handler.ScheduleService.UpdateSchedule(portainer.ScheduleID(scheduleID), schedule) err = handler.DataStore.Schedule().UpdateSchedule(portainer.ScheduleID(scheduleID), schedule)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist schedule changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist schedule changes inside the database", err}
} }
@ -104,7 +104,7 @@ func (handler *Handler) updateEdgeSchedule(schedule *portainer.Schedule, payload
edgeEndpointIDs := make([]portainer.EndpointID, 0) edgeEndpointIDs := make([]portainer.EndpointID, 0)
for _, ID := range payload.Endpoints { for _, ID := range payload.Endpoints {
endpoint, err := handler.EndpointService.Endpoint(ID) endpoint, err := handler.DataStore.Endpoint().Endpoint(ID)
if err != nil { if err != nil {
return err return err
} }

View File

@ -17,13 +17,10 @@ func hideFields(settings *portainer.Settings) {
// Handler is the HTTP handler used to handle settings operations. // Handler is the HTTP handler used to handle settings operations.
type Handler struct { type Handler struct {
*mux.Router *mux.Router
SettingsService portainer.SettingsService DataStore portainer.DataStore
LDAPService portainer.LDAPService LDAPService portainer.LDAPService
FileService portainer.FileService FileService portainer.FileService
JobScheduler portainer.JobScheduler JobScheduler portainer.JobScheduler
ScheduleService portainer.ScheduleService
RoleService portainer.RoleService
ExtensionService portainer.ExtensionService
AuthorizationService *portainer.AuthorizationService AuthorizationService *portainer.AuthorizationService
} }

View File

@ -9,7 +9,7 @@ import (
// GET request on /api/settings // GET request on /api/settings
func (handler *Handler) settingsInspect(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { func (handler *Handler) settingsInspect(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
settings, err := handler.SettingsService.Settings() settings, err := handler.DataStore.Settings().Settings()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve the settings from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve the settings from the database", err}
} }

View File

@ -22,7 +22,7 @@ type publicSettingsResponse struct {
// GET request on /api/settings/public // GET request on /api/settings/public
func (handler *Handler) settingsPublic(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { func (handler *Handler) settingsPublic(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
settings, err := handler.SettingsService.Settings() settings, err := handler.DataStore.Settings().Settings()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve the settings from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve the settings from the database", err}
} }

View File

@ -48,7 +48,7 @@ func (handler *Handler) settingsUpdate(w http.ResponseWriter, r *http.Request) *
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
} }
settings, err := handler.SettingsService.Settings() settings, err := handler.DataStore.Settings().Settings()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve the settings from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve the settings from the database", err}
} }
@ -130,7 +130,7 @@ func (handler *Handler) settingsUpdate(w http.ResponseWriter, r *http.Request) *
return tlsError return tlsError
} }
err = handler.SettingsService.UpdateSettings(settings) err = handler.DataStore.Settings().UpdateSettings(settings)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist settings changes inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist settings changes inside the database", err}
} }
@ -151,7 +151,7 @@ func (handler *Handler) updateVolumeBrowserSetting(settings *portainer.Settings)
return err return err
} }
extension, err := handler.ExtensionService.Extension(portainer.RBACExtension) extension, err := handler.DataStore.Extension().Extension(portainer.RBACExtension)
if err != nil && err != portainer.ErrObjectNotFound { if err != nil && err != portainer.ErrObjectNotFound {
return err return err
} }
@ -169,7 +169,7 @@ func (handler *Handler) updateVolumeBrowserSetting(settings *portainer.Settings)
func (handler *Handler) updateSnapshotInterval(settings *portainer.Settings, snapshotInterval string) error { func (handler *Handler) updateSnapshotInterval(settings *portainer.Settings, snapshotInterval string) error {
settings.SnapshotInterval = snapshotInterval settings.SnapshotInterval = snapshotInterval
schedules, err := handler.ScheduleService.SchedulesByJobType(portainer.SnapshotJobType) schedules, err := handler.DataStore.Schedule().SchedulesByJobType(portainer.SnapshotJobType)
if err != nil { if err != nil {
return err return err
} }
@ -183,7 +183,7 @@ func (handler *Handler) updateSnapshotInterval(settings *portainer.Settings, sna
return err return err
} }
err = handler.ScheduleService.UpdateSchedule(snapshotSchedule.ID, &snapshotSchedule) err = handler.DataStore.Schedule().UpdateSchedule(snapshotSchedule.ID, &snapshotSchedule)
if err != nil { if err != nil {
return err return err
} }

View File

@ -47,7 +47,7 @@ func (handler *Handler) createComposeStackFromFileContent(w http.ResponseWriter,
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
} }
stacks, err := handler.StackService.Stacks() stacks, err := handler.DataStore.Stack().Stacks()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve stacks from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve stacks from the database", err}
} }
@ -58,7 +58,7 @@ func (handler *Handler) createComposeStackFromFileContent(w http.ResponseWriter,
} }
} }
stackID := handler.StackService.GetNextIdentifier() stackID := handler.DataStore.Stack().GetNextIdentifier()
stack := &portainer.Stack{ stack := &portainer.Stack{
ID: portainer.StackID(stackID), ID: portainer.StackID(stackID),
Name: payload.Name, Name: payload.Name,
@ -88,7 +88,7 @@ func (handler *Handler) createComposeStackFromFileContent(w http.ResponseWriter,
return &httperror.HandlerError{http.StatusInternalServerError, err.Error(), err} return &httperror.HandlerError{http.StatusInternalServerError, err.Error(), err}
} }
err = handler.StackService.CreateStack(stack) err = handler.DataStore.Stack().CreateStack(stack)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the stack inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the stack inside the database", err}
} }
@ -132,7 +132,7 @@ func (handler *Handler) createComposeStackFromGitRepository(w http.ResponseWrite
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
} }
stacks, err := handler.StackService.Stacks() stacks, err := handler.DataStore.Stack().Stacks()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve stacks from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve stacks from the database", err}
} }
@ -143,7 +143,7 @@ func (handler *Handler) createComposeStackFromGitRepository(w http.ResponseWrite
} }
} }
stackID := handler.StackService.GetNextIdentifier() stackID := handler.DataStore.Stack().GetNextIdentifier()
stack := &portainer.Stack{ stack := &portainer.Stack{
ID: portainer.StackID(stackID), ID: portainer.StackID(stackID),
Name: payload.Name, Name: payload.Name,
@ -183,7 +183,7 @@ func (handler *Handler) createComposeStackFromGitRepository(w http.ResponseWrite
return &httperror.HandlerError{http.StatusInternalServerError, err.Error(), err} return &httperror.HandlerError{http.StatusInternalServerError, err.Error(), err}
} }
err = handler.StackService.CreateStack(stack) err = handler.DataStore.Stack().CreateStack(stack)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the stack inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the stack inside the database", err}
} }
@ -227,7 +227,7 @@ func (handler *Handler) createComposeStackFromFileUpload(w http.ResponseWriter,
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
} }
stacks, err := handler.StackService.Stacks() stacks, err := handler.DataStore.Stack().Stacks()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve stacks from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve stacks from the database", err}
} }
@ -238,7 +238,7 @@ func (handler *Handler) createComposeStackFromFileUpload(w http.ResponseWriter,
} }
} }
stackID := handler.StackService.GetNextIdentifier() stackID := handler.DataStore.Stack().GetNextIdentifier()
stack := &portainer.Stack{ stack := &portainer.Stack{
ID: portainer.StackID(stackID), ID: portainer.StackID(stackID),
Name: payload.Name, Name: payload.Name,
@ -268,7 +268,7 @@ func (handler *Handler) createComposeStackFromFileUpload(w http.ResponseWriter,
return &httperror.HandlerError{http.StatusInternalServerError, err.Error(), err} return &httperror.HandlerError{http.StatusInternalServerError, err.Error(), err}
} }
err = handler.StackService.CreateStack(stack) err = handler.DataStore.Stack().CreateStack(stack)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the stack inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the stack inside the database", err}
} }
@ -291,12 +291,12 @@ func (handler *Handler) createComposeDeployConfig(r *http.Request, stack *portai
return nil, &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve info from request context", err} return nil, &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve info from request context", err}
} }
dockerhub, err := handler.DockerHubService.DockerHub() dockerhub, err := handler.DataStore.DockerHub().DockerHub()
if err != nil { if err != nil {
return nil, &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve DockerHub details from the database", err} return nil, &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve DockerHub details from the database", err}
} }
registries, err := handler.RegistryService.Registries() registries, err := handler.DataStore.Registry().Registries()
if err != nil { if err != nil {
return nil, &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve registries from the database", err} return nil, &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve registries from the database", err}
} }
@ -319,7 +319,7 @@ func (handler *Handler) createComposeDeployConfig(r *http.Request, stack *portai
// clean it. Hence the use of the mutex. // clean it. Hence the use of the mutex.
// We should contribute to libcompose to support authentication without using the config.json file. // We should contribute to libcompose to support authentication without using the config.json file.
func (handler *Handler) deployComposeStack(config *composeStackDeploymentConfig) error { func (handler *Handler) deployComposeStack(config *composeStackDeploymentConfig) error {
settings, err := handler.SettingsService.Settings() settings, err := handler.DataStore.Settings().Settings()
if err != nil { if err != nil {
return err return err
} }

View File

@ -42,7 +42,7 @@ func (handler *Handler) createSwarmStackFromFileContent(w http.ResponseWriter, r
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
} }
stacks, err := handler.StackService.Stacks() stacks, err := handler.DataStore.Stack().Stacks()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve stacks from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve stacks from the database", err}
} }
@ -53,7 +53,7 @@ func (handler *Handler) createSwarmStackFromFileContent(w http.ResponseWriter, r
} }
} }
stackID := handler.StackService.GetNextIdentifier() stackID := handler.DataStore.Stack().GetNextIdentifier()
stack := &portainer.Stack{ stack := &portainer.Stack{
ID: portainer.StackID(stackID), ID: portainer.StackID(stackID),
Name: payload.Name, Name: payload.Name,
@ -84,7 +84,7 @@ func (handler *Handler) createSwarmStackFromFileContent(w http.ResponseWriter, r
return &httperror.HandlerError{http.StatusInternalServerError, err.Error(), err} return &httperror.HandlerError{http.StatusInternalServerError, err.Error(), err}
} }
err = handler.StackService.CreateStack(stack) err = handler.DataStore.Stack().CreateStack(stack)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the stack inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the stack inside the database", err}
} }
@ -131,7 +131,7 @@ func (handler *Handler) createSwarmStackFromGitRepository(w http.ResponseWriter,
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
} }
stacks, err := handler.StackService.Stacks() stacks, err := handler.DataStore.Stack().Stacks()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve stacks from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve stacks from the database", err}
} }
@ -142,7 +142,7 @@ func (handler *Handler) createSwarmStackFromGitRepository(w http.ResponseWriter,
} }
} }
stackID := handler.StackService.GetNextIdentifier() stackID := handler.DataStore.Stack().GetNextIdentifier()
stack := &portainer.Stack{ stack := &portainer.Stack{
ID: portainer.StackID(stackID), ID: portainer.StackID(stackID),
Name: payload.Name, Name: payload.Name,
@ -183,7 +183,7 @@ func (handler *Handler) createSwarmStackFromGitRepository(w http.ResponseWriter,
return &httperror.HandlerError{http.StatusInternalServerError, err.Error(), err} return &httperror.HandlerError{http.StatusInternalServerError, err.Error(), err}
} }
err = handler.StackService.CreateStack(stack) err = handler.DataStore.Stack().CreateStack(stack)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the stack inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the stack inside the database", err}
} }
@ -234,7 +234,7 @@ func (handler *Handler) createSwarmStackFromFileUpload(w http.ResponseWriter, r
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
} }
stacks, err := handler.StackService.Stacks() stacks, err := handler.DataStore.Stack().Stacks()
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve stacks from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve stacks from the database", err}
} }
@ -245,7 +245,7 @@ func (handler *Handler) createSwarmStackFromFileUpload(w http.ResponseWriter, r
} }
} }
stackID := handler.StackService.GetNextIdentifier() stackID := handler.DataStore.Stack().GetNextIdentifier()
stack := &portainer.Stack{ stack := &portainer.Stack{
ID: portainer.StackID(stackID), ID: portainer.StackID(stackID),
Name: payload.Name, Name: payload.Name,
@ -276,7 +276,7 @@ func (handler *Handler) createSwarmStackFromFileUpload(w http.ResponseWriter, r
return &httperror.HandlerError{http.StatusInternalServerError, err.Error(), err} return &httperror.HandlerError{http.StatusInternalServerError, err.Error(), err}
} }
err = handler.StackService.CreateStack(stack) err = handler.DataStore.Stack().CreateStack(stack)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the stack inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the stack inside the database", err}
} }
@ -300,12 +300,12 @@ func (handler *Handler) createSwarmDeployConfig(r *http.Request, stack *portaine
return nil, &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve info from request context", err} return nil, &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve info from request context", err}
} }
dockerhub, err := handler.DockerHubService.DockerHub() dockerhub, err := handler.DataStore.DockerHub().DockerHub()
if err != nil { if err != nil {
return nil, &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve DockerHub details from the database", err} return nil, &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve DockerHub details from the database", err}
} }
registries, err := handler.RegistryService.Registries() registries, err := handler.DataStore.Registry().Registries()
if err != nil { if err != nil {
return nil, &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve registries from the database", err} return nil, &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve registries from the database", err}
} }
@ -324,7 +324,7 @@ func (handler *Handler) createSwarmDeployConfig(r *http.Request, stack *portaine
} }
func (handler *Handler) deploySwarmStack(config *swarmStackDeploymentConfig) error { func (handler *Handler) deploySwarmStack(config *swarmStackDeploymentConfig) error {
settings, err := handler.SettingsService.Settings() settings, err := handler.DataStore.Settings().Settings()
if err != nil { if err != nil {
return err return err
} }

View File

@ -16,18 +16,11 @@ type Handler struct {
stackDeletionMutex *sync.Mutex stackDeletionMutex *sync.Mutex
requestBouncer *security.RequestBouncer requestBouncer *security.RequestBouncer
*mux.Router *mux.Router
FileService portainer.FileService DataStore portainer.DataStore
GitService portainer.GitService FileService portainer.FileService
StackService portainer.StackService GitService portainer.GitService
EndpointService portainer.EndpointService SwarmStackManager portainer.SwarmStackManager
ResourceControlService portainer.ResourceControlService ComposeStackManager portainer.ComposeStackManager
RegistryService portainer.RegistryService
DockerHubService portainer.DockerHubService
SwarmStackManager portainer.SwarmStackManager
ComposeStackManager portainer.ComposeStackManager
SettingsService portainer.SettingsService
UserService portainer.UserService
ExtensionService portainer.ExtensionService
} }
// NewHandler creates a handler to manage stack operations. // NewHandler creates a handler to manage stack operations.
@ -69,14 +62,14 @@ func (handler *Handler) userCanAccessStack(securityContext *security.RestrictedR
return true, nil return true, nil
} }
_, err := handler.ExtensionService.Extension(portainer.RBACExtension) _, err := handler.DataStore.Extension().Extension(portainer.RBACExtension)
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return false, nil return false, nil
} else if err != nil && err != portainer.ErrObjectNotFound { } else if err != nil && err != portainer.ErrObjectNotFound {
return false, err return false, err
} }
user, err := handler.UserService.User(securityContext.UserID) user, err := handler.DataStore.User().User(securityContext.UserID)
if err != nil { if err != nil {
return false, err return false, err
} }

View File

@ -43,7 +43,7 @@ func (handler *Handler) stackCreate(w http.ResponseWriter, r *http.Request) *htt
return &httperror.HandlerError{http.StatusBadRequest, "Invalid query parameter: endpointId", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid query parameter: endpointId", err}
} }
endpoint, err := handler.EndpointService.Endpoint(portainer.EndpointID(endpointID)) endpoint, err := handler.DataStore.Endpoint().Endpoint(portainer.EndpointID(endpointID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -135,7 +135,7 @@ func (handler *Handler) isValidStackFile(stackFileContent []byte) (bool, error)
func (handler *Handler) decorateStackResponse(w http.ResponseWriter, stack *portainer.Stack, userID portainer.UserID) *httperror.HandlerError { func (handler *Handler) decorateStackResponse(w http.ResponseWriter, stack *portainer.Stack, userID portainer.UserID) *httperror.HandlerError {
resourceControl := portainer.NewPrivateResourceControl(stack.Name, portainer.StackResourceControl, userID) resourceControl := portainer.NewPrivateResourceControl(stack.Name, portainer.StackResourceControl, userID)
err := handler.ResourceControlService.CreateResourceControl(resourceControl) err := handler.DataStore.ResourceControl().CreateResourceControl(resourceControl)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist resource control inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist resource control inside the database", err}
} }

View File

@ -36,7 +36,7 @@ func (handler *Handler) stackDelete(w http.ResponseWriter, r *http.Request) *htt
return &httperror.HandlerError{http.StatusBadRequest, "Invalid stack identifier route variable", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid stack identifier route variable", err}
} }
stack, err := handler.StackService.Stack(portainer.StackID(id)) stack, err := handler.DataStore.Stack().Stack(portainer.StackID(id))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a stack with the specified identifier inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find a stack with the specified identifier inside the database", err}
} else if err != nil { } else if err != nil {
@ -56,7 +56,7 @@ func (handler *Handler) stackDelete(w http.ResponseWriter, r *http.Request) *htt
endpointIdentifier = portainer.EndpointID(endpointID) endpointIdentifier = portainer.EndpointID(endpointID)
} }
endpoint, err := handler.EndpointService.Endpoint(endpointIdentifier) endpoint, err := handler.DataStore.Endpoint().Endpoint(endpointIdentifier)
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find the endpoint associated to the stack inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find the endpoint associated to the stack inside the database", err}
} else if err != nil { } else if err != nil {
@ -68,7 +68,7 @@ func (handler *Handler) stackDelete(w http.ResponseWriter, r *http.Request) *htt
return &httperror.HandlerError{http.StatusForbidden, "Permission denied to access endpoint", err} return &httperror.HandlerError{http.StatusForbidden, "Permission denied to access endpoint", err}
} }
resourceControl, err := handler.ResourceControlService.ResourceControlByResourceIDAndType(stack.Name, portainer.StackResourceControl) resourceControl, err := handler.DataStore.ResourceControl().ResourceControlByResourceIDAndType(stack.Name, portainer.StackResourceControl)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve a resource control associated to the stack", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve a resource control associated to the stack", err}
} }
@ -86,13 +86,13 @@ func (handler *Handler) stackDelete(w http.ResponseWriter, r *http.Request) *htt
return &httperror.HandlerError{http.StatusInternalServerError, err.Error(), err} return &httperror.HandlerError{http.StatusInternalServerError, err.Error(), err}
} }
err = handler.StackService.DeleteStack(portainer.StackID(id)) err = handler.DataStore.Stack().DeleteStack(portainer.StackID(id))
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove the stack from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove the stack from the database", err}
} }
if resourceControl != nil { if resourceControl != nil {
err = handler.ResourceControlService.DeleteResourceControl(resourceControl.ID) err = handler.DataStore.ResourceControl().DeleteResourceControl(resourceControl.ID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove the associated resource control from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove the associated resource control from the database", err}
} }
@ -112,12 +112,12 @@ func (handler *Handler) deleteExternalStack(r *http.Request, w http.ResponseWrit
return &httperror.HandlerError{http.StatusBadRequest, "Invalid query parameter: endpointId", err} return &httperror.HandlerError{http.StatusBadRequest, "Invalid query parameter: endpointId", err}
} }
user, err := handler.UserService.User(securityContext.UserID) user, err := handler.DataStore.User().User(securityContext.UserID)
if err != nil { if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to load user information from the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to load user information from the database", err}
} }
rbacExtension, err := handler.ExtensionService.Extension(portainer.RBACExtension) rbacExtension, err := handler.DataStore.Extension().Extension(portainer.RBACExtension)
if err != nil && err != portainer.ErrObjectNotFound { if err != nil && err != portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to verify if RBAC extension is loaded", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to verify if RBAC extension is loaded", err}
} }
@ -138,7 +138,7 @@ func (handler *Handler) deleteExternalStack(r *http.Request, w http.ResponseWrit
} }
} }
stack, err := handler.StackService.StackByName(stackName) stack, err := handler.DataStore.Stack().StackByName(stackName)
if err != nil && err != portainer.ErrObjectNotFound { if err != nil && err != portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to check for stack existence inside the database", err} return &httperror.HandlerError{http.StatusInternalServerError, "Unable to check for stack existence inside the database", err}
} }
@ -146,7 +146,7 @@ func (handler *Handler) deleteExternalStack(r *http.Request, w http.ResponseWrit
return &httperror.HandlerError{http.StatusBadRequest, "A stack with this name exists inside the database. Cannot use external delete method", portainer.ErrStackNotExternal} return &httperror.HandlerError{http.StatusBadRequest, "A stack with this name exists inside the database. Cannot use external delete method", portainer.ErrStackNotExternal}
} }
endpoint, err := handler.EndpointService.Endpoint(portainer.EndpointID(endpointID)) endpoint, err := handler.DataStore.Endpoint().Endpoint(portainer.EndpointID(endpointID))
if err == portainer.ErrObjectNotFound { if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find the endpoint associated to the stack inside the database", err} return &httperror.HandlerError{http.StatusNotFound, "Unable to find the endpoint associated to the stack inside the database", err}
} else if err != nil { } else if err != nil {

Some files were not shown because too many files have changed in this diff Show More