routes

package
v0.0.0-...-d44e891 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SetupServer = func(appPort string) {
	var router = httprouter.New()
	router.GET("/ping", TokenAuthentication(controllers.Ping))
	router.GET("/env", TokenAuthentication(controllers.GetEnvVars))
	router.POST("/env", TokenAuthentication(controllers.SetEnvVars))
	router.GET("/env/:name", TokenAuthentication(controllers.GetEnvVar))
	router.GET("/about", TokenAuthentication(controllers.About))
	router.GET("/file", TokenAuthentication(controllers.GetFile))
	router.PUT("/file", TokenAuthentication(controllers.PutFile))
	router.GET("/folder", TokenAuthentication(controllers.GetFolder))
	router.POST("/command", TokenAuthentication(controllers.CommandPost))
	router.POST("/commandparallel", TokenAuthentication(controllers.CommandParallelPost))
	router.POST("/commanddetached/:cid", TokenAuthentication(controllers.CommandDetachedPost))

	err := http.ListenAndServe(":"+appPort, router)
	if err != nil {
		fmt.Print(err)
	}
}
View Source
var TokenAuthentication = func(h httprouter.Handle) httprouter.Handle {
	return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

		tokenHeader := r.Header.Get("Token")

		if tokenHeader == os.Getenv("HTTP_AUTH_TOKEN") {

			h(w, r, ps)
		} else {
			response, _ := json.Marshal(u.ApiMessage(uint32(constants.UNAUTHORIZED),
				u.GetMessage()[uint32(constants.UNAUTHORIZED)],
				"Invalid Token",
				r.URL.Path))
			w.Header().Add("Content-Type", "application/json")
			http.Error(w, string(response), http.StatusUnauthorized)
		}
	}
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL