2016-12-18 05:21:29 +00:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
2018-05-07 18:01:39 +00:00
|
|
|
"time"
|
|
|
|
|
2016-12-18 05:21:29 +00:00
|
|
|
"github.com/portainer/portainer"
|
2018-09-03 10:08:03 +00:00
|
|
|
"github.com/portainer/portainer/docker"
|
2017-05-23 18:56:10 +00:00
|
|
|
"github.com/portainer/portainer/http/handler"
|
2018-06-11 13:13:19 +00:00
|
|
|
"github.com/portainer/portainer/http/handler/auth"
|
|
|
|
"github.com/portainer/portainer/http/handler/dockerhub"
|
|
|
|
"github.com/portainer/portainer/http/handler/endpointgroups"
|
|
|
|
"github.com/portainer/portainer/http/handler/endpointproxy"
|
|
|
|
"github.com/portainer/portainer/http/handler/endpoints"
|
|
|
|
"github.com/portainer/portainer/http/handler/file"
|
2018-08-21 18:40:42 +00:00
|
|
|
"github.com/portainer/portainer/http/handler/motd"
|
2018-06-11 13:13:19 +00:00
|
|
|
"github.com/portainer/portainer/http/handler/registries"
|
|
|
|
"github.com/portainer/portainer/http/handler/resourcecontrols"
|
2018-11-05 20:58:15 +00:00
|
|
|
"github.com/portainer/portainer/http/handler/schedules"
|
2018-06-11 13:13:19 +00:00
|
|
|
"github.com/portainer/portainer/http/handler/settings"
|
|
|
|
"github.com/portainer/portainer/http/handler/stacks"
|
|
|
|
"github.com/portainer/portainer/http/handler/status"
|
2018-06-15 07:18:25 +00:00
|
|
|
"github.com/portainer/portainer/http/handler/tags"
|
2018-06-11 13:13:19 +00:00
|
|
|
"github.com/portainer/portainer/http/handler/teammemberships"
|
|
|
|
"github.com/portainer/portainer/http/handler/teams"
|
|
|
|
"github.com/portainer/portainer/http/handler/templates"
|
|
|
|
"github.com/portainer/portainer/http/handler/upload"
|
|
|
|
"github.com/portainer/portainer/http/handler/users"
|
2018-09-03 10:08:03 +00:00
|
|
|
"github.com/portainer/portainer/http/handler/webhooks"
|
2018-06-11 13:13:19 +00:00
|
|
|
"github.com/portainer/portainer/http/handler/websocket"
|
2017-05-23 18:56:10 +00:00
|
|
|
"github.com/portainer/portainer/http/proxy"
|
|
|
|
"github.com/portainer/portainer/http/security"
|
2016-12-18 05:21:29 +00:00
|
|
|
|
|
|
|
"net/http"
|
2017-10-26 09:17:45 +00:00
|
|
|
"path/filepath"
|
2016-12-18 05:21:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Server implements the portainer.Server interface
|
|
|
|
type Server struct {
|
2017-03-12 16:24:15 +00:00
|
|
|
BindAddress string
|
|
|
|
AssetsPath string
|
|
|
|
AuthDisabled bool
|
|
|
|
EndpointManagement bool
|
2017-06-01 08:14:55 +00:00
|
|
|
Status *portainer.Status
|
2018-06-15 07:18:25 +00:00
|
|
|
ComposeStackManager portainer.ComposeStackManager
|
|
|
|
CryptoService portainer.CryptoService
|
|
|
|
SignatureService portainer.DigitalSignatureService
|
2018-07-11 08:39:20 +00:00
|
|
|
JobScheduler portainer.JobScheduler
|
2018-07-23 07:51:33 +00:00
|
|
|
Snapshotter portainer.Snapshotter
|
2018-06-15 07:18:25 +00:00
|
|
|
DockerHubService portainer.DockerHubService
|
2017-03-12 16:24:15 +00:00
|
|
|
EndpointService portainer.EndpointService
|
2018-04-26 16:08:46 +00:00
|
|
|
EndpointGroupService portainer.EndpointGroupService
|
2017-03-12 16:24:15 +00:00
|
|
|
FileService portainer.FileService
|
2018-06-15 07:18:25 +00:00
|
|
|
GitService portainer.GitService
|
|
|
|
JWTService portainer.JWTService
|
|
|
|
LDAPService portainer.LDAPService
|
2017-06-20 11:00:32 +00:00
|
|
|
RegistryService portainer.RegistryService
|
2018-06-15 07:18:25 +00:00
|
|
|
ResourceControlService portainer.ResourceControlService
|
2018-11-05 20:58:15 +00:00
|
|
|
ScheduleService portainer.ScheduleService
|
2018-06-15 07:18:25 +00:00
|
|
|
SettingsService portainer.SettingsService
|
2017-10-15 17:24:40 +00:00
|
|
|
StackService portainer.StackService
|
2018-06-11 13:13:19 +00:00
|
|
|
SwarmStackManager portainer.SwarmStackManager
|
2018-06-15 07:18:25 +00:00
|
|
|
TagService portainer.TagService
|
|
|
|
TeamService portainer.TeamService
|
|
|
|
TeamMembershipService portainer.TeamMembershipService
|
2018-07-03 18:31:02 +00:00
|
|
|
TemplateService portainer.TemplateService
|
2018-06-15 07:18:25 +00:00
|
|
|
UserService portainer.UserService
|
2018-09-03 10:08:03 +00:00
|
|
|
WebhookService portainer.WebhookService
|
2017-05-23 18:56:10 +00:00
|
|
|
Handler *handler.Handler
|
2017-04-25 09:51:22 +00:00
|
|
|
SSL bool
|
|
|
|
SSLCert string
|
|
|
|
SSLKey string
|
2018-09-03 10:08:03 +00:00
|
|
|
DockerClientFactory *docker.ClientFactory
|
2018-10-22 21:03:30 +00:00
|
|
|
JobService portainer.JobService
|
2016-12-18 05:21:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start starts the HTTP server
|
|
|
|
func (server *Server) Start() error {
|
2018-06-18 09:56:31 +00:00
|
|
|
requestBouncerParameters := &security.RequestBouncerParams{
|
|
|
|
JWTService: server.JWTService,
|
|
|
|
UserService: server.UserService,
|
|
|
|
TeamMembershipService: server.TeamMembershipService,
|
|
|
|
EndpointGroupService: server.EndpointGroupService,
|
|
|
|
AuthDisabled: server.AuthDisabled,
|
|
|
|
}
|
|
|
|
requestBouncer := security.NewRequestBouncer(requestBouncerParameters)
|
2018-11-05 20:58:15 +00:00
|
|
|
|
2018-05-06 07:15:57 +00:00
|
|
|
proxyManagerParameters := &proxy.ManagerParams{
|
|
|
|
ResourceControlService: server.ResourceControlService,
|
|
|
|
TeamMembershipService: server.TeamMembershipService,
|
|
|
|
SettingsService: server.SettingsService,
|
|
|
|
RegistryService: server.RegistryService,
|
|
|
|
DockerHubService: server.DockerHubService,
|
|
|
|
SignatureService: server.SignatureService,
|
|
|
|
}
|
|
|
|
proxyManager := proxy.NewManager(proxyManagerParameters)
|
2018-11-05 20:58:15 +00:00
|
|
|
|
2018-05-07 18:01:39 +00:00
|
|
|
rateLimiter := security.NewRateLimiter(10, 1*time.Second, 1*time.Hour)
|
2016-12-25 20:34:02 +00:00
|
|
|
|
2018-06-11 13:13:19 +00:00
|
|
|
var authHandler = auth.NewHandler(requestBouncer, rateLimiter, server.AuthDisabled)
|
2016-12-18 05:21:29 +00:00
|
|
|
authHandler.UserService = server.UserService
|
|
|
|
authHandler.CryptoService = server.CryptoService
|
|
|
|
authHandler.JWTService = server.JWTService
|
2017-08-10 08:35:23 +00:00
|
|
|
authHandler.LDAPService = server.LDAPService
|
|
|
|
authHandler.SettingsService = server.SettingsService
|
2018-07-23 04:57:38 +00:00
|
|
|
authHandler.TeamService = server.TeamService
|
|
|
|
authHandler.TeamMembershipService = server.TeamMembershipService
|
2018-06-11 13:13:19 +00:00
|
|
|
|
|
|
|
var dockerHubHandler = dockerhub.NewHandler(requestBouncer)
|
|
|
|
dockerHubHandler.DockerHubService = server.DockerHubService
|
|
|
|
|
|
|
|
var endpointHandler = endpoints.NewHandler(requestBouncer, server.EndpointManagement)
|
2016-12-25 20:34:02 +00:00
|
|
|
endpointHandler.EndpointService = server.EndpointService
|
2018-04-26 16:08:46 +00:00
|
|
|
endpointHandler.EndpointGroupService = server.EndpointGroupService
|
2016-12-25 20:34:02 +00:00
|
|
|
endpointHandler.FileService = server.FileService
|
2017-05-23 18:56:10 +00:00
|
|
|
endpointHandler.ProxyManager = proxyManager
|
2018-07-23 07:51:33 +00:00
|
|
|
endpointHandler.Snapshotter = server.Snapshotter
|
2018-10-22 21:03:30 +00:00
|
|
|
endpointHandler.JobService = server.JobService
|
2018-06-11 13:13:19 +00:00
|
|
|
|
|
|
|
var endpointGroupHandler = endpointgroups.NewHandler(requestBouncer)
|
2018-04-26 16:08:46 +00:00
|
|
|
endpointGroupHandler.EndpointGroupService = server.EndpointGroupService
|
|
|
|
endpointGroupHandler.EndpointService = server.EndpointService
|
2018-06-11 13:13:19 +00:00
|
|
|
|
|
|
|
var endpointProxyHandler = endpointproxy.NewHandler(requestBouncer)
|
|
|
|
endpointProxyHandler.EndpointService = server.EndpointService
|
|
|
|
endpointProxyHandler.ProxyManager = proxyManager
|
|
|
|
|
|
|
|
var fileHandler = file.NewHandler(filepath.Join(server.AssetsPath, "public"))
|
|
|
|
|
2018-08-21 18:40:42 +00:00
|
|
|
var motdHandler = motd.NewHandler(requestBouncer)
|
|
|
|
|
2018-06-11 13:13:19 +00:00
|
|
|
var registryHandler = registries.NewHandler(requestBouncer)
|
2017-06-20 11:00:32 +00:00
|
|
|
registryHandler.RegistryService = server.RegistryService
|
2018-06-11 13:13:19 +00:00
|
|
|
|
|
|
|
var resourceControlHandler = resourcecontrols.NewHandler(requestBouncer)
|
|
|
|
resourceControlHandler.ResourceControlService = server.ResourceControlService
|
|
|
|
|
2018-11-05 20:58:15 +00:00
|
|
|
var schedulesHandler = schedules.NewHandler(requestBouncer)
|
|
|
|
schedulesHandler.ScheduleService = server.ScheduleService
|
|
|
|
schedulesHandler.EndpointService = server.EndpointService
|
|
|
|
schedulesHandler.FileService = server.FileService
|
|
|
|
schedulesHandler.JobService = server.JobService
|
|
|
|
schedulesHandler.JobScheduler = server.JobScheduler
|
2018-12-05 22:36:25 +00:00
|
|
|
schedulesHandler.SettingsService = server.SettingsService
|
2018-11-05 20:58:15 +00:00
|
|
|
|
2018-06-11 13:13:19 +00:00
|
|
|
var settingsHandler = settings.NewHandler(requestBouncer)
|
|
|
|
settingsHandler.SettingsService = server.SettingsService
|
|
|
|
settingsHandler.LDAPService = server.LDAPService
|
|
|
|
settingsHandler.FileService = server.FileService
|
2018-07-11 08:39:20 +00:00
|
|
|
settingsHandler.JobScheduler = server.JobScheduler
|
2018-11-06 09:49:48 +00:00
|
|
|
settingsHandler.ScheduleService = server.ScheduleService
|
2018-06-11 13:13:19 +00:00
|
|
|
|
|
|
|
var stackHandler = stacks.NewHandler(requestBouncer)
|
2017-10-15 17:24:40 +00:00
|
|
|
stackHandler.FileService = server.FileService
|
|
|
|
stackHandler.StackService = server.StackService
|
|
|
|
stackHandler.EndpointService = server.EndpointService
|
|
|
|
stackHandler.ResourceControlService = server.ResourceControlService
|
2018-06-11 13:13:19 +00:00
|
|
|
stackHandler.SwarmStackManager = server.SwarmStackManager
|
|
|
|
stackHandler.ComposeStackManager = server.ComposeStackManager
|
2017-10-15 17:24:40 +00:00
|
|
|
stackHandler.GitService = server.GitService
|
2017-10-26 12:22:09 +00:00
|
|
|
stackHandler.RegistryService = server.RegistryService
|
|
|
|
stackHandler.DockerHubService = server.DockerHubService
|
2018-06-11 13:13:19 +00:00
|
|
|
|
2018-06-15 07:18:25 +00:00
|
|
|
var tagHandler = tags.NewHandler(requestBouncer)
|
|
|
|
tagHandler.TagService = server.TagService
|
|
|
|
|
2018-06-11 13:13:19 +00:00
|
|
|
var teamHandler = teams.NewHandler(requestBouncer)
|
|
|
|
teamHandler.TeamService = server.TeamService
|
|
|
|
teamHandler.TeamMembershipService = server.TeamMembershipService
|
|
|
|
|
|
|
|
var teamMembershipHandler = teammemberships.NewHandler(requestBouncer)
|
|
|
|
teamMembershipHandler.TeamMembershipService = server.TeamMembershipService
|
|
|
|
var statusHandler = status.NewHandler(requestBouncer, server.Status)
|
|
|
|
|
|
|
|
var templatesHandler = templates.NewHandler(requestBouncer)
|
2018-07-03 18:31:02 +00:00
|
|
|
templatesHandler.TemplateService = server.TemplateService
|
2018-08-07 15:43:36 +00:00
|
|
|
templatesHandler.SettingsService = server.SettingsService
|
2018-06-11 13:13:19 +00:00
|
|
|
|
|
|
|
var uploadHandler = upload.NewHandler(requestBouncer)
|
|
|
|
uploadHandler.FileService = server.FileService
|
|
|
|
|
2018-09-05 06:49:43 +00:00
|
|
|
var userHandler = users.NewHandler(requestBouncer, rateLimiter)
|
2018-06-11 13:13:19 +00:00
|
|
|
userHandler.UserService = server.UserService
|
|
|
|
userHandler.TeamService = server.TeamService
|
|
|
|
userHandler.TeamMembershipService = server.TeamMembershipService
|
|
|
|
userHandler.CryptoService = server.CryptoService
|
|
|
|
userHandler.ResourceControlService = server.ResourceControlService
|
|
|
|
userHandler.SettingsService = server.SettingsService
|
|
|
|
|
2018-06-18 09:56:31 +00:00
|
|
|
var websocketHandler = websocket.NewHandler(requestBouncer)
|
2018-06-11 13:13:19 +00:00
|
|
|
websocketHandler.EndpointService = server.EndpointService
|
|
|
|
websocketHandler.SignatureService = server.SignatureService
|
2016-12-18 05:21:29 +00:00
|
|
|
|
2018-09-03 10:08:03 +00:00
|
|
|
var webhookHandler = webhooks.NewHandler(requestBouncer)
|
|
|
|
webhookHandler.WebhookService = server.WebhookService
|
|
|
|
webhookHandler.EndpointService = server.EndpointService
|
|
|
|
webhookHandler.DockerClientFactory = server.DockerClientFactory
|
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
server.Handler = &handler.Handler{
|
2018-06-11 13:13:19 +00:00
|
|
|
AuthHandler: authHandler,
|
|
|
|
DockerHubHandler: dockerHubHandler,
|
|
|
|
EndpointGroupHandler: endpointGroupHandler,
|
|
|
|
EndpointHandler: endpointHandler,
|
|
|
|
EndpointProxyHandler: endpointProxyHandler,
|
|
|
|
FileHandler: fileHandler,
|
2018-08-21 18:40:42 +00:00
|
|
|
MOTDHandler: motdHandler,
|
2018-06-11 13:13:19 +00:00
|
|
|
RegistryHandler: registryHandler,
|
|
|
|
ResourceControlHandler: resourceControlHandler,
|
|
|
|
SettingsHandler: settingsHandler,
|
|
|
|
StatusHandler: statusHandler,
|
|
|
|
StackHandler: stackHandler,
|
2018-06-15 07:18:25 +00:00
|
|
|
TagHandler: tagHandler,
|
2018-06-11 13:13:19 +00:00
|
|
|
TeamHandler: teamHandler,
|
|
|
|
TeamMembershipHandler: teamMembershipHandler,
|
|
|
|
TemplatesHandler: templatesHandler,
|
|
|
|
UploadHandler: uploadHandler,
|
|
|
|
UserHandler: userHandler,
|
|
|
|
WebSocketHandler: websocketHandler,
|
2018-09-03 10:08:03 +00:00
|
|
|
WebhookHandler: webhookHandler,
|
2018-11-05 20:58:15 +00:00
|
|
|
SchedulesHanlder: schedulesHandler,
|
2016-12-25 20:34:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 09:51:22 +00:00
|
|
|
if server.SSL {
|
|
|
|
return http.ListenAndServeTLS(server.BindAddress, server.SSLCert, server.SSLKey, server.Handler)
|
|
|
|
}
|
2016-12-25 20:34:02 +00:00
|
|
|
return http.ListenAndServe(server.BindAddress, server.Handler)
|
2016-12-18 05:21:29 +00:00
|
|
|
}
|