2016-12-18 05:21:29 +00:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/portainer/portainer"
|
2017-05-23 18:56:10 +00:00
|
|
|
"github.com/portainer/portainer/http/handler"
|
|
|
|
"github.com/portainer/portainer/http/proxy"
|
|
|
|
"github.com/portainer/portainer/http/security"
|
2016-12-18 05:21:29 +00:00
|
|
|
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
2017-03-12 16:24:15 +00:00
|
|
|
UserService portainer.UserService
|
2017-05-23 18:56:10 +00:00
|
|
|
TeamService portainer.TeamService
|
|
|
|
TeamMembershipService portainer.TeamMembershipService
|
2017-03-12 16:24:15 +00:00
|
|
|
EndpointService portainer.EndpointService
|
|
|
|
ResourceControlService portainer.ResourceControlService
|
2017-06-01 08:14:55 +00:00
|
|
|
SettingsService portainer.SettingsService
|
2017-03-12 16:24:15 +00:00
|
|
|
CryptoService portainer.CryptoService
|
|
|
|
JWTService portainer.JWTService
|
|
|
|
FileService portainer.FileService
|
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
|
2016-12-18 05:21:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start starts the HTTP server
|
|
|
|
func (server *Server) Start() error {
|
2017-05-23 18:56:10 +00:00
|
|
|
requestBouncer := security.NewRequestBouncer(server.JWTService, server.TeamMembershipService, server.AuthDisabled)
|
2017-06-01 08:14:55 +00:00
|
|
|
proxyManager := proxy.NewManager(server.ResourceControlService, server.TeamMembershipService, server.SettingsService)
|
2016-12-25 20:34:02 +00:00
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
var authHandler = handler.NewAuthHandler(requestBouncer, server.AuthDisabled)
|
2016-12-18 05:21:29 +00:00
|
|
|
authHandler.UserService = server.UserService
|
|
|
|
authHandler.CryptoService = server.CryptoService
|
|
|
|
authHandler.JWTService = server.JWTService
|
2017-05-23 18:56:10 +00:00
|
|
|
var userHandler = handler.NewUserHandler(requestBouncer)
|
2016-12-18 05:21:29 +00:00
|
|
|
userHandler.UserService = server.UserService
|
2017-05-23 18:56:10 +00:00
|
|
|
userHandler.TeamService = server.TeamService
|
|
|
|
userHandler.TeamMembershipService = server.TeamMembershipService
|
2016-12-18 05:21:29 +00:00
|
|
|
userHandler.CryptoService = server.CryptoService
|
2017-03-12 16:24:15 +00:00
|
|
|
userHandler.ResourceControlService = server.ResourceControlService
|
2017-05-23 18:56:10 +00:00
|
|
|
var teamHandler = handler.NewTeamHandler(requestBouncer)
|
|
|
|
teamHandler.TeamService = server.TeamService
|
|
|
|
teamHandler.TeamMembershipService = server.TeamMembershipService
|
|
|
|
var teamMembershipHandler = handler.NewTeamMembershipHandler(requestBouncer)
|
|
|
|
teamMembershipHandler.TeamMembershipService = server.TeamMembershipService
|
2017-06-01 08:14:55 +00:00
|
|
|
var statusHandler = handler.NewStatusHandler(requestBouncer, server.Status)
|
|
|
|
var settingsHandler = handler.NewSettingsHandler(requestBouncer)
|
|
|
|
settingsHandler.SettingsService = server.SettingsService
|
|
|
|
var templatesHandler = handler.NewTemplatesHandler(requestBouncer)
|
|
|
|
templatesHandler.SettingsService = server.SettingsService
|
2017-05-23 18:56:10 +00:00
|
|
|
var dockerHandler = handler.NewDockerHandler(requestBouncer)
|
2017-03-12 16:24:15 +00:00
|
|
|
dockerHandler.EndpointService = server.EndpointService
|
2017-05-23 18:56:10 +00:00
|
|
|
dockerHandler.TeamMembershipService = server.TeamMembershipService
|
|
|
|
dockerHandler.ProxyManager = proxyManager
|
|
|
|
var websocketHandler = handler.NewWebSocketHandler()
|
2017-03-12 16:24:15 +00:00
|
|
|
websocketHandler.EndpointService = server.EndpointService
|
2017-05-23 18:56:10 +00:00
|
|
|
var endpointHandler = handler.NewEndpointHandler(requestBouncer, server.EndpointManagement)
|
2016-12-25 20:34:02 +00:00
|
|
|
endpointHandler.EndpointService = server.EndpointService
|
|
|
|
endpointHandler.FileService = server.FileService
|
2017-05-23 18:56:10 +00:00
|
|
|
endpointHandler.ProxyManager = proxyManager
|
|
|
|
var resourceHandler = handler.NewResourceHandler(requestBouncer)
|
|
|
|
resourceHandler.ResourceControlService = server.ResourceControlService
|
|
|
|
var uploadHandler = handler.NewUploadHandler(requestBouncer)
|
2016-12-25 20:34:02 +00:00
|
|
|
uploadHandler.FileService = server.FileService
|
2017-05-23 18:56:10 +00:00
|
|
|
var fileHandler = handler.NewFileHandler(server.AssetsPath)
|
2016-12-18 05:21:29 +00:00
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
server.Handler = &handler.Handler{
|
|
|
|
AuthHandler: authHandler,
|
|
|
|
UserHandler: userHandler,
|
|
|
|
TeamHandler: teamHandler,
|
|
|
|
TeamMembershipHandler: teamMembershipHandler,
|
|
|
|
EndpointHandler: endpointHandler,
|
|
|
|
ResourceHandler: resourceHandler,
|
|
|
|
SettingsHandler: settingsHandler,
|
2017-06-01 08:14:55 +00:00
|
|
|
StatusHandler: statusHandler,
|
2017-05-23 18:56:10 +00:00
|
|
|
TemplatesHandler: templatesHandler,
|
|
|
|
DockerHandler: dockerHandler,
|
|
|
|
WebSocketHandler: websocketHandler,
|
|
|
|
FileHandler: fileHandler,
|
|
|
|
UploadHandler: uploadHandler,
|
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
|
|
|
}
|