Skip to content

Commit

Permalink
format go code
Browse files Browse the repository at this point in the history
  • Loading branch information
stremovsky committed Aug 6, 2024
1 parent 8b2cd99 commit 67cfade
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 90 deletions.
2 changes: 1 addition & 1 deletion src/bunker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down
10 changes: 5 additions & 5 deletions src/cryptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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)

Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/expiration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package main

import (
"fmt"
"time"
"strings"
"net/http/httptest"
"strings"
"testing"
"time"
)

func helpGetExpStatus(utoken string) (map[string]interface{}, error) {
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions src/geoip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions src/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions src/requests_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
2 changes: 2 additions & 0 deletions src/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 18 additions & 18 deletions src/storage/mysql-storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
28 changes: 14 additions & 14 deletions src/storage/pgsql-storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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{}) {
Expand Down
57 changes: 29 additions & 28 deletions src/storage/sqlite-storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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{}) {
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var TblName = &listTbls{
}

var (
allTables []string
allTables []string
)

func GetTable(t Tbl) string {
Expand Down
4 changes: 2 additions & 2 deletions src/userapps_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/userapps_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/users_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion src/users_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/users_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Loading

0 comments on commit 67cfade

Please sign in to comment.