Пример #1
0
func main() {
	err := migration.Migrate()
	if err != nil {
		log.Error(err)
		return
	}
	p := echo.New()
	go p.Run(":8181")

	err = initVms()
	if err != nil {
		log.Error(err)
		return
	}

	e := echo.New()
	e.SetLogLevel(logger.DEBUG)
	e.Use(middleware.Logger())
	e.Use(middleware.Recover())

	e.SetHTTPErrorHandler(apiErrors.Handler)

	/**
	 * APPS
	 */
	e.Get("/api/applications", m.OAuth2(apps.ListApplications))
	e.Delete("/api/applications/:app_id", m.OAuth2(m.Admin(apps.UnpublishApplication)))
	e.Post("/api/applications", m.OAuth2(m.Admin(apps.PublishApplication)))
	e.Get("/api/applications/connections", m.OAuth2(apps.GetConnections))
	e.Patch("/api/applications/:app_id", m.OAuth2(m.Admin(apps.ChangeAppName)))

	/**
	 * SESSIONS
	 */

	e.Get("/api/sessions", m.OAuth2(sessions.List))
	e.Delete("/api/sessions", m.OAuth2(sessions.Logoff))

	/**
	 * HISTORY
	 */
	e.Get("/api/histories", m.OAuth2(histories.List))
	e.Post("/api/histories", m.OAuth2(histories.Add))
	//m.OAuth2(

	/**
	 * USERS
	 */
	e.Patch("/api/users/:id", m.OAuth2(m.Admin(users.Update)))
	e.Get("/api/users", m.OAuth2(users.Get))
	e.Post("/api/users", m.OAuth2(m.Admin(users.Post)))
	e.Delete("/api/users/:id", m.OAuth2(m.Admin(users.Delete)))
	e.Put("/api/users/:id", m.OAuth2(m.Admin(users.UpdatePassword)))
	e.Get("/api/users/:id", m.OAuth2(users.GetUser))

	/**
	 * MACHINES
	 */
	e.Get("/api/machines", m.OAuth2(m.Admin(machines.Machines)))
	e.Get("/api/machines/:id", m.OAuth2(m.Admin(machines.GetMachine)))
	e.Patch("/api/machines/:id", m.OAuth2(m.Admin(machines.PatchMachine)))
	e.Post("/api/machines", m.OAuth2(m.Admin(machines.CreateMachine)))
	e.Delete("/api/machines/:id", m.OAuth2(m.Admin(machines.DeleteMachine)))

	/**
	 * MACHINES DRIVERS
	 */
	e.Get("/api/machine-drivers", m.OAuth2(m.Admin(machinedrivers.FindAll)))

	/**
	 * Files
	 */
	e.Get("/api/files", files.Get)
	e.Get("/api/files/token", m.OAuth2(files.GetDownloadToken))

	/**
	 * FRONT
	 */
	e.Static("/", front.StaticDirectory)

	/**
	 * OAUTH
	 */
	e.Any("/oauth/*", oauth.Handler)

	/**
	 * TOKENS
	 */
	e.Get("/api/tokens", m.OAuth2(tokens.Get))
	e.Delete("/api/tokens/:id", m.OAuth2(tokens.Delete))

	/**
	 * UPLOAD
	 */
	e.Post("/upload", upload.Post)
	e.Get("/upload", upload.Get)

	addr := ":" + utils.Env("BACKEND_PORT", "8080")
	log.Info("Server running at ", addr)
	e.Run(addr)
}
Пример #2
0
func main() {
	err := migration.Migrate()
	if err != nil {
		log.Error(err)
		return
	}

	err = initVms()
	if err != nil {
		log.Error(err)
		return
	}

	e := echo.New()
	e.SetLogLevel(logger.DEBUG)
	e.Use(middleware.Logger())
	e.Use(middleware.Recover())

	/**
	 * LOGOUT
	 */
	e.Post("/api/logout", m.OAuth2(logout.Post))

	/**
	 * APPS
	 */
	e.Get("/api/apps", m.OAuth2(m.Admin(apps.ListApplications)))
	e.Delete("/api/apps/:app_id", m.OAuth2(m.Admin(apps.UnpublishApplication)))
	e.Get("/api/apps/me", m.OAuth2(apps.ListUserApps))
	e.Post("/api/apps", m.OAuth2(m.Admin(apps.PublishApplication)))
	e.Get("/api/apps/connections", m.OAuth2(apps.GetConnections))
	e.Patch("/api/apps/:app_id", m.OAuth2(m.Admin(apps.ChangeAppName)))

	go appsModel.CheckPublishedApps()

	/**
	 * HISTORY
	 */
	e.Get("/api/history", m.OAuth2(history.List))
	e.Post("/api/history", m.OAuth2(history.Add))

	/**
	 * USERS
	 */
	e.Patch("/api/users/:id", m.OAuth2(m.Admin(users.Update)))
	e.Get("/api/users", m.OAuth2(m.Admin(users.Get)))
	e.Post("/api/users", m.OAuth2(m.Admin(users.Post)))
	e.Delete("/api/users/:id", m.OAuth2(m.Admin(users.Delete)))
	e.Put("/api/users/:id", m.OAuth2(m.Admin(users.UpdatePassword)))
	e.Get("/api/users/:id", m.OAuth2(m.Admin(users.GetUser)))

	/**
	 * IAAS
	 */
	e.Get("/api/iaas", m.OAuth2(m.Admin(iaas.ListRunningVM)))
	e.Post("/api/iaas/:id/stop", m.OAuth2(m.Admin(iaas.StopVM)))
	e.Post("/api/iaas/:id/start", m.OAuth2(m.Admin(iaas.StartVM)))
	e.Post("/api/iaas/:id/download", m.OAuth2(m.Admin(iaas.CreateVM)))

	/**
	 * FRONT
	 */
	e.Static("/canva/", front.StaticCanvaDirectory)
	e.Static("/", front.StaticDirectory)

	/**
	 * ME
	 */
	e.Get("/api/me", m.OAuth2(me.Get))

	/**
	 * VERSION
	 */
	e.Get("/api/version", version.Get)

	/**
	 * OAUTH
	 */
	e.Any("/oauth/*", oauth.Handler)

	/**
	 * TOKENS
	 */
	e.Get("/api/tokens", m.OAuth2(tokens.Get))
	e.Delete("/api/tokens/:id", m.OAuth2(tokens.Delete))

	/**
	 * UPLOAD
	 */
	e.Post("/upload", upload.Post)
	e.Get("/upload", upload.Get)

	addr := ":" + utils.Env("PORT", "8080")
	log.Info("Server running at ", addr)
	e.Run(addr)
}