Example #1
0
func SetupRoutes(r *mux.Router) {
	adminRouter := r.PathPrefix("/admin").Subrouter()
	adminRouter.Handle("/users", authAdminUser(admin.UserIndexController)).Methods("GET")
	adminRouter.Handle("/users/{id:[0-9]+}/edit", authAdminUser(admin.UserEditController)).Methods("GET")
	adminRouter.Handle("/users/{id:[0-9]+}/edit", authAdminUser(admin.UserUpdateController)).Methods("POST")
	adminRouter.Handle("/users/{id:[0-9]+}/delete", authAdminUser(admin.UserDeleteController)).Methods("POST")

	apiRouter := r.PathPrefix("/api").Subrouter()
	apiRouter.Handle("/jobs", authUser(job.IndexController)).Methods("GET")
	apiRouter.Handle("/jobs/{id:[0-9]+}", authUser(job.ShowController)).Methods("GET")
	apiRouter.Handle("/jobs", authUser(job.CreateController)).Methods("POST")
	apiRouter.Handle("/jobs/{id:[0-9]+}", authUser(job.UpdateController)).Methods("PUT")
	apiRouter.Handle("/jobs/{id:[0-9]+}", authUser(job.DeleteController)).Methods("DELETE")
	apiRouter.Handle("/plans/{id:[0-9]+}", authUser(plan.ShowController)).Methods("GET")
	apiRouter.Handle("/plans", authUser(plan.CreateController)).Methods("POST")
	apiRouter.Handle("/plans/{id:[0-9]+}", authUser(plan.UpdateController)).Methods("PUT")
	apiRouter.Handle("/plans/{id:[0-9]+}", authUser(plan.DeleteController)).Methods("DELETE")

	r.Handle("/app", authUser(app.AppController)).Methods("GET")

	r.Handle("/user", redirectUser(user.CreateController)).Methods("POST")
	r.Handle("/user/edit", authUser(user.EditController)).Methods("GET")
	r.Handle("/user/edit", authUser(user.UpdateController)).Methods("POST")
	r.Handle("/user/sign_in", redirectUser(user.LoginController)).Methods("POST")
	// Ideally we want this to be a DELETE method but it is a bitch to send a DELETE
	// request client side.  POST will do for now.
	r.Handle("/user/sign_out", authUser(user.LogoutController)).Methods("POST")

	r.HandleFunc("/mobile", mobile.MobileController).Methods("GET")
	r.Handle("/", redirectUser(marketing.HomeController)).Methods("GET")
}
Example #2
0
func restAPI(r *mux.Router) {
	sr := r.PathPrefix("/_api/").MatcherFunc(adminRequired).Subrouter()
	sr.HandleFunc("/buckets",
		restGetBuckets).Methods("GET")
	sr.HandleFunc("/buckets",
		restPostBucket).Methods("POST")
	sr.HandleFunc("/buckets/{bucketname}",
		restGetBucket).Methods("GET")
	sr.HandleFunc("/buckets/{bucketname}",
		restDeleteBucket).Methods("DELETE")
	sr.HandleFunc("/buckets/{bucketname}/compact",
		restPostBucketCompact).Methods("POST")
	sr.HandleFunc("/buckets/{bucketname}/flushDirty",
		restPostBucketFlushDirty).Methods("POST")
	sr.HandleFunc("/buckets/{bucketname}/stats",
		restGetBucketStats).Methods("GET")
	sr.HandleFunc("/bucketsRescan",
		restPostBucketsRescan).Methods("POST")
	sr.HandleFunc("/profile/cpu",
		restProfileCPU).Methods("POST")
	sr.HandleFunc("/profile/memory",
		restProfileMemory).Methods("POST")
	sr.HandleFunc("/runtime",
		restGetRuntime).Methods("GET")
	sr.HandleFunc("/runtime/memStats",
		restGetRuntimeMemStats).Methods("GET")
	sr.HandleFunc("/runtime/gc",
		restPostRuntimeGC).Methods("POST")
	sr.HandleFunc("/settings",
		restGetSettings).Methods("GET")

	r.PathPrefix("/_api/").HandlerFunc(authError)
}
Example #3
0
func InitAdmin(r *mux.Router) {
	l4g.Debug("Initializing admin api routes")

	sr := r.PathPrefix("/admin").Subrouter()
	sr.Handle("/logs", ApiUserRequired(getLogs)).Methods("GET")
	sr.Handle("/client_props", ApiAppHandler(getClientProperties)).Methods("GET")
}
Example #4
0
func (this V1HttpApi) addRoutesToRouter(router *mux.Router) {
	v1 := router.PathPrefix("/v1/").Subrouter()
	v1.HandleFunc("/log/{__level}/{__category}/{__slug}/", this.PostLogHandler).Methods("POST")
	v1.HandleFunc("/log/bulk/", this.PostBulkLogHandler).Methods("POST")
	v1.HandleFunc("/ping", this.PingHandler)
	v1.HandleFunc("/ping/", this.PingHandler)
}
Example #5
0
func InitLicense(r *mux.Router) {
	l4g.Debug("Initializing license api routes")

	sr := r.PathPrefix("/license").Subrouter()
	sr.Handle("/add", ApiAdminSystemRequired(addLicense)).Methods("POST")
	sr.Handle("/remove", ApiAdminSystemRequired(removeLicense)).Methods("POST")
}
Example #6
0
//AddRoutesWithMiddleware will add annotate routes to the given router, using the specified prefix. It accepts two middleware functions that will be applied to each route,
//depending on whether they are a "read" operation, or a "write" operation
func AddRoutesWithMiddleware(router *mux.Router, prefix string, b []backend.Backend, enableUI, useLocalAssets bool, readMiddleware, modifyMiddleware func(http.HandlerFunc) http.Handler) error {
	if readMiddleware == nil {
		readMiddleware = noopMiddleware
	}
	if modifyMiddleware == nil {
		modifyMiddleware = noopMiddleware
	}
	backends = b
	router.Handle(prefix+"/annotation", modifyMiddleware(InsertAnnotation)).Methods("POST", "PUT")
	router.Handle(prefix+"/annotation/query", readMiddleware(GetAnnotations)).Methods("GET")
	router.Handle(prefix+"/annotation/{id}", readMiddleware(GetAnnotation)).Methods("GET")
	router.Handle(prefix+"/annotation/{id}", modifyMiddleware(InsertAnnotation)).Methods("PUT")
	router.Handle(prefix+"/annotation/{id}", modifyMiddleware(DeleteAnnotation)).Methods("DELETE")
	router.Handle(prefix+"/annotation/values/{field}", readMiddleware(GetFieldValues)).Methods("GET")
	if !enableUI {
		return nil
	}
	webFS := FS(useLocalAssets)
	index, err := webFS.Open("/static/index.html")
	if err != nil {
		return fmt.Errorf("Error opening static file: %v", err)
	}
	indexHTML, err = ioutil.ReadAll(index)
	if err != nil {
		return err
	}
	router.PathPrefix("/static/").Handler(http.FileServer(webFS))
	router.PathPrefix("/").Handler(readMiddleware(Index)).Methods("GET")
	return nil
}
Example #7
0
func setupApiRoutes(r *mux.Router) {
	// api
	a := r.PathPrefix(data.ApiUrlSuffix).Subrouter()

	// user
	a.HandleFunc("/{user}", userHandler)
	u := a.PathPrefix("/{user}").Subrouter()
	u.StrictSlash(true)

	u.HandleFunc("/", userHandler).Methods("GET")
	u.HandleFunc("/user/add", userAddHandler).Methods("POST")
	u.HandleFunc("/user/info", userInfoHandler).Methods("GET", "POST")
	u.HandleFunc("/user/pass", userPassHandler).Methods("POST")
	u.HandleFunc("/user/auth", userAuthHandler).Methods("POST")
	u.HandleFunc("/user/awscred", userAwsCredHandler).Methods("GET")

	// user/dataset
	u.HandleFunc("/{dataset}", dsHomeHandler)
	d := u.PathPrefix("/{dataset}").Subrouter()
	d.StrictSlash(true)

	dget := d.Methods("GET").Subrouter()
	// dpost := d.Methods("POST").Subrouter()

	dget.HandleFunc("/", dsHomeHandler)
	dget.HandleFunc("/Datafile", dsDatafileHandler)
	dget.HandleFunc("/refs", dsRefsHandler)
	d.HandleFunc("/refs/{ref}", dsRefHandler).Methods("GET", "POST")
	// dget.HandleFunc("/tree/{ref}/", dsTreeHandler)
	dget.HandleFunc("/blob/{ref}/", dsBlobHandler)
	dget.HandleFunc("/archive/", dsArchivesHandler)
	dget.HandleFunc("/archives/", dsArchivesHandler)
	dget.HandleFunc("/archive/{ref}.tar.gz", dsDownloadArchiveHandler)
	// dget.HandleFunc("/archive/{ref}.zip", dsArchiveHandler)
}
Example #8
0
func setupWebsiteRoutes(r *mux.Router) {
	// serve static files
	r.HandleFunc("/static/config.js", webConfigHandler)
	r.PathPrefix("/static").Handler(http.FileServer(http.Dir("web/build/")))

	r.HandleFunc("/version", versionHandler).Methods("GET")

	// docs
	for _, p := range webDocPages {
		r.HandleFunc(p.route, webDocHandler)
	}

	// lists
	r.HandleFunc("/list/{kind}/by-{order}", webListHandler)

	// user
	r.HandleFunc("/{user}", webUserHandler)
	u := r.PathPrefix("/{user}").Subrouter()
	u.StrictSlash(true)

	u.HandleFunc("/", webUserHandler).Methods("GET")
	// u.HandleFunc("/user/add", webUserAddHandler).Methods("POST")
	// u.HandleFunc("/user/info", webUserInfoHandler).Methods("GET", "POST")
	// u.HandleFunc("/user/pass", webUserPassHandler).Methods("POST")

	// user/dataset
	u.HandleFunc("/{dataset}", webDsHomeHandler)
	// d := u.PathPrefix("/{dataset}@{ref}").Subrouter()
	// d.StrictSlash(true)

	// d.HandleFunc("/", webDsHomeHandler)
	// d.HandleFunc("/blob/", webDsBlobHandler)
}
Example #9
0
// AttachRESTHandler attaches a router at the given root that hooks up REST endpoint URIs to be
// handled by the given restAPIService.
func AttachRESTHandler(root *mux.Router, service restAPIService) http.Handler {
	rtr := root.PathPrefix("/rest/v1/").Subrouter().StrictSlash(true)

	// REST routes
	rest := restAPI{service}

	//restRouter := root.PathPrefix("/rest/v1/").Subrouter().StrictSlash(true)
	rtr.HandleFunc("/projects", rest.loadCtx(rest.getProjectIds)).Name("project_list").Methods("GET")
	rtr.HandleFunc("/projects/{project_id}", rest.loadCtx(rest.getProject)).Name("project_info").Methods("GET")
	rtr.HandleFunc("/projects/{project_id}/versions", rest.loadCtx(rest.getRecentVersions)).Name("recent_versions").Methods("GET")
	rtr.HandleFunc("/projects/{project_id}/revisions/{revision}", rest.loadCtx(rest.getVersionInfoViaRevision)).Name("version_info_via_revision").Methods("GET")
	rtr.HandleFunc("/projects/{project_id}/last_green", rest.loadCtx(rest.lastGreen)).Name("last_green_version").Methods("GET")
	rtr.HandleFunc("/patches/{patch_id}", rest.loadCtx(rest.getPatch)).Name("patch_info").Methods("GET")
	rtr.HandleFunc("/versions/{version_id}", rest.loadCtx(rest.getVersionInfo)).Name("version_info").Methods("GET")
	rtr.HandleFunc("/versions/{version_id}", requireUser(rest.loadCtx(rest.modifyVersionInfo), nil)).Name("").Methods("PATCH")
	rtr.HandleFunc("/versions/{version_id}/status", rest.loadCtx(rest.getVersionStatus)).Name("version_status").Methods("GET")
	rtr.HandleFunc("/versions/{version_id}/config", rest.loadCtx(rest.getVersionConfig)).Name("version_config").Methods("GET")
	rtr.HandleFunc("/builds/{build_id}", rest.loadCtx(rest.getBuildInfo)).Name("build_info").Methods("GET")
	rtr.HandleFunc("/builds/{build_id}/status", rest.loadCtx(rest.getBuildStatus)).Name("build_status").Methods("GET")
	rtr.HandleFunc("/tasks/{task_id}", rest.loadCtx(rest.getTaskInfo)).Name("task_info").Methods("GET")
	rtr.HandleFunc("/tasks/{task_id}/status", rest.loadCtx(rest.getTaskStatus)).Name("task_status").Methods("GET")
	rtr.HandleFunc("/tasks/{task_name}/history", rest.loadCtx(rest.getTaskHistory)).Name("task_history").Methods("GET")
	rtr.HandleFunc("/scheduler/host_utilization", rest.loadCtx(rest.getHostUtilizationStats)).Name("host_utilization").Methods("GET")
	rtr.HandleFunc("/scheduler/distro/{distro_id}/stats", rest.loadCtx(rest.getAverageSchedulerStats)).Name("avg_stats").Methods("GET")
	rtr.HandleFunc("/scheduler/makespans", rest.loadCtx(rest.getOptimalAndActualMakespans)).Name("makespan").Methods("GET")

	return root

}
Example #10
0
// registerWebuiHandler registers handlers for serving web UI
func registerWebuiHandler(router *mux.Router) {
	// Setup the router to serve the web UI
	goPath := os.Getenv("GOPATH")
	if goPath != "" {
		webPath := goPath + "/src/github.com/contiv/contivmodel/www/"

		// Make sure we have the web UI files
		_, err := os.Stat(webPath)
		if err != nil {
			webPath = goPath + "/src/github.com/contiv/netplugin/" +
				"Godeps/_workspace/src/github.com/contiv/contivmodel/www/"
			_, err := os.Stat(webPath)
			if err != nil {
				log.Errorf("Can not find the web UI directory")
			}
		}

		log.Infof("Using webPath: %s", webPath)

		// serve static files
		router.PathPrefix("/web/").Handler(http.StripPrefix("/web/", http.FileServer(http.Dir(webPath))))

		// Special case to serve main index.html
		router.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
			http.ServeFile(rw, req, webPath+"index.html")
		})
	}

	// proxy Handler
	router.PathPrefix("/proxy/").HandlerFunc(proxyHandler)
}
Example #11
0
// RegisterRoutes operates over `Routes` and registers all of them
func RegisterRoutes(router *mux.Router) *mux.Router {
	for _, route := range routes {
		router.Methods(route.Method).Path(route.Pattern).Name(route.Name).Handler(route.HandlerFunc)
	}
	router.PathPrefix("/").Handler(http.FileServer(assetFS()))
	return router
}
Example #12
0
func handlePlayground(r *mux.Router) {
	r = r.PathPrefix("/api/playground").Subrouter()

	r.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
		results.View("playground/form", nil, w)
	})
}
Example #13
0
//AddRoutes registers the http routes with the router
func (service *Service) AddRoutes(router *mux.Router) {
	router.Methods("GET").Path("/").HandlerFunc(service.HomePage)
	//Registration form
	router.Methods("GET").Path("/register").HandlerFunc(service.ShowRegistrationForm)
	router.Methods("POST").Path("/register").HandlerFunc(service.ProcessRegistrationForm)
	//Login form
	router.Methods("GET").Path("/login").HandlerFunc(service.ShowLoginForm)
	router.Methods("POST").Path("/login").HandlerFunc(service.ProcessLoginForm)
	//Logout link
	router.Methods("GET").Path("/logout").HandlerFunc(service.Logout)
	//Error page
	router.Methods("GET").Path("/error").HandlerFunc(service.ErrorPage)
	router.Methods("GET").Path("/error{errornumber}").HandlerFunc(service.ErrorPage)

	//host the assets used in the htmlpages
	router.PathPrefix("/assets/").Handler(http.StripPrefix("/assets/", http.FileServer(
		&assetfs.AssetFS{Asset: assets.Asset, AssetDir: assets.AssetDir, AssetInfo: assets.AssetInfo})))
	router.PathPrefix("/thirdpartyassets/").Handler(http.StripPrefix("/thirdpartyassets/", http.FileServer(
		&assetfs.AssetFS{Asset: thirdpartyassets.Asset, AssetDir: thirdpartyassets.AssetDir, AssetInfo: thirdpartyassets.AssetInfo})))
	router.PathPrefix("/components/").Handler(http.StripPrefix("/components/", http.FileServer(
		&assetfs.AssetFS{Asset: components.Asset, AssetDir: components.AssetDir, AssetInfo: components.AssetInfo})))

	//host the apidocumentation
	router.Methods("GET").Path("/apidocumentation").HandlerFunc(service.APIDocs)
	router.PathPrefix("/apidocumentation/raml/").Handler(http.StripPrefix("/apidocumentation/raml", http.FileServer(
		&assetfs.AssetFS{Asset: specifications.Asset, AssetDir: specifications.AssetDir, AssetInfo: specifications.AssetInfo})))
	router.PathPrefix("/apidocumentation/").Handler(http.StripPrefix("/apidocumentation/", http.FileServer(
		&assetfs.AssetFS{Asset: apiconsole.Asset, AssetDir: apiconsole.AssetDir, AssetInfo: apiconsole.AssetInfo})))

}
Example #14
0
//InitUser Initialize user routes
func InitUser(r *mux.Router) {
	l4g.Debug("Initializing user api routes")
	sr := r.PathPrefix("/users").Subrouter()
	sr.Handle("/login", negroni.New(
		negroni.HandlerFunc(RequireContext),
		negroni.HandlerFunc(login),
	)).Methods("POST")
	sr.Handle("/create", negroni.New(
		negroni.HandlerFunc(RequireContext),
		negroni.HandlerFunc(createUser),
	)).Methods("POST")
	sr.Handle("/", negroni.New(
		negroni.HandlerFunc(RequireAuth),
		negroni.HandlerFunc(allUsers),
	)).Methods("GET")
	sr.Handle("/{uuid}", negroni.New(
		negroni.HandlerFunc(RequireAuthAndUser),
		negroni.HandlerFunc(getUser),
	)).Methods("GET")
	sr.Handle("/{uuid}", negroni.New(
		negroni.HandlerFunc(RequireAuth),
		negroni.HandlerFunc(deleteUser),
	)).Methods("DELETE")
	sr.Handle("/{uuid}", negroni.New(
		negroni.HandlerFunc(RequireAuthAndUser),
		negroni.HandlerFunc(updateUser),
	)).Methods("POST")
}
Example #15
0
func InitLicense(r *mux.Router) {
	l4g.Debug(utils.T("api.license.init.debug"))

	sr := r.PathPrefix("/license").Subrouter()
	sr.Handle("/add", ApiAdminSystemRequired(addLicense)).Methods("POST")
	sr.Handle("/remove", ApiAdminSystemRequired(removeLicense)).Methods("POST")
}
func setupRouters(router *mux.Router, parentMiddleWare []http.HandlerFunc, routers []*Router) {
	if len(routers) == 0 {
		return
	}

	for _, rd := range routers {
		combinedMiddleWareHandlers := []http.HandlerFunc{}
		combinedMiddleWareHandlers = append(combinedMiddleWareHandlers, parentMiddleWare...)
		combinedMiddleWareHandlers = append(combinedMiddleWareHandlers, rd.middlewares...)

		panicOnZeroMethods := len(rd.subRouters) == 0 //Panic if we have no controller methods and also no subrouters
		for method, handler := range GetControllerMethods(rd.controller, panicOnZeroMethods) {
			for _, urlPart := range rd.urlParts {
				muxRoute := router.Handle(urlPart, newNegroniMiddleware(combinedMiddleWareHandlers, handler))
				muxRoute.Methods(method)
			}
		}

		if len(rd.urlParts) == 0 {
			setupRouters(router, combinedMiddleWareHandlers, rd.subRouters)
			continue
		}

		for _, urlPart := range rd.urlParts {
			var subRouterToUse *mux.Router
			if urlPart != "" {
				subRouterToUse = router.PathPrefix(urlPart).Subrouter()
			} else {
				subRouterToUse = router
			}
			setupRouters(subRouterToUse, combinedMiddleWareHandlers, rd.subRouters)
		}
	}
}
Example #17
0
func InitPost(r *mux.Router) {
	l4g.Debug("Initializing post api routes")

	r.Handle("/posts/{post_id}", negroni.New(
		negroni.HandlerFunc(RequireAuth),
		negroni.HandlerFunc(getPost),
	)).Methods("GET")

	sr := r.PathPrefix("/channels/{id}").Subrouter()

	sr.Handle("/create", negroni.New(
		negroni.HandlerFunc(RequireAuth),
		negroni.HandlerFunc(createPost),
	)).Methods("POST")

	sr.Handle("/update", negroni.New(
		negroni.HandlerFunc(RequireAuth),
		negroni.HandlerFunc(updatePost),
	)).Methods("POST")

	// {offset:[0-9]+}/{limit:[0-9]+}
	sr.Handle("/posts/", negroni.New(
		negroni.HandlerFunc(RequireAuth),
		negroni.HandlerFunc(getPosts),
	)).Methods("GET")
}
Example #18
0
func Register(rtr *mux.Router, client_ service.ServiceIf) {
	client = client_
	rtr.HandleFunc("/", RedirectHandler).Methods("GET")
	rtr.HandleFunc("/status", StatusHandler).Methods("GET")
	rtr.PathPrefix("/").Handler(http.FileServer(
		&assetfs.AssetFS{Asset, AssetDir, "/"}))
}
Example #19
0
func InitUser(r *mux.Router) {
	l4g.Debug("Initializing user api routes")

	sr := r.PathPrefix("/users").Subrouter()
	sr.Handle("/create", ApiAppHandler(createUser)).Methods("POST")
	sr.Handle("/update", ApiUserRequired(updateUser)).Methods("POST")
	sr.Handle("/update_roles", ApiUserRequired(updateRoles)).Methods("POST")
	sr.Handle("/update_active", ApiUserRequired(updateActive)).Methods("POST")
	sr.Handle("/update_notify", ApiUserRequired(updateUserNotify)).Methods("POST")
	sr.Handle("/newpassword", ApiUserRequired(updatePassword)).Methods("POST")
	sr.Handle("/send_password_reset", ApiAppHandler(sendPasswordReset)).Methods("POST")
	sr.Handle("/reset_password", ApiAppHandler(resetPassword)).Methods("POST")
	sr.Handle("/login", ApiAppHandler(login)).Methods("POST")
	sr.Handle("/logout", ApiUserRequired(logout)).Methods("POST")
	sr.Handle("/revoke_session", ApiUserRequired(revokeSession)).Methods("POST")

	sr.Handle("/newimage", ApiUserRequired(uploadProfileImage)).Methods("POST")

	sr.Handle("/me", ApiAppHandler(getMe)).Methods("GET")
	sr.Handle("/status", ApiUserRequiredActivity(getStatuses, false)).Methods("GET")
	sr.Handle("/profiles", ApiUserRequired(getProfiles)).Methods("GET")
	sr.Handle("/profiles/{id:[A-Za-z0-9]+}", ApiUserRequired(getProfiles)).Methods("GET")
	sr.Handle("/{id:[A-Za-z0-9]+}", ApiUserRequired(getUser)).Methods("GET")
	sr.Handle("/{id:[A-Za-z0-9]+}/sessions", ApiUserRequired(getSessions)).Methods("GET")
	sr.Handle("/{id:[A-Za-z0-9]+}/audits", ApiUserRequired(getAudits)).Methods("GET")
	sr.Handle("/{id:[A-Za-z0-9]+}/image", ApiUserRequired(getProfileImage)).Methods("GET")
}
func setupRouters(ctx *RouterContext.RouterContext, router *mux.Router, parentMiddleWare []HttpHandlerFunc, routeDefinitions []*RouteDefinition) {
	if len(routeDefinitions) == 0 {
		return
	}

	for _, rh := range routeDefinitions {
		var routerToUse *mux.Router
		if rh.prefix != "" {
			routerToUse = router.PathPrefix(rh.prefix).Subrouter()
		} else {
			routerToUse = router
		}

		combinedMiddleWareHandlers := []HttpHandlerFunc{}
		combinedMiddleWareHandlers = append(combinedMiddleWareHandlers, parentMiddleWare...)
		combinedMiddleWareHandlers = append(combinedMiddleWareHandlers, rh.middlewares...)

		for _, singleRouteDefinition := range rh.routeDefinitions {
			for method, h := range GetIRouteControllers(singleRouteDefinition) {
				muxRoute := routerToUse.Handle(singleRouteDefinition.GetPathPart(), newNegroniMiddleware(ctx, combinedMiddleWareHandlers, h))
				muxRoute.Methods(method)
			}
		}

		setupRouters(ctx, routerToUse, combinedMiddleWareHandlers, rh.subRoutes)
	}
}
Example #21
0
func SetAuthenticationRoutes(router *mux.Router) *mux.Router {

	tokenRouter := mux.NewRouter()

	tokenRouter.Handle("/api/auth/token/new", negroni.New(
		negroni.HandlerFunc(controllers.Login),
	)).Methods("POST")

	tokenRouter.Handle("/api/auth/logout", negroni.New(
		negroni.HandlerFunc(auth.RequireTokenAuthentication),
		negroni.HandlerFunc(controllers.Logout),
	))

	tokenRouter.Handle("/api/auth/token/refresh", negroni.New(
		negroni.HandlerFunc(auth.RequireTokenAuthentication),
		negroni.HandlerFunc(controllers.RefreshToken),
	)).Methods("GET")

	tokenRouter.Handle("/api/auth/token/validate", negroni.New(
		negroni.HandlerFunc(auth.RequireTokenAuthentication),
		negroni.HandlerFunc(func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
			w.WriteHeader(http.StatusOK)
		}),
	))

	router.PathPrefix("/api/auth").Handler(negroni.New(
		negroni.Wrap(tokenRouter),
	))

	return router
}
Example #22
0
func Install(r *mux.Router) {
	r.HandleFunc("/", App)
	r.HandleFunc("/ws", WsHandler)

	r.HandleFunc("/jobs", ListJobs).Methods("GET")
	r.HandleFunc("/jobs", AddJob).Methods("POST")
	r.HandleFunc("/jobs/{job}", GetJob).Methods("GET")
	r.HandleFunc("/jobs/{job}", DeleteJob).Methods("DELETE")
	r.HandleFunc("/jobs/{job}/tasks", AddTaskToJob).Methods("POST")
	r.HandleFunc("/jobs/{job}/tasks/{task}", RemoveTaskFromJob).Methods("DELETE")
	r.HandleFunc("/jobs/{job}/triggers", AddTriggerToJob).Methods("POST")
	r.HandleFunc("/jobs/{job}/triggers/{trigger}", RemoveTriggerFromJob).Methods("DELETE")

	r.HandleFunc("/tasks", ListTasks).Methods("GET")
	r.HandleFunc("/tasks", AddTask).Methods("POST")
	r.HandleFunc("/tasks/{task}", GetTask).Methods("GET")
	r.HandleFunc("/tasks/{task}", UpdateTask).Methods("PUT")
	r.HandleFunc("/tasks/{task}", DeleteTask).Methods("DELETE")
	r.HandleFunc("/tasks/{task}/jobs", ListJobsForTask).Methods("GET")

	r.HandleFunc("/runs", ListRuns).Methods("GET")
	r.HandleFunc("/runs", AddRun).Methods("POST")
	r.HandleFunc("/runs/{run}", GetRun).Methods("GET")

	r.HandleFunc("/triggers", ListTriggers).Methods("GET")
	r.HandleFunc("/triggers", AddTrigger).Methods("POST")
	r.HandleFunc("/triggers/{trigger}", GetTrigger).Methods("GET")
	r.HandleFunc("/triggers/{trigger}", UpdateTrigger).Methods("PUT")
	r.HandleFunc("/triggers/{trigger}", DeleteTrigger).Methods("DELETE")
	r.HandleFunc("/triggers/{trigger}/jobs", ListJobsForTrigger).Methods("GET")

	r.PathPrefix("/static/").Handler(http.FileServer(http.Dir("web/")))
}
Example #23
0
func InitFile(r *mux.Router) {
	l4g.Debug("Initializing file api routes")

	sr := r.PathPrefix("/files").Subrouter()
	sr.Handle("/upload", ApiUserRequired(uploadFile)).Methods("POST")
	sr.Handle("/get/{channel_id:[A-Za-z0-9]+}/{user_id:[A-Za-z0-9]+}/{filename:([A-Za-z0-9]+/)?.+\\.[A-Za-z0-9]{3,}}", ApiAppHandler(getFile)).Methods("GET")
	sr.Handle("/get_public_link", ApiUserRequired(getPublicLink)).Methods("POST")
}
Example #24
0
func InitWebhook(r *mux.Router) {
	l4g.Debug("Initializing webhook api routes")

	sr := r.PathPrefix("/hooks").Subrouter()
	sr.Handle("/incoming/create", ApiUserRequired(createIncomingHook)).Methods("POST")
	sr.Handle("/incoming/delete", ApiUserRequired(deleteIncomingHook)).Methods("POST")
	sr.Handle("/incoming/list", ApiUserRequired(getIncomingHooks)).Methods("GET")
}
Example #25
0
// Register adds the filtered handler to the mux.
func (n networkRoute) Register(m *mux.Router, handler http.Handler) {
	logrus.Debugf("Registering %s, %v", n.path, httpMethods)
	subrouter := m.PathPrefix(router.VersionMatcher + n.path).Subrouter()
	subrouter.Methods(httpMethods...).Handler(handler)

	subrouter = m.PathPrefix(n.path).Subrouter()
	subrouter.Methods(httpMethods...).Handler(handler)
}
Example #26
0
// registerStorageLockers - register locker rpc handlers for net/rpc library clients
func registerStorageLockers(mux *router.Router, lockServers []*lockServer) {
	for _, lockServer := range lockServers {
		lockRPCServer := rpc.NewServer()
		lockRPCServer.RegisterName("Dsync", lockServer)
		lockRouter := mux.PathPrefix(reservedBucket).Subrouter()
		lockRouter.Path(path.Join("/lock", lockServer.rpcPath)).Handler(lockRPCServer)
	}
}
Example #27
0
//LoadController Middleware of the controller
func (l *UserController) LoadController(r *mux.Router, db dbm.DatabaseQuerier, userManager user.Manager) {
	l.db = db
	l.userManager = userManager
	sub := r.PathPrefix(l.BasePath()).Subrouter()
	sub.Handle("/login", middlewares.NewMiddlewaresFunc(l.Login)).Methods("POST")
	sub.Handle("/logout", middlewares.NewMiddlewaresFunc(l.Logout)).Methods("GET")
	sub.Handle("/", middlewares.NewMiddlewaresFunc(l.Register)).Methods("POST")
}
Example #28
0
// Register attaches a api to the given router.
func Register(router *mux.Router) (api *ShrtURLAPI, err error) {
	api = &ShrtURLAPI{}
	api.router = router.PathPrefix(fmt.Sprintf("/%s", Version)).Subrouter()

	err = urls.Register(api.router, api.handleFunc)

	return api, err
}
Example #29
0
func InitPreference(r *mux.Router) {
	l4g.Debug("Initializing preference api routes")

	sr := r.PathPrefix("/preferences").Subrouter()
	sr.Handle("/save", ApiUserRequired(savePreferences)).Methods("POST")
	sr.Handle("/{category:[A-Za-z0-9_]+}", ApiUserRequired(getPreferenceCategory)).Methods("GET")
	sr.Handle("/{category:[A-Za-z0-9_]+}/{name:[A-Za-z0-9_]+}", ApiUserRequired(getPreference)).Methods("GET")
}
Example #30
0
func serveDir(m *mux.Router, url string, path string) {
	m.PathPrefix(url).Handler(
		http.StripPrefix(
			url,
			http.FileServer(http.Dir(path)),
		),
	)
}