mirror of
https://github.com/optim-enterprises-bv/databunker.git
synced 2025-11-02 10:57:57 +00:00
revert custom package name, add new API
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Package databunker - Personal Identifiable Information (PII) database.
|
// Package main - Personal Identifiable Information (PII) database.
|
||||||
// For more info check https://paranoidguy.com
|
// For more info check https://paranoidguy.com
|
||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -172,6 +172,7 @@ func (e mainEnv) setupRouter() *httprouter.Router {
|
|||||||
router.GET("/v1/consent/:mode/:address", e.consentAllUserRecords)
|
router.GET("/v1/consent/:mode/:address", e.consentAllUserRecords)
|
||||||
router.GET("/v1/consent/:mode/:address/:brief", e.consentUserRecord)
|
router.GET("/v1/consent/:mode/:address/:brief", e.consentUserRecord)
|
||||||
router.GET("/v1/consents/:brief", e.consentFilterRecords)
|
router.GET("/v1/consents/:brief", e.consentFilterRecords)
|
||||||
|
router.GET("/v1/consents", e.consentTypes)
|
||||||
router.POST("/v1/consent/:mode/:address/:brief", e.consentAccept)
|
router.POST("/v1/consent/:mode/:address/:brief", e.consentAccept)
|
||||||
router.DELETE("/v1/consent/:mode/:address/:brief", e.consentWithdraw)
|
router.DELETE("/v1/consent/:mode/:address/:brief", e.consentWithdraw)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -377,3 +377,22 @@ func (e mainEnv) consentFilterRecords(w http.ResponseWriter, r *http.Request, ps
|
|||||||
str := fmt.Sprintf(`{"status":"ok","total":%d,"rows":%s}`, numRecords, resultJSON)
|
str := fmt.Sprintf(`{"status":"ok","total":%d,"rows":%s}`, numRecords, resultJSON)
|
||||||
w.Write([]byte(str))
|
w.Write([]byte(str))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e mainEnv) consentTypes(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
|
if e.enforceAuth(w, r, nil) == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resultJSON, numRecords, err := e.db.getConsentTypes()
|
||||||
|
if err != nil {
|
||||||
|
returnError(w, r, "internal error", 405, err, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Printf("Total count of rows: %d\n", numRecords)
|
||||||
|
//fmt.Fprintf(w, "<html><head><title>title</title></head>")
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
w.WriteHeader(200)
|
||||||
|
str := fmt.Sprintf(`{"status":"ok","total":%d,"briefs":%s}`, numRecords, resultJSON)
|
||||||
|
w.Write([]byte(str))
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -194,6 +194,25 @@ func (dbobj dbcon) filterConsentRecords(brief string, offset int32, limit int32)
|
|||||||
return resultJSON, count, nil
|
return resultJSON, count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dbobj dbcon) getConsentTypes() ([]byte, int64, error) {
|
||||||
|
records, err := dbobj.getUniqueList(TblName.Consent, "brief")
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
count:= int64(len(records))
|
||||||
|
// we need to return only list of briefs
|
||||||
|
var result []string
|
||||||
|
for _, rec := range records {
|
||||||
|
result = append(result, rec["brief"].(string))
|
||||||
|
}
|
||||||
|
resultJSON, err := json.Marshal(result)
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
//fmt.Printf("Found multiple documents (array of pointers): %+v\n", results)
|
||||||
|
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")
|
records, err := dbobj.getExpiring(TblName.Consent, "status", "yes")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|||||||
18
src/qldb.go
18
src/qldb.go
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
// github.com/mattn/go-sqlite3
|
// github.com/mattn/go-sqlite3
|
||||||
|
|
||||||
@@ -677,6 +677,14 @@ func (dbobj dbcon) getExpiring(t Tbl, keyName string, keyValue string) ([]bson.M
|
|||||||
return dbobj.getListDo(q, keyValue)
|
return dbobj.getListDo(q, keyValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dbobj dbcon) getUniqueList(t Tbl, keyName string) ([]bson.M, error) {
|
||||||
|
table := getTable(t)
|
||||||
|
keyName = escapeName(keyName)
|
||||||
|
q := "select distinct " + keyName +" from " + table + " ORDER BY " + keyName
|
||||||
|
fmt.Printf("q: %s\n", q)
|
||||||
|
return dbobj.getListDo(q, "")
|
||||||
|
}
|
||||||
|
|
||||||
func (dbobj dbcon) getList(t Tbl, keyName string, keyValue string, start int32, limit int32) ([]bson.M, error) {
|
func (dbobj dbcon) getList(t Tbl, keyName string, keyValue string, start int32, limit int32) ([]bson.M, error) {
|
||||||
table := getTable(t)
|
table := getTable(t)
|
||||||
if limit > 100 {
|
if limit > 100 {
|
||||||
@@ -797,12 +805,12 @@ func (dbobj dbcon) indexNewApp(appName string) {
|
|||||||
}
|
}
|
||||||
defer tx.Rollback()
|
defer tx.Rollback()
|
||||||
_, err = tx.Exec("CREATE TABLE IF NOT EXISTS " + appName + ` (
|
_, err = tx.Exec("CREATE TABLE IF NOT EXISTS " + appName + ` (
|
||||||
token STRING,
|
token STRING,
|
||||||
md5 STRING,
|
md5 STRING,
|
||||||
rofields STRING,
|
rofields STRING,
|
||||||
data STRING,
|
data STRING,
|
||||||
status STRING,
|
status STRING,
|
||||||
` + "`when` int);")
|
` + "`when` int);")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package databunker
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|||||||
Reference in New Issue
Block a user