mirror of
https://github.com/optim-enterprises-bv/databunker.git
synced 2025-10-31 18:07:47 +00:00
code optimization
This commit is contained in:
@@ -40,8 +40,7 @@ func (e mainEnv) getAuditEvents(w http.ResponseWriter, r *http.Request, ps httpr
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e mainEnv) getAdminAuditEvents(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
func (e mainEnv) getAdminAuditEvents(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
authResult := e.enforceAdmin(w, r)
|
if e.enforceAdmin(w, r) == "" {
|
||||||
if authResult == "" {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var offset int32
|
var offset int32
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ import (
|
|||||||
|
|
||||||
func (e mainEnv) createLegalBasis(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
func (e mainEnv) createLegalBasis(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
brief := ps.ByName("brief")
|
brief := ps.ByName("brief")
|
||||||
authResult := e.enforceAdmin(w, r)
|
if e.enforceAdmin(w, r) == "" {
|
||||||
if authResult == "" {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
brief = normalizeBrief(brief)
|
brief = normalizeBrief(brief)
|
||||||
@@ -83,8 +82,7 @@ func (e mainEnv) createLegalBasis(w http.ResponseWriter, r *http.Request, ps htt
|
|||||||
|
|
||||||
func (e mainEnv) deleteLegalBasis(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
func (e mainEnv) deleteLegalBasis(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
brief := ps.ByName("brief")
|
brief := ps.ByName("brief")
|
||||||
authResult := e.enforceAdmin(w, r)
|
if e.enforceAdmin(w, r) == "" {
|
||||||
if authResult == "" {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
brief = normalizeBrief(brief)
|
brief = normalizeBrief(brief)
|
||||||
@@ -100,8 +98,7 @@ func (e mainEnv) deleteLegalBasis(w http.ResponseWriter, r *http.Request, ps htt
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e mainEnv) listLegalBasisRecords(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
func (e mainEnv) listLegalBasisRecords(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
authResult := e.enforceAdmin(w, r)
|
if e.enforceAdmin(w, r) == "" {
|
||||||
if authResult == "" {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resultJSON, numRecords, err := e.db.getLegalBasisRecords()
|
resultJSON, numRecords, err := e.db.getLegalBasisRecords()
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ import (
|
|||||||
|
|
||||||
func (e mainEnv) pactivityCreate(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
func (e mainEnv) pactivityCreate(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
activity := ps.ByName("activity")
|
activity := ps.ByName("activity")
|
||||||
authResult := e.enforceAdmin(w, r)
|
if e.enforceAdmin(w, r) == "" {
|
||||||
if authResult == "" {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
activity = normalizeBrief(activity)
|
activity = normalizeBrief(activity)
|
||||||
@@ -71,8 +70,7 @@ func (e mainEnv) pactivityCreate(w http.ResponseWriter, r *http.Request, ps http
|
|||||||
|
|
||||||
func (e mainEnv) pactivityDelete(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
func (e mainEnv) pactivityDelete(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
activity := ps.ByName("activity")
|
activity := ps.ByName("activity")
|
||||||
authResult := e.enforceAdmin(w, r)
|
if e.enforceAdmin(w, r) == "" {
|
||||||
if authResult == "" {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
activity = normalizeBrief(activity)
|
activity = normalizeBrief(activity)
|
||||||
@@ -89,8 +87,7 @@ func (e mainEnv) pactivityDelete(w http.ResponseWriter, r *http.Request, ps http
|
|||||||
func (e mainEnv) pactivityLink(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
func (e mainEnv) pactivityLink(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
activity := ps.ByName("activity")
|
activity := ps.ByName("activity")
|
||||||
brief := ps.ByName("brief")
|
brief := ps.ByName("brief")
|
||||||
authResult := e.enforceAdmin(w, r)
|
if e.enforceAdmin(w, r) == "" {
|
||||||
if authResult == "" {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
activity = normalizeBrief(activity)
|
activity = normalizeBrief(activity)
|
||||||
@@ -125,8 +122,7 @@ func (e mainEnv) pactivityLink(w http.ResponseWriter, r *http.Request, ps httpro
|
|||||||
func (e mainEnv) pactivityUnlink(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
func (e mainEnv) pactivityUnlink(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
activity := ps.ByName("activity")
|
activity := ps.ByName("activity")
|
||||||
brief := ps.ByName("brief")
|
brief := ps.ByName("brief")
|
||||||
authResult := e.enforceAdmin(w, r)
|
if e.enforceAdmin(w, r) == "" {
|
||||||
if authResult == "" {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
activity = normalizeBrief(activity)
|
activity = normalizeBrief(activity)
|
||||||
@@ -150,8 +146,7 @@ func (e mainEnv) pactivityUnlink(w http.ResponseWriter, r *http.Request, ps http
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e mainEnv) pactivityList(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
func (e mainEnv) pactivityList(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
authResult := e.enforceAdmin(w, r)
|
if e.enforceAdmin(w, r) == "" {
|
||||||
if authResult == "" {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resultJSON, numRecords, err := e.db.listProcessingActivities()
|
resultJSON, numRecords, err := e.db.listProcessingActivities()
|
||||||
|
|||||||
@@ -114,8 +114,7 @@ func (e mainEnv) getUserRequest(w http.ResponseWriter, r *http.Request, ps httpr
|
|||||||
if len(userTOKEN) != 0 {
|
if len(userTOKEN) != 0 {
|
||||||
event.Record = userTOKEN
|
event.Record = userTOKEN
|
||||||
}
|
}
|
||||||
authResult := e.enforceAuth(w, r, event)
|
if e.enforceAdmin(w, r) == "" {
|
||||||
if authResult == "" {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
change := getStringValue(requestInfo["change"])
|
change := getStringValue(requestInfo["change"])
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
uuid "github.com/hashicorp/go-uuid"
|
uuid "github.com/hashicorp/go-uuid"
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
"github.com/securitybunker/databunker/src/storage"
|
"github.com/securitybunker/databunker/src/storage"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (e mainEnv) createSession(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
func (e mainEnv) createSession(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
@@ -23,8 +24,7 @@ func (e mainEnv) createSession(w http.ResponseWriter, r *http.Request, ps httpro
|
|||||||
//returnError(w, r, "bad session format", nil, event)
|
//returnError(w, r, "bad session format", nil, event)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
authResult := e.enforceAdmin(w, r)
|
if e.enforceAdmin(w, r) == "" {
|
||||||
if authResult == "" {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
expiration := e.conf.Policy.MaxSessionRetentionPeriod
|
expiration := e.conf.Policy.MaxSessionRetentionPeriod
|
||||||
@@ -77,8 +77,7 @@ func (e mainEnv) deleteSession(w http.ResponseWriter, r *http.Request, ps httpro
|
|||||||
//returnError(w, r, "bad session format", nil, event)
|
//returnError(w, r, "bad session format", nil, event)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
authResult := e.enforceAdmin(w, r)
|
if e.enforceAdmin(w, r) == "" {
|
||||||
if authResult == "" {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
e.db.deleteSession(session)
|
e.db.deleteSession(session)
|
||||||
@@ -147,7 +146,6 @@ func (e mainEnv) newUserSession(w http.ResponseWriter, r *http.Request, ps httpr
|
|||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
w.WriteHeader(200)
|
w.WriteHeader(200)
|
||||||
fmt.Fprintf(w, `{"status":"ok","session":"%s"}`, sessionID)
|
fmt.Fprintf(w, `{"status":"ok","session":"%s"}`, sessionID)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e mainEnv) getUserSessions(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
func (e mainEnv) getUserSessions(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
@@ -201,7 +199,6 @@ func (e mainEnv) getUserSessions(w http.ResponseWriter, r *http.Request, ps http
|
|||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
w.WriteHeader(200)
|
w.WriteHeader(200)
|
||||||
fmt.Fprintf(w, `{"status":"ok","total":%d,"rows":[%s]}`, count, data)
|
fmt.Fprintf(w, `{"status":"ok","total":%d,"rows":[%s]}`, count, data)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e mainEnv) getSession(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
func (e mainEnv) getSession(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
@@ -227,5 +224,4 @@ func (e mainEnv) getSession(w http.ResponseWriter, r *http.Request, ps httproute
|
|||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
w.WriteHeader(200)
|
w.WriteHeader(200)
|
||||||
fmt.Fprintf(w, `{"status":"ok","session":"%s","when":%d,"data":%s}`, session, when, record)
|
fmt.Fprintf(w, `{"status":"ok","session":"%s","when":%d,"data":%s}`, session, when, record)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ func (e mainEnv) userGet(w http.ResponseWriter, r *http.Request, ps httprouter.P
|
|||||||
mode := ps.ByName("mode")
|
mode := ps.ByName("mode")
|
||||||
event := audit("get user record by "+mode, identity, mode, identity)
|
event := audit("get user record by "+mode, identity, mode, identity)
|
||||||
defer func() { event.submit(e.db, e.conf) }()
|
defer func() { event.submit(e.db, e.conf) }()
|
||||||
|
|
||||||
if validateMode(mode) == false {
|
if validateMode(mode) == false {
|
||||||
returnError(w, r, "bad mode", 405, nil, event)
|
returnError(w, r, "bad mode", 405, nil, event)
|
||||||
return
|
return
|
||||||
@@ -165,8 +166,7 @@ func (e mainEnv) userGet(w http.ResponseWriter, r *http.Request, ps httprouter.P
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e mainEnv) userList(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
func (e mainEnv) userList(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
authResult := e.enforceAdmin(w, r)
|
if e.enforceAdmin(w, r) == "" {
|
||||||
if authResult == "" {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if e.conf.Generic.ListUsers == false {
|
if e.conf.Generic.ListUsers == false {
|
||||||
|
|||||||
Reference in New Issue
Block a user