mirror of
https://github.com/optim-enterprises-bv/databunker.git
synced 2025-10-29 17:12:22 +00:00
format go code
This commit is contained in:
@@ -47,7 +47,7 @@ type Config struct {
|
||||
CreateUserWithoutAccessToken bool `yaml:"create_user_without_access_token" default:"false"`
|
||||
UseSeparateAppTables bool `yaml:"use_separate_app_tables" default:"false"`
|
||||
UserRecordSchema string `yaml:"user_record_schema"`
|
||||
DisableAudit bool `yaml:"disable_audit" default:"false"`
|
||||
DisableAudit bool `yaml:"disable_audit" default:"false"`
|
||||
AdminEmail string `yaml:"admin_email" envconfig:"ADMIN_EMAIL"`
|
||||
ListUsers bool `yaml:"list_users" default:"false"`
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func decrypt(masterKey []byte, userKey []byte, data []byte) ([]byte, error) {
|
||||
// DO NOT USE THE FOLLOWING LINE. It is broken!!!
|
||||
//key := append(masterKey, userKey...)
|
||||
la := len(masterKey)
|
||||
key := make([]byte, la + len(userKey))
|
||||
key := make([]byte, la+len(userKey))
|
||||
copy(key, masterKey)
|
||||
copy(key[la:], userKey)
|
||||
|
||||
@@ -59,7 +59,7 @@ func encrypt(masterKey []byte, userKey []byte, plaintext []byte) ([]byte, error)
|
||||
// comprising 24 master key
|
||||
// and 8 bytes record key
|
||||
la := len(masterKey)
|
||||
key := make([]byte, la + len(userKey))
|
||||
key := make([]byte, la+len(userKey))
|
||||
copy(key, masterKey)
|
||||
copy(key[la:], userKey)
|
||||
|
||||
@@ -81,7 +81,7 @@ func encrypt(masterKey []byte, userKey []byte, plaintext []byte) ([]byte, error)
|
||||
// apppend random nonce bvalue to the end
|
||||
//ciphertext := append(ciphertext0, nonce...)
|
||||
la = len(ciphertext0)
|
||||
ciphertext := make([]byte, la + len(nonce))
|
||||
ciphertext := make([]byte, la+len(nonce))
|
||||
copy(ciphertext, ciphertext0)
|
||||
copy(ciphertext[la:], nonce)
|
||||
return ciphertext, nil
|
||||
@@ -91,7 +91,7 @@ func basicStringEncrypt(plaintext string, masterKey []byte, code []byte) (string
|
||||
//log.Printf("Going to encrypt %s", plaintext)
|
||||
nonce := []byte("$DataBunker$")
|
||||
la := len(masterKey)
|
||||
key := make([]byte, la + len(code))
|
||||
key := make([]byte, la+len(code))
|
||||
copy(key, masterKey)
|
||||
copy(key[la:], code)
|
||||
|
||||
@@ -118,7 +118,7 @@ func basicStringDecrypt(data string, masterKey []byte, code []byte) (string, err
|
||||
}
|
||||
nonce := []byte("$DataBunker$")
|
||||
la := len(masterKey)
|
||||
key := make([]byte, la + len(code))
|
||||
key := make([]byte, la+len(code))
|
||||
copy(key, masterKey)
|
||||
copy(key[la:], code)
|
||||
block, err := aes.NewCipher(key)
|
||||
|
||||
@@ -2,10 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"strings"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func helpGetExpStatus(utoken string) (map[string]interface{}, error) {
|
||||
@@ -130,7 +130,7 @@ func TestExpCancel(t *testing.T) {
|
||||
|
||||
func TestExpAuto(t *testing.T) {
|
||||
userJSON := `{"login":"william4"}`
|
||||
now := int32(time.Now().Unix())+1
|
||||
now := int32(time.Now().Unix()) + 1
|
||||
raw, _ := helpCreateUser(userJSON)
|
||||
if _, ok := raw["status"]; !ok || raw["status"].(string) != "ok" {
|
||||
t.Fatalf("Failed to create user")
|
||||
|
||||
@@ -5,16 +5,16 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gobuffalo/packr"
|
||||
"github.com/oschwald/geoip2-golang"
|
||||
)
|
||||
|
||||
var (
|
||||
geoipBytes []byte
|
||||
geoip * geoip2.Reader
|
||||
geoip *geoip2.Reader
|
||||
)
|
||||
|
||||
|
||||
func initGeoIP() {
|
||||
var err error
|
||||
box := packr.NewBox("../ui")
|
||||
|
||||
@@ -56,10 +56,10 @@ func notifyConsentChange(notifyURL string, brief string, status string, mode str
|
||||
return
|
||||
}
|
||||
requestBody, _ := json.Marshal(map[string]string{
|
||||
"action": "consentchange",
|
||||
"brief": brief,
|
||||
"status": status,
|
||||
"mode": mode,
|
||||
"action": "consentchange",
|
||||
"brief": brief,
|
||||
"status": status,
|
||||
"mode": mode,
|
||||
"identity": identity,
|
||||
})
|
||||
host := autocontext.GetAuto("host")
|
||||
|
||||
@@ -217,9 +217,9 @@ func (e mainEnv) approveUserRequest(w http.ResponseWriter, r *http.Request, ps h
|
||||
event.Msg = "failed to delete"
|
||||
}
|
||||
if err != nil {
|
||||
returnError(w, r, "internal error", 405, err, event)
|
||||
return
|
||||
}
|
||||
returnError(w, r, "internal error", 405, err, event)
|
||||
return
|
||||
}
|
||||
notifyURL := e.conf.Notification.NotificationURL
|
||||
notifyForgetMe(notifyURL, userJSON, "token", userTOKEN)
|
||||
} else if action == "change-profile" {
|
||||
|
||||
@@ -20,8 +20,10 @@ var userSchema *jsonschema.Schema
|
||||
|
||||
// IsAdmin - admin/DPO approval is required
|
||||
type IsAdmin bool
|
||||
|
||||
// IsLocked - variable is locked from changes
|
||||
type IsLocked bool
|
||||
|
||||
// IsPreserve variable can never be deleted
|
||||
type IsPreserve bool
|
||||
|
||||
|
||||
@@ -247,15 +247,15 @@ func (dbobj MySQLDB) decodeFieldsValues(data interface{}) (string, []interface{}
|
||||
|
||||
func (dbobj MySQLDB) decodeForCleanup(bdel []string) string {
|
||||
fields := ""
|
||||
if bdel != nil {
|
||||
for _, colname := range bdel {
|
||||
if len(fields) == 0 {
|
||||
fields = dbobj.escapeName(colname) + "=null"
|
||||
} else {
|
||||
fields = fields + "," + dbobj.escapeName(colname) + "=null"
|
||||
}
|
||||
}
|
||||
}
|
||||
if bdel != nil {
|
||||
for _, colname := range bdel {
|
||||
if len(fields) == 0 {
|
||||
fields = dbobj.escapeName(colname) + "=null"
|
||||
} else {
|
||||
fields = fields + "," + dbobj.escapeName(colname) + "=null"
|
||||
}
|
||||
}
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
@@ -281,15 +281,15 @@ func (dbobj MySQLDB) decodeForUpdate(bdoc *bson.M, bdel []string) (string, []int
|
||||
}
|
||||
}
|
||||
|
||||
if bdel != nil {
|
||||
for _, colname := range bdel {
|
||||
if len(fields) == 0 {
|
||||
fields = dbobj.escapeName(colname) + "=null"
|
||||
} else {
|
||||
fields = fields + "," + dbobj.escapeName(colname) + "=null"
|
||||
}
|
||||
}
|
||||
}
|
||||
if bdel != nil {
|
||||
for _, colname := range bdel {
|
||||
if len(fields) == 0 {
|
||||
fields = dbobj.escapeName(colname) + "=null"
|
||||
} else {
|
||||
fields = fields + "," + dbobj.escapeName(colname) + "=null"
|
||||
}
|
||||
}
|
||||
}
|
||||
return fields, values
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ func (dbobj PGSQLDB) getConnectionString(dbname *string) string {
|
||||
//fmt.Printf("myql connection string: %s\n", str0)
|
||||
//str := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s", user, pass, host, port, dbnameString)
|
||||
str := fmt.Sprintf("user='%s' password='%s' host='%s' port='%s' dbname='%s'",
|
||||
user, pass, host, port, dbnameString)
|
||||
user, pass, host, port, dbnameString)
|
||||
return str
|
||||
}
|
||||
|
||||
@@ -123,8 +123,8 @@ func (dbobj *PGSQLDB) OpenDB(dbname *string) error {
|
||||
}
|
||||
dbobj.db = db
|
||||
// load all table names
|
||||
q := "SELECT table_name FROM information_schema.tables where table_schema NOT IN ('pg_catalog', 'information_schema');"
|
||||
tx, err := dbobj.db.Begin()
|
||||
q := "SELECT table_name FROM information_schema.tables where table_schema NOT IN ('pg_catalog', 'information_schema');"
|
||||
tx, err := dbobj.db.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -244,17 +244,17 @@ func (dbobj PGSQLDB) decodeFieldsValues(data interface{}) (string, []interface{}
|
||||
}
|
||||
|
||||
func (dbobj PGSQLDB) decodeForCleanup(bdel []string) string {
|
||||
fields := ""
|
||||
if bdel != nil {
|
||||
for _, colname := range bdel {
|
||||
if len(fields) == 0 {
|
||||
fields = dbobj.escapeName(colname) + "=null"
|
||||
} else {
|
||||
fields = fields + "," + dbobj.escapeName(colname) + "=null"
|
||||
}
|
||||
}
|
||||
}
|
||||
return fields
|
||||
fields := ""
|
||||
if bdel != nil {
|
||||
for _, colname := range bdel {
|
||||
if len(fields) == 0 {
|
||||
fields = dbobj.escapeName(colname) + "=null"
|
||||
} else {
|
||||
fields = fields + "," + dbobj.escapeName(colname) + "=null"
|
||||
}
|
||||
}
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
func (dbobj PGSQLDB) decodeForUpdate(bdoc *bson.M, bdel []string) (string, []interface{}) {
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
_ "modernc.org/sqlite"
|
||||
_ "modernc.org/sqlite"
|
||||
//"github.com/schollz/sqlite3dump"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
@@ -176,13 +176,14 @@ func (dbobj *SQLiteDB) CloseDB() {
|
||||
|
||||
// BackupDB function backups existing database and prints database structure to http.ResponseWriter
|
||||
func (dbobj SQLiteDB) BackupDB(w http.ResponseWriter) {
|
||||
/*
|
||||
err := sqlite3dump.DumpDB(dbobj.db, w)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
log.Printf("error in backup: %s", err)
|
||||
}
|
||||
*/
|
||||
/*
|
||||
err := sqlite3dump.DumpDB(dbobj.db, w)
|
||||
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
log.Printf("error in backup: %s", err)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
func (dbobj SQLiteDB) escapeName(name string) string {
|
||||
@@ -234,17 +235,17 @@ func (dbobj SQLiteDB) decodeFieldsValues(data interface{}) (string, []interface{
|
||||
}
|
||||
|
||||
func (dbobj SQLiteDB) decodeForCleanup(bdel []string) string {
|
||||
fields := ""
|
||||
if bdel != nil {
|
||||
for _, colname := range bdel {
|
||||
if len(fields) == 0 {
|
||||
fields = dbobj.escapeName(colname) + "=null"
|
||||
} else {
|
||||
fields = fields + "," + dbobj.escapeName(colname) + "=null"
|
||||
}
|
||||
}
|
||||
}
|
||||
return fields
|
||||
fields := ""
|
||||
if bdel != nil {
|
||||
for _, colname := range bdel {
|
||||
if len(fields) == 0 {
|
||||
fields = dbobj.escapeName(colname) + "=null"
|
||||
} else {
|
||||
fields = fields + "," + dbobj.escapeName(colname) + "=null"
|
||||
}
|
||||
}
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
func (dbobj SQLiteDB) decodeForUpdate(bdoc *bson.M, bdel []string) (string, []interface{}) {
|
||||
@@ -269,15 +270,15 @@ func (dbobj SQLiteDB) decodeForUpdate(bdoc *bson.M, bdel []string) (string, []in
|
||||
}
|
||||
}
|
||||
|
||||
if bdel != nil {
|
||||
for _, colname := range bdel {
|
||||
if len(fields) == 0 {
|
||||
fields = dbobj.escapeName(colname) + "=null"
|
||||
} else {
|
||||
fields = fields + "," + dbobj.escapeName(colname) + "=null"
|
||||
}
|
||||
}
|
||||
}
|
||||
if bdel != nil {
|
||||
for _, colname := range bdel {
|
||||
if len(fields) == 0 {
|
||||
fields = dbobj.escapeName(colname) + "=null"
|
||||
} else {
|
||||
fields = fields + "," + dbobj.escapeName(colname) + "=null"
|
||||
}
|
||||
}
|
||||
}
|
||||
return fields, values
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ var TblName = &listTbls{
|
||||
}
|
||||
|
||||
var (
|
||||
allTables []string
|
||||
allTables []string
|
||||
)
|
||||
|
||||
func GetTable(t Tbl) string {
|
||||
|
||||
@@ -42,7 +42,7 @@ func (dbobj dbcon) deleteUserApp(userTOKEN string, appName string, conf Config)
|
||||
|
||||
func (dbobj dbcon) deleteUserApps(userTOKEN string, conf Config) {
|
||||
if conf.Generic.UseSeparateAppTables == true {
|
||||
userApps, _:= dbobj.listAllAppsOnly(conf)
|
||||
userApps, _ := dbobj.listAllAppsOnly(conf)
|
||||
// delete all user app records
|
||||
for _, appName := range userApps {
|
||||
appNameFull := "app_" + appName
|
||||
@@ -84,7 +84,7 @@ func (dbobj dbcon) createAppRecord(jsonData []byte, userTOKEN string, appName st
|
||||
}
|
||||
if record != nil {
|
||||
_, err = dbobj.store.UpdateRecordInTable(appNameFull, "token", userTOKEN, &bdoc)
|
||||
} else {
|
||||
} else {
|
||||
_, err = dbobj.store.CreateRecordInTable(appNameFull, bdoc)
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http/httptest"
|
||||
"encoding/json"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
uuid "github.com/hashicorp/go-uuid"
|
||||
jsonpatch "github.com/evanphx/json-patch"
|
||||
uuid "github.com/hashicorp/go-uuid"
|
||||
)
|
||||
|
||||
func helpCreateUserApp(userTOKEN string, appName string, appJSON string) (map[string]interface{}, error) {
|
||||
|
||||
@@ -81,9 +81,9 @@ func (e mainEnv) userCreate(w http.ResponseWriter, r *http.Request, ps httproute
|
||||
}
|
||||
}
|
||||
if len(parsedData.loginIdx) == 0 &&
|
||||
len(parsedData.emailIdx) == 0 &&
|
||||
len(parsedData.phoneIdx) == 0 &&
|
||||
len(parsedData.customIdx) == 0 {
|
||||
len(parsedData.emailIdx) == 0 &&
|
||||
len(parsedData.phoneIdx) == 0 &&
|
||||
len(parsedData.customIdx) == 0 {
|
||||
returnError(w, r, "failed to create user, all user lookup fields are missing", 405, err, event)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -454,7 +454,6 @@ func (dbobj dbcon) dumpUserPII(email string, conf Config) (string, error) {
|
||||
return fullJSON, err
|
||||
}
|
||||
|
||||
|
||||
func (dbobj dbcon) getUserJSONByIndex(indexValue string, indexName string, conf Config) ([]byte, string, error) {
|
||||
userBson, err := dbobj.lookupUserRecordByIndex(indexName, indexValue, conf)
|
||||
if userBson == nil || err != nil {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
uuid "github.com/hashicorp/go-uuid"
|
||||
jsonpatch "github.com/evanphx/json-patch"
|
||||
uuid "github.com/hashicorp/go-uuid"
|
||||
)
|
||||
|
||||
func helpCreateUser(userJSON string) (map[string]interface{}, error) {
|
||||
|
||||
@@ -2,8 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
|
||||
Reference in New Issue
Block a user