|
@@ -23,7 +23,7 @@ func (g *Gateway) ExtAPIHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
sysdb := g.Option.UserHandler.GetDatabase()
|
|
|
|
|
|
if !sysdb.TableExists("external_agi") {
|
|
|
- common.SendErrorResponse(w, "Bad Request, invaild database")
|
|
|
+ common.SendErrorResponse(w, "Invalid Request")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -33,7 +33,7 @@ func (g *Gateway) ExtAPIHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
// check if it contains only two part, [rexec uuid]
|
|
|
if len(subpathElements) != 3 {
|
|
|
- common.SendErrorResponse(w, "Bad Request, invaild request sent")
|
|
|
+ common.SendErrorResponse(w, "Invalid Request")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -41,7 +41,7 @@ func (g *Gateway) ExtAPIHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
// get the info from the database
|
|
|
data, isExist := g.checkIfExternalEndpointExist(subpathElements[2])
|
|
|
if !isExist {
|
|
|
- common.SendErrorResponse(w, "Bad Request, invaild UUID entered")
|
|
|
+ common.SendErrorResponse(w, "Malform Request, invaild UUID given")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -51,12 +51,12 @@ func (g *Gateway) ExtAPIHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
// get the userinfo and the realPath
|
|
|
userInfo, err := g.Option.UserHandler.GetUserInfoFromUsername(usernameFromDb)
|
|
|
if err != nil {
|
|
|
- common.SendErrorResponse(w, "Bad username")
|
|
|
+ common.SendErrorResponse(w, "Invalid username")
|
|
|
return
|
|
|
}
|
|
|
_, realPath, err := virtualPathToRealPath(pathFromDb, userInfo)
|
|
|
if err != nil {
|
|
|
- common.SendErrorResponse(w, "Bad filepath")
|
|
|
+ common.SendErrorResponse(w, "Invalid filepath")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -79,7 +79,7 @@ func (g *Gateway) ExtAPIHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
func (g *Gateway) AddExternalEndPoint(w http.ResponseWriter, r *http.Request) {
|
|
|
userInfo, err := g.Option.UserHandler.GetUserInfoFromRequest(w, r)
|
|
|
if err != nil {
|
|
|
- common.SendErrorResponse(w, "Bad user!")
|
|
|
+ common.SendErrorResponse(w, "User not logged in")
|
|
|
return
|
|
|
}
|
|
|
// get db
|
|
@@ -92,7 +92,7 @@ func (g *Gateway) AddExternalEndPoint(w http.ResponseWriter, r *http.Request) {
|
|
|
// uuid: [path, id]
|
|
|
path, err := common.Mv(r, "path", false)
|
|
|
if err != nil {
|
|
|
- common.SendErrorResponse(w, "Bad parameter")
|
|
|
+ common.SendErrorResponse(w, "Invalid path given")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -104,7 +104,7 @@ func (g *Gateway) AddExternalEndPoint(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
jsonStr, err := json.Marshal(dat)
|
|
|
if err != nil {
|
|
|
- common.SendErrorResponse(w, "Bad JSON")
|
|
|
+ common.SendErrorResponse(w, "Invalid JSON string: " + err.Error())
|
|
|
return
|
|
|
}
|
|
|
sysdb.Write("external_agi", id, string(jsonStr))
|
|
@@ -116,7 +116,7 @@ func (g *Gateway) AddExternalEndPoint(w http.ResponseWriter, r *http.Request) {
|
|
|
func (g *Gateway) RemoveExternalEndPoint(w http.ResponseWriter, r *http.Request) {
|
|
|
userInfo, err := g.Option.UserHandler.GetUserInfoFromRequest(w, r)
|
|
|
if err != nil {
|
|
|
- common.SendErrorResponse(w, "Bad User")
|
|
|
+ common.SendErrorResponse(w, "User not logged in")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -128,7 +128,7 @@ func (g *Gateway) RemoveExternalEndPoint(w http.ResponseWriter, r *http.Request)
|
|
|
// get path
|
|
|
uuid, err := common.Mv(r, "uuid", false)
|
|
|
if err != nil {
|
|
|
- common.SendErrorResponse(w, "Bad parameter")
|
|
|
+ common.SendErrorResponse(w, "Invalid uuid given")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -141,7 +141,7 @@ func (g *Gateway) RemoveExternalEndPoint(w http.ResponseWriter, r *http.Request)
|
|
|
|
|
|
// make sure user cant see other's endpoint
|
|
|
if data.Username != userInfo.Username {
|
|
|
- common.SendErrorResponse(w, "Bad Request, you have no permission to access this UUID entry!")
|
|
|
+ common.SendErrorResponse(w, "Permission denied")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -154,7 +154,7 @@ func (g *Gateway) RemoveExternalEndPoint(w http.ResponseWriter, r *http.Request)
|
|
|
func (g *Gateway) ListExternalEndpoint(w http.ResponseWriter, r *http.Request) {
|
|
|
userInfo, err := g.Option.UserHandler.GetUserInfoFromRequest(w, r)
|
|
|
if err != nil {
|
|
|
- common.SendErrorResponse(w, "Bad User")
|
|
|
+ common.SendErrorResponse(w, "User not logged in")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -170,7 +170,7 @@ func (g *Gateway) ListExternalEndpoint(w http.ResponseWriter, r *http.Request) {
|
|
|
// O(n) method to do the lookup
|
|
|
entries, err := sysdb.ListTable("external_agi")
|
|
|
if err != nil {
|
|
|
- common.SendErrorResponse(w, "Bad table")
|
|
|
+ common.SendErrorResponse(w, "Invalid table")
|
|
|
return
|
|
|
}
|
|
|
for _, keypairs := range entries {
|
|
@@ -189,7 +189,7 @@ func (g *Gateway) ListExternalEndpoint(w http.ResponseWriter, r *http.Request) {
|
|
|
// marhsal and return
|
|
|
returnJson, err := json.Marshal(dataFromDB)
|
|
|
if err != nil {
|
|
|
- common.SendErrorResponse(w, "Bad JSON")
|
|
|
+ common.SendErrorResponse(w, "Invalid JSON: " + err.Error())
|
|
|
return
|
|
|
}
|
|
|
sendJSONResponse(w, string(returnJson))
|