mirror of
https://github.com/optim-enterprises-bv/databunker.git
synced 2025-11-01 18:38:06 +00:00
add userapp delete operation
This commit is contained in:
@@ -211,6 +211,7 @@ func (e mainEnv) setupRouter() *httprouter.Router {
|
||||
router.POST("/v1/userapp/token/:token/:appname", e.userappNew)
|
||||
router.GET("/v1/userapp/token/:token/:appname", e.userappGet)
|
||||
router.PUT("/v1/userapp/token/:token/:appname", e.userappChange)
|
||||
router.DELETE("/v1/userapp/token/:token/:appname", e.userappDelete)
|
||||
router.GET("/v1/userapp/token/:token", e.userappList)
|
||||
router.GET("/v1/userapps", e.appList)
|
||||
|
||||
|
||||
@@ -179,6 +179,31 @@ func (e mainEnv) userappGet(w http.ResponseWriter, r *http.Request, ps httproute
|
||||
w.Write([]byte(finalJSON))
|
||||
}
|
||||
|
||||
func (e mainEnv) userappDelete(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
userTOKEN := ps.ByName("token")
|
||||
appName := strings.ToLower(ps.ByName("appname"))
|
||||
event := auditApp("delete user app record", userTOKEN, appName, "token", userTOKEN)
|
||||
defer func() { event.submit(e.db) }()
|
||||
|
||||
if enforceUUID(w, userTOKEN, event) == false {
|
||||
return
|
||||
}
|
||||
if e.enforceAuth(w, r, event) == "" {
|
||||
return
|
||||
}
|
||||
if isValidApp(appName) == false {
|
||||
returnError(w, r, "bad appname", 405, nil, event)
|
||||
return
|
||||
}
|
||||
|
||||
e.db.deleteUserApp(userTOKEN, appName)
|
||||
|
||||
finalJSON := fmt.Sprintf(`{"status":"ok","token":"%s"}`, userTOKEN)
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(200)
|
||||
w.Write([]byte(finalJSON))
|
||||
}
|
||||
|
||||
func (e mainEnv) appList(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
fmt.Printf("/APPLIST\n")
|
||||
if e.enforceAuth(w, r, nil) == "" {
|
||||
|
||||
@@ -25,6 +25,11 @@ func (dbobj dbcon) getUserApp(userTOKEN string, appName string) ([]byte, error)
|
||||
return dbobj.userDecrypt(userTOKEN, encData0)
|
||||
}
|
||||
|
||||
func (dbobj dbcon) deleteUserApp(userTOKEN string, appName string) {
|
||||
appNameFull := "app_" + appName
|
||||
dbobj.store.DeleteRecordInTable(appNameFull, "token", userTOKEN)
|
||||
}
|
||||
|
||||
func (dbobj dbcon) createAppRecord(jsonData []byte, userTOKEN string, appName string, event *auditEvent) (string, error) {
|
||||
fmt.Printf("createAppRecord app is : %s\n", appName)
|
||||
encodedStr, err := dbobj.userEncrypt(userTOKEN, jsonData)
|
||||
|
||||
Reference in New Issue
Block a user