-
Notifications
You must be signed in to change notification settings - Fork 1
/
log_descriptor.pb.fieldmask.go
401 lines (360 loc) · 13.5 KB
/
log_descriptor.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
396
397
398
399
400
401
// Code generated by protoc-gen-goten-object
// File: edgelq/logging/proto/v1alpha2/log_descriptor.proto
// DO NOT EDIT!!!
package log_descriptor
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"
googlefieldmaskpb "google.golang.org/protobuf/types/known/fieldmaskpb"
gotenobject "github.com/cloudwan/goten-sdk/runtime/object"
)
// proto imports
import (
iam_organization "github.com/cloudwan/edgelq-sdk/iam/resources/v1alpha2/organization"
iam_project "github.com/cloudwan/edgelq-sdk/iam/resources/v1alpha2/project"
common "github.com/cloudwan/edgelq-sdk/logging/resources/v1alpha2/common"
meta "github.com/cloudwan/goten-sdk/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)
_ = googlefieldmaskpb.FieldMask{}
_ = new(gotenobject.FieldMask)
)
// make sure we're using proto imports
var (
_ = &iam_organization.Organization{}
_ = &iam_project.Project{}
_ = &common.LabelDescriptor{}
_ = &meta.Meta{}
)
type LogDescriptor_FieldMask struct {
Paths []LogDescriptor_FieldPath
}
func FullLogDescriptor_FieldMask() *LogDescriptor_FieldMask {
res := &LogDescriptor_FieldMask{}
res.Paths = append(res.Paths, &LogDescriptor_FieldTerminalPath{selector: LogDescriptor_FieldPathSelectorName})
res.Paths = append(res.Paths, &LogDescriptor_FieldTerminalPath{selector: LogDescriptor_FieldPathSelectorDisplayName})
res.Paths = append(res.Paths, &LogDescriptor_FieldTerminalPath{selector: LogDescriptor_FieldPathSelectorDescription})
res.Paths = append(res.Paths, &LogDescriptor_FieldTerminalPath{selector: LogDescriptor_FieldPathSelectorLabels})
res.Paths = append(res.Paths, &LogDescriptor_FieldTerminalPath{selector: LogDescriptor_FieldPathSelectorPromotedLabelKeySets})
res.Paths = append(res.Paths, &LogDescriptor_FieldTerminalPath{selector: LogDescriptor_FieldPathSelectorMetadata})
return res
}
func (fieldMask *LogDescriptor_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 *LogDescriptor_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 *LogDescriptor_FieldMask) DecodeFirestore(fpbv *firestorepb.Value) error {
for _, value := range fpbv.GetArrayValue().GetValues() {
parsedPath, err := ParseLogDescriptor_FieldPath(value.GetStringValue())
if err != nil {
return err
}
fieldMask.Paths = append(fieldMask.Paths, parsedPath)
}
return nil
}
func (fieldMask *LogDescriptor_FieldMask) IsFull() bool {
if fieldMask == nil {
return false
}
presentSelectors := make([]bool, 6)
for _, path := range fieldMask.Paths {
if asFinal, ok := path.(*LogDescriptor_FieldTerminalPath); ok {
presentSelectors[int(asFinal.selector)] = true
}
}
for _, flag := range presentSelectors {
if !flag {
return false
}
}
return true
}
func (fieldMask *LogDescriptor_FieldMask) ProtoReflect() preflect.Message {
return gotenobject.MakeFieldMaskReflection(fieldMask, func(raw string) (gotenobject.FieldPath, error) {
return ParseLogDescriptor_FieldPath(raw)
})
}
func (fieldMask *LogDescriptor_FieldMask) ProtoMessage() {}
func (fieldMask *LogDescriptor_FieldMask) Reset() {
if fieldMask != nil {
fieldMask.Paths = nil
}
}
func (fieldMask *LogDescriptor_FieldMask) Subtract(other *LogDescriptor_FieldMask) *LogDescriptor_FieldMask {
result := &LogDescriptor_FieldMask{}
removedSelectors := make([]bool, 6)
otherSubMasks := map[LogDescriptor_FieldPathSelector]gotenobject.FieldMask{
LogDescriptor_FieldPathSelectorLabels: &common.LabelDescriptor_FieldMask{},
LogDescriptor_FieldPathSelectorPromotedLabelKeySets: &common.LabelKeySet_FieldMask{},
LogDescriptor_FieldPathSelectorMetadata: &meta.Meta_FieldMask{},
}
mySubMasks := map[LogDescriptor_FieldPathSelector]gotenobject.FieldMask{
LogDescriptor_FieldPathSelectorLabels: &common.LabelDescriptor_FieldMask{},
LogDescriptor_FieldPathSelectorPromotedLabelKeySets: &common.LabelKeySet_FieldMask{},
LogDescriptor_FieldPathSelectorMetadata: &meta.Meta_FieldMask{},
}
for _, path := range other.GetPaths() {
switch tp := path.(type) {
case *LogDescriptor_FieldTerminalPath:
removedSelectors[int(tp.selector)] = true
case *LogDescriptor_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.(*LogDescriptor_FieldTerminalPath); ok {
switch tp.selector {
case LogDescriptor_FieldPathSelectorLabels:
mySubMasks[LogDescriptor_FieldPathSelectorLabels] = common.FullLabelDescriptor_FieldMask()
case LogDescriptor_FieldPathSelectorPromotedLabelKeySets:
mySubMasks[LogDescriptor_FieldPathSelectorPromotedLabelKeySets] = common.FullLabelKeySet_FieldMask()
case LogDescriptor_FieldPathSelectorMetadata:
mySubMasks[LogDescriptor_FieldPathSelectorMetadata] = meta.FullMeta_FieldMask()
}
} else if tp, ok := path.(*LogDescriptor_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, &LogDescriptor_FieldSubPath{selector: selector, subPath: allowedPath})
}
}
}
if len(result.Paths) == 0 {
return nil
}
return result
}
func (fieldMask *LogDescriptor_FieldMask) SubtractRaw(other gotenobject.FieldMask) gotenobject.FieldMask {
return fieldMask.Subtract(other.(*LogDescriptor_FieldMask))
}
// FilterInputFields generates copy of field paths with output_only field paths removed
func (fieldMask *LogDescriptor_FieldMask) FilterInputFields() *LogDescriptor_FieldMask {
result := &LogDescriptor_FieldMask{}
for _, path := range fieldMask.Paths {
switch path.Selector() {
case LogDescriptor_FieldPathSelectorMetadata:
if _, ok := path.(*LogDescriptor_FieldTerminalPath); ok {
for _, subpath := range meta.FullMeta_FieldMask().FilterInputFields().Paths {
result.Paths = append(result.Paths, &LogDescriptor_FieldSubPath{selector: path.Selector(), subPath: subpath})
}
} else if sub, ok := path.(*LogDescriptor_FieldSubPath); ok {
selectedMask := &meta.Meta_FieldMask{
Paths: []meta.Meta_FieldPath{sub.subPath.(meta.Meta_FieldPath)},
}
for _, allowedPath := range selectedMask.FilterInputFields().Paths {
result.Paths = append(result.Paths, &LogDescriptor_FieldSubPath{selector: LogDescriptor_FieldPathSelectorMetadata, subPath: allowedPath})
}
}
default:
result.Paths = append(result.Paths, path)
}
}
return result
}
// ToFieldMask is used for proto conversions
func (fieldMask *LogDescriptor_FieldMask) ToProtoFieldMask() *googlefieldmaskpb.FieldMask {
protoFieldMask := &googlefieldmaskpb.FieldMask{}
for _, path := range fieldMask.Paths {
protoFieldMask.Paths = append(protoFieldMask.Paths, path.String())
}
return protoFieldMask
}
func (fieldMask *LogDescriptor_FieldMask) FromProtoFieldMask(protoFieldMask *googlefieldmaskpb.FieldMask) error {
if fieldMask == nil {
return status.Error(codes.Internal, "target field mask is nil")
}
fieldMask.Paths = make([]LogDescriptor_FieldPath, 0, len(protoFieldMask.Paths))
for _, strPath := range protoFieldMask.Paths {
path, err := ParseLogDescriptor_FieldPath(strPath)
if err != nil {
return err
}
fieldMask.Paths = append(fieldMask.Paths, path)
}
return nil
}
// implement methods required by customType
func (fieldMask LogDescriptor_FieldMask) Marshal() ([]byte, error) {
protoFieldMask := fieldMask.ToProtoFieldMask()
return proto.Marshal(protoFieldMask)
}
func (fieldMask *LogDescriptor_FieldMask) Unmarshal(data []byte) error {
protoFieldMask := &googlefieldmaskpb.FieldMask{}
if err := proto.Unmarshal(data, protoFieldMask); err != nil {
return err
}
if err := fieldMask.FromProtoFieldMask(protoFieldMask); err != nil {
return err
}
return nil
}
func (fieldMask *LogDescriptor_FieldMask) Size() int {
return proto.Size(fieldMask.ToProtoFieldMask())
}
func (fieldMask LogDescriptor_FieldMask) MarshalJSON() ([]byte, error) {
return json.Marshal(fieldMask.ToProtoFieldMask())
}
func (fieldMask *LogDescriptor_FieldMask) UnmarshalJSON(data []byte) error {
protoFieldMask := &googlefieldmaskpb.FieldMask{}
if err := json.Unmarshal(data, protoFieldMask); err != nil {
return err
}
if err := fieldMask.FromProtoFieldMask(protoFieldMask); err != nil {
return err
}
return nil
}
func (fieldMask *LogDescriptor_FieldMask) AppendPath(path LogDescriptor_FieldPath) {
fieldMask.Paths = append(fieldMask.Paths, path)
}
func (fieldMask *LogDescriptor_FieldMask) AppendRawPath(path gotenobject.FieldPath) {
fieldMask.Paths = append(fieldMask.Paths, path.(LogDescriptor_FieldPath))
}
func (fieldMask *LogDescriptor_FieldMask) GetPaths() []LogDescriptor_FieldPath {
if fieldMask == nil {
return nil
}
return fieldMask.Paths
}
func (fieldMask *LogDescriptor_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 *LogDescriptor_FieldMask) SetFromCliFlag(raw string) error {
path, err := ParseLogDescriptor_FieldPath(raw)
if err != nil {
return err
}
fieldMask.Paths = append(fieldMask.Paths, path)
return nil
}
func (fieldMask *LogDescriptor_FieldMask) Set(target, source *LogDescriptor) {
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 *LogDescriptor_FieldMask) SetRaw(target, source gotenobject.GotenObjectExt) {
fieldMask.Set(target.(*LogDescriptor), source.(*LogDescriptor))
}
func (fieldMask *LogDescriptor_FieldMask) Project(source *LogDescriptor) *LogDescriptor {
if source == nil {
return nil
}
if fieldMask == nil {
return source
}
result := &LogDescriptor{}
labelsMask := &common.LabelDescriptor_FieldMask{}
wholeLabelsAccepted := false
promotedLabelKeySetsMask := &common.LabelKeySet_FieldMask{}
wholePromotedLabelKeySetsAccepted := false
metadataMask := &meta.Meta_FieldMask{}
wholeMetadataAccepted := false
for _, p := range fieldMask.Paths {
switch tp := p.(type) {
case *LogDescriptor_FieldTerminalPath:
switch tp.selector {
case LogDescriptor_FieldPathSelectorName:
result.Name = source.Name
case LogDescriptor_FieldPathSelectorDisplayName:
result.DisplayName = source.DisplayName
case LogDescriptor_FieldPathSelectorDescription:
result.Description = source.Description
case LogDescriptor_FieldPathSelectorLabels:
result.Labels = source.Labels
wholeLabelsAccepted = true
case LogDescriptor_FieldPathSelectorPromotedLabelKeySets:
result.PromotedLabelKeySets = source.PromotedLabelKeySets
wholePromotedLabelKeySetsAccepted = true
case LogDescriptor_FieldPathSelectorMetadata:
result.Metadata = source.Metadata
wholeMetadataAccepted = true
}
case *LogDescriptor_FieldSubPath:
switch tp.selector {
case LogDescriptor_FieldPathSelectorLabels:
labelsMask.AppendPath(tp.subPath.(common.LabelDescriptor_FieldPath))
case LogDescriptor_FieldPathSelectorPromotedLabelKeySets:
promotedLabelKeySetsMask.AppendPath(tp.subPath.(common.LabelKeySet_FieldPath))
case LogDescriptor_FieldPathSelectorMetadata:
metadataMask.AppendPath(tp.subPath.(meta.Meta_FieldPath))
}
}
}
if wholeLabelsAccepted == false && len(labelsMask.Paths) > 0 {
for _, sourceItem := range source.GetLabels() {
result.Labels = append(result.Labels, labelsMask.Project(sourceItem))
}
}
if wholePromotedLabelKeySetsAccepted == false && len(promotedLabelKeySetsMask.Paths) > 0 {
for _, sourceItem := range source.GetPromotedLabelKeySets() {
result.PromotedLabelKeySets = append(result.PromotedLabelKeySets, promotedLabelKeySetsMask.Project(sourceItem))
}
}
if wholeMetadataAccepted == false && len(metadataMask.Paths) > 0 {
result.Metadata = metadataMask.Project(source.GetMetadata())
}
return result
}
func (fieldMask *LogDescriptor_FieldMask) ProjectRaw(source gotenobject.GotenObjectExt) gotenobject.GotenObjectExt {
return fieldMask.Project(source.(*LogDescriptor))
}
func (fieldMask *LogDescriptor_FieldMask) PathsCount() int {
if fieldMask == nil {
return 0
}
return len(fieldMask.Paths)
}