func TestInit(t *testing.T) { cfg := common.ContextCfg{ Docker: testDocker, Registry: testRegistry, Cocaine: testCocaine, KeyFile: "/Users/noxiouz/Gotest/src/github.com/cocaine/cocaine-flow/test/keyfile.cfg", } err := common.InitializeContext(cfg) if err != nil { t.Fatalf("Context initialization error %s", err) } _, err = common.GetContext() if err != nil { t.Fatalf("GetContext error %s", err) } }
func NewBackend() (ac AuthCocaine, err error) { context, err := common.GetContext() if err != nil { return } app, err := NewAppWrapper("flow-tools", context.CocaineEndpoint()) if err != nil { return } ciph, err := aes.NewCipher(context.SecretKey()) if err != nil { log.Printf("Error %s", err) return } ac = &authCocaine{ app: app, tokener: &Token{ciph}, context: context, } return }
func ConstructHandler() http.Handler { var err error cocs, err = backend.NewBackend() if err != nil { log.Fatalln(err) } context, err := common.GetContext() if err != nil { log.Fatalln(err) } store = sessions.NewCookieStore(context.SecretKey()) //main router router := mux.NewRouter() router.StrictSlash(true) router.HandleFunc("/ping", Ping) //flow router rootRouter := router.PathPrefix(pathPrefix).Subrouter() //profiles router profilesRouter := rootRouter.PathPrefix("/profiles").Subrouter() profilesRouter.StrictSlash(true) profilesRouter.HandleFunc("/", Guest(ProfileList)).Methods("GET") profilesRouter.HandleFunc("/{name}", AuthRequired(ProfileRead)).Methods("GET") profilesRouter.HandleFunc("/{name}", AuthRequired(ProfileUpload)).Methods("PUT", "POST") profilesRouter.HandleFunc("/{name}", AuthRequired(ProfileRemove)).Methods("DELETE") //hosts router hostsRouter := rootRouter.PathPrefix("/hosts").Subrouter() hostsRouter.HandleFunc("/", AuthRequired(HostList)).Methods("GET") hostsRouter.HandleFunc("/{host}", AuthRequired(HostAdd)).Methods("POST", "PUT") hostsRouter.HandleFunc("/{host}", AuthRequired(HostRemove)).Methods("DELETE") //runlists router runlistsRouter := rootRouter.PathPrefix("/runlists").Subrouter() runlistsRouter.StrictSlash(true) runlistsRouter.HandleFunc("/", AuthRequired(RunlistList)).Methods("GET") runlistsRouter.HandleFunc("/{name}", AuthRequired(RunlistRead)).Methods("GET") runlistsRouter.HandleFunc("/{name}", AuthRequired(RunlistRemove)).Methods("DELETE") //routing groups groupsRouter := rootRouter.PathPrefix("/groups").Subrouter() groupsRouter.StrictSlash(true) groupsRouter.HandleFunc("/", AuthRequired(GroupList)).Methods("GET") groupsRouter.HandleFunc("/{name}", AuthRequired(GroupRead)).Methods("GET") groupsRouter.HandleFunc("/{name}", AuthRequired(GroupCreate)).Methods("POST") groupsRouter.HandleFunc("/{name}", AuthRequired(GroupRemove)).Methods("DELETE") groupsRouter.HandleFunc("/{name}/{app}", AuthRequired(GroupPushApp)).Methods("POST", "PUT") groupsRouter.HandleFunc("/{name}/{app}", AuthRequired(GroupPopApp)).Methods("DELETE") rootRouter.HandleFunc("/groupsrefresh/", AuthRequired(GroupRefresh)).Methods("POST") rootRouter.HandleFunc("/groupsrefresh/{name}", AuthRequired(GroupRefresh)).Methods("POST") //crashlog router crashlogRouter := rootRouter.PathPrefix("/crashlogs").Subrouter() crashlogRouter.StrictSlash(true) crashlogRouter.HandleFunc("/{name}", AuthRequired(CrashlogList)).Methods("GET") crashlogRouter.HandleFunc("/{name}/{timestamp}", AuthRequired(CrashlogView)).Methods("GET") // crashlogRouter.HandleFunc("/{name}/{timestamp}", AuthRequired(CrashlogRemove)).Methods("DELETE") //auth router authRouter := rootRouter.PathPrefix("/users").Subrouter() authRouter.StrictSlash(true) authRouter.HandleFunc("/token", GenToken).Methods("POST") authRouter.HandleFunc("/signup", UserSignup).Methods("POST") authRouter.HandleFunc("/signin", UserSignin).Methods("POST") //buildlog router buildlogRouter := rootRouter.PathPrefix("/buildlog").Subrouter() buildlogRouter.StrictSlash(true) buildlogRouter.HandleFunc("/", AuthRequired(BuildLogList)).Methods("GET") buildlogRouter.HandleFunc("/{id}", AuthRequired(BuildLogRead)).Methods("GET") //app router appRouter := rootRouter.PathPrefix("/app/").Subrouter() appRouter.StrictSlash(true) appRouter.HandleFunc("/", AuthRequired(ApplicationList)).Methods("GET") appRouter.HandleFunc("/{name}/{version}", AuthRequired(ApplicationUpload)).Methods("POST", "PUT") appRouter.HandleFunc("/start", AuthRequired(ApplicationStart)).Methods("POST", "PUT") // appRouter.HandleFunc("/stop", AuthRequired(ApplicationStop)).Methods("POST", "PUT") //return handlers.LoggingHandler(os.Stdout, router) router.PathPrefix("/").Handler(http.FileServer(http.Dir("./static/"))) return router }