forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gke_subnetworks_endpoint.go
45 lines (35 loc) · 988 Bytes
/
gke_subnetworks_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
package capabilities
import (
"fmt"
"net/http"
)
// NewGKESubnetworksHandler creates a new GKESubnetworksHandler
func NewGKESubnetworksHandler() *GKESubnetworksHandler {
return &GKESubnetworksHandler{}
}
// GKESubnetworksHandler lists available networks in GKE
type GKESubnetworksHandler struct {
}
type subnetworkCapabilitiesRequestBody struct {
capabilitiesRequestBody
Region string `json:"region"`
}
func (g *GKESubnetworksHandler) ServeHTTP(writer http.ResponseWriter, req *http.Request) {
body := preCheck(writer, req)
if body == nil {
return
}
if body.Region == "" {
writer.WriteHeader(http.StatusBadRequest)
handleErr(writer, fmt.Errorf("invalid region"))
return
}
client, err := getComputeServiceClient(req.Context(), body.Credentials)
if err != nil {
writer.WriteHeader(http.StatusInternalServerError)
handleErr(writer, err)
return
}
result, err := client.Subnetworks.List(body.ProjectID, body.Region).Do()
postCheck(writer, result, err)
}