Example #1
0
func NewRouter(s *Server) *mux.Router {
	schemas := newSchema()
	router := mux.NewRouter().StrictSlash(true)
	f := HandleError

	// API framework routes
	router.Methods("GET").Path("/").Handler(api.VersionsHandler(schemas, "v1"))
	router.Methods("GET").Path("/v1/schemas").Handler(api.SchemasHandler(schemas))
	router.Methods("GET").Path("/v1/schemas/{id}").Handler(api.SchemaHandler(schemas))
	router.Methods("GET").Path("/v1").Handler(api.VersionHandler(schemas, "v1"))

	// Volume(s)
	router.Methods("GET").Path("/v1/volumes").Handler(f(schemas, s.ListVolumes))
	router.Methods("GET").Path("/v1/volumes/{id}").Handler(f(schemas, s.GetVolume))
	router.Methods("POST").Path("/v1/volumes/{id}").Queries("action", "reverttosnapshot").Handler(f(schemas, s.RevertToSnapshot))
	router.Methods("POST").Path("/v1/volumes/{id}").Queries("action", "restorefrombackup").Handler(f(schemas, s.RestoreFromBackup))

	// Snapshots
	router.Methods("GET").Path("/v1/snapshots").Handler(f(schemas, s.ListSnapshots))
	router.Methods("GET").Path("/v1/snapshots/{id}").Handler(f(schemas, s.GetSnapshot))
	router.Methods("POST").Path("/v1/snapshots").Handler(f(schemas, s.CreateSnapshot))
	router.Methods("DELETE").Path("/v1/snapshots/{id}").Handler(f(schemas, s.DeleteSnapshot))
	router.Methods("POST").Path("/v1/snapshots/{id}").Queries("action", "backup").Handler(f(schemas, s.CreateBackup))
	router.Methods("POST").Path("/v1/snapshots/{id}").Queries("action", "removebackup").Handler(f(schemas, s.RemoveBackup))

	// Restore status
	router.Methods("GET").Path("/v1/backupstatuses/{id}").Handler(f(schemas, s.GetBackupStatus))
	router.Methods("GET").Path("/v1/restorestatuses/{id}").Handler(f(schemas, s.GetRestoreStatus))

	return router
}
Example #2
0
func New(s *server.Server) *mux.Router {
	schemas := model.NewSchema()
	router := mux.NewRouter().StrictSlash(true)

	// API framework routes
	router.Methods("GET").Path("/").Handler(api.VersionsHandler(schemas, "v1", "v2"))
	router.Methods("GET").Path("/v2/schemas").Handler(api.SchemasHandler(schemas))
	router.Methods("GET").Path("/v2/schemas/{id}").Handler(api.SchemaHandler(schemas))
	router.Methods("GET").Path("/v2").Handler(api.VersionHandler(schemas, "v2"))

	router.Methods("GET").Path("/v2/stacks").Handler(s.HandlerFunc(schemas, s.StackList))

	return router
}
Example #3
0
func NewRouter(s *Server) *mux.Router {
	schemas := NewSchema()
	router := mux.NewRouter().StrictSlash(true)
	f := HandleError

	// API framework routes
	router.Methods("GET").Path("/").Handler(api.VersionsHandler(schemas, "v1"))
	router.Methods("GET").Path("/v1/schemas").Handler(api.SchemasHandler(schemas))
	router.Methods("GET").Path("/v1/schemas/{id}").Handler(api.SchemaHandler(schemas))
	router.Methods("GET").Path("/v1").Handler(api.VersionHandler(schemas, "v1"))

	// Process
	router.Methods("GET").Path("/v1/processes").Handler(f(schemas, s.ListProcesses))
	router.Methods("GET").Path("/v1/processes/{id}").Handler(f(schemas, s.GetProcess))
	router.Methods("POST").Path("/v1/processes").Handler(f(schemas, s.CreateProcess))

	return router
}
//NewRouter creates and configures a mux router
func NewRouter() *mux.Router {
	schemas = &client.Schemas{}

	// ApiVersion
	apiVersion := schemas.AddType("apiVersion", client.Resource{})
	apiVersion.CollectionMethods = []string{}

	// Schema
	schemas.AddType("schema", client.Schema{})

	// Question
	question := schemas.AddType("question", model.Question{})
	question.CollectionMethods = []string{}

	// Output
	output := schemas.AddType("output", model.Output{})
	output.CollectionMethods = []string{}

	// Template
	template := schemas.AddType("template", model.Template{})
	refreshAction := client.Action{}
	tempActions := make(map[string]client.Action)
	tempActions["refresh"] = refreshAction
	template.CollectionActions = tempActions

	delete(template.ResourceFields, "rancherCompose")
	delete(template.ResourceFields, "dockerCompose")
	delete(template.ResourceFields, "uuid")
	delete(template.ResourceFields, "questions")
	delete(template.ResourceFields, "TemplateVersionRancherVersion")
	delete(template.ResourceFields, "iconLink")
	delete(template.ResourceFields, "readmeLink")
	delete(template.ResourceFields, "projectURL")
	delete(template.ResourceFields, "version")
	f1 := template.ResourceFields["output"]
	f1.Type = "output"
	template.ResourceFields["output"] = f1

	// Template Version
	templateVersion := schemas.AddType("templateVersion", model.Template{})
	templateVersion.CollectionMethods = []string{}
	f2 := templateVersion.ResourceFields["questions"]
	f2.Type = "array[question]"
	templateVersion.ResourceFields["questions"] = f2
	f3 := templateVersion.ResourceFields["output"]
	f3.Type = "output"
	templateVersion.ResourceFields["output"] = f3

	// Catalog
	catalog := schemas.AddType("catalog", manager.Catalog{})
	delete(catalog.ResourceFields, "catalogLink")

	// Error
	err := schemas.AddType("error", model.CatalogError{})
	err.CollectionMethods = []string{}

	// API framework routes
	router := mux.NewRouter().StrictSlash(true)

	router.Methods("GET").Path("/").Handler(api.VersionsHandler(schemas, "v1-catalog"))
	router.Methods("GET").Path("/v1-catalog/schemas").Handler(api.SchemasHandler(schemas))
	router.Methods("GET").Path("/v1-catalog/schemas/{id}").Handler(api.SchemaHandler(schemas))
	router.Methods("GET").Path("/v1-catalog").Handler(api.VersionHandler(schemas, "v1-catalog"))

	// Application routes

	for _, route := range routes {
		router.
			Methods(route.Method).
			Path(route.Pattern).
			Name(route.Name).
			Handler(api.ApiHandler(schemas, route.HandlerFunc))
	}

	router.GetRoute("RefreshCatalog").Queries("action", "refresh")
	router.GetRoute("RefreshCatalogTemplates").Queries("action", "refresh")

	return router
}