1
0
Fork 0

Reduce Go cyclo complexity

master
Philip O Toole 8 years ago
parent 877177d309
commit 1152886216

@ -1,6 +1,7 @@
## 3.4.1 (unreleased) ## 3.4.1 (unreleased)
- [PR #170](https://github.com/rqlite/rqlite/pull/170): Log any failure to call `Serve()` on HTTP service. - [PR #170](https://github.com/rqlite/rqlite/pull/170): Log any failure to call `Serve()` on HTTP service.
- Go lint fixes. - Go lint fixes.
- Go cyclo complexity changes.
## 3.4.0 (July 7th 2016) ## 3.4.0 (July 7th 2016)
- [PR #159](https://github.com/rqlite/rqlite/pull/159): All HTTP responses set X-RQLITE-VERSION. - [PR #159](https://github.com/rqlite/rqlite/pull/159): All HTTP responses set X-RQLITE-VERSION.

@ -543,14 +543,9 @@ func (s *Service) handleQuery(w http.ResponseWriter, r *http.Request) {
} }
// Validate queries, unless disabled. // Validate queries, unless disabled.
if !s.NoVerifySelect { if !s.NoVerifySelect && !queriesValid(queries) {
for _, q := range queries { w.WriteHeader(http.StatusForbidden)
u := strings.ToUpper(strings.TrimSpace(q)) return
if !strings.HasPrefix(u, "SELECT ") {
w.WriteHeader(http.StatusForbidden)
return
}
}
} }
results, err := s.store.Query(queries, timings, isTx, lvl) results, err := s.store.Query(queries, timings, isTx, lvl)
@ -602,6 +597,17 @@ func (s *Service) CheckRequestPerm(r *http.Request, perm string) bool {
return s.credentialStore.HasPerm(username, PermAll) || s.credentialStore.HasPerm(username, perm) return s.credentialStore.HasPerm(username, PermAll) || s.credentialStore.HasPerm(username, perm)
} }
// queriesValid returns whether the slice of queries is valid.
func queriesValid(queries []string) bool {
for _, q := range queries {
u := strings.ToUpper(strings.TrimSpace(q))
if !strings.HasPrefix(u, "SELECT ") {
return false
}
}
return true
}
// serveExpvar serves registered expvar information over HTTP. // serveExpvar serves registered expvar information over HTTP.
func serveExpvar(w http.ResponseWriter, r *http.Request) { func serveExpvar(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json; charset=utf-8")

Loading…
Cancel
Save