-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy_store.go
54 lines (44 loc) · 1.18 KB
/
proxy_store.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
50
51
52
53
54
package userstored
import (
"context"
"strings"
"github.com/rancher/norman/store/proxy"
"github.com/rancher/norman/types"
clusterSchema "github.com/rancher/types/apis/cluster.cattle.io/v3/schema"
"github.com/rancher/types/apis/project.cattle.io/v3/schema"
"github.com/rancher/types/config"
)
type storeWrapperFunc func(types.Store) types.Store
func addProxyStore(ctx context.Context, schemas *types.Schemas, context *config.ScaledContext, schemaType, apiVersion string, storeWrapper storeWrapperFunc) *types.Schema {
s := schemas.Schema(&schema.Version, schemaType)
if s == nil {
s = schemas.Schema(&clusterSchema.Version, schemaType)
}
if s == nil {
panic("Failed to find schema " + schemaType)
}
prefix := []string{"api"}
group := ""
version := "v1"
kind := s.CodeName
plural := s.PluralName
parts := strings.SplitN(apiVersion, "/", 2)
if len(parts) == 1 {
version = parts[0]
} else {
group = parts[0]
version = parts[1]
prefix = []string{"apis"}
}
s.Store = proxy.NewProxyStore(ctx, context.ClientGetter,
config.UserStorageContext,
prefix,
group,
version,
kind,
plural)
if storeWrapper != nil {
s.Store = storeWrapper(s.Store)
}
return s
}