commit eac62d894b2e185fdaecb4a62e274951a52a27eb
parent a0128e3c4925c60f15cbab23cca921e240405661
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date: Wed, 6 Jul 2022 18:56:01 +0200
handle missing scripts better
Diffstat:
2 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/cmd/taldir-server/main.go b/cmd/taldir-server/main.go
@@ -359,24 +359,24 @@ func registerRequest(w http.ResponseWriter, r *http.Request){
}
}
err = db.First(&validation, "h_address = ?", validation.HAddress).Error
+ validation.Code = util.GenerateCode()
+ validation.Inbox = req.Inbox
+ validation.Duration = req.Duration
+ validation.PublicKey = req.PublicKey
if err == nil {
// FIXME: Validation already pending for this address
// How should we proceed here? Expire old validations?
- w.WriteHeader(202)
- return
- } else {
- validation.Code = util.GenerateCode()
- validation.Inbox = req.Inbox
- validation.Duration = req.Duration
- validation.PublicKey = req.PublicKey
+ log.Println("Validation for this address already exists")
+ err = db.Save(&validation).Error
+ } else {
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)
}
+ if err != nil {
+ // FIXME: API needs 400 error codes in such cases
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+ fmt.Println("Address registration request created:", validation)
if !cfg.Section("taldir-" + vars["method"]).HasKey("command") {
log.Fatal(err)
db.Delete(&validation)
@@ -384,15 +384,22 @@ func registerRequest(w http.ResponseWriter, r *http.Request){
return
}
command := cfg.Section("taldir-" + vars["method"]).Key("command").String()
- out, err := exec.Command(command, req.Address, validation.Code).Output()
+ path, err := exec.LookPath(command)
if err != nil {
- log.Fatal(err)
+ log.Println(err)
+ db.Delete(&validation)
+ w.WriteHeader(500)
+ return
+ }
+ out, err := exec.Command(path, req.Address, validation.Code).Output()
+ if err != nil {
+ log.Println(err)
db.Delete(&validation)
w.WriteHeader(500)
return
}
w.WriteHeader(202)
- fmt.Printf("Output from method script is %s\n", out)
+ fmt.Printf("Output from method script %s is %s\n", path, out)
}
func notImplemented(w http.ResponseWriter, r *http.Request) {
diff --git a/taldir.conf b/taldir.conf
@@ -19,7 +19,7 @@ command = validate_phone.sh
[taldir-test]
challenge_fee = KUDOS:23
-command = taldir-validate-test.sh
+command = taldir-validate-test
[taldir-twitter]
challenge_fee = KUDOS:2