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 (
|
||||
"fmt"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"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
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"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/:brief", e.consentUserRecord)
|
||||
router.GET("/v1/consents/:brief", e.consentFilterRecords)
|
||||
router.GET("/v1/consents", e.consentTypes)
|
||||
router.POST("/v1/consent/:mode/:address/:brief", e.consentAccept)
|
||||
router.DELETE("/v1/consent/:mode/:address/:brief", e.consentWithdraw)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"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)
|
||||
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 (
|
||||
"encoding/json"
|
||||
@@ -194,6 +194,25 @@ func (dbobj dbcon) filterConsentRecords(brief string, offset int32, limit int32)
|
||||
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 {
|
||||
records, err := dbobj.getExpiring(TblName.Consent, "status", "yes")
|
||||
if err != nil {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/aes"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
10
src/qldb.go
10
src/qldb.go
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
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) {
|
||||
table := getTable(t)
|
||||
if limit > 100 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http/httptest"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package databunker
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
Reference in New Issue
Block a user