Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
stremovsky committed Jan 27, 2025
1 parent d3c5d0c commit eea53ab
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 31 deletions.
2 changes: 1 addition & 1 deletion docker-build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh

VERSION=$(cat ./version.txt)
docker build --progress=plain -t securitybunker/databunker:$VERSION .
BUILDKIT_PROGRESS=plain docker build -t securitybunker/databunker:$VERSION .
docker tag securitybunker/databunker:$VERSION securitybunker/databunker:latest
40 changes: 40 additions & 0 deletions src/userlist_api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"fmt"
"log"
"net/http"

"github.com/julienschmidt/httprouter"
"github.com/securitybunker/databunker/src/utils"
)

func (e mainEnv) userList(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if e.EnforceAdmin(w, r, nil) == "" {
return
}
if e.conf.Generic.ListUsers == false {
utils.ReturnError(w, r, "access denied", 403, nil, nil)
return
}
var offset int32 = 0
var limit int32 = 10
args := r.URL.Query()
if value, ok := args["offset"]; ok {
offset = utils.Atoi(value[0])
}
if value, ok := args["limit"]; ok {
limit = utils.Atoi(value[0])
}
resultJSON, counter, _ := e.db.getUsers(offset, limit)
log.Printf("Total count of events: %d\n", counter)
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200)
if counter == 0 {
str := fmt.Sprintf(`{"status":"ok","total":%d,"rows":[]}`, counter)
w.Write([]byte(str))
} else {
str := fmt.Sprintf(`{"status":"ok","total":%d,"rows":%s}`, counter, resultJSON)
w.Write([]byte(str))
}
}
30 changes: 0 additions & 30 deletions src/users_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,36 +167,6 @@ func (e mainEnv) userGet(w http.ResponseWriter, r *http.Request, ps httprouter.P
w.Write([]byte(finalJSON))
}

func (e mainEnv) userList(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if e.EnforceAdmin(w, r, nil) == "" {
return
}
if e.conf.Generic.ListUsers == false {
utils.ReturnError(w, r, "access denied", 403, nil, nil)
return
}
var offset int32 = 0
var limit int32 = 10
args := r.URL.Query()
if value, ok := args["offset"]; ok {
offset = utils.Atoi(value[0])
}
if value, ok := args["limit"]; ok {
limit = utils.Atoi(value[0])
}
resultJSON, counter, _ := e.db.getUsers(offset, limit)
log.Printf("Total count of events: %d\n", counter)
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200)
if counter == 0 {
str := fmt.Sprintf(`{"status":"ok","total":%d,"rows":[]}`, counter)
w.Write([]byte(str))
} else {
str := fmt.Sprintf(`{"status":"ok","total":%d,"rows":%s}`, counter, resultJSON)
w.Write([]byte(str))
}
}

func (e mainEnv) userChange(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
identity := ps.ByName("identity")
mode := ps.ByName("mode")
Expand Down

0 comments on commit eea53ab

Please sign in to comment.