|
@@ -97,6 +97,8 @@ func (g *Gateway) AddExternalEndPoint(w http.ResponseWriter, r *http.Request) {
|
|
common.SendErrorResponse(w, "Bad parameter")
|
|
common.SendErrorResponse(w, "Bad parameter")
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // put the data in then marshal
|
|
id := uuid.New().String()
|
|
id := uuid.New().String()
|
|
|
|
|
|
dat.Path = path
|
|
dat.Path = path
|
|
@@ -109,6 +111,7 @@ func (g *Gateway) AddExternalEndPoint(w http.ResponseWriter, r *http.Request) {
|
|
}
|
|
}
|
|
sysdb.Write("external_agi", id, string(jsonStr))
|
|
sysdb.Write("external_agi", id, string(jsonStr))
|
|
|
|
|
|
|
|
+ // send the uuid to frontend
|
|
common.SendJSONResponse(w, "\""+id+"\"")
|
|
common.SendJSONResponse(w, "\""+id+"\"")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -130,17 +133,21 @@ func (g *Gateway) RemoveExternalEndPoint(w http.ResponseWriter, r *http.Request)
|
|
common.SendErrorResponse(w, "Bad parameter")
|
|
common.SendErrorResponse(w, "Bad parameter")
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // check if endpoint is here
|
|
data, isExist := g.checkIfExternalEndpointExist(uuid)
|
|
data, isExist := g.checkIfExternalEndpointExist(uuid)
|
|
if !isExist {
|
|
if !isExist {
|
|
common.SendErrorResponse(w, "UUID does not exists in the database!")
|
|
common.SendErrorResponse(w, "UUID does not exists in the database!")
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // make sure user cant see other's endpoint
|
|
if data.Username != userInfo.Username {
|
|
if data.Username != userInfo.Username {
|
|
common.SendErrorResponse(w, "Bad Request, you have no permission to access this UUID entry!")
|
|
common.SendErrorResponse(w, "Bad Request, you have no permission to access this UUID entry!")
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // delete record
|
|
sysdb.Delete("external_agi", uuid)
|
|
sysdb.Delete("external_agi", uuid)
|
|
|
|
|
|
common.SendOK(w)
|
|
common.SendOK(w)
|
|
@@ -181,6 +188,7 @@ func (g *Gateway) ListExternalEndpoint(w http.ResponseWriter, r *http.Request) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // marhsal and return
|
|
returnJson, err := json.Marshal(dataFromDB)
|
|
returnJson, err := json.Marshal(dataFromDB)
|
|
if err != nil {
|
|
if err != nil {
|
|
common.SendErrorResponse(w, "Bad JSON")
|
|
common.SendErrorResponse(w, "Bad JSON")
|
|
@@ -197,10 +205,12 @@ func (g *Gateway) checkIfExternalEndpointExist(uuid string) (endpointFormat, boo
|
|
}
|
|
}
|
|
var dat endpointFormat
|
|
var dat endpointFormat
|
|
|
|
|
|
|
|
+ // check if key exist
|
|
if !sysdb.KeyExists("external_agi", uuid) {
|
|
if !sysdb.KeyExists("external_agi", uuid) {
|
|
return dat, false
|
|
return dat, false
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // if yes then return the value
|
|
jsonData := ""
|
|
jsonData := ""
|
|
sysdb.Read("external_agi", uuid, &jsonData)
|
|
sysdb.Read("external_agi", uuid, &jsonData)
|
|
json.Unmarshal([]byte(jsonData), &dat)
|
|
json.Unmarshal([]byte(jsonData), &dat)
|