blob: fa0bcca5e8462c2fdf0d1aa1826c99036f2d3d41 [file] [log] [blame]
khenaidood948f772021-08-11 17:49:24 -04001// Copyright 2015 The etcd Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package v2http
16
17import (
18 "fmt"
19 "net/http"
20
21 "github.com/coreos/etcd/etcdserver/api"
22 "github.com/coreos/etcd/etcdserver/api/v2http/httptypes"
23)
24
25func capabilityHandler(c api.Capability, fn func(http.ResponseWriter, *http.Request)) http.HandlerFunc {
26 return func(w http.ResponseWriter, r *http.Request) {
27 if !api.IsCapabilityEnabled(c) {
28 notCapable(w, r, c)
29 return
30 }
31 fn(w, r)
32 }
33}
34
35func notCapable(w http.ResponseWriter, r *http.Request, c api.Capability) {
36 herr := httptypes.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Not capable of accessing %s feature during rolling upgrades.", c))
37 if err := herr.WriteTo(w); err != nil {
38 plog.Debugf("error writing HTTPError (%v) to %s", err, r.RemoteAddr)
39 }
40}