mirror of
https://github.com/optim-enterprises-bv/databunker.git
synced 2025-11-01 02:17:53 +00:00
fix linter errors
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user