revert custom package name, add new API

This commit is contained in:
Yuli
2020-01-27 10:18:19 +02:00
parent 0ca31b27b4
commit ac6bd11a76
28 changed files with 80 additions and 33 deletions

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"encoding/json"

View File

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

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"encoding/hex"

View File

@@ -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))
}

View File

@@ -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 {

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"crypto/aes"

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"bytes"

View File

@@ -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 {

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"encoding/json"

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"encoding/json"

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"encoding/base64"

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"encoding/json"

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"errors"

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"encoding/json"

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"encoding/json"

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"encoding/json"

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"crypto/md5"

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"encoding/json"

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"crypto/md5"

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"crypto/sha256"

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"net/http/httptest"

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"errors"

View File

@@ -1,4 +1,4 @@
package databunker
package main
import (
"fmt"