mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
Package serialized version of openapi
This commit is contained in:
parent
93841ffbcb
commit
1502ad2530
1
main.go
1
main.go
@ -1,6 +1,7 @@
|
|||||||
//go:generate go run types/codegen/cleanup/main.go
|
//go:generate go run types/codegen/cleanup/main.go
|
||||||
//go:generate go run types/codegen/main.go
|
//go:generate go run types/codegen/main.go
|
||||||
//go:generate go fmt pkg/deploy/zz_generated_bindata.go
|
//go:generate go fmt pkg/deploy/zz_generated_bindata.go
|
||||||
|
//go:generate go fmt pkg/openapi/zz_generated_bindata.go
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
258
pkg/openapi/zz_generated_bindata.go
Normal file
258
pkg/openapi/zz_generated_bindata.go
Normal file
File diff suppressed because one or more lines are too long
@ -2,12 +2,21 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/rancher/k3s/pkg/daemons/config"
|
"github.com/rancher/k3s/pkg/daemons/config"
|
||||||
|
"github.com/rancher/k3s/pkg/openapi"
|
||||||
"k8s.io/apimachinery/pkg/util/json"
|
"k8s.io/apimachinery/pkg/util/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
jsonMediaType = "application/json"
|
||||||
|
binaryMediaType = "application/octet-stream"
|
||||||
|
pbMediaType = "application/com.github.proto-openapi.spec.v2@v1.0+protobuf"
|
||||||
|
openapiPrefix = "openapi."
|
||||||
|
)
|
||||||
|
|
||||||
type CACertsGetter func() (string, error)
|
type CACertsGetter func() (string, error)
|
||||||
|
|
||||||
func router(serverConfig *config.Control, tunnel http.Handler, cacertsGetter CACertsGetter) http.Handler {
|
func router(serverConfig *config.Control, tunnel http.Handler, cacertsGetter CACertsGetter) http.Handler {
|
||||||
@ -22,6 +31,7 @@ func router(serverConfig *config.Control, tunnel http.Handler, cacertsGetter CAC
|
|||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
router.NotFoundHandler = authed
|
router.NotFoundHandler = authed
|
||||||
router.Path("/cacerts").Handler(cacerts(cacertsGetter))
|
router.Path("/cacerts").Handler(cacerts(cacertsGetter))
|
||||||
|
router.Path("/openapi/v2").Handler(serveOpenapi())
|
||||||
|
|
||||||
return router
|
return router
|
||||||
}
|
}
|
||||||
@ -68,3 +78,25 @@ func configHandler(server *config.Control) http.Handler {
|
|||||||
json.NewEncoder(resp).Encode(server)
|
json.NewEncoder(resp).Encode(server)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func serveOpenapi() http.Handler {
|
||||||
|
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
|
||||||
|
suffix := "json"
|
||||||
|
contentType := jsonMediaType
|
||||||
|
if req.Header.Get("Accept") == pbMediaType {
|
||||||
|
suffix = "pb"
|
||||||
|
contentType = binaryMediaType
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := openapi.Asset(openapiPrefix + suffix)
|
||||||
|
if err != nil {
|
||||||
|
resp.WriteHeader(http.StatusInternalServerError)
|
||||||
|
resp.Write([]byte(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
resp.Header().Set("Content-Type", contentType)
|
||||||
|
resp.Header().Set("Content-Length", strconv.Itoa(len(data)))
|
||||||
|
resp.Write(data)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -44,6 +44,24 @@ func main() {
|
|||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bc = &bindata.Config{
|
||||||
|
Input: []bindata.InputConfig{
|
||||||
|
{
|
||||||
|
Path: "vendor/k8s.io/kubernetes/openapi.json",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: "vendor/k8s.io/kubernetes/openapi.pb",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Package: "openapi",
|
||||||
|
NoMetadata: true,
|
||||||
|
Prefix: "vendor/k8s.io/kubernetes/",
|
||||||
|
Output: "pkg/openapi/zz_generated_bindata.go",
|
||||||
|
}
|
||||||
|
if err := bindata.Translate(bc); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := generator.DefaultGenerate(v1.Schemas, basePackage, false, nil); err != nil {
|
if err := generator.DefaultGenerate(v1.Schemas, basePackage, false, nil); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user