From b7c40ca03c6d0e31f32386d610dd0eaa74e7043f Mon Sep 17 00:00:00 2001 From: stremovsky Date: Tue, 7 Jan 2020 13:40:22 +0200 Subject: [PATCH] fix linter errors --- src/bunker.go | 30 +++++++++++++++--------------- src/consent_api.go | 18 +++++++++--------- src/consent_db.go | 6 +++--- src/email.go | 8 ++++---- src/notify.go | 28 ++++++++++++++-------------- src/sessions_api.go | 4 ++-- src/sharedrecords_api.go | 4 ++-- src/sms.go | 6 +++--- src/users_api.go | 16 ++++++++-------- src/users_db.go | 2 +- 10 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/bunker.go b/src/bunker.go index ba3c112..c30760d 100644 --- a/src/bunker.go +++ b/src/bunker.go @@ -56,25 +56,25 @@ type Config struct { ForgetmeNotificationURL string `yaml:"forgetme_notification_url"` } Policy struct { - Max_audit_retention_period string `yaml:"max_audit_retention_period"` - Max_session_retention_period string `yaml:"max_session_retention_period"` - Max_shareable_record_retention_period string `yaml:"max_shareable_record_retention_period"` + MaxAuditRetentionPeriod string `yaml:"max_audit_retention_period"` + MaxSessionRetentionPeriod string `yaml:"max_session_retention_period"` + MaxShareableRecordRetentionPeriod string `yaml:"max_shareable_record_retention_period"` } Ssl struct { - Ssl_certificate string `yaml:"ssl_certificate", envconfig:"SSL_CERTIFICATE"` - Ssl_certificate_key string `yaml:"ssl_certificate_key", envconfig:"SSL_CERTIFICATE_KEY"` + SslCertificate string `yaml:"ssl_certificate", envconfig:"SSL_CERTIFICATE"` + SslCertificateKey string `yaml:"ssl_certificate_key", envconfig:"SSL_CERTIFICATE_KEY"` } Sms struct { - Default_country string `yaml:"default_country"` - Twilio_account string `yaml:"twilio_account"` - Twilio_token string `yaml:"twilio_token"` - Twilio_from string `yaml:"twilio_from"` + DefaultCountry string `yaml:"default_country"` + TwilioAccount string `yaml:"twilio_account"` + TwilioToken string `yaml:"twilio_token"` + TwilioFrom string `yaml:"twilio_from"` } Server struct { Port string `yaml:"port", envconfig:"BUNKER_PORT"` Host string `yaml:"host", envconfig:"BUNKER_HOST"` } `yaml:"server"` - Smtp struct { + SMTP struct { Server string `yaml:"server", envconfig:"SMTP_SERVER"` Port string `yaml:"port", envconfig:"SMTP_PORT"` User string `yaml:"user", envconfig:"SMTP_USER"` @@ -260,12 +260,12 @@ func (e mainEnv) dbCleanup() { select { case <-ticker.C: log.Printf("db cleanup timeout\n") - exp, _ := parseExpiration0(e.conf.Policy.Max_audit_retention_period) + exp, _ := parseExpiration0(e.conf.Policy.MaxAuditRetentionPeriod) if exp > 0 { e.db.deleteExpired0(TblName.Audit, exp) } - notifyUrl := e.conf.Notification.ConsentNotificationURL - e.db.expireConsentRecords(notifyUrl) + notifyURL := e.conf.Notification.ConsentNotificationURL + e.db.expireConsentRecords(notifyURL) case <-e.stopChan: log.Printf("db cleanup closed\n") ticker.Stop() @@ -392,9 +392,9 @@ func main() { //os.Exit(0) }() - if _, err := os.Stat(cfg.Ssl.Ssl_certificate); !os.IsNotExist(err) { + if _, err := os.Stat(cfg.Ssl.SslCertificate); !os.IsNotExist(err) { log.Printf("Loading ssl\n") - err := srv.ListenAndServeTLS(cfg.Ssl.Ssl_certificate, cfg.Ssl.Ssl_certificate_key) + err := srv.ListenAndServeTLS(cfg.Ssl.SslCertificate, cfg.Ssl.SslCertificateKey) if err != nil { log.Printf("ListenAndServeSSL: %s\n", err) } diff --git a/src/consent_api.go b/src/consent_api.go index 2c48e53..acdb865 100644 --- a/src/consent_api.go +++ b/src/consent_api.go @@ -136,17 +136,17 @@ func (e mainEnv) consentAccept(w http.ResponseWriter, r *http.Request, ps httpro case "email": address = normalizeEmail(address) case "phone": - address = normalizePhone(address, e.conf.Sms.Default_country) + address = normalizePhone(address, e.conf.Sms.DefaultCountry) } newStatus, _ := e.db.createConsentRecord(userTOKEN, mode, address, brief, message, status, lawfulbasis, consentmethod, referencecode, freetext, lastmodifiedby, starttime, expiration) - notifyUrl := e.conf.Notification.ConsentNotificationURL - if newStatus == true && len(notifyUrl) > 0 { + notifyURL := e.conf.Notification.ConsentNotificationURL + if newStatus == true && len(notifyURL) > 0 { // change notificate on new record or if status change if len(userTOKEN) > 0 { - notifyConsentChange(notifyUrl, brief, status, "token", userTOKEN) + notifyConsentChange(notifyURL, brief, status, "token", userTOKEN) } else { - notifyConsentChange(notifyUrl, brief, status, mode, address) + notifyConsentChange(notifyURL, brief, status, mode, address) } } } @@ -216,17 +216,17 @@ func (e mainEnv) consentWithdraw(w http.ResponseWriter, r *http.Request, ps http case "email": address = normalizeEmail(address) case "phone": - address = normalizePhone(address, e.conf.Sms.Default_country) + address = normalizePhone(address, e.conf.Sms.DefaultCountry) } e.db.withdrawConsentRecord(userTOKEN, brief, mode, address, lastmodifiedby) w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(200) w.Write([]byte(`{"status":"ok"}`)) - notifyUrl := e.conf.Notification.ConsentNotificationURL + notifyURL := e.conf.Notification.ConsentNotificationURL if len(userTOKEN) > 0 { - notifyConsentChange(notifyUrl, brief, "no", "token", userTOKEN) + notifyConsentChange(notifyURL, brief, "no", "token", userTOKEN) } else { - notifyConsentChange(notifyUrl, brief, "no", mode, address) + notifyConsentChange(notifyURL, brief, "no", mode, address) } } diff --git a/src/consent_db.go b/src/consent_db.go index 6a5e738..50f625a 100644 --- a/src/consent_db.go +++ b/src/consent_db.go @@ -185,7 +185,7 @@ func (dbobj dbcon) filterConsentRecords(brief string, offset int32, limit int32) return resultJSON, count, nil } -func (dbobj dbcon) expireConsentRecords(notifyUrl string) error { +func (dbobj dbcon) expireConsentRecords(notifyURL string) error { records, err := dbobj.getExpiring(TblName.Consent, "status", "yes") if err != nil { return err @@ -202,11 +202,11 @@ func (dbobj dbcon) expireConsentRecords(notifyUrl string) error { if len(userTOKEN) > 0 { fmt.Printf("%s %s\n", userTOKEN, brief) dbobj.updateRecord2(TblName.Consent, "token", userTOKEN, "brief", brief, &bdoc, nil) - notifyConsentChange(notifyUrl, brief, "expired", "token", userTOKEN) + notifyConsentChange(notifyURL, brief, "expired", "token", userTOKEN) } else { usercode := rec["who"].(string) dbobj.updateRecord2(TblName.Consent, "who", usercode, "brief", brief, &bdoc, nil) - notifyConsentChange(notifyUrl, brief, "expired", rec["mode"].(string), usercode) + notifyConsentChange(notifyURL, brief, "expired", rec["mode"].(string), usercode) } } diff --git a/src/email.go b/src/email.go index 08f878b..697a253 100644 --- a/src/email.go +++ b/src/email.go @@ -34,13 +34,13 @@ func sendCodeByEmail(code int32, address string, cfg Config) { Dest := []string{"stremovsky@gmail.com", address} Subject := "Access Code" bodyMessage := "Data bunker access code is " + strconv.Itoa(int((code))) - msg := "From: " + cfg.Smtp.Sender + "\n" + + msg := "From: " + cfg.SMTP.Sender + "\n" + "To: " + strings.Join(Dest, ",") + "\n" + "Subject: " + Subject + "\n" + bodyMessage - err := smtp.SendMail(cfg.Smtp.Server+":"+cfg.Smtp.Port, - smtp.PlainAuth("", cfg.Smtp.User, cfg.Smtp.Pass, cfg.Smtp.Server), - cfg.Smtp.User, Dest, []byte(msg)) + err := smtp.SendMail(cfg.SMTP.Server+":"+cfg.SMTP.Port, + smtp.PlainAuth("", cfg.SMTP.User, cfg.SMTP.Pass, cfg.SMTP.Server), + cfg.SMTP.User, Dest, []byte(msg)) if err != nil { fmt.Printf("smtp error: %s", err) diff --git a/src/notify.go b/src/notify.go index 0fbf3ed..85ea375 100644 --- a/src/notify.go +++ b/src/notify.go @@ -9,35 +9,35 @@ import ( "net/http" ) -func notifyProfileNew(notifyUrl string, profile []byte, mode string, address string) { - if len(notifyUrl) == 0 { +func notifyProfileNew(notifyURL string, profile []byte, mode string, address string) { + if len(notifyURL) == 0 { return } requestBody := fmt.Sprintf(`{"action":"%s","address":"%s","mode":"%s","profile":%s}`, "profilenew", address, mode, profile) - go notify(notifyUrl, []byte(requestBody)) + go notify(notifyURL, []byte(requestBody)) } -func notifyProfileChange(notifyUrl string, old []byte, profile []byte, mode string, address string) { - if len(notifyUrl) == 0 { +func notifyProfileChange(notifyURL string, old []byte, profile []byte, mode string, address string) { + if len(notifyURL) == 0 { return } requestBody := fmt.Sprintf(`{"action":"%s","address":"%s","mode":"%s","old":%s,"profile":%s}`, "profilechange", address, mode, old, profile) - go notify(notifyUrl, []byte(requestBody)) + go notify(notifyURL, []byte(requestBody)) } -func notifyForgetMe(notifyUrl string, profile []byte, mode string, address string) { - if len(notifyUrl) == 0 { +func notifyForgetMe(notifyURL string, profile []byte, mode string, address string) { + if len(notifyURL) == 0 { return } requestBody := fmt.Sprintf(`{"action":"%s","address":"%s","mode":"%s","profile":%s}`, "forgetme", address, mode, profile) - go notify(notifyUrl, []byte(requestBody)) + go notify(notifyURL, []byte(requestBody)) } -func notifyConsentChange(notifyUrl string, brief string, status string, mode string, address string) { - if len(notifyUrl) == 0 { +func notifyConsentChange(notifyURL string, brief string, status string, mode string, address string) { + if len(notifyURL) == 0 { return } requestBody, _ := json.Marshal(map[string]string{ @@ -47,11 +47,11 @@ func notifyConsentChange(notifyUrl string, brief string, status string, mode str "mode": mode, "address": address, }) - go notify(notifyUrl, requestBody) + go notify(notifyURL, requestBody) } -func notify(notifyUrl string, requestBody []byte) { - resp, err := http.Post(notifyUrl, "application/json", bytes.NewBuffer(requestBody)) +func notify(notifyURL string, requestBody []byte) { + resp, err := http.Post(notifyURL, "application/json", bytes.NewBuffer(requestBody)) if err != nil { log.Printf("error in notify: %s", err) return diff --git a/src/sessions_api.go b/src/sessions_api.go index f17b66b..c3cb05b 100644 --- a/src/sessions_api.go +++ b/src/sessions_api.go @@ -45,7 +45,7 @@ func (e mainEnv) newSession(w http.ResponseWriter, r *http.Request, ps httproute if e.enforceAuth(w, r, event) == false { return } - expiration := e.conf.Policy.Max_session_retention_period + expiration := e.conf.Policy.MaxSessionRetentionPeriod records, err := getJSONPostData(r) if err != nil { returnError(w, r, "failed to decode request body", 405, err, event) @@ -57,7 +57,7 @@ func (e mainEnv) newSession(w http.ResponseWriter, r *http.Request, ps httproute } if value, ok := records["expiration"]; ok { if reflect.TypeOf(value) == reflect.TypeOf("string") { - expiration = setExpiration(e.conf.Policy.Max_session_retention_period, value.(string)) + expiration = setExpiration(e.conf.Policy.MaxSessionRetentionPeriod, value.(string)) } else { returnError(w, r, "failed to parse expiration field", 405, err, event) return diff --git a/src/sharedrecords_api.go b/src/sharedrecords_api.go index f6439b2..29e3351 100644 --- a/src/sharedrecords_api.go +++ b/src/sharedrecords_api.go @@ -31,7 +31,7 @@ func (e mainEnv) newSharedRecord(w http.ResponseWriter, r *http.Request, ps http session := "" partner := "" appName := "" - expiration := e.conf.Policy.Max_shareable_record_retention_period + expiration := e.conf.Policy.MaxShareableRecordRetentionPeriod if value, ok := records["fields"]; ok { if reflect.TypeOf(value) == reflect.TypeOf("string") { fields = value.(string) @@ -49,7 +49,7 @@ func (e mainEnv) newSharedRecord(w http.ResponseWriter, r *http.Request, ps http } if value, ok := records["expiration"]; ok { if reflect.TypeOf(value) == reflect.TypeOf("string") { - expiration = setExpiration(e.conf.Policy.Max_shareable_record_retention_period, value.(string)) + expiration = setExpiration(e.conf.Policy.MaxShareableRecordRetentionPeriod, value.(string)) } else { returnError(w, r, "failed to parse expiration field", 405, err, event) return diff --git a/src/sms.go b/src/sms.go index 4e61808..042eb09 100644 --- a/src/sms.go +++ b/src/sms.go @@ -10,16 +10,16 @@ import ( ) func sendCodeByPhone(code int32, address string, cfg Config) { - urlStr := "https://api.twilio.com/2010-04-01/Accounts/" + cfg.Sms.Twilio_account + "/Messages.json" + urlStr := "https://api.twilio.com/2010-04-01/Accounts/" + cfg.Sms.TwilioAccount + "/Messages.json" fmt.Printf("url %s\n", urlStr) msgData := url.Values{} msgData.Set("To", address) - msgData.Set("From", cfg.Sms.Twilio_from) + msgData.Set("From", cfg.Sms.TwilioFrom) msgData.Set("Body", "Data Bunker code "+strconv.Itoa(int(code))) msgDataReader := *strings.NewReader(msgData.Encode()) client := &http.Client{} req, _ := http.NewRequest("POST", urlStr, &msgDataReader) - req.SetBasicAuth(cfg.Sms.Twilio_account, cfg.Sms.Twilio_token) + req.SetBasicAuth(cfg.Sms.TwilioAccount, cfg.Sms.TwilioToken) req.Header.Add("Accept", "application/json") req.Header.Add("Content-Type", "application/x-www-form-urlencoded") resp, _ := client.Do(req) diff --git a/src/users_api.go b/src/users_api.go index 8941770..24db375 100644 --- a/src/users_api.go +++ b/src/users_api.go @@ -18,7 +18,7 @@ func (e mainEnv) userNew(w http.ResponseWriter, r *http.Request, ps httprouter.P return } } - parsedData, err := getJSONPost(r, e.conf.Sms.Default_country) + parsedData, err := getJSONPost(r, e.conf.Sms.DefaultCountry) if err != nil { returnError(w, r, "failed to decode request body", 405, err, event) return @@ -92,8 +92,8 @@ func (e mainEnv) userNew(w http.ResponseWriter, r *http.Request, ps httprouter.P } event.Record = userTOKEN returnUUID(w, userTOKEN) - notifyUrl := e.conf.Notification.ProfileNotificationURL - notifyProfileNew(notifyUrl, parsedData.jsonData, "token", userTOKEN) + notifyURL := e.conf.Notification.ProfileNotificationURL + notifyProfileNew(notifyURL, parsedData.jsonData, "token", userTOKEN) return } @@ -153,7 +153,7 @@ func (e mainEnv) userChange(w http.ResponseWriter, r *http.Request, ps httproute if mode == "token" && enforceUUID(w, address, event) == false { return } - parsedData, err := getJSONPost(r, e.conf.Sms.Default_country) + parsedData, err := getJSONPost(r, e.conf.Sms.DefaultCountry) if err != nil { returnError(w, r, "failed to decode request body", 405, err, event) return @@ -182,8 +182,8 @@ func (e mainEnv) userChange(w http.ResponseWriter, r *http.Request, ps httproute return } returnUUID(w, userTOKEN) - notifyUrl := e.conf.Notification.ProfileNotificationURL - notifyProfileChange(notifyUrl, oldJSON, newJSON, "token", userTOKEN) + notifyURL := e.conf.Notification.ProfileNotificationURL + notifyProfileChange(notifyURL, oldJSON, newJSON, "token", userTOKEN) } // user forgetme request comes here @@ -234,8 +234,8 @@ func (e mainEnv) userDelete(w http.ResponseWriter, r *http.Request, ps httproute w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(200) fmt.Fprintf(w, `{"status":"ok","result":"done"}`) - notifyUrl := e.conf.Notification.ForgetmeNotificationURL - notifyForgetMe(notifyUrl, resultJSON, "token", userTOKEN) + notifyURL := e.conf.Notification.ForgetmeNotificationURL + notifyForgetMe(notifyURL, resultJSON, "token", userTOKEN) } func (e mainEnv) userLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { diff --git a/src/users_db.go b/src/users_db.go index 1fce81a..f124ce3 100644 --- a/src/users_db.go +++ b/src/users_db.go @@ -253,7 +253,7 @@ func (dbobj dbcon) lookupUserRecordByIndex(indexName string, indexValue string, if indexName == "email" { indexValue = normalizeEmail(indexValue) } else if indexName == "phone" { - indexValue = normalizePhone(indexValue, conf.Sms.Default_country) + indexValue = normalizePhone(indexValue, conf.Sms.DefaultCountry) } if len(indexValue) == 0 { return nil, nil