diff --git a/src/bunker.go b/src/bunker.go index a5989ba..0232fe0 100644 --- a/src/bunker.go +++ b/src/bunker.go @@ -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"` } diff --git a/src/cryptor.go b/src/cryptor.go index 255ab58..178cad8 100644 --- a/src/cryptor.go +++ b/src/cryptor.go @@ -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) diff --git a/src/expiration_test.go b/src/expiration_test.go index d583df4..f7e8c45 100644 --- a/src/expiration_test.go +++ b/src/expiration_test.go @@ -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") diff --git a/src/geoip.go b/src/geoip.go index c24e555..5f7c645 100644 --- a/src/geoip.go +++ b/src/geoip.go @@ -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") diff --git a/src/notify.go b/src/notify.go index 5a15e2c..44da387 100644 --- a/src/notify.go +++ b/src/notify.go @@ -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") diff --git a/src/requests_api.go b/src/requests_api.go index c6403c8..b674921 100644 --- a/src/requests_api.go +++ b/src/requests_api.go @@ -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" { diff --git a/src/schema.go b/src/schema.go index eccc6b2..42f0351 100644 --- a/src/schema.go +++ b/src/schema.go @@ -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 diff --git a/src/storage/mysql-storage.go b/src/storage/mysql-storage.go index 0f81f42..48a1c8a 100644 --- a/src/storage/mysql-storage.go +++ b/src/storage/mysql-storage.go @@ -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 } diff --git a/src/storage/pgsql-storage.go b/src/storage/pgsql-storage.go index e8df897..6a19008 100644 --- a/src/storage/pgsql-storage.go +++ b/src/storage/pgsql-storage.go @@ -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{}) { diff --git a/src/storage/sqlite-storage.go b/src/storage/sqlite-storage.go index 8a0a895..ca31179 100644 --- a/src/storage/sqlite-storage.go +++ b/src/storage/sqlite-storage.go @@ -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 } diff --git a/src/storage/storage.go b/src/storage/storage.go index 191a51a..e8c24bb 100644 --- a/src/storage/storage.go +++ b/src/storage/storage.go @@ -38,7 +38,7 @@ var TblName = &listTbls{ } var ( - allTables []string + allTables []string ) func GetTable(t Tbl) string { diff --git a/src/userapps_db.go b/src/userapps_db.go index 85a4642..02f7e98 100644 --- a/src/userapps_db.go +++ b/src/userapps_db.go @@ -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 { diff --git a/src/userapps_test.go b/src/userapps_test.go index 0dce58f..3c8980a 100644 --- a/src/userapps_test.go +++ b/src/userapps_test.go @@ -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) { diff --git a/src/users_api.go b/src/users_api.go index ca2ecdf..da838e6 100644 --- a/src/users_api.go +++ b/src/users_api.go @@ -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 } diff --git a/src/users_db.go b/src/users_db.go index b0ac8f5..65afce4 100644 --- a/src/users_db.go +++ b/src/users_db.go @@ -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 { diff --git a/src/users_test.go b/src/users_test.go index 8220219..84feeec 100644 --- a/src/users_test.go +++ b/src/users_test.go @@ -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) { diff --git a/src/utils_test.go b/src/utils_test.go index 2d4536a..51b881e 100644 --- a/src/utils_test.go +++ b/src/utils_test.go @@ -2,8 +2,8 @@ package main import ( "fmt" - "log" "io/ioutil" + "log" "net/http" "net/http/httptest" "strings"