-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathdiscovery_resource.go
More file actions
29 lines (24 loc) · 878 Bytes
/
discovery_resource.go
File metadata and controls
29 lines (24 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package server
import (
"net/http"
"path"
"github.com/coreos/dex/pkg/log"
schema "github.com/coreos/dex/schema/workerschema"
)
type discoveryResource struct{}
func registerDiscoveryResource(prefix string, mux *http.ServeMux) {
c := &discoveryResource{}
p := path.Join(prefix, "discovery")
mux.Handle(p, c)
}
func (d *discoveryResource) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
writeAPIError(w, http.StatusMethodNotAllowed, newAPIError(errorInvalidRequest, "only HTTP GET supported against this resource"))
return
}
w.Header().Set("Content-Type", "application/json")
if _, err := w.Write([]byte(schema.DiscoveryJSON)); err != nil {
log.Errorf("Failed sending discovery JSON HTTP response body: %v", err)
writeAPIError(w, http.StatusInternalServerError, newAPIError(errorServerError, "error serving discovery JSON"))
}
}