forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.go
40 lines (31 loc) · 994 Bytes
/
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
package preference
import (
"strings"
"github.com/rancher/norman/store/transform"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/rancher/pkg/api/store/userscope"
"github.com/rancher/types/apis/core/v1"
"github.com/rancher/types/client/management/v3"
)
const (
NamespaceID = client.PreferenceFieldNamespaceId
)
func NewStore(nsClient v1.NamespaceInterface, store types.Store) types.Store {
return userscope.NewStore(nsClient,
&transform.Store{
Store: store,
Transformer: transformer,
})
}
func transformer(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}, opts *types.QueryOptions) (map[string]interface{}, error) {
if data == nil {
return nil, nil
}
ns := convert.ToString(data[NamespaceID])
id := convert.ToString(data[types.ResourceFieldID])
id = strings.TrimPrefix(id, ns+":")
data[client.PreferenceFieldName] = id
data[types.ResourceFieldID] = id
return data, nil
}