[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taldir] 01/03: add validation scripts
From: |
gnunet |
Subject: |
[taler-taldir] 01/03: add validation scripts |
Date: |
Tue, 05 Jul 2022 12:40:44 +0200 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository taldir.
commit 0cb37955d24f95c106bbb93552fc8db8f3ea2a46
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Tue Jul 5 10:00:39 2022 +0200
add validation scripts
---
taldir.conf | 11 +++++++++--
taldir.go | 56 +++++++++++++++++++++++++++++++++++++++++---------------
validate_test.sh | 2 ++
3 files changed, 52 insertions(+), 17 deletions(-)
diff --git a/taldir.conf b/taldir.conf
index 2f8fdf3..e49c25a 100644
--- a/taldir.conf
+++ b/taldir.conf
@@ -1,17 +1,24 @@
[taldir]
production = false
-validators = "email phone"
+validators = "email phone test"
host = "https://taldir.net"
bind_to = "localhost:11000"
salt = "ChangeMe"
monthly_fee = 1 Bazillion Kudos
+request_frequency = 3
[taldir-email]
sender = "taldir@taler.net"
-challenge_fee = 0.5 Fantastillion Kudos
+challenge_fee = 0.5 Fantastillion Kudos
+command = validate_email.sh
[taldir-phone]
challenge_fee = 5 Kudos
+command = validate_phone.sh
+
+[taldir-test]
+challenge_fee = 23 Kudos
+command = ./validate_test.sh
[taldir-pq]
host = "localhost"
diff --git a/taldir.go b/taldir.go
index 3ba1bc0..387cf33 100644
--- a/taldir.go
+++ b/taldir.go
@@ -2,6 +2,7 @@ package main
import (
"os"
+ "os/exec"
"fmt"
"log"
"net/http"
@@ -49,7 +50,7 @@ type RateLimitedResponse struct {
Code int `json:"code"`
// At what frequency are new registrations allowed. FIXME: In what?
- Request_frequency uint64 `json:"request_frequency"`
+ Request_frequency uint `json:"request_frequency"`
// The human readable error message.
Hint string `json:"hint"`
@@ -94,6 +95,7 @@ type Validation struct {
Method string `json:"method"`
ValidationReference string `json:"reference"`
PublicKey string `json:"public_key"`
+ RetryCount uint
}
type ErrorDetail struct {
@@ -271,26 +273,50 @@ func registerRequest(w http.ResponseWriter, r
*http.Request){
h := sha256.New()
h.Write([]byte(req.Address))
validation.HAddress = base32.StdEncoding.EncodeToString(h.Sum(nil))
- validation.ValidationReference = generateToken()
err = db.First(&validation, "h_address = ?", validation.HAddress).Error
if err == nil {
- // FIXME: We need to handle this properly:
- // Registration already exists for this address for the specified duration.
- // Returns for how long this registration is paid for.
- w.WriteHeader(200)
- return
- }
- err = db.Create(&validation).Error
- if err != nil {
- // FIXME: API needs 400 error codes in such cases
- w.WriteHeader(http.StatusInternalServerError)
- return
+ reqFrequency := cfg.Section("taldir").Key("request_frequency").MustUint(1)
+ if validation.RetryCount >= reqFrequency - 1 {
+ w.WriteHeader(429)
+ rlResponse := RateLimitedResponse{
+ Code: 23, //FIXME TALER_EC_TALDIR_REGISTER_RATE_LIMITED
+ Request_frequency: reqFrequency,
+ Hint: "Retry maximum reached. Deleting validation",
+ }
+ jsonResp, _ := json.Marshal(rlResponse)
+ w.Write(jsonResp)
+ db.Delete(&validation)
+ return
+ }
+ validation.RetryCount++
+ validation.ValidationReference = generateToken()
+ db.Save(&validation)
+ fmt.Printf("Retrying validation send\n")
+ } else {
+ validation.ValidationReference = generateToken()
+ err = db.Create(&validation).Error
+ if err != nil {
+ // FIXME: API needs 400 error codes in such cases
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+ fmt.Println("Address registration request created:", validation)
}
- fmt.Println("Address registration request created:", validation)
w.WriteHeader(202)
// FIXME: Here we should call the validator shell script with the
// parsed parameters to initiate the validation.
- sendEmail(vars["identity"], validation)
+ if !cfg.Section("taldir-" + vars["method"]).HasKey("command") {
+ log.Fatal(err)
+ // FIXME cleanup validation?
+ return
+ }
+ command := cfg.Section("taldir-" + vars["method"]).Key("command").String()
+ out, err := exec.Command(command, req.Address,
validation.ValidationReference).Output()
+ if err != nil {
+ log.Fatal(err)
+ }
+ fmt.Printf("Output from method script is %s\n", out)
+ // sendEmail(vars["identity"], validation)
}
func notImplemented(w http.ResponseWriter, r *http.Request) {
diff --git a/validate_test.sh b/validate_test.sh
new file mode 100755
index 0000000..8a46772
--- /dev/null
+++ b/validate_test.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+echo $1 $2
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.