Skip to content

Commit

Permalink
Add check for CLI call in production server
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznet committed Nov 21, 2023
1 parent 4d61020 commit e3c482b
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions web/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1016,25 +1016,29 @@ func APIHandler(w http.ResponseWriter, r *http.Request) {
return
}
user = creds.UserName()
config := r.FormValue("config")
var data = Record{}
data["User"] = user
err = json.Unmarshal([]byte(config), &data)
if err != nil {
msg := "unable to unmarshal configuration data"
handleError(w, r, msg, err)
return
}
err = insertData(schema, data)
if err != nil {
msg := "unable to insert data"
handleError(w, r, msg, err)
userAgent := r.Header.Get("User-Agent")
// check if we got request from CLI, we proceed here only for web clients
if !strings.Contains(userAgent, "Go-http-client") {
config := r.FormValue("config")
var data = Record{}
data["User"] = user
err = json.Unmarshal([]byte(config), &data)
if err != nil {
msg := "unable to unmarshal configuration data"
handleError(w, r, msg, err)
return
}
err = insertData(schema, data)
if err != nil {
msg := "unable to insert data"
handleError(w, r, msg, err)
return
}
msg := fmt.Sprintf("Successfully inserted:\n%v", data.ToString())
w.WriteHeader(http.StatusOK)
w.Write([]byte(msg))
return
}
msg := fmt.Sprintf("Successfully inserted:\n%v", data.ToString())
w.WriteHeader(http.StatusOK)
w.Write([]byte(msg))
return
}
}

Expand Down

0 comments on commit e3c482b

Please sign in to comment.