summaryrefslogtreecommitdiff
path: root/src/helsinki.at/rhimportd
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-19 22:07:08 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-19 22:07:15 (GMT)
commit94eab548c583491912335d58f6442eb952cec5ab (patch)
tree1cfcd618f196343fab14ff2b75e48da60292f3b2 /src/helsinki.at/rhimportd
parent5559994f6c1cde34cb806fbc6bcc30e0ac4751f0 (diff)
fetcher now checks for permissions
improved error handling for fetcher
Diffstat (limited to 'src/helsinki.at/rhimportd')
-rw-r--r--src/helsinki.at/rhimportd/ctrlTelnet.go41
-rw-r--r--src/helsinki.at/rhimportd/ctrlWebSimple.go14
2 files changed, 39 insertions, 16 deletions
diff --git a/src/helsinki.at/rhimportd/ctrlTelnet.go b/src/helsinki.at/rhimportd/ctrlTelnet.go
index eb3c607..65504f4 100644
--- a/src/helsinki.at/rhimportd/ctrlTelnet.go
+++ b/src/helsinki.at/rhimportd/ctrlTelnet.go
@@ -152,11 +152,23 @@ func (c *TelnetClient) handle_cmd_set(args []string) {
}
switch strings.ToLower(args[0]) {
case "username":
- c.ctx.UserName = args[1]
+ if args[1] == "\"\"" || args[1] == "''" {
+ c.ctx.UserName = ""
+ } else {
+ c.ctx.UserName = args[1]
+ }
case "password":
- c.ctx.Password = args[1]
+ if args[1] == "\"\"" || args[1] == "''" {
+ c.ctx.Password = ""
+ } else {
+ c.ctx.Password = args[1]
+ }
case "sourceuri":
- c.ctx.SourceUri = args[1]
+ if args[1] == "\"\"" || args[1] == "''" {
+ c.ctx.SourceUri = ""
+ } else {
+ c.ctx.SourceUri = args[1]
+ }
case "showid":
if id, err := strconv.ParseUint(args[1], 10, 32); err != nil {
c.say("invalid value (must be an positive integer)")
@@ -170,7 +182,11 @@ func (c *TelnetClient) handle_cmd_set(args []string) {
c.ctx.ClearShowCarts = val
}
case "groupname":
- c.ctx.GroupName = args[1]
+ if args[1] == "\"\"" || args[1] == "''" {
+ c.ctx.GroupName = ""
+ } else {
+ c.ctx.GroupName = args[1]
+ }
case "cart":
if cart, err := strconv.ParseUint(args[1], 10, 32); err != nil {
c.say("invalid value (must be an positive integer)")
@@ -263,22 +279,25 @@ func (c *TelnetClient) handle_cmd_run(args []string) {
}
c.say("fetching file from '%s'", ctx.SourceUri)
- if err := rhimport.FetchFile(&ctx); err != nil {
+ if fres, err := rhimport.FetchFile(&ctx); err != nil {
c.say("fetch file error: %s", err)
return
+ } else if fres.ResponseCode != http.StatusOK {
+ c.say("fetch file error: %s", fres.ErrorString)
+ return
}
c.say("importing file '%s'", ctx.SourceFile)
- if result, err := rhimport.ImportFile(&ctx); err != nil {
+ if ires, err := rhimport.ImportFile(&ctx); err != nil {
c.say("import file error: %s", err)
return
} else {
- if result.ResponseCode == http.StatusOK {
- c.say("File got succesfully imported into Cart/Cut %d/%d", result.Cart, result.Cut)
- rhl.Printf("File got succesfully imported into Cart/Cut %d/%d", result.Cart, result.Cut)
+ if ires.ResponseCode == http.StatusOK {
+ c.say("File got succesfully imported into Cart/Cut %d/%d", ires.Cart, ires.Cut)
+ rhl.Printf("File got succesfully imported into Cart/Cut %d/%d", ires.Cart, ires.Cut)
} else {
- c.say("Fileimport has failed (Cart/Cut %d/%d): %s", result.Cart, result.Cut, result.ErrorString)
- rhl.Printf("Fileimport has failed (Cart/Cut %d/%d): %s", result.Cart, result.Cut, result.ErrorString)
+ c.say("Fileimport has failed (Cart/Cut %d/%d): %s", ires.Cart, ires.Cut, ires.ErrorString)
+ rhl.Printf("Fileimport has failed (Cart/Cut %d/%d): %s", ires.Cart, ires.Cut, ires.ErrorString)
}
}
}
diff --git a/src/helsinki.at/rhimportd/ctrlWebSimple.go b/src/helsinki.at/rhimportd/ctrlWebSimple.go
index 2de324f..c5b81ce 100644
--- a/src/helsinki.at/rhimportd/ctrlWebSimple.go
+++ b/src/helsinki.at/rhimportd/ctrlWebSimple.go
@@ -141,22 +141,26 @@ func webSimpleHandler(conf *rhimport.Config, rddb *rhimport.RdDb, trusted bool,
return
}
- if err = rhimport.FetchFile(ctx); err != nil {
+ var fres *rhimport.FetchResult
+ if fres, err = rhimport.FetchFile(ctx); err != nil {
webSimpleErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
+ if fres.ResponseCode != http.StatusOK {
+ webSimpleErrorResponse(w, fres.ResponseCode, fres.ErrorString)
+ }
- var result *rhimport.ImportResult
- if result, err = rhimport.ImportFile(ctx); err != nil {
+ var ires *rhimport.ImportResult
+ if ires, err = rhimport.ImportFile(ctx); err != nil {
webSimpleErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
- if result.ResponseCode == http.StatusOK {
+ if ires.ResponseCode == http.StatusOK {
rhl.Println("ImportFile succesfully imported", ctx.SourceFile)
} else {
rhl.Println("ImportFile import of", ctx.SourceFile, "was unsuccesful")
}
- webSimpleResponse(w, result)
+ webSimpleResponse(w, ires)
return
}