Skip to content

Commit

Permalink
Merge pull request #129 from sapcc/fix-high-drift-not-optional
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 authored Sep 27, 2024
2 parents 3d3d746 + 450b1de commit 6e5008c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## v2.8.0 - TBD
## v2.7.1 - TBD

Changes:
- Fix a server error being returned if the optional `high_drift` parameter is not given.

## v2.7.0 - 2024-09-10

Expand Down
23 changes: 13 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,17 @@ func handlerMetrics(w http.ResponseWriter, r *http.Request) {
hd := ntpHighDrift

if ntpSource == "http" {
query := r.URL.Query()
for _, i := range []string{"target", "protocol", "duration"} {
if r.URL.Query().Get(i) == "" {
if query.Get(i) == "" {
http.Error(w, "Get parameter is empty: "+i, http.StatusBadRequest)
return
}
}

s = r.URL.Query().Get("target")
s = query.Get("target")

if v, err := strconv.ParseInt(r.URL.Query().Get("protocol"), 10, 32); err != nil {
if v, err := strconv.ParseInt(query.Get("protocol"), 10, 32); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
} else if v < 2 || v > 4 {
Expand All @@ -120,18 +121,20 @@ func handlerMetrics(w http.ResponseWriter, r *http.Request) {
p = int(v)
}

if t, err := time.ParseDuration(r.URL.Query().Get("duration")); err == nil {
if t, err := time.ParseDuration(query.Get("duration")); err == nil {
d = t
} else {
http.Error(w, err.Error(), http.StatusBadRequest)
http.Error(w, "while parsing duration: "+err.Error(), http.StatusBadRequest)
return
}

if u, err := time.ParseDuration(r.URL.Query().Get("high_drift")); err == nil {
hd = u
} else {
http.Error(w, err.Error(), http.StatusBadRequest)
return
if query.Get("high_drift") != "" {
if u, err := time.ParseDuration(query.Get("high_drift")); err == nil {
hd = u
} else {
http.Error(w, "while parsing high_drift: "+err.Error(), http.StatusBadRequest)
return
}
}
}

Expand Down

0 comments on commit 6e5008c

Please sign in to comment.