// routes manages the handling of the API endpoints. func routes(w *web.Web) { w.Handle("GET", "/v1/version", handlers.Version.List) // Execute the CRUD needed for forms. w.Handle("GET", "/v1/form", fixtures.Handler("forms/forms", http.StatusOK)) w.Handle("POST", "/v1/form", fixtures.Handler("forms/form", http.StatusCreated)) w.Handle("GET", "/v1/form/:form_id", fixtures.Handler("forms/form", http.StatusOK)) w.Handle("PUT", "/v1/form/:form_id", fixtures.NoContent) // Execute the :query_set on the view :view_name on this :item_key. w.Handle("GET", "/v1/exec/:query_set/view/:view_name/:item_key", handlers.Proxy(xeniadURL, func(c *web.Context) string { return "/v1/exec/" + c.Params["query_set"] + "/view/" + c.Params["view_name"] + "/" + c.Params["item_key"] })) // Get all the items from the view :view_name on this :item_key. w.Handle("POST", "/v1/exec/view/:view_name/:item_key", handlers.Proxy(xeniadURL, func(c *web.Context) string { return "/v1/exec/view/" + c.Params["view_name"] + "/" + c.Params["item_key"] })) // Execute xenia queries directly. w.Handle("GET", "/v1/exec/:query_set", handlers.Proxy(xeniadURL, func(c *web.Context) string { return "/v1/exec/" + c.Params["query_set"] })) // Create or removes Actions. w.Handle("POST", "/v1/action/:action/user/:user_key/on/item/:item_key", handlers.Action.Add) w.Handle("DELETE", "/v1/action/:action/user/:user_key/on/item/:item_key", handlers.Action.Remove) // Save or Update Items. w.Handle("PUT", "/v1/item", handlers.Proxy(spongedURL, func(c *web.Context) string { return "/v1/item" })) w.Handle("POST", "/v1/item", handlers.Proxy(spongedURL, func(c *web.Context) string { return "/v1/item" })) }
// routes manages the handling of the API endpoints. func routes(w *web.Web) { w.Handle("GET", "/v1/version", handlers.Version.List) w.Handle("GET", "/v1/script", handlers.Script.List) w.Handle("PUT", "/v1/script", handlers.Script.Upsert) w.Handle("GET", "/v1/script/:name", handlers.Script.Retrieve) w.Handle("DELETE", "/v1/script/:name", handlers.Script.Delete) w.Handle("GET", "/v1/query", handlers.Query.List) w.Handle("PUT", "/v1/query", handlers.Query.Upsert) w.Handle("GET", "/v1/query/:name", handlers.Query.Retrieve) w.Handle("DELETE", "/v1/query/:name", handlers.Query.Delete) w.Handle("PUT", "/v1/index/:name", handlers.Query.EnsureIndexes) w.Handle("GET", "/v1/regex", handlers.Regex.List) w.Handle("PUT", "/v1/regex", handlers.Regex.Upsert) w.Handle("GET", "/v1/regex/:name", handlers.Regex.Retrieve) w.Handle("DELETE", "/v1/regex/:name", handlers.Regex.Delete) w.Handle("GET", "/v1/mask", handlers.Mask.List) w.Handle("PUT", "/v1/mask", handlers.Mask.Upsert) w.Handle("GET", "/v1/mask/:collection/:field", handlers.Mask.Retrieve) w.Handle("GET", "/v1/mask/:collection", handlers.Mask.Retrieve) w.Handle("DELETE", "/v1/mask/:collection/:field", handlers.Mask.Delete) w.Handle("POST", "/v1/exec", handlers.Exec.Custom) w.Handle("GET", "/v1/exec/:name", handlers.Exec.Name) // Create the Cayley middleware which will only be binded to specific // endpoints. cayleym := cayley.Midware(cfg.MustURL(cfgMongoURI)) // These endpoints require Cayley, we will add the middleware onto the routes. w.Handle("GET", "/v1/exec/:name/view/:view/:item", handlers.Exec.NameOnView, cayleym) w.Handle("POST", "/v1/exec/view/:view/:item", handlers.Exec.CustomOnView, cayleym) w.Handle("GET", "/v1/relationship", handlers.Relationship.List) w.Handle("PUT", "/v1/relationship", handlers.Relationship.Upsert) w.Handle("GET", "/v1/relationship/:predicate", handlers.Relationship.Retrieve) w.Handle("DELETE", "/v1/relationship/:predicate", handlers.Relationship.Delete) w.Handle("GET", "/v1/view", handlers.View.List) w.Handle("PUT", "/v1/view", handlers.View.Upsert) w.Handle("GET", "/v1/view/:name", handlers.View.Retrieve) w.Handle("DELETE", "/v1/view/:name", handlers.View.Delete) }
// routes manages the handling of the API endpoints. func routes(w *web.Web) { w.Handle("GET", "/v1/version", handlers.Version.List) w.Handle("GET", "/v1/item/:id", handlers.Item.Retrieve) w.Handle("PUT", "/v1/item", handlers.Item.Import) w.Handle("POST", "/v1/item", handlers.Item.Import) w.Handle("DELETE", "/v1/item/:id", handlers.Item.Remove) w.Handle("GET", "/v1/pattern", handlers.Pattern.List) w.Handle("PUT", "/v1/pattern", handlers.Pattern.Upsert) w.Handle("GET", "/v1/pattern/:type", handlers.Pattern.Retrieve) w.Handle("DELETE", "/v1/pattern/:type", handlers.Pattern.Delete) w.Handle("POST", "/v1/data/:type", handlers.Data.Import) }
func routes(w *web.Web) { // Create a new app group which will be for internal functions that may have // an optional layer of auth added to it. internal := w.Group() // Now we will load in the public key from the config. If found, we'll add a // middleware to all internal endpoints that will ensure that we validate the // requests coming in. publicKey, err := cfg.String(cfgAuthPublicKey) if err != nil || publicKey == "" { log.User("startup", "Init", "%s is missing, internal authentication is disabled", cfgAuthPublicKey) } // If the public key is provided then add the auth middleware or fail using // the provided public key. if publicKey != "" { log.Dev("startup", "Init", "Initializing Auth") // We are allowing the query string to act as the access token provider // because this service has endpoints that are accessed directly currently // and we need someway to authenticate to these endpoints. authmOpts := auth.MidwareOpts{ AllowQueryString: true, } authm, err := auth.Midware(publicKey, authmOpts) if err != nil { log.Error("startup", "Init", err, "Initializing Auth") os.Exit(1) } // Apply the authentication middleware on top of the application as the // first middleware. internal.Use(authm) } // global internal.Handle("GET", "/v1/version", handlers.Version.List) // forms internal.Handle("POST", "/v1/form", handlers.Form.Upsert) internal.Handle("GET", "/v1/form", handlers.Form.List) internal.Handle("PUT", "/v1/form/:id", handlers.Form.Upsert) internal.Handle("PUT", "/v1/form/:id/status/:status", handlers.Form.UpdateStatus) internal.Handle("GET", "/v1/form/:id", handlers.Form.Retrieve) internal.Handle("DELETE", "/v1/form/:id", handlers.Form.Delete) // form aggregations internal.Handle("GET", "/v1/form/:form_id/digest", handlers.Aggregation.Digest) internal.Handle("GET", "/v1/form/:form_id/aggregate", handlers.Aggregation.Aggregate) internal.Handle("GET", "/v1/form/:form_id/aggregate/:group_id", handlers.Aggregation.AggregateGroup) internal.Handle("GET", "/v1/form/:form_id/aggregate/:group_id/submission", handlers.Aggregation.SubmissionGroup) // form submissions internal.Handle("GET", "/v1/form/:form_id/submission", handlers.FormSubmission.Search) internal.Handle("GET", "/v1/form/:form_id/submission/:id", handlers.FormSubmission.Retrieve) internal.Handle("PUT", "/v1/form/:form_id/submission/:id/status/:status", handlers.FormSubmission.UpdateStatus) internal.Handle("POST", "/v1/form/:form_id/submission/:id/flag/:flag", handlers.FormSubmission.AddFlag) internal.Handle("DELETE", "/v1/form/:form_id/submission/:id/flag/:flag", handlers.FormSubmission.RemoveFlag) internal.Handle("PUT", "/v1/form/:form_id/submission/:id/answer/:answer_id", handlers.FormSubmission.UpdateAnswer) internal.Handle("DELETE", "/v1/form/:form_id/submission/:id", handlers.FormSubmission.Delete) // temporal route to get CSV file - TO DO : move into a different service internal.Handle("GET", "/v1/form/:form_id/submission/export", handlers.FormSubmission.Download) // form form galleries internal.Handle("GET", "/v1/form/:form_id/gallery", handlers.FormGallery.RetrieveForForm) // form galleries internal.Handle("GET", "/v1/form_gallery/:id", handlers.FormGallery.Retrieve) internal.Handle("PUT", "/v1/form_gallery/:id", handlers.FormGallery.Update) internal.Handle("POST", "/v1/form_gallery/:id/submission/:submission_id/:answer_id", handlers.FormGallery.AddAnswer) internal.Handle("DELETE", "/v1/form_gallery/:id/submission/:submission_id/:answer_id", handlers.FormGallery.RemoveAnswer) // Create a new app group which will be for external functions that will need // to be publically exposed. external := w.Group() external.Handle("POST", "/v1/form/:form_id/submission", handlers.FormSubmission.Create) }