forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gke_version_endpoint.go
49 lines (38 loc) · 1016 Bytes
/
gke_version_endpoint.go
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package capabilities
import (
"fmt"
"net/http"
)
const (
defaultCredentialEnv = "GOOGLE_APPLICATION_CREDENTIALS"
)
// NewGKEVersionsHandler creates a new GKEVersionsHandler
func NewGKEVersionsHandler() *GKEVersionHandler {
return &GKEVersionHandler{}
}
// GKEVersionHandler for listing available Kubernetes versions in GKE
type GKEVersionHandler struct {
}
type errorResponse struct {
Error string `json:"error"`
}
func (g *GKEVersionHandler) ServeHTTP(writer http.ResponseWriter, req *http.Request) {
body := preCheck(writer, req)
if body == nil {
return
}
zone := body.Zone
if zone == "" {
writer.WriteHeader(http.StatusBadRequest)
handleErr(writer, fmt.Errorf("invalid zone"))
return
}
client, err := getContainerServiceClient(req.Context(), body.Credentials)
if err != nil {
writer.WriteHeader(http.StatusInternalServerError)
handleErr(writer, err)
return
}
result, err := client.Projects.Zones.GetServerconfig(body.ProjectID, zone).Do()
postCheck(writer, result, err)
}