-
Notifications
You must be signed in to change notification settings - Fork 1
/
os_image_profile.pb.fieldmask.go
389 lines (348 loc) · 13.1 KB
/
os_image_profile.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
// Code generated by protoc-gen-goten-object
// File: edgelq/devices/proto/v1alpha2/os_image_profile.proto
// DO NOT EDIT!!!
package os_image_profile
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 (
device_type "github.com/cloudwan/edgelq-sdk/devices/resources/v1alpha2/device_type"
project "github.com/cloudwan/edgelq-sdk/devices/resources/v1alpha2/project"
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 (
_ = &device_type.DeviceType{}
_ = &project.Project{}
_ = &meta.Meta{}
)
type OsImageProfile_FieldMask struct {
Paths []OsImageProfile_FieldPath
}
func FullOsImageProfile_FieldMask() *OsImageProfile_FieldMask {
res := &OsImageProfile_FieldMask{}
res.Paths = append(res.Paths, &OsImageProfile_FieldTerminalPath{selector: OsImageProfile_FieldPathSelectorName})
res.Paths = append(res.Paths, &OsImageProfile_FieldTerminalPath{selector: OsImageProfile_FieldPathSelectorMetadata})
res.Paths = append(res.Paths, &OsImageProfile_FieldTerminalPath{selector: OsImageProfile_FieldPathSelectorDisplayName})
res.Paths = append(res.Paths, &OsImageProfile_FieldTerminalPath{selector: OsImageProfile_FieldPathSelectorDeviceType})
res.Paths = append(res.Paths, &OsImageProfile_FieldTerminalPath{selector: OsImageProfile_FieldPathSelectorInstallAiAccelerator})
res.Paths = append(res.Paths, &OsImageProfile_FieldTerminalPath{selector: OsImageProfile_FieldPathSelectorEncryption})
res.Paths = append(res.Paths, &OsImageProfile_FieldTerminalPath{selector: OsImageProfile_FieldPathSelectorDiskMapping})
res.Paths = append(res.Paths, &OsImageProfile_FieldTerminalPath{selector: OsImageProfile_FieldPathSelectorNetworkAgent})
res.Paths = append(res.Paths, &OsImageProfile_FieldTerminalPath{selector: OsImageProfile_FieldPathSelectorNtp})
res.Paths = append(res.Paths, &OsImageProfile_FieldTerminalPath{selector: OsImageProfile_FieldPathSelectorHttpProxy})
res.Paths = append(res.Paths, &OsImageProfile_FieldTerminalPath{selector: OsImageProfile_FieldPathSelectorHttpsProxy})
res.Paths = append(res.Paths, &OsImageProfile_FieldTerminalPath{selector: OsImageProfile_FieldPathSelectorNoProxy})
return res
}
func (fieldMask *OsImageProfile_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 *OsImageProfile_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 *OsImageProfile_FieldMask) DecodeFirestore(fpbv *firestorepb.Value) error {
for _, value := range fpbv.GetArrayValue().GetValues() {
parsedPath, err := ParseOsImageProfile_FieldPath(value.GetStringValue())
if err != nil {
return err
}
fieldMask.Paths = append(fieldMask.Paths, parsedPath)
}
return nil
}
func (fieldMask *OsImageProfile_FieldMask) IsFull() bool {
if fieldMask == nil {
return false
}
presentSelectors := make([]bool, 12)
for _, path := range fieldMask.Paths {
if asFinal, ok := path.(*OsImageProfile_FieldTerminalPath); ok {
presentSelectors[int(asFinal.selector)] = true
}
}
for _, flag := range presentSelectors {
if !flag {
return false
}
}
return true
}
func (fieldMask *OsImageProfile_FieldMask) ProtoReflect() preflect.Message {
return gotenobject.MakeFieldMaskReflection(fieldMask, func(raw string) (gotenobject.FieldPath, error) {
return ParseOsImageProfile_FieldPath(raw)
})
}
func (fieldMask *OsImageProfile_FieldMask) ProtoMessage() {}
func (fieldMask *OsImageProfile_FieldMask) Reset() {
if fieldMask != nil {
fieldMask.Paths = nil
}
}
func (fieldMask *OsImageProfile_FieldMask) Subtract(other *OsImageProfile_FieldMask) *OsImageProfile_FieldMask {
result := &OsImageProfile_FieldMask{}
removedSelectors := make([]bool, 12)
otherSubMasks := map[OsImageProfile_FieldPathSelector]gotenobject.FieldMask{
OsImageProfile_FieldPathSelectorMetadata: &meta.Meta_FieldMask{},
}
mySubMasks := map[OsImageProfile_FieldPathSelector]gotenobject.FieldMask{
OsImageProfile_FieldPathSelectorMetadata: &meta.Meta_FieldMask{},
}
for _, path := range other.GetPaths() {
switch tp := path.(type) {
case *OsImageProfile_FieldTerminalPath:
removedSelectors[int(tp.selector)] = true
case *OsImageProfile_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.(*OsImageProfile_FieldTerminalPath); ok {
switch tp.selector {
case OsImageProfile_FieldPathSelectorMetadata:
mySubMasks[OsImageProfile_FieldPathSelectorMetadata] = meta.FullMeta_FieldMask()
}
} else if tp, ok := path.(*OsImageProfile_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, &OsImageProfile_FieldSubPath{selector: selector, subPath: allowedPath})
}
}
}
if len(result.Paths) == 0 {
return nil
}
return result
}
func (fieldMask *OsImageProfile_FieldMask) SubtractRaw(other gotenobject.FieldMask) gotenobject.FieldMask {
return fieldMask.Subtract(other.(*OsImageProfile_FieldMask))
}
// FilterInputFields generates copy of field paths with output_only field paths removed
func (fieldMask *OsImageProfile_FieldMask) FilterInputFields() *OsImageProfile_FieldMask {
result := &OsImageProfile_FieldMask{}
for _, path := range fieldMask.Paths {
switch path.Selector() {
case OsImageProfile_FieldPathSelectorMetadata:
if _, ok := path.(*OsImageProfile_FieldTerminalPath); ok {
for _, subpath := range meta.FullMeta_FieldMask().FilterInputFields().Paths {
result.Paths = append(result.Paths, &OsImageProfile_FieldSubPath{selector: path.Selector(), subPath: subpath})
}
} else if sub, ok := path.(*OsImageProfile_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, &OsImageProfile_FieldSubPath{selector: OsImageProfile_FieldPathSelectorMetadata, subPath: allowedPath})
}
}
default:
result.Paths = append(result.Paths, path)
}
}
return result
}
// ToFieldMask is used for proto conversions
func (fieldMask *OsImageProfile_FieldMask) ToProtoFieldMask() *googlefieldmaskpb.FieldMask {
protoFieldMask := &googlefieldmaskpb.FieldMask{}
for _, path := range fieldMask.Paths {
protoFieldMask.Paths = append(protoFieldMask.Paths, path.String())
}
return protoFieldMask
}
func (fieldMask *OsImageProfile_FieldMask) FromProtoFieldMask(protoFieldMask *googlefieldmaskpb.FieldMask) error {
if fieldMask == nil {
return status.Error(codes.Internal, "target field mask is nil")
}
fieldMask.Paths = make([]OsImageProfile_FieldPath, 0, len(protoFieldMask.Paths))
for _, strPath := range protoFieldMask.Paths {
path, err := ParseOsImageProfile_FieldPath(strPath)
if err != nil {
return err
}
fieldMask.Paths = append(fieldMask.Paths, path)
}
return nil
}
// implement methods required by customType
func (fieldMask OsImageProfile_FieldMask) Marshal() ([]byte, error) {
protoFieldMask := fieldMask.ToProtoFieldMask()
return proto.Marshal(protoFieldMask)
}
func (fieldMask *OsImageProfile_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 *OsImageProfile_FieldMask) Size() int {
return proto.Size(fieldMask.ToProtoFieldMask())
}
func (fieldMask OsImageProfile_FieldMask) MarshalJSON() ([]byte, error) {
return json.Marshal(fieldMask.ToProtoFieldMask())
}
func (fieldMask *OsImageProfile_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 *OsImageProfile_FieldMask) AppendPath(path OsImageProfile_FieldPath) {
fieldMask.Paths = append(fieldMask.Paths, path)
}
func (fieldMask *OsImageProfile_FieldMask) AppendRawPath(path gotenobject.FieldPath) {
fieldMask.Paths = append(fieldMask.Paths, path.(OsImageProfile_FieldPath))
}
func (fieldMask *OsImageProfile_FieldMask) GetPaths() []OsImageProfile_FieldPath {
if fieldMask == nil {
return nil
}
return fieldMask.Paths
}
func (fieldMask *OsImageProfile_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 *OsImageProfile_FieldMask) SetFromCliFlag(raw string) error {
path, err := ParseOsImageProfile_FieldPath(raw)
if err != nil {
return err
}
fieldMask.Paths = append(fieldMask.Paths, path)
return nil
}
func (fieldMask *OsImageProfile_FieldMask) Set(target, source *OsImageProfile) {
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 *OsImageProfile_FieldMask) SetRaw(target, source gotenobject.GotenObjectExt) {
fieldMask.Set(target.(*OsImageProfile), source.(*OsImageProfile))
}
func (fieldMask *OsImageProfile_FieldMask) Project(source *OsImageProfile) *OsImageProfile {
if source == nil {
return nil
}
if fieldMask == nil {
return source
}
result := &OsImageProfile{}
metadataMask := &meta.Meta_FieldMask{}
wholeMetadataAccepted := false
for _, p := range fieldMask.Paths {
switch tp := p.(type) {
case *OsImageProfile_FieldTerminalPath:
switch tp.selector {
case OsImageProfile_FieldPathSelectorName:
result.Name = source.Name
case OsImageProfile_FieldPathSelectorMetadata:
result.Metadata = source.Metadata
wholeMetadataAccepted = true
case OsImageProfile_FieldPathSelectorDisplayName:
result.DisplayName = source.DisplayName
case OsImageProfile_FieldPathSelectorDeviceType:
result.DeviceType = source.DeviceType
case OsImageProfile_FieldPathSelectorInstallAiAccelerator:
result.InstallAiAccelerator = source.InstallAiAccelerator
case OsImageProfile_FieldPathSelectorEncryption:
result.Encryption = source.Encryption
case OsImageProfile_FieldPathSelectorDiskMapping:
result.DiskMapping = source.DiskMapping
case OsImageProfile_FieldPathSelectorNetworkAgent:
result.NetworkAgent = source.NetworkAgent
case OsImageProfile_FieldPathSelectorNtp:
result.Ntp = source.Ntp
case OsImageProfile_FieldPathSelectorHttpProxy:
result.HttpProxy = source.HttpProxy
case OsImageProfile_FieldPathSelectorHttpsProxy:
result.HttpsProxy = source.HttpsProxy
case OsImageProfile_FieldPathSelectorNoProxy:
result.NoProxy = source.NoProxy
}
case *OsImageProfile_FieldSubPath:
switch tp.selector {
case OsImageProfile_FieldPathSelectorMetadata:
metadataMask.AppendPath(tp.subPath.(meta.Meta_FieldPath))
}
}
}
if wholeMetadataAccepted == false && len(metadataMask.Paths) > 0 {
result.Metadata = metadataMask.Project(source.GetMetadata())
}
return result
}
func (fieldMask *OsImageProfile_FieldMask) ProjectRaw(source gotenobject.GotenObjectExt) gotenobject.GotenObjectExt {
return fieldMask.Project(source.(*OsImageProfile))
}
func (fieldMask *OsImageProfile_FieldMask) PathsCount() int {
if fieldMask == nil {
return 0
}
return len(fieldMask.Paths)
}