Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var About = func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { resp := u.ApiMessage(uint32(constants.SUCCESS), u.GetMessage()[uint32(constants.SUCCESS)], constants.About(), r.URL.Path) u.ApiResponse(w, resp) }
View Source
var CommandDetachedPost = func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { body, _ := ioutil.ReadAll(r.Body) cmd_id := ps.ByName("cid") commands := u.TrimSpacesAndLineEndings(strings.Split(string(body), "\n")) if len(commands) == 0 { u.ApiResponse(w, u.ApiMessage(uint32(constants.EMPTY_REQUEST_BODY_PROVIDED), u.GetMessage()[uint32(constants.EMPTY_REQUEST_BODY_PROVIDED)], u.GetMessage()[uint32(constants.EMPTY_REQUEST_BODY_PROVIDED)], r.URL.Path)) return } cmdBackground := []string{"./runcmd", "--cid=" + cmd_id, "--args=" + strings.Join(commands, ";;")} log.Print(fmt.Sprintf("Starting command '%s' in background", strings.Join(cmdBackground, " "))) err := u.StartCommandAndGetError(cmdBackground) if err != nil { u.ApiResponse(w, u.ApiMessage(uint32(constants.COMMAND_DETACHED_START_FAILURE), fmt.Sprintf(u.GetMessage()[uint32(constants.COMMAND_DETACHED_START_FAILURE)], cmd_id), err.Error(), r.URL.Path)) return } resp := u.ApiMessage(uint32(constants.SUCCESS), u.GetMessage()[uint32(constants.SUCCESS)], cmd_id, r.URL.Path) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusAccepted) u.ApiResponse(w, resp) }
View Source
var CommandParallelPost = func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { body, _ := ioutil.ReadAll(r.Body) commands := u.TrimSpacesAndLineEndings(strings.Split(string(body), "\n")) if len(commands) == 0 { u.ApiResponse(w, u.ApiMessage(uint32(constants.EMPTY_REQUEST_BODY_PROVIDED), u.GetMessage()[uint32(constants.EMPTY_REQUEST_BODY_PROVIDED)], u.GetMessage()[uint32(constants.EMPTY_REQUEST_BODY_PROVIDED)], r.URL.Path)) return } cip := command.NewCommandInParallel() commandDescription := cip.RunCommands(commands) resp := u.ApiMessage(uint32(constants.SUCCESS), u.GetMessage()[uint32(constants.SUCCESS)], commandDescription, r.URL.Path) u.ApiResponse(w, resp) }
View Source
var CommandPost = func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { body, _ := ioutil.ReadAll(r.Body) commands := u.TrimSpacesAndLineEndings(strings.Split(string(body), "\n")) if len(commands) == 0 { u.ApiResponse(w, u.ApiMessage(uint32(constants.EMPTY_REQUEST_BODY_PROVIDED), u.GetMessage()[uint32(constants.EMPTY_REQUEST_BODY_PROVIDED)], u.GetMessage()[uint32(constants.EMPTY_REQUEST_BODY_PROVIDED)], r.URL.Path)) return } cim := command.NewCommandInMemory() commandDescription := cim.RunCommands(commands) resp := u.ApiMessage(uint32(constants.SUCCESS), u.GetMessage()[uint32(constants.SUCCESS)], commandDescription, r.URL.Path) u.ApiResponse(w, resp) }
View Source
var GetEnvVar = func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { env := environment.GetInstance() envVar := env.GetEnvAndVirtualEnv()[ps.ByName("name")] resp := u.ApiMessage(uint32(constants.SUCCESS), u.GetMessage()[uint32(constants.SUCCESS)], envVar, r.URL.Path) u.ApiResponse(w, resp) }
View Source
var GetEnvVars = func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { env := environment.GetInstance() envVars := env.GetEnvAndVirtualEnv() resp := u.ApiMessage(uint32(constants.SUCCESS), u.GetMessage()[uint32(constants.SUCCESS)], envVars, r.URL.Path) u.ApiResponse(w, resp) }
View Source
var GetFile = func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { fileName := r.Header.Get("File-Path") if fileName == "" { u.ApiResponse(w, u.ApiMessage(uint32(constants.HTTP_HEADER_NOT_PROVIDED), fmt.Sprintf(u.GetMessage()[uint32(constants.HTTP_HEADER_NOT_PROVIDED)], fileName), fmt.Sprintf(u.GetMessage()[uint32(constants.HTTP_HEADER_NOT_PROVIDED)], fileName), r.URL.Path)) return } content, err := ioutil.ReadFile(fileName) if err != nil { u.ApiResponse(w, u.ApiMessage(uint32(constants.GET_FILE_FAILURE), fmt.Sprintf(u.GetMessage()[uint32(constants.GET_FILE_FAILURE)], fileName), err.Error(), r.URL.Path)) return } w.Header().Set("Content-Disposition", "attachment; filename="+filepath.Base(fileName)) u.ApiResponseByteArray(w, content) }
View Source
var GetFolder = func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { folderName := r.Header.Get("Folder-Path") if folderName == "" { u.ApiResponse(w, u.ApiMessage(uint32(constants.HTTP_HEADER_NOT_PROVIDED), fmt.Sprintf(u.GetMessage()[uint32(constants.HTTP_HEADER_NOT_PROVIDED)], folderName), fmt.Sprintf(u.GetMessage()[uint32(constants.HTTP_HEADER_NOT_PROVIDED)], folderName), r.URL.Path)) return } zipFileName := "response.zip" err := zipFolder(folderName, zipFileName) if err != nil { u.ApiResponse(w, u.ApiMessage(uint32(constants.FOLDER_ZIP_FAILURE), fmt.Sprintf(u.GetMessage()[uint32(constants.FOLDER_ZIP_FAILURE)], folderName), err.Error(), r.URL.Path)) return } content, err := ioutil.ReadFile(zipFileName) if err != nil { u.ApiResponse(w, u.ApiMessage(uint32(constants.GET_FILE_FAILURE), fmt.Sprintf(u.GetMessage()[uint32(constants.GET_FILE_FAILURE)], folderName), err.Error(), r.URL.Path)) return } w.Header().Set("Content-Disposition", "attachment; filename="+filepath.Base(zipFileName)) u.ApiResponseZip(w, content) }
View Source
var Ping = func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { resp := u.ApiMessage(uint32(constants.SUCCESS), u.GetMessage()[uint32(constants.SUCCESS)], "pong", r.URL.Path) u.ApiResponse(w, resp) }
View Source
var PutFile = func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { fileName := r.Header.Get("File-Path") if fileName == "" { u.ApiResponse(w, u.ApiMessage(uint32(constants.HTTP_HEADER_NOT_PROVIDED), fmt.Sprintf(u.GetMessage()[uint32(constants.HTTP_HEADER_NOT_PROVIDED)], fileName), fmt.Sprintf(u.GetMessage()[uint32(constants.HTTP_HEADER_NOT_PROVIDED)], fileName), r.URL.Path)) return } body, _ := ioutil.ReadAll(r.Body) if len(body) == 0 { u.ApiResponse(w, u.ApiMessage(uint32(constants.EMPTY_REQUEST_BODY_PROVIDED), u.GetMessage()[uint32(constants.EMPTY_REQUEST_BODY_PROVIDED)], u.GetMessage()[uint32(constants.EMPTY_REQUEST_BODY_PROVIDED)], r.URL.Path)) return } err := ioutil.WriteFile(fileName, body, 0644) if err != nil { u.ApiResponse(w, u.ApiMessage(uint32(constants.UPLOAD_FILE_FAILURE), u.GetMessage()[uint32(constants.UPLOAD_FILE_FAILURE)], err.Error(), r.URL.Path)) return } u.ApiResponse(w, u.ApiMessage(uint32(constants.SUCCESS), u.GetMessage()[uint32(constants.SUCCESS)], u.GetMessage()[uint32(constants.SUCCESS)], r.URL.Path)) }
View Source
var SetEnvVars = func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { env := environment.GetInstance() body, err := ioutil.ReadAll(r.Body) attemptedEnvVars := make(map[string]string) if err != nil { u.ApiResponse(w, u.ApiMessage(uint32(constants.SET_ENV_VAR_FAILURE), fmt.Sprintf(u.GetMessage()[uint32(constants.SET_ENV_VAR_FAILURE)], string(body)), err.Error(), r.URL.Path)) return } err = json.Unmarshal(body, &attemptedEnvVars) if err != nil { u.ApiResponse(w, u.ApiMessage(uint32(constants.SET_ENV_VAR_FAILURE), fmt.Sprintf(u.GetMessage()[uint32(constants.SET_ENV_VAR_FAILURE)], string(body)), err.Error(), r.URL.Path)) return } addedEnvVars := env.SetEnvVars(attemptedEnvVars) u.ApiResponse(w, u.ApiMessage(uint32(constants.SUCCESS), u.GetMessage()[uint32(constants.SUCCESS)], addedEnvVars, r.URL.Path)) }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.