...
1
16
17 package openapi
18
19 import (
20 "context"
21 "encoding/json"
22 "strings"
23
24 "k8s.io/client-go/rest"
25 "k8s.io/kube-openapi/pkg/handler3"
26 )
27
28 type Client interface {
29 Paths() (map[string]GroupVersion, error)
30 }
31
32 type client struct {
33
34 restClient rest.Interface
35 }
36
37 func NewClient(restClient rest.Interface) Client {
38 return &client{
39 restClient: restClient,
40 }
41 }
42
43 func (c *client) Paths() (map[string]GroupVersion, error) {
44 data, err := c.restClient.Get().
45 AbsPath("/openapi/v3").
46 Do(context.TODO()).
47 Raw()
48
49 if err != nil {
50 return nil, err
51 }
52
53 discoMap := &handler3.OpenAPIV3Discovery{}
54 err = json.Unmarshal(data, discoMap)
55 if err != nil {
56 return nil, err
57 }
58
59
60 result := map[string]GroupVersion{}
61 for k, v := range discoMap.Paths {
62
63
64
65 useClientPrefix := strings.HasPrefix(v.ServerRelativeURL, "/openapi/v3")
66 result[k] = newGroupVersion(c, v, useClientPrefix)
67 }
68 return result, nil
69 }
70
View as plain text