added check for invalid database and sanity check for executor

This commit is contained in:
Todd Gruben 2014-12-03 18:00:13 +00:00
parent aa00270de8
commit e4dcf867c3
3 changed files with 20 additions and 1 deletions

View file

@ -283,6 +283,10 @@ func (self *WebService) HandleQuery(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Provide a database (db)", http.StatusNotFound)
return
}
if !self.service.Cluster.IsValidDatabase(database_name) {
http.Error(w, "Unknown Database:"+database_name, http.StatusNotFound)
return
}
pql := r.Form.Get("pql")
if pql == "" {
http.Error(w, "Provide a valid query string (pql)", http.StatusNotFound)

View file

@ -117,6 +117,16 @@ func (self *Cluster) GetDatabases() map[string]*Database {
}
func (self *Cluster) IsValidDatabase(dbname string) bool {
for name, _ := range self.GetDatabases() {
if name == dbname {
return true
}
}
return false
}
/////////// DATABASES ////////////////////////////////////////////////////////////////////
// A database is a collection of all the frames within a given profile space

View file

@ -97,7 +97,12 @@ func (self *Executor) runQuery(database *db.Database, qry *query.Query) error {
msg.Data = qs
switch step := qs.(type) {
case query.PortableQueryStep:
self.service.Transport.Send(msg, step.GetLocation().ProcessId)
loc := step.GetLocation()
if loc != nil {
self.service.Transport.Send(msg, loc.ProcessId)
} else {
log.Println("Problem with querystep(nil location)", spew.Sdump(step))
}
}
}
return nil