[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taldir] branch master updated: improve config parsing for enabled
From: |
gnunet |
Subject: |
[taler-taldir] branch master updated: improve config parsing for enabled methods |
Date: |
Mon, 04 Jul 2022 22:17:30 +0200 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository taldir.
The following commit(s) were added to refs/heads/master by this push:
new 713dba9 improve config parsing for enabled methods
713dba9 is described below
commit 713dba94a3a515bcd35a2dd40f27c0cfaa2d129a
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Mon Jul 4 22:17:27 2022 +0200
improve config parsing for enabled methods
---
taldir.conf | 4 +++-
taldir.go | 67 ++++++++++++++++++++++++++++++++++++++++++++-----------------
2 files changed, 52 insertions(+), 19 deletions(-)
diff --git a/taldir.conf b/taldir.conf
index 1d2d95f..2f8fdf3 100644
--- a/taldir.conf
+++ b/taldir.conf
@@ -4,13 +4,15 @@ validators = "email phone"
host = "https://taldir.net"
bind_to = "localhost:11000"
salt = "ChangeMe"
-supported_methods = email
monthly_fee = 1 Bazillion Kudos
[taldir-email]
sender = "taldir@taler.net"
challenge_fee = 0.5 Fantastillion Kudos
+[taldir-phone]
+challenge_fee = 5 Kudos
+
[taldir-pq]
host = "localhost"
port = 5432
diff --git a/taldir.go b/taldir.go
index cd502e3..2c7aa73 100644
--- a/taldir.go
+++ b/taldir.go
@@ -43,6 +43,38 @@ type Method struct {
}
+type RateLimitedResponse struct {
+
+ // Taler error code, TALER_EC_TALDIR_REGISTER_RATE_LIMITED.
+ Code int `json:"code"`
+
+ // At what frequency are new registrations allowed. FIXME: In what?
+ Request_frequency uint64 `json:"request_frequency"`
+
+ // The human readable error message.
+ Hint string `json:"hint"`
+}
+
+type RegisterMessage struct {
+
+ // Address, in method-specific format
+ Address string `json:"address"`
+
+ // Public key of the user to register
+ Public_key string `json:"public_key"`
+
+ // (HTTPS) endpoint URL for the inbox service for this address
+ Inbox string `json:"inbox_url"`
+
+ // For how long should the registration last
+ Duration uint64 `json:"duration"`
+
+ // Order ID, if the client recently paid for this registration
+ // FIXME: As an optional field, maybe we want to parse this separately
+ // instead?
+ // Order_id string `json:"order_id"`
+}
+
// A mappind entry from the identity key hash to a wallet key
// The identity key hash is sha256(sha256(identity)|salt) where identity is
// one of the identity key types supported (e.g. email)
@@ -171,22 +203,20 @@ func generateToken() string {
return base32.StdEncoding.EncodeToString(randBytes)
}
-// Initiate a registration request for an identity
-func addPendingValidation(w http.ResponseWriter, r *http.Request){
- vars := mux.Vars(r)
- var validation Validation
+func registerRequest(w http.ResponseWriter, r *http.Request){
+ //vars := mux.Vars(r)
+ var req RegisterMessage
if r.Body == nil {
http.Error(w, "No request body", 400)
return
}
- err := json.NewDecoder(r.Body).Decode(&validation)
+ err := json.NewDecoder(r.Body).Decode(&req)
if err != nil {
http.Error(w, err.Error(), 400)
return
}
fmt.Println(validators)
- fmt.Println(validation)
- if !validators[validation.IdentityKeyType] {
+ /*if !validators[validation.IdentityKeyType] {
http.Error(w, "Identity key type not supported.", 400)
return
}
@@ -215,7 +245,7 @@ func addPendingValidation(w http.ResponseWriter, r
*http.Request){
return
}
fmt.Println("Pending validation created:", validation)
- sendEmail(vars["identity"], validation)
+ sendEmail(vars["identity"], validation)*/
}
func notImplemented(w http.ResponseWriter, r *http.Request) {
@@ -223,19 +253,20 @@ func notImplemented(w http.ResponseWriter, r
*http.Request) {
}
func configResponse(w http.ResponseWriter, r *http.Request) {
- //FIXME properly collect configured methods
- //cfg.Section("taldir").Key("methods").MustString(""),
- //=> cfg.Section("taldir-<method>").Key("challenge_fee").MustString("1
Kudos"),
+ meths := []Method{}
+ i := 0
+ for key, _ := range validators {
+ var meth Method
+ meth.Name = key
+ meth.Challenge_fee = cfg.Section("taldir-" +
key).Key("challenge_fee").MustString("1 Kudos")
+ i++
+ meths = append(meths, meth)
+ }
cfg := VersionResponse{
Version: "0:0:0",
Name: "taler-directory",
Monthly_fee: cfg.Section("taldir").Key("monthly_fee").MustString("1
Kudos"),
- Methods: []Method{
- Method{
- Name: "email",
- Challenge_fee:
cfg.Section("taldir-email").Key("challenge_fee").MustString("1 Kudos"),
- },
- },
+ Methods: meths,
}
w.Header().Set("Content-Type", "application/json")
response, _ := json.Marshal(cfg)
@@ -256,7 +287,7 @@ func handleRequests() {
/* Registration API */
myRouter.HandleFunc("/directory/{identity_key}",
returnSingleEntry).Methods("GET")
myRouter.HandleFunc("/validation/{reference}",
validateSingleEntry).Methods("GET")
- myRouter.HandleFunc("/register/{identity}",
addPendingValidation).Methods("POST")
+ myRouter.HandleFunc("/register/{method}", registerRequest).Methods("POST")
log.Fatal(http.ListenAndServe(cfg.Section("taldir").Key("bind_to").MustString("localhost:11000"),
myRouter))
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-taldir] branch master updated: improve config parsing for enabled methods,
gnunet <=