-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_map.pb.fieldmask.go
395 lines (354 loc) · 12 KB
/
config_map.pb.fieldmask.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
// Code generated by protoc-gen-goten-object
// File: edgelq/applications/proto/v1alpha2/config_map.proto
// DO NOT EDIT!!!
package config_map
import (
"encoding/json"
"strings"
firestorepb "google.golang.org/genproto/googleapis/firestore/v1"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
preflect "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/types/known/fieldmaskpb"
gotenobject "github.com/cloudwan/goten-sdk/runtime/object"
)
// proto imports
import (
project "github.com/cloudwan/edgelq-sdk/applications/resources/v1alpha2/project"
ntt_meta "github.com/cloudwan/edgelq-sdk/common/types/meta"
)
// ensure the imports are used
var (
_ = new(json.Marshaler)
_ = strings.Builder{}
_ = firestorepb.Value{}
_ = codes.NotFound
_ = status.Status{}
_ = new(proto.Message)
_ = new(preflect.Message)
_ = fieldmaskpb.FieldMask{}
_ = new(gotenobject.FieldMask)
)
// make sure we're using proto imports
var (
_ = &project.Project{}
_ = &ntt_meta.Meta{}
)
type ConfigMap_FieldMask struct {
Paths []ConfigMap_FieldPath
}
func FullConfigMap_FieldMask() *ConfigMap_FieldMask {
res := &ConfigMap_FieldMask{}
res.Paths = append(res.Paths, &ConfigMap_FieldTerminalPath{selector: ConfigMap_FieldPathSelectorName})
res.Paths = append(res.Paths, &ConfigMap_FieldTerminalPath{selector: ConfigMap_FieldPathSelectorDisplayName})
res.Paths = append(res.Paths, &ConfigMap_FieldTerminalPath{selector: ConfigMap_FieldPathSelectorMetadata})
res.Paths = append(res.Paths, &ConfigMap_FieldTerminalPath{selector: ConfigMap_FieldPathSelectorData})
res.Paths = append(res.Paths, &ConfigMap_FieldTerminalPath{selector: ConfigMap_FieldPathSelectorBinaryData})
return res
}
func (fieldMask *ConfigMap_FieldMask) String() string {
if fieldMask == nil {
return "<nil>"
}
pathsStr := make([]string, 0, len(fieldMask.Paths))
for _, path := range fieldMask.Paths {
pathsStr = append(pathsStr, path.String())
}
return strings.Join(pathsStr, ", ")
}
// firestore encoding/decoding integration
func (fieldMask *ConfigMap_FieldMask) EncodeFirestore() (*firestorepb.Value, error) {
if fieldMask == nil {
return &firestorepb.Value{ValueType: &firestorepb.Value_NullValue{}}, nil
}
arrayValues := make([]*firestorepb.Value, 0, len(fieldMask.Paths))
for _, path := range fieldMask.GetPaths() {
arrayValues = append(arrayValues, &firestorepb.Value{ValueType: &firestorepb.Value_StringValue{StringValue: path.String()}})
}
return &firestorepb.Value{
ValueType: &firestorepb.Value_ArrayValue{ArrayValue: &firestorepb.ArrayValue{Values: arrayValues}},
}, nil
}
func (fieldMask *ConfigMap_FieldMask) DecodeFirestore(fpbv *firestorepb.Value) error {
for _, value := range fpbv.GetArrayValue().GetValues() {
parsedPath, err := ParseConfigMap_FieldPath(value.GetStringValue())
if err != nil {
return err
}
fieldMask.Paths = append(fieldMask.Paths, parsedPath)
}
return nil
}
func (fieldMask *ConfigMap_FieldMask) IsFull() bool {
if fieldMask == nil {
return false
}
presentSelectors := make([]bool, 5)
for _, path := range fieldMask.Paths {
if asFinal, ok := path.(*ConfigMap_FieldTerminalPath); ok {
presentSelectors[int(asFinal.selector)] = true
}
}
for _, flag := range presentSelectors {
if !flag {
return false
}
}
return true
}
func (fieldMask *ConfigMap_FieldMask) ProtoReflect() preflect.Message {
return gotenobject.MakeFieldMaskReflection(fieldMask, func(raw string) (gotenobject.FieldPath, error) {
return ParseConfigMap_FieldPath(raw)
})
}
func (fieldMask *ConfigMap_FieldMask) ProtoMessage() {}
func (fieldMask *ConfigMap_FieldMask) Reset() {
if fieldMask != nil {
fieldMask.Paths = nil
}
}
func (fieldMask *ConfigMap_FieldMask) Subtract(other *ConfigMap_FieldMask) *ConfigMap_FieldMask {
result := &ConfigMap_FieldMask{}
removedSelectors := make([]bool, 5)
otherSubMasks := map[ConfigMap_FieldPathSelector]gotenobject.FieldMask{
ConfigMap_FieldPathSelectorMetadata: &ntt_meta.Meta_FieldMask{},
}
mySubMasks := map[ConfigMap_FieldPathSelector]gotenobject.FieldMask{
ConfigMap_FieldPathSelectorMetadata: &ntt_meta.Meta_FieldMask{},
}
for _, path := range other.GetPaths() {
switch tp := path.(type) {
case *ConfigMap_FieldTerminalPath:
removedSelectors[int(tp.selector)] = true
case *ConfigMap_FieldSubPath:
otherSubMasks[tp.selector].AppendRawPath(tp.subPath)
}
}
for _, path := range fieldMask.GetPaths() {
if !removedSelectors[int(path.Selector())] {
if otherSubMask := otherSubMasks[path.Selector()]; otherSubMask != nil && otherSubMask.PathsCount() > 0 {
if tp, ok := path.(*ConfigMap_FieldTerminalPath); ok {
switch tp.selector {
case ConfigMap_FieldPathSelectorMetadata:
mySubMasks[ConfigMap_FieldPathSelectorMetadata] = ntt_meta.FullMeta_FieldMask()
}
} else if tp, ok := path.(*ConfigMap_FieldSubPath); ok {
mySubMasks[tp.selector].AppendRawPath(tp.subPath)
}
} else {
result.Paths = append(result.Paths, path)
}
}
}
for selector, mySubMask := range mySubMasks {
if mySubMask.PathsCount() > 0 {
for _, allowedPath := range mySubMask.SubtractRaw(otherSubMasks[selector]).GetRawPaths() {
result.Paths = append(result.Paths, &ConfigMap_FieldSubPath{selector: selector, subPath: allowedPath})
}
}
}
if len(result.Paths) == 0 {
return nil
}
return result
}
func (fieldMask *ConfigMap_FieldMask) SubtractRaw(other gotenobject.FieldMask) gotenobject.FieldMask {
return fieldMask.Subtract(other.(*ConfigMap_FieldMask))
}
// FilterInputFields generates copy of field paths with output_only field paths removed
func (fieldMask *ConfigMap_FieldMask) FilterInputFields() *ConfigMap_FieldMask {
result := &ConfigMap_FieldMask{}
for _, path := range fieldMask.Paths {
switch path.Selector() {
case ConfigMap_FieldPathSelectorMetadata:
if _, ok := path.(*ConfigMap_FieldTerminalPath); ok {
for _, subpath := range ntt_meta.FullMeta_FieldMask().FilterInputFields().Paths {
result.Paths = append(result.Paths, &ConfigMap_FieldSubPath{selector: path.Selector(), subPath: subpath})
}
} else if sub, ok := path.(*ConfigMap_FieldSubPath); ok {
selectedMask := &ntt_meta.Meta_FieldMask{
Paths: []ntt_meta.Meta_FieldPath{sub.subPath.(ntt_meta.Meta_FieldPath)},
}
for _, allowedPath := range selectedMask.FilterInputFields().Paths {
result.Paths = append(result.Paths, &ConfigMap_FieldSubPath{selector: ConfigMap_FieldPathSelectorMetadata, subPath: allowedPath})
}
}
default:
result.Paths = append(result.Paths, path)
}
}
return result
}
// ToFieldMask is used for proto conversions
func (fieldMask *ConfigMap_FieldMask) ToProtoFieldMask() *fieldmaskpb.FieldMask {
protoFieldMask := &fieldmaskpb.FieldMask{}
for _, path := range fieldMask.Paths {
protoFieldMask.Paths = append(protoFieldMask.Paths, path.String())
}
return protoFieldMask
}
func (fieldMask *ConfigMap_FieldMask) FromProtoFieldMask(protoFieldMask *fieldmaskpb.FieldMask) error {
if fieldMask == nil {
return status.Error(codes.Internal, "target field mask is nil")
}
fieldMask.Paths = make([]ConfigMap_FieldPath, 0, len(protoFieldMask.Paths))
for _, strPath := range protoFieldMask.Paths {
path, err := ParseConfigMap_FieldPath(strPath)
if err != nil {
return err
}
fieldMask.Paths = append(fieldMask.Paths, path)
}
return nil
}
// implement methods required by customType
func (fieldMask ConfigMap_FieldMask) Marshal() ([]byte, error) {
protoFieldMask := fieldMask.ToProtoFieldMask()
return proto.Marshal(protoFieldMask)
}
func (fieldMask *ConfigMap_FieldMask) Unmarshal(data []byte) error {
protoFieldMask := &fieldmaskpb.FieldMask{}
if err := proto.Unmarshal(data, protoFieldMask); err != nil {
return err
}
if err := fieldMask.FromProtoFieldMask(protoFieldMask); err != nil {
return err
}
return nil
}
func (fieldMask *ConfigMap_FieldMask) Size() int {
return proto.Size(fieldMask.ToProtoFieldMask())
}
func (fieldMask ConfigMap_FieldMask) MarshalJSON() ([]byte, error) {
return json.Marshal(fieldMask.ToProtoFieldMask())
}
func (fieldMask *ConfigMap_FieldMask) UnmarshalJSON(data []byte) error {
protoFieldMask := &fieldmaskpb.FieldMask{}
if err := json.Unmarshal(data, protoFieldMask); err != nil {
return err
}
if err := fieldMask.FromProtoFieldMask(protoFieldMask); err != nil {
return err
}
return nil
}
func (fieldMask *ConfigMap_FieldMask) AppendPath(path ConfigMap_FieldPath) {
fieldMask.Paths = append(fieldMask.Paths, path)
}
func (fieldMask *ConfigMap_FieldMask) AppendRawPath(path gotenobject.FieldPath) {
fieldMask.Paths = append(fieldMask.Paths, path.(ConfigMap_FieldPath))
}
func (fieldMask *ConfigMap_FieldMask) GetPaths() []ConfigMap_FieldPath {
if fieldMask == nil {
return nil
}
return fieldMask.Paths
}
func (fieldMask *ConfigMap_FieldMask) GetRawPaths() []gotenobject.FieldPath {
if fieldMask == nil {
return nil
}
rawPaths := make([]gotenobject.FieldPath, 0, len(fieldMask.Paths))
for _, path := range fieldMask.Paths {
rawPaths = append(rawPaths, path)
}
return rawPaths
}
func (fieldMask *ConfigMap_FieldMask) SetFromCliFlag(raw string) error {
path, err := ParseConfigMap_FieldPath(raw)
if err != nil {
return err
}
fieldMask.Paths = append(fieldMask.Paths, path)
return nil
}
func (fieldMask *ConfigMap_FieldMask) Set(target, source *ConfigMap) {
for _, path := range fieldMask.Paths {
val, _ := path.GetSingle(source)
// if val is nil, then field does not exist in source, skip
// otherwise, process (can still reflect.ValueOf(val).IsNil!)
if val != nil {
path.WithIValue(val).SetTo(&target)
}
}
}
func (fieldMask *ConfigMap_FieldMask) SetRaw(target, source gotenobject.GotenObjectExt) {
fieldMask.Set(target.(*ConfigMap), source.(*ConfigMap))
}
func (fieldMask *ConfigMap_FieldMask) Project(source *ConfigMap) *ConfigMap {
if source == nil {
return nil
}
if fieldMask == nil {
return source
}
result := &ConfigMap{}
metadataMask := &ntt_meta.Meta_FieldMask{}
wholeMetadataAccepted := false
var dataMapKeys []string
wholeDataAccepted := false
var binaryDataMapKeys []string
wholeBinaryDataAccepted := false
for _, p := range fieldMask.Paths {
switch tp := p.(type) {
case *ConfigMap_FieldTerminalPath:
switch tp.selector {
case ConfigMap_FieldPathSelectorName:
result.Name = source.Name
case ConfigMap_FieldPathSelectorDisplayName:
result.DisplayName = source.DisplayName
case ConfigMap_FieldPathSelectorMetadata:
result.Metadata = source.Metadata
wholeMetadataAccepted = true
case ConfigMap_FieldPathSelectorData:
result.Data = source.Data
wholeDataAccepted = true
case ConfigMap_FieldPathSelectorBinaryData:
result.BinaryData = source.BinaryData
wholeBinaryDataAccepted = true
}
case *ConfigMap_FieldSubPath:
switch tp.selector {
case ConfigMap_FieldPathSelectorMetadata:
metadataMask.AppendPath(tp.subPath.(ntt_meta.Meta_FieldPath))
}
case *ConfigMap_FieldPathMap:
switch tp.selector {
case ConfigMap_FieldPathSelectorData:
dataMapKeys = append(dataMapKeys, tp.key)
case ConfigMap_FieldPathSelectorBinaryData:
binaryDataMapKeys = append(binaryDataMapKeys, tp.key)
}
}
}
if wholeMetadataAccepted == false && len(metadataMask.Paths) > 0 {
result.Metadata = metadataMask.Project(source.GetMetadata())
}
if wholeDataAccepted == false && len(dataMapKeys) > 0 && source.GetData() != nil {
copiedMap := map[string]string{}
sourceMap := source.GetData()
for _, key := range dataMapKeys {
copiedMap[key] = sourceMap[key]
}
result.Data = copiedMap
}
if wholeBinaryDataAccepted == false && len(binaryDataMapKeys) > 0 && source.GetBinaryData() != nil {
copiedMap := map[string][]byte{}
sourceMap := source.GetBinaryData()
for _, key := range binaryDataMapKeys {
copiedMap[key] = sourceMap[key]
}
result.BinaryData = copiedMap
}
return result
}
func (fieldMask *ConfigMap_FieldMask) ProjectRaw(source gotenobject.GotenObjectExt) gotenobject.GotenObjectExt {
return fieldMask.Project(source.(*ConfigMap))
}
func (fieldMask *ConfigMap_FieldMask) PathsCount() int {
if fieldMask == nil {
return 0
}
return len(fieldMask.Paths)
}