github.com/cloudwan/edgelq-sdk@v1.15.4/alerting/resources/v1/policy/policy.pb.fieldpath.go (about) 1 // Code generated by protoc-gen-goten-object 2 // File: edgelq/alerting/proto/v1/policy.proto 3 // DO NOT EDIT!!! 4 5 package policy 6 7 import ( 8 "encoding/json" 9 "fmt" 10 "reflect" 11 "strings" 12 "time" 13 14 "google.golang.org/grpc/codes" 15 "google.golang.org/grpc/status" 16 "google.golang.org/protobuf/encoding/protojson" 17 "google.golang.org/protobuf/proto" 18 "google.golang.org/protobuf/reflect/protoregistry" 19 20 gotenobject "github.com/cloudwan/goten-sdk/runtime/object" 21 "github.com/cloudwan/goten-sdk/runtime/strcase" 22 ) 23 24 // proto imports 25 import ( 26 rcommon "github.com/cloudwan/edgelq-sdk/alerting/resources/v1/common" 27 document "github.com/cloudwan/edgelq-sdk/alerting/resources/v1/document" 28 notification_channel "github.com/cloudwan/edgelq-sdk/alerting/resources/v1/notification_channel" 29 policy_template "github.com/cloudwan/edgelq-sdk/alerting/resources/v1/policy_template" 30 iam_project "github.com/cloudwan/edgelq-sdk/iam/resources/v1/project" 31 meta "github.com/cloudwan/goten-sdk/types/meta" 32 fieldmaskpb "google.golang.org/protobuf/types/known/fieldmaskpb" 33 ) 34 35 // ensure the imports are used 36 var ( 37 _ = new(json.Marshaler) 38 _ = new(fmt.Stringer) 39 _ = reflect.DeepEqual 40 _ = strings.Builder{} 41 _ = time.Second 42 43 _ = strcase.ToLowerCamel 44 _ = codes.NotFound 45 _ = status.Status{} 46 _ = protojson.UnmarshalOptions{} 47 _ = new(proto.Message) 48 _ = protoregistry.GlobalTypes 49 50 _ = new(gotenobject.FieldPath) 51 ) 52 53 // make sure we're using proto imports 54 var ( 55 _ = &document.Document{} 56 _ = ¬ification_channel.NotificationChannel{} 57 _ = &policy_template.PolicyTemplate{} 58 _ = &rcommon.LogCndSpec{} 59 _ = &iam_project.Project{} 60 _ = &fieldmaskpb.FieldMask{} 61 _ = &meta.Meta{} 62 ) 63 64 // FieldPath provides implementation to handle 65 // https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/field_mask.proto 66 type Policy_FieldPath interface { 67 gotenobject.FieldPath 68 Selector() Policy_FieldPathSelector 69 Get(source *Policy) []interface{} 70 GetSingle(source *Policy) (interface{}, bool) 71 ClearValue(item *Policy) 72 73 // Those methods build corresponding Policy_FieldPathValue 74 // (or array of values) and holds passed value. Panics if injected type is incorrect. 75 WithIValue(value interface{}) Policy_FieldPathValue 76 WithIArrayOfValues(values interface{}) Policy_FieldPathArrayOfValues 77 WithIArrayItemValue(value interface{}) Policy_FieldPathArrayItemValue 78 } 79 80 type Policy_FieldPathSelector int32 81 82 const ( 83 Policy_FieldPathSelectorName Policy_FieldPathSelector = 0 84 Policy_FieldPathSelectorMetadata Policy_FieldPathSelector = 1 85 Policy_FieldPathSelectorDisplayName Policy_FieldPathSelector = 2 86 Policy_FieldPathSelectorDescription Policy_FieldPathSelector = 3 87 Policy_FieldPathSelectorSupportingDocs Policy_FieldPathSelector = 4 88 Policy_FieldPathSelectorSpec Policy_FieldPathSelector = 5 89 Policy_FieldPathSelectorTemplateSource Policy_FieldPathSelector = 6 90 Policy_FieldPathSelectorNotificationChannels Policy_FieldPathSelector = 7 91 ) 92 93 func (s Policy_FieldPathSelector) String() string { 94 switch s { 95 case Policy_FieldPathSelectorName: 96 return "name" 97 case Policy_FieldPathSelectorMetadata: 98 return "metadata" 99 case Policy_FieldPathSelectorDisplayName: 100 return "display_name" 101 case Policy_FieldPathSelectorDescription: 102 return "description" 103 case Policy_FieldPathSelectorSupportingDocs: 104 return "supporting_docs" 105 case Policy_FieldPathSelectorSpec: 106 return "spec" 107 case Policy_FieldPathSelectorTemplateSource: 108 return "template_source" 109 case Policy_FieldPathSelectorNotificationChannels: 110 return "notification_channels" 111 default: 112 panic(fmt.Sprintf("Invalid selector for Policy: %d", s)) 113 } 114 } 115 116 func BuildPolicy_FieldPath(fp gotenobject.RawFieldPath) (Policy_FieldPath, error) { 117 if len(fp) == 0 { 118 return nil, status.Error(codes.InvalidArgument, "empty field path for object Policy") 119 } 120 if len(fp) == 1 { 121 switch fp[0] { 122 case "name": 123 return &Policy_FieldTerminalPath{selector: Policy_FieldPathSelectorName}, nil 124 case "metadata": 125 return &Policy_FieldTerminalPath{selector: Policy_FieldPathSelectorMetadata}, nil 126 case "display_name", "displayName", "display-name": 127 return &Policy_FieldTerminalPath{selector: Policy_FieldPathSelectorDisplayName}, nil 128 case "description": 129 return &Policy_FieldTerminalPath{selector: Policy_FieldPathSelectorDescription}, nil 130 case "supporting_docs", "supportingDocs", "supporting-docs": 131 return &Policy_FieldTerminalPath{selector: Policy_FieldPathSelectorSupportingDocs}, nil 132 case "spec": 133 return &Policy_FieldTerminalPath{selector: Policy_FieldPathSelectorSpec}, nil 134 case "template_source", "templateSource", "template-source": 135 return &Policy_FieldTerminalPath{selector: Policy_FieldPathSelectorTemplateSource}, nil 136 case "notification_channels", "notificationChannels", "notification-channels": 137 return &Policy_FieldTerminalPath{selector: Policy_FieldPathSelectorNotificationChannels}, nil 138 } 139 } else { 140 switch fp[0] { 141 case "metadata": 142 if subpath, err := meta.BuildMeta_FieldPath(fp[1:]); err != nil { 143 return nil, err 144 } else { 145 return &Policy_FieldSubPath{selector: Policy_FieldPathSelectorMetadata, subPath: subpath}, nil 146 } 147 case "spec": 148 if subpath, err := rcommon.BuildPolicySpec_FieldPath(fp[1:]); err != nil { 149 return nil, err 150 } else { 151 return &Policy_FieldSubPath{selector: Policy_FieldPathSelectorSpec, subPath: subpath}, nil 152 } 153 case "template_source", "templateSource", "template-source": 154 if subpath, err := BuildPolicyTemplateSource_FieldPath(fp[1:]); err != nil { 155 return nil, err 156 } else { 157 return &Policy_FieldSubPath{selector: Policy_FieldPathSelectorTemplateSource, subPath: subpath}, nil 158 } 159 } 160 } 161 return nil, status.Errorf(codes.InvalidArgument, "unknown field path '%s' for object Policy", fp) 162 } 163 164 func ParsePolicy_FieldPath(rawField string) (Policy_FieldPath, error) { 165 fp, err := gotenobject.ParseRawFieldPath(rawField) 166 if err != nil { 167 return nil, err 168 } 169 return BuildPolicy_FieldPath(fp) 170 } 171 172 func MustParsePolicy_FieldPath(rawField string) Policy_FieldPath { 173 fp, err := ParsePolicy_FieldPath(rawField) 174 if err != nil { 175 panic(err) 176 } 177 return fp 178 } 179 180 type Policy_FieldTerminalPath struct { 181 selector Policy_FieldPathSelector 182 } 183 184 var _ Policy_FieldPath = (*Policy_FieldTerminalPath)(nil) 185 186 func (fp *Policy_FieldTerminalPath) Selector() Policy_FieldPathSelector { 187 return fp.selector 188 } 189 190 // String returns path representation in proto convention 191 func (fp *Policy_FieldTerminalPath) String() string { 192 return fp.selector.String() 193 } 194 195 // JSONString returns path representation is JSON convention 196 func (fp *Policy_FieldTerminalPath) JSONString() string { 197 return strcase.ToLowerCamel(fp.String()) 198 } 199 200 // Get returns all values pointed by specific field from source Policy 201 func (fp *Policy_FieldTerminalPath) Get(source *Policy) (values []interface{}) { 202 if source != nil { 203 switch fp.selector { 204 case Policy_FieldPathSelectorName: 205 if source.Name != nil { 206 values = append(values, source.Name) 207 } 208 case Policy_FieldPathSelectorMetadata: 209 if source.Metadata != nil { 210 values = append(values, source.Metadata) 211 } 212 case Policy_FieldPathSelectorDisplayName: 213 values = append(values, source.DisplayName) 214 case Policy_FieldPathSelectorDescription: 215 values = append(values, source.Description) 216 case Policy_FieldPathSelectorSupportingDocs: 217 for _, value := range source.GetSupportingDocs() { 218 values = append(values, value) 219 } 220 case Policy_FieldPathSelectorSpec: 221 if source.Spec != nil { 222 values = append(values, source.Spec) 223 } 224 case Policy_FieldPathSelectorTemplateSource: 225 if source.TemplateSource != nil { 226 values = append(values, source.TemplateSource) 227 } 228 case Policy_FieldPathSelectorNotificationChannels: 229 for _, value := range source.GetNotificationChannels() { 230 values = append(values, value) 231 } 232 default: 233 panic(fmt.Sprintf("Invalid selector for Policy: %d", fp.selector)) 234 } 235 } 236 return 237 } 238 239 func (fp *Policy_FieldTerminalPath) GetRaw(source proto.Message) []interface{} { 240 return fp.Get(source.(*Policy)) 241 } 242 243 // GetSingle returns value pointed by specific field of from source Policy 244 func (fp *Policy_FieldTerminalPath) GetSingle(source *Policy) (interface{}, bool) { 245 switch fp.selector { 246 case Policy_FieldPathSelectorName: 247 res := source.GetName() 248 return res, res != nil 249 case Policy_FieldPathSelectorMetadata: 250 res := source.GetMetadata() 251 return res, res != nil 252 case Policy_FieldPathSelectorDisplayName: 253 return source.GetDisplayName(), source != nil 254 case Policy_FieldPathSelectorDescription: 255 return source.GetDescription(), source != nil 256 case Policy_FieldPathSelectorSupportingDocs: 257 res := source.GetSupportingDocs() 258 return res, res != nil 259 case Policy_FieldPathSelectorSpec: 260 res := source.GetSpec() 261 return res, res != nil 262 case Policy_FieldPathSelectorTemplateSource: 263 res := source.GetTemplateSource() 264 return res, res != nil 265 case Policy_FieldPathSelectorNotificationChannels: 266 res := source.GetNotificationChannels() 267 return res, res != nil 268 default: 269 panic(fmt.Sprintf("Invalid selector for Policy: %d", fp.selector)) 270 } 271 } 272 273 func (fp *Policy_FieldTerminalPath) GetSingleRaw(source proto.Message) (interface{}, bool) { 274 return fp.GetSingle(source.(*Policy)) 275 } 276 277 // GetDefault returns a default value of the field type 278 func (fp *Policy_FieldTerminalPath) GetDefault() interface{} { 279 switch fp.selector { 280 case Policy_FieldPathSelectorName: 281 return (*Name)(nil) 282 case Policy_FieldPathSelectorMetadata: 283 return (*meta.Meta)(nil) 284 case Policy_FieldPathSelectorDisplayName: 285 return "" 286 case Policy_FieldPathSelectorDescription: 287 return "" 288 case Policy_FieldPathSelectorSupportingDocs: 289 return ([]*document.Reference)(nil) 290 case Policy_FieldPathSelectorSpec: 291 return (*rcommon.PolicySpec)(nil) 292 case Policy_FieldPathSelectorTemplateSource: 293 return (*Policy_TemplateSource)(nil) 294 case Policy_FieldPathSelectorNotificationChannels: 295 return ([]*notification_channel.Reference)(nil) 296 default: 297 panic(fmt.Sprintf("Invalid selector for Policy: %d", fp.selector)) 298 } 299 } 300 301 func (fp *Policy_FieldTerminalPath) ClearValue(item *Policy) { 302 if item != nil { 303 switch fp.selector { 304 case Policy_FieldPathSelectorName: 305 item.Name = nil 306 case Policy_FieldPathSelectorMetadata: 307 item.Metadata = nil 308 case Policy_FieldPathSelectorDisplayName: 309 item.DisplayName = "" 310 case Policy_FieldPathSelectorDescription: 311 item.Description = "" 312 case Policy_FieldPathSelectorSupportingDocs: 313 item.SupportingDocs = nil 314 case Policy_FieldPathSelectorSpec: 315 item.Spec = nil 316 case Policy_FieldPathSelectorTemplateSource: 317 item.TemplateSource = nil 318 case Policy_FieldPathSelectorNotificationChannels: 319 item.NotificationChannels = nil 320 default: 321 panic(fmt.Sprintf("Invalid selector for Policy: %d", fp.selector)) 322 } 323 } 324 } 325 326 func (fp *Policy_FieldTerminalPath) ClearValueRaw(item proto.Message) { 327 fp.ClearValue(item.(*Policy)) 328 } 329 330 // IsLeaf - whether field path is holds simple value 331 func (fp *Policy_FieldTerminalPath) IsLeaf() bool { 332 return fp.selector == Policy_FieldPathSelectorName || 333 fp.selector == Policy_FieldPathSelectorDisplayName || 334 fp.selector == Policy_FieldPathSelectorDescription || 335 fp.selector == Policy_FieldPathSelectorSupportingDocs || 336 fp.selector == Policy_FieldPathSelectorNotificationChannels 337 } 338 339 func (fp *Policy_FieldTerminalPath) SplitIntoTerminalIPaths() []gotenobject.FieldPath { 340 return []gotenobject.FieldPath{fp} 341 } 342 343 func (fp *Policy_FieldTerminalPath) WithIValue(value interface{}) Policy_FieldPathValue { 344 switch fp.selector { 345 case Policy_FieldPathSelectorName: 346 return &Policy_FieldTerminalPathValue{Policy_FieldTerminalPath: *fp, value: value.(*Name)} 347 case Policy_FieldPathSelectorMetadata: 348 return &Policy_FieldTerminalPathValue{Policy_FieldTerminalPath: *fp, value: value.(*meta.Meta)} 349 case Policy_FieldPathSelectorDisplayName: 350 return &Policy_FieldTerminalPathValue{Policy_FieldTerminalPath: *fp, value: value.(string)} 351 case Policy_FieldPathSelectorDescription: 352 return &Policy_FieldTerminalPathValue{Policy_FieldTerminalPath: *fp, value: value.(string)} 353 case Policy_FieldPathSelectorSupportingDocs: 354 return &Policy_FieldTerminalPathValue{Policy_FieldTerminalPath: *fp, value: value.([]*document.Reference)} 355 case Policy_FieldPathSelectorSpec: 356 return &Policy_FieldTerminalPathValue{Policy_FieldTerminalPath: *fp, value: value.(*rcommon.PolicySpec)} 357 case Policy_FieldPathSelectorTemplateSource: 358 return &Policy_FieldTerminalPathValue{Policy_FieldTerminalPath: *fp, value: value.(*Policy_TemplateSource)} 359 case Policy_FieldPathSelectorNotificationChannels: 360 return &Policy_FieldTerminalPathValue{Policy_FieldTerminalPath: *fp, value: value.([]*notification_channel.Reference)} 361 default: 362 panic(fmt.Sprintf("Invalid selector for Policy: %d", fp.selector)) 363 } 364 } 365 366 func (fp *Policy_FieldTerminalPath) WithRawIValue(value interface{}) gotenobject.FieldPathValue { 367 return fp.WithIValue(value) 368 } 369 370 func (fp *Policy_FieldTerminalPath) WithIArrayOfValues(values interface{}) Policy_FieldPathArrayOfValues { 371 fpaov := &Policy_FieldTerminalPathArrayOfValues{Policy_FieldTerminalPath: *fp} 372 switch fp.selector { 373 case Policy_FieldPathSelectorName: 374 return &Policy_FieldTerminalPathArrayOfValues{Policy_FieldTerminalPath: *fp, values: values.([]*Name)} 375 case Policy_FieldPathSelectorMetadata: 376 return &Policy_FieldTerminalPathArrayOfValues{Policy_FieldTerminalPath: *fp, values: values.([]*meta.Meta)} 377 case Policy_FieldPathSelectorDisplayName: 378 return &Policy_FieldTerminalPathArrayOfValues{Policy_FieldTerminalPath: *fp, values: values.([]string)} 379 case Policy_FieldPathSelectorDescription: 380 return &Policy_FieldTerminalPathArrayOfValues{Policy_FieldTerminalPath: *fp, values: values.([]string)} 381 case Policy_FieldPathSelectorSupportingDocs: 382 return &Policy_FieldTerminalPathArrayOfValues{Policy_FieldTerminalPath: *fp, values: values.([][]*document.Reference)} 383 case Policy_FieldPathSelectorSpec: 384 return &Policy_FieldTerminalPathArrayOfValues{Policy_FieldTerminalPath: *fp, values: values.([]*rcommon.PolicySpec)} 385 case Policy_FieldPathSelectorTemplateSource: 386 return &Policy_FieldTerminalPathArrayOfValues{Policy_FieldTerminalPath: *fp, values: values.([]*Policy_TemplateSource)} 387 case Policy_FieldPathSelectorNotificationChannels: 388 return &Policy_FieldTerminalPathArrayOfValues{Policy_FieldTerminalPath: *fp, values: values.([][]*notification_channel.Reference)} 389 default: 390 panic(fmt.Sprintf("Invalid selector for Policy: %d", fp.selector)) 391 } 392 return fpaov 393 } 394 395 func (fp *Policy_FieldTerminalPath) WithRawIArrayOfValues(values interface{}) gotenobject.FieldPathArrayOfValues { 396 return fp.WithIArrayOfValues(values) 397 } 398 399 func (fp *Policy_FieldTerminalPath) WithIArrayItemValue(value interface{}) Policy_FieldPathArrayItemValue { 400 switch fp.selector { 401 case Policy_FieldPathSelectorSupportingDocs: 402 return &Policy_FieldTerminalPathArrayItemValue{Policy_FieldTerminalPath: *fp, value: value.(*document.Reference)} 403 case Policy_FieldPathSelectorNotificationChannels: 404 return &Policy_FieldTerminalPathArrayItemValue{Policy_FieldTerminalPath: *fp, value: value.(*notification_channel.Reference)} 405 default: 406 panic(fmt.Sprintf("Invalid selector for Policy: %d", fp.selector)) 407 } 408 } 409 410 func (fp *Policy_FieldTerminalPath) WithRawIArrayItemValue(value interface{}) gotenobject.FieldPathArrayItemValue { 411 return fp.WithIArrayItemValue(value) 412 } 413 414 type Policy_FieldSubPath struct { 415 selector Policy_FieldPathSelector 416 subPath gotenobject.FieldPath 417 } 418 419 var _ Policy_FieldPath = (*Policy_FieldSubPath)(nil) 420 421 func (fps *Policy_FieldSubPath) Selector() Policy_FieldPathSelector { 422 return fps.selector 423 } 424 func (fps *Policy_FieldSubPath) AsMetadataSubPath() (meta.Meta_FieldPath, bool) { 425 res, ok := fps.subPath.(meta.Meta_FieldPath) 426 return res, ok 427 } 428 func (fps *Policy_FieldSubPath) AsSpecSubPath() (rcommon.PolicySpec_FieldPath, bool) { 429 res, ok := fps.subPath.(rcommon.PolicySpec_FieldPath) 430 return res, ok 431 } 432 func (fps *Policy_FieldSubPath) AsTemplateSourceSubPath() (PolicyTemplateSource_FieldPath, bool) { 433 res, ok := fps.subPath.(PolicyTemplateSource_FieldPath) 434 return res, ok 435 } 436 437 // String returns path representation in proto convention 438 func (fps *Policy_FieldSubPath) String() string { 439 return fps.selector.String() + "." + fps.subPath.String() 440 } 441 442 // JSONString returns path representation is JSON convention 443 func (fps *Policy_FieldSubPath) JSONString() string { 444 return strcase.ToLowerCamel(fps.selector.String()) + "." + fps.subPath.JSONString() 445 } 446 447 // Get returns all values pointed by selected field from source Policy 448 func (fps *Policy_FieldSubPath) Get(source *Policy) (values []interface{}) { 449 switch fps.selector { 450 case Policy_FieldPathSelectorMetadata: 451 values = append(values, fps.subPath.GetRaw(source.GetMetadata())...) 452 case Policy_FieldPathSelectorSpec: 453 values = append(values, fps.subPath.GetRaw(source.GetSpec())...) 454 case Policy_FieldPathSelectorTemplateSource: 455 values = append(values, fps.subPath.GetRaw(source.GetTemplateSource())...) 456 default: 457 panic(fmt.Sprintf("Invalid selector for Policy: %d", fps.selector)) 458 } 459 return 460 } 461 462 func (fps *Policy_FieldSubPath) GetRaw(source proto.Message) []interface{} { 463 return fps.Get(source.(*Policy)) 464 } 465 466 // GetSingle returns value of selected field from source Policy 467 func (fps *Policy_FieldSubPath) GetSingle(source *Policy) (interface{}, bool) { 468 switch fps.selector { 469 case Policy_FieldPathSelectorMetadata: 470 if source.GetMetadata() == nil { 471 return nil, false 472 } 473 return fps.subPath.GetSingleRaw(source.GetMetadata()) 474 case Policy_FieldPathSelectorSpec: 475 if source.GetSpec() == nil { 476 return nil, false 477 } 478 return fps.subPath.GetSingleRaw(source.GetSpec()) 479 case Policy_FieldPathSelectorTemplateSource: 480 if source.GetTemplateSource() == nil { 481 return nil, false 482 } 483 return fps.subPath.GetSingleRaw(source.GetTemplateSource()) 484 default: 485 panic(fmt.Sprintf("Invalid selector for Policy: %d", fps.selector)) 486 } 487 } 488 489 func (fps *Policy_FieldSubPath) GetSingleRaw(source proto.Message) (interface{}, bool) { 490 return fps.GetSingle(source.(*Policy)) 491 } 492 493 // GetDefault returns a default value of the field type 494 func (fps *Policy_FieldSubPath) GetDefault() interface{} { 495 return fps.subPath.GetDefault() 496 } 497 498 func (fps *Policy_FieldSubPath) ClearValue(item *Policy) { 499 if item != nil { 500 switch fps.selector { 501 case Policy_FieldPathSelectorMetadata: 502 fps.subPath.ClearValueRaw(item.Metadata) 503 case Policy_FieldPathSelectorSpec: 504 fps.subPath.ClearValueRaw(item.Spec) 505 case Policy_FieldPathSelectorTemplateSource: 506 fps.subPath.ClearValueRaw(item.TemplateSource) 507 default: 508 panic(fmt.Sprintf("Invalid selector for Policy: %d", fps.selector)) 509 } 510 } 511 } 512 513 func (fps *Policy_FieldSubPath) ClearValueRaw(item proto.Message) { 514 fps.ClearValue(item.(*Policy)) 515 } 516 517 // IsLeaf - whether field path is holds simple value 518 func (fps *Policy_FieldSubPath) IsLeaf() bool { 519 return fps.subPath.IsLeaf() 520 } 521 522 func (fps *Policy_FieldSubPath) SplitIntoTerminalIPaths() []gotenobject.FieldPath { 523 iPaths := []gotenobject.FieldPath{&Policy_FieldTerminalPath{selector: fps.selector}} 524 iPaths = append(iPaths, fps.subPath.SplitIntoTerminalIPaths()...) 525 return iPaths 526 } 527 528 func (fps *Policy_FieldSubPath) WithIValue(value interface{}) Policy_FieldPathValue { 529 return &Policy_FieldSubPathValue{fps, fps.subPath.WithRawIValue(value)} 530 } 531 532 func (fps *Policy_FieldSubPath) WithRawIValue(value interface{}) gotenobject.FieldPathValue { 533 return fps.WithIValue(value) 534 } 535 536 func (fps *Policy_FieldSubPath) WithIArrayOfValues(values interface{}) Policy_FieldPathArrayOfValues { 537 return &Policy_FieldSubPathArrayOfValues{fps, fps.subPath.WithRawIArrayOfValues(values)} 538 } 539 540 func (fps *Policy_FieldSubPath) WithRawIArrayOfValues(values interface{}) gotenobject.FieldPathArrayOfValues { 541 return fps.WithIArrayOfValues(values) 542 } 543 544 func (fps *Policy_FieldSubPath) WithIArrayItemValue(value interface{}) Policy_FieldPathArrayItemValue { 545 return &Policy_FieldSubPathArrayItemValue{fps, fps.subPath.WithRawIArrayItemValue(value)} 546 } 547 548 func (fps *Policy_FieldSubPath) WithRawIArrayItemValue(value interface{}) gotenobject.FieldPathArrayItemValue { 549 return fps.WithIArrayItemValue(value) 550 } 551 552 // Policy_FieldPathValue allows storing values for Policy fields according to their type 553 type Policy_FieldPathValue interface { 554 Policy_FieldPath 555 gotenobject.FieldPathValue 556 SetTo(target **Policy) 557 CompareWith(*Policy) (cmp int, comparable bool) 558 } 559 560 func ParsePolicy_FieldPathValue(pathStr, valueStr string) (Policy_FieldPathValue, error) { 561 fp, err := ParsePolicy_FieldPath(pathStr) 562 if err != nil { 563 return nil, err 564 } 565 fpv, err := gotenobject.ParseFieldPathValue(fp, valueStr) 566 if err != nil { 567 return nil, status.Errorf(codes.InvalidArgument, "error parsing Policy field path value from %s: %v", valueStr, err) 568 } 569 return fpv.(Policy_FieldPathValue), nil 570 } 571 572 func MustParsePolicy_FieldPathValue(pathStr, valueStr string) Policy_FieldPathValue { 573 fpv, err := ParsePolicy_FieldPathValue(pathStr, valueStr) 574 if err != nil { 575 panic(err) 576 } 577 return fpv 578 } 579 580 type Policy_FieldTerminalPathValue struct { 581 Policy_FieldTerminalPath 582 value interface{} 583 } 584 585 var _ Policy_FieldPathValue = (*Policy_FieldTerminalPathValue)(nil) 586 587 // GetRawValue returns raw value stored under selected path for 'Policy' as interface{} 588 func (fpv *Policy_FieldTerminalPathValue) GetRawValue() interface{} { 589 return fpv.value 590 } 591 func (fpv *Policy_FieldTerminalPathValue) AsNameValue() (*Name, bool) { 592 res, ok := fpv.value.(*Name) 593 return res, ok 594 } 595 func (fpv *Policy_FieldTerminalPathValue) AsMetadataValue() (*meta.Meta, bool) { 596 res, ok := fpv.value.(*meta.Meta) 597 return res, ok 598 } 599 func (fpv *Policy_FieldTerminalPathValue) AsDisplayNameValue() (string, bool) { 600 res, ok := fpv.value.(string) 601 return res, ok 602 } 603 func (fpv *Policy_FieldTerminalPathValue) AsDescriptionValue() (string, bool) { 604 res, ok := fpv.value.(string) 605 return res, ok 606 } 607 func (fpv *Policy_FieldTerminalPathValue) AsSupportingDocsValue() ([]*document.Reference, bool) { 608 res, ok := fpv.value.([]*document.Reference) 609 return res, ok 610 } 611 func (fpv *Policy_FieldTerminalPathValue) AsSpecValue() (*rcommon.PolicySpec, bool) { 612 res, ok := fpv.value.(*rcommon.PolicySpec) 613 return res, ok 614 } 615 func (fpv *Policy_FieldTerminalPathValue) AsTemplateSourceValue() (*Policy_TemplateSource, bool) { 616 res, ok := fpv.value.(*Policy_TemplateSource) 617 return res, ok 618 } 619 func (fpv *Policy_FieldTerminalPathValue) AsNotificationChannelsValue() ([]*notification_channel.Reference, bool) { 620 res, ok := fpv.value.([]*notification_channel.Reference) 621 return res, ok 622 } 623 624 // SetTo stores value for selected field for object Policy 625 func (fpv *Policy_FieldTerminalPathValue) SetTo(target **Policy) { 626 if *target == nil { 627 *target = new(Policy) 628 } 629 switch fpv.selector { 630 case Policy_FieldPathSelectorName: 631 (*target).Name = fpv.value.(*Name) 632 case Policy_FieldPathSelectorMetadata: 633 (*target).Metadata = fpv.value.(*meta.Meta) 634 case Policy_FieldPathSelectorDisplayName: 635 (*target).DisplayName = fpv.value.(string) 636 case Policy_FieldPathSelectorDescription: 637 (*target).Description = fpv.value.(string) 638 case Policy_FieldPathSelectorSupportingDocs: 639 (*target).SupportingDocs = fpv.value.([]*document.Reference) 640 case Policy_FieldPathSelectorSpec: 641 (*target).Spec = fpv.value.(*rcommon.PolicySpec) 642 case Policy_FieldPathSelectorTemplateSource: 643 (*target).TemplateSource = fpv.value.(*Policy_TemplateSource) 644 case Policy_FieldPathSelectorNotificationChannels: 645 (*target).NotificationChannels = fpv.value.([]*notification_channel.Reference) 646 default: 647 panic(fmt.Sprintf("Invalid selector for Policy: %d", fpv.selector)) 648 } 649 } 650 651 func (fpv *Policy_FieldTerminalPathValue) SetToRaw(target proto.Message) { 652 typedObject := target.(*Policy) 653 fpv.SetTo(&typedObject) 654 } 655 656 // CompareWith compares value in the 'Policy_FieldTerminalPathValue' with the value under path in 'Policy'. 657 func (fpv *Policy_FieldTerminalPathValue) CompareWith(source *Policy) (int, bool) { 658 switch fpv.selector { 659 case Policy_FieldPathSelectorName: 660 leftValue := fpv.value.(*Name) 661 rightValue := source.GetName() 662 if leftValue == nil { 663 if rightValue != nil { 664 return -1, true 665 } 666 return 0, true 667 } 668 if rightValue == nil { 669 return 1, true 670 } 671 if leftValue.String() == rightValue.String() { 672 return 0, true 673 } else if leftValue.String() < rightValue.String() { 674 return -1, true 675 } else { 676 return 1, true 677 } 678 case Policy_FieldPathSelectorMetadata: 679 return 0, false 680 case Policy_FieldPathSelectorDisplayName: 681 leftValue := fpv.value.(string) 682 rightValue := source.GetDisplayName() 683 if (leftValue) == (rightValue) { 684 return 0, true 685 } else if (leftValue) < (rightValue) { 686 return -1, true 687 } else { 688 return 1, true 689 } 690 case Policy_FieldPathSelectorDescription: 691 leftValue := fpv.value.(string) 692 rightValue := source.GetDescription() 693 if (leftValue) == (rightValue) { 694 return 0, true 695 } else if (leftValue) < (rightValue) { 696 return -1, true 697 } else { 698 return 1, true 699 } 700 case Policy_FieldPathSelectorSupportingDocs: 701 return 0, false 702 case Policy_FieldPathSelectorSpec: 703 return 0, false 704 case Policy_FieldPathSelectorTemplateSource: 705 return 0, false 706 case Policy_FieldPathSelectorNotificationChannels: 707 return 0, false 708 default: 709 panic(fmt.Sprintf("Invalid selector for Policy: %d", fpv.selector)) 710 } 711 } 712 713 func (fpv *Policy_FieldTerminalPathValue) CompareWithRaw(source proto.Message) (int, bool) { 714 return fpv.CompareWith(source.(*Policy)) 715 } 716 717 type Policy_FieldSubPathValue struct { 718 Policy_FieldPath 719 subPathValue gotenobject.FieldPathValue 720 } 721 722 var _ Policy_FieldPathValue = (*Policy_FieldSubPathValue)(nil) 723 724 func (fpvs *Policy_FieldSubPathValue) AsMetadataPathValue() (meta.Meta_FieldPathValue, bool) { 725 res, ok := fpvs.subPathValue.(meta.Meta_FieldPathValue) 726 return res, ok 727 } 728 func (fpvs *Policy_FieldSubPathValue) AsSpecPathValue() (rcommon.PolicySpec_FieldPathValue, bool) { 729 res, ok := fpvs.subPathValue.(rcommon.PolicySpec_FieldPathValue) 730 return res, ok 731 } 732 func (fpvs *Policy_FieldSubPathValue) AsTemplateSourcePathValue() (PolicyTemplateSource_FieldPathValue, bool) { 733 res, ok := fpvs.subPathValue.(PolicyTemplateSource_FieldPathValue) 734 return res, ok 735 } 736 737 func (fpvs *Policy_FieldSubPathValue) SetTo(target **Policy) { 738 if *target == nil { 739 *target = new(Policy) 740 } 741 switch fpvs.Selector() { 742 case Policy_FieldPathSelectorMetadata: 743 fpvs.subPathValue.(meta.Meta_FieldPathValue).SetTo(&(*target).Metadata) 744 case Policy_FieldPathSelectorSpec: 745 fpvs.subPathValue.(rcommon.PolicySpec_FieldPathValue).SetTo(&(*target).Spec) 746 case Policy_FieldPathSelectorTemplateSource: 747 fpvs.subPathValue.(PolicyTemplateSource_FieldPathValue).SetTo(&(*target).TemplateSource) 748 default: 749 panic(fmt.Sprintf("Invalid selector for Policy: %d", fpvs.Selector())) 750 } 751 } 752 753 func (fpvs *Policy_FieldSubPathValue) SetToRaw(target proto.Message) { 754 typedObject := target.(*Policy) 755 fpvs.SetTo(&typedObject) 756 } 757 758 func (fpvs *Policy_FieldSubPathValue) GetRawValue() interface{} { 759 return fpvs.subPathValue.GetRawValue() 760 } 761 762 func (fpvs *Policy_FieldSubPathValue) CompareWith(source *Policy) (int, bool) { 763 switch fpvs.Selector() { 764 case Policy_FieldPathSelectorMetadata: 765 return fpvs.subPathValue.(meta.Meta_FieldPathValue).CompareWith(source.GetMetadata()) 766 case Policy_FieldPathSelectorSpec: 767 return fpvs.subPathValue.(rcommon.PolicySpec_FieldPathValue).CompareWith(source.GetSpec()) 768 case Policy_FieldPathSelectorTemplateSource: 769 return fpvs.subPathValue.(PolicyTemplateSource_FieldPathValue).CompareWith(source.GetTemplateSource()) 770 default: 771 panic(fmt.Sprintf("Invalid selector for Policy: %d", fpvs.Selector())) 772 } 773 } 774 775 func (fpvs *Policy_FieldSubPathValue) CompareWithRaw(source proto.Message) (int, bool) { 776 return fpvs.CompareWith(source.(*Policy)) 777 } 778 779 // Policy_FieldPathArrayItemValue allows storing single item in Path-specific values for Policy according to their type 780 // Present only for array (repeated) types. 781 type Policy_FieldPathArrayItemValue interface { 782 gotenobject.FieldPathArrayItemValue 783 Policy_FieldPath 784 ContainsValue(*Policy) bool 785 } 786 787 // ParsePolicy_FieldPathArrayItemValue parses string and JSON-encoded value to its Value 788 func ParsePolicy_FieldPathArrayItemValue(pathStr, valueStr string) (Policy_FieldPathArrayItemValue, error) { 789 fp, err := ParsePolicy_FieldPath(pathStr) 790 if err != nil { 791 return nil, err 792 } 793 fpaiv, err := gotenobject.ParseFieldPathArrayItemValue(fp, valueStr) 794 if err != nil { 795 return nil, status.Errorf(codes.InvalidArgument, "error parsing Policy field path array item value from %s: %v", valueStr, err) 796 } 797 return fpaiv.(Policy_FieldPathArrayItemValue), nil 798 } 799 800 func MustParsePolicy_FieldPathArrayItemValue(pathStr, valueStr string) Policy_FieldPathArrayItemValue { 801 fpaiv, err := ParsePolicy_FieldPathArrayItemValue(pathStr, valueStr) 802 if err != nil { 803 panic(err) 804 } 805 return fpaiv 806 } 807 808 type Policy_FieldTerminalPathArrayItemValue struct { 809 Policy_FieldTerminalPath 810 value interface{} 811 } 812 813 var _ Policy_FieldPathArrayItemValue = (*Policy_FieldTerminalPathArrayItemValue)(nil) 814 815 // GetRawValue returns stored element value for array in object Policy as interface{} 816 func (fpaiv *Policy_FieldTerminalPathArrayItemValue) GetRawItemValue() interface{} { 817 return fpaiv.value 818 } 819 func (fpaiv *Policy_FieldTerminalPathArrayItemValue) AsSupportingDocsItemValue() (*document.Reference, bool) { 820 res, ok := fpaiv.value.(*document.Reference) 821 return res, ok 822 } 823 func (fpaiv *Policy_FieldTerminalPathArrayItemValue) AsNotificationChannelsItemValue() (*notification_channel.Reference, bool) { 824 res, ok := fpaiv.value.(*notification_channel.Reference) 825 return res, ok 826 } 827 828 func (fpaiv *Policy_FieldTerminalPathArrayItemValue) GetSingle(source *Policy) (interface{}, bool) { 829 return nil, false 830 } 831 832 func (fpaiv *Policy_FieldTerminalPathArrayItemValue) GetSingleRaw(source proto.Message) (interface{}, bool) { 833 return fpaiv.GetSingle(source.(*Policy)) 834 } 835 836 // Contains returns a boolean indicating if value that is being held is present in given 'Policy' 837 func (fpaiv *Policy_FieldTerminalPathArrayItemValue) ContainsValue(source *Policy) bool { 838 slice := fpaiv.Policy_FieldTerminalPath.Get(source) 839 for _, v := range slice { 840 if asProtoMsg, ok := fpaiv.value.(proto.Message); ok { 841 if proto.Equal(asProtoMsg, v.(proto.Message)) { 842 return true 843 } 844 } else if reflect.DeepEqual(v, fpaiv.value) { 845 return true 846 } 847 } 848 return false 849 } 850 851 type Policy_FieldSubPathArrayItemValue struct { 852 Policy_FieldPath 853 subPathItemValue gotenobject.FieldPathArrayItemValue 854 } 855 856 // GetRawValue returns stored array item value 857 func (fpaivs *Policy_FieldSubPathArrayItemValue) GetRawItemValue() interface{} { 858 return fpaivs.subPathItemValue.GetRawItemValue() 859 } 860 func (fpaivs *Policy_FieldSubPathArrayItemValue) AsMetadataPathItemValue() (meta.Meta_FieldPathArrayItemValue, bool) { 861 res, ok := fpaivs.subPathItemValue.(meta.Meta_FieldPathArrayItemValue) 862 return res, ok 863 } 864 func (fpaivs *Policy_FieldSubPathArrayItemValue) AsSpecPathItemValue() (rcommon.PolicySpec_FieldPathArrayItemValue, bool) { 865 res, ok := fpaivs.subPathItemValue.(rcommon.PolicySpec_FieldPathArrayItemValue) 866 return res, ok 867 } 868 func (fpaivs *Policy_FieldSubPathArrayItemValue) AsTemplateSourcePathItemValue() (PolicyTemplateSource_FieldPathArrayItemValue, bool) { 869 res, ok := fpaivs.subPathItemValue.(PolicyTemplateSource_FieldPathArrayItemValue) 870 return res, ok 871 } 872 873 // Contains returns a boolean indicating if value that is being held is present in given 'Policy' 874 func (fpaivs *Policy_FieldSubPathArrayItemValue) ContainsValue(source *Policy) bool { 875 switch fpaivs.Selector() { 876 case Policy_FieldPathSelectorMetadata: 877 return fpaivs.subPathItemValue.(meta.Meta_FieldPathArrayItemValue).ContainsValue(source.GetMetadata()) 878 case Policy_FieldPathSelectorSpec: 879 return fpaivs.subPathItemValue.(rcommon.PolicySpec_FieldPathArrayItemValue).ContainsValue(source.GetSpec()) 880 case Policy_FieldPathSelectorTemplateSource: 881 return fpaivs.subPathItemValue.(PolicyTemplateSource_FieldPathArrayItemValue).ContainsValue(source.GetTemplateSource()) 882 default: 883 panic(fmt.Sprintf("Invalid selector for Policy: %d", fpaivs.Selector())) 884 } 885 } 886 887 // Policy_FieldPathArrayOfValues allows storing slice of values for Policy fields according to their type 888 type Policy_FieldPathArrayOfValues interface { 889 gotenobject.FieldPathArrayOfValues 890 Policy_FieldPath 891 } 892 893 func ParsePolicy_FieldPathArrayOfValues(pathStr, valuesStr string) (Policy_FieldPathArrayOfValues, error) { 894 fp, err := ParsePolicy_FieldPath(pathStr) 895 if err != nil { 896 return nil, err 897 } 898 fpaov, err := gotenobject.ParseFieldPathArrayOfValues(fp, valuesStr) 899 if err != nil { 900 return nil, status.Errorf(codes.InvalidArgument, "error parsing Policy field path array of values from %s: %v", valuesStr, err) 901 } 902 return fpaov.(Policy_FieldPathArrayOfValues), nil 903 } 904 905 func MustParsePolicy_FieldPathArrayOfValues(pathStr, valuesStr string) Policy_FieldPathArrayOfValues { 906 fpaov, err := ParsePolicy_FieldPathArrayOfValues(pathStr, valuesStr) 907 if err != nil { 908 panic(err) 909 } 910 return fpaov 911 } 912 913 type Policy_FieldTerminalPathArrayOfValues struct { 914 Policy_FieldTerminalPath 915 values interface{} 916 } 917 918 var _ Policy_FieldPathArrayOfValues = (*Policy_FieldTerminalPathArrayOfValues)(nil) 919 920 func (fpaov *Policy_FieldTerminalPathArrayOfValues) GetRawValues() (values []interface{}) { 921 switch fpaov.selector { 922 case Policy_FieldPathSelectorName: 923 for _, v := range fpaov.values.([]*Name) { 924 values = append(values, v) 925 } 926 case Policy_FieldPathSelectorMetadata: 927 for _, v := range fpaov.values.([]*meta.Meta) { 928 values = append(values, v) 929 } 930 case Policy_FieldPathSelectorDisplayName: 931 for _, v := range fpaov.values.([]string) { 932 values = append(values, v) 933 } 934 case Policy_FieldPathSelectorDescription: 935 for _, v := range fpaov.values.([]string) { 936 values = append(values, v) 937 } 938 case Policy_FieldPathSelectorSupportingDocs: 939 for _, v := range fpaov.values.([][]*document.Reference) { 940 values = append(values, v) 941 } 942 case Policy_FieldPathSelectorSpec: 943 for _, v := range fpaov.values.([]*rcommon.PolicySpec) { 944 values = append(values, v) 945 } 946 case Policy_FieldPathSelectorTemplateSource: 947 for _, v := range fpaov.values.([]*Policy_TemplateSource) { 948 values = append(values, v) 949 } 950 case Policy_FieldPathSelectorNotificationChannels: 951 for _, v := range fpaov.values.([][]*notification_channel.Reference) { 952 values = append(values, v) 953 } 954 } 955 return 956 } 957 func (fpaov *Policy_FieldTerminalPathArrayOfValues) AsNameArrayOfValues() ([]*Name, bool) { 958 res, ok := fpaov.values.([]*Name) 959 return res, ok 960 } 961 func (fpaov *Policy_FieldTerminalPathArrayOfValues) AsMetadataArrayOfValues() ([]*meta.Meta, bool) { 962 res, ok := fpaov.values.([]*meta.Meta) 963 return res, ok 964 } 965 func (fpaov *Policy_FieldTerminalPathArrayOfValues) AsDisplayNameArrayOfValues() ([]string, bool) { 966 res, ok := fpaov.values.([]string) 967 return res, ok 968 } 969 func (fpaov *Policy_FieldTerminalPathArrayOfValues) AsDescriptionArrayOfValues() ([]string, bool) { 970 res, ok := fpaov.values.([]string) 971 return res, ok 972 } 973 func (fpaov *Policy_FieldTerminalPathArrayOfValues) AsSupportingDocsArrayOfValues() ([][]*document.Reference, bool) { 974 res, ok := fpaov.values.([][]*document.Reference) 975 return res, ok 976 } 977 func (fpaov *Policy_FieldTerminalPathArrayOfValues) AsSpecArrayOfValues() ([]*rcommon.PolicySpec, bool) { 978 res, ok := fpaov.values.([]*rcommon.PolicySpec) 979 return res, ok 980 } 981 func (fpaov *Policy_FieldTerminalPathArrayOfValues) AsTemplateSourceArrayOfValues() ([]*Policy_TemplateSource, bool) { 982 res, ok := fpaov.values.([]*Policy_TemplateSource) 983 return res, ok 984 } 985 func (fpaov *Policy_FieldTerminalPathArrayOfValues) AsNotificationChannelsArrayOfValues() ([][]*notification_channel.Reference, bool) { 986 res, ok := fpaov.values.([][]*notification_channel.Reference) 987 return res, ok 988 } 989 990 type Policy_FieldSubPathArrayOfValues struct { 991 Policy_FieldPath 992 subPathArrayOfValues gotenobject.FieldPathArrayOfValues 993 } 994 995 var _ Policy_FieldPathArrayOfValues = (*Policy_FieldSubPathArrayOfValues)(nil) 996 997 func (fpsaov *Policy_FieldSubPathArrayOfValues) GetRawValues() []interface{} { 998 return fpsaov.subPathArrayOfValues.GetRawValues() 999 } 1000 func (fpsaov *Policy_FieldSubPathArrayOfValues) AsMetadataPathArrayOfValues() (meta.Meta_FieldPathArrayOfValues, bool) { 1001 res, ok := fpsaov.subPathArrayOfValues.(meta.Meta_FieldPathArrayOfValues) 1002 return res, ok 1003 } 1004 func (fpsaov *Policy_FieldSubPathArrayOfValues) AsSpecPathArrayOfValues() (rcommon.PolicySpec_FieldPathArrayOfValues, bool) { 1005 res, ok := fpsaov.subPathArrayOfValues.(rcommon.PolicySpec_FieldPathArrayOfValues) 1006 return res, ok 1007 } 1008 func (fpsaov *Policy_FieldSubPathArrayOfValues) AsTemplateSourcePathArrayOfValues() (PolicyTemplateSource_FieldPathArrayOfValues, bool) { 1009 res, ok := fpsaov.subPathArrayOfValues.(PolicyTemplateSource_FieldPathArrayOfValues) 1010 return res, ok 1011 } 1012 1013 // FieldPath provides implementation to handle 1014 // https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/field_mask.proto 1015 type PolicyTemplateSource_FieldPath interface { 1016 gotenobject.FieldPath 1017 Selector() PolicyTemplateSource_FieldPathSelector 1018 Get(source *Policy_TemplateSource) []interface{} 1019 GetSingle(source *Policy_TemplateSource) (interface{}, bool) 1020 ClearValue(item *Policy_TemplateSource) 1021 1022 // Those methods build corresponding PolicyTemplateSource_FieldPathValue 1023 // (or array of values) and holds passed value. Panics if injected type is incorrect. 1024 WithIValue(value interface{}) PolicyTemplateSource_FieldPathValue 1025 WithIArrayOfValues(values interface{}) PolicyTemplateSource_FieldPathArrayOfValues 1026 WithIArrayItemValue(value interface{}) PolicyTemplateSource_FieldPathArrayItemValue 1027 } 1028 1029 type PolicyTemplateSource_FieldPathSelector int32 1030 1031 const ( 1032 PolicyTemplateSource_FieldPathSelectorTemplate PolicyTemplateSource_FieldPathSelector = 0 1033 PolicyTemplateSource_FieldPathSelectorUpdatedFields PolicyTemplateSource_FieldPathSelector = 1 1034 ) 1035 1036 func (s PolicyTemplateSource_FieldPathSelector) String() string { 1037 switch s { 1038 case PolicyTemplateSource_FieldPathSelectorTemplate: 1039 return "template" 1040 case PolicyTemplateSource_FieldPathSelectorUpdatedFields: 1041 return "updated_fields" 1042 default: 1043 panic(fmt.Sprintf("Invalid selector for Policy_TemplateSource: %d", s)) 1044 } 1045 } 1046 1047 func BuildPolicyTemplateSource_FieldPath(fp gotenobject.RawFieldPath) (PolicyTemplateSource_FieldPath, error) { 1048 if len(fp) == 0 { 1049 return nil, status.Error(codes.InvalidArgument, "empty field path for object Policy_TemplateSource") 1050 } 1051 if len(fp) == 1 { 1052 switch fp[0] { 1053 case "template": 1054 return &PolicyTemplateSource_FieldTerminalPath{selector: PolicyTemplateSource_FieldPathSelectorTemplate}, nil 1055 case "updated_fields", "updatedFields", "updated-fields": 1056 return &PolicyTemplateSource_FieldTerminalPath{selector: PolicyTemplateSource_FieldPathSelectorUpdatedFields}, nil 1057 } 1058 } 1059 return nil, status.Errorf(codes.InvalidArgument, "unknown field path '%s' for object Policy_TemplateSource", fp) 1060 } 1061 1062 func ParsePolicyTemplateSource_FieldPath(rawField string) (PolicyTemplateSource_FieldPath, error) { 1063 fp, err := gotenobject.ParseRawFieldPath(rawField) 1064 if err != nil { 1065 return nil, err 1066 } 1067 return BuildPolicyTemplateSource_FieldPath(fp) 1068 } 1069 1070 func MustParsePolicyTemplateSource_FieldPath(rawField string) PolicyTemplateSource_FieldPath { 1071 fp, err := ParsePolicyTemplateSource_FieldPath(rawField) 1072 if err != nil { 1073 panic(err) 1074 } 1075 return fp 1076 } 1077 1078 type PolicyTemplateSource_FieldTerminalPath struct { 1079 selector PolicyTemplateSource_FieldPathSelector 1080 } 1081 1082 var _ PolicyTemplateSource_FieldPath = (*PolicyTemplateSource_FieldTerminalPath)(nil) 1083 1084 func (fp *PolicyTemplateSource_FieldTerminalPath) Selector() PolicyTemplateSource_FieldPathSelector { 1085 return fp.selector 1086 } 1087 1088 // String returns path representation in proto convention 1089 func (fp *PolicyTemplateSource_FieldTerminalPath) String() string { 1090 return fp.selector.String() 1091 } 1092 1093 // JSONString returns path representation is JSON convention 1094 func (fp *PolicyTemplateSource_FieldTerminalPath) JSONString() string { 1095 return strcase.ToLowerCamel(fp.String()) 1096 } 1097 1098 // Get returns all values pointed by specific field from source Policy_TemplateSource 1099 func (fp *PolicyTemplateSource_FieldTerminalPath) Get(source *Policy_TemplateSource) (values []interface{}) { 1100 if source != nil { 1101 switch fp.selector { 1102 case PolicyTemplateSource_FieldPathSelectorTemplate: 1103 if source.Template != nil { 1104 values = append(values, source.Template) 1105 } 1106 case PolicyTemplateSource_FieldPathSelectorUpdatedFields: 1107 if source.UpdatedFields != nil { 1108 values = append(values, source.UpdatedFields) 1109 } 1110 default: 1111 panic(fmt.Sprintf("Invalid selector for Policy_TemplateSource: %d", fp.selector)) 1112 } 1113 } 1114 return 1115 } 1116 1117 func (fp *PolicyTemplateSource_FieldTerminalPath) GetRaw(source proto.Message) []interface{} { 1118 return fp.Get(source.(*Policy_TemplateSource)) 1119 } 1120 1121 // GetSingle returns value pointed by specific field of from source Policy_TemplateSource 1122 func (fp *PolicyTemplateSource_FieldTerminalPath) GetSingle(source *Policy_TemplateSource) (interface{}, bool) { 1123 switch fp.selector { 1124 case PolicyTemplateSource_FieldPathSelectorTemplate: 1125 res := source.GetTemplate() 1126 return res, res != nil 1127 case PolicyTemplateSource_FieldPathSelectorUpdatedFields: 1128 res := source.GetUpdatedFields() 1129 return res, res != nil 1130 default: 1131 panic(fmt.Sprintf("Invalid selector for Policy_TemplateSource: %d", fp.selector)) 1132 } 1133 } 1134 1135 func (fp *PolicyTemplateSource_FieldTerminalPath) GetSingleRaw(source proto.Message) (interface{}, bool) { 1136 return fp.GetSingle(source.(*Policy_TemplateSource)) 1137 } 1138 1139 // GetDefault returns a default value of the field type 1140 func (fp *PolicyTemplateSource_FieldTerminalPath) GetDefault() interface{} { 1141 switch fp.selector { 1142 case PolicyTemplateSource_FieldPathSelectorTemplate: 1143 return (*policy_template.Reference)(nil) 1144 case PolicyTemplateSource_FieldPathSelectorUpdatedFields: 1145 return (*fieldmaskpb.FieldMask)(nil) 1146 default: 1147 panic(fmt.Sprintf("Invalid selector for Policy_TemplateSource: %d", fp.selector)) 1148 } 1149 } 1150 1151 func (fp *PolicyTemplateSource_FieldTerminalPath) ClearValue(item *Policy_TemplateSource) { 1152 if item != nil { 1153 switch fp.selector { 1154 case PolicyTemplateSource_FieldPathSelectorTemplate: 1155 item.Template = nil 1156 case PolicyTemplateSource_FieldPathSelectorUpdatedFields: 1157 item.UpdatedFields = nil 1158 default: 1159 panic(fmt.Sprintf("Invalid selector for Policy_TemplateSource: %d", fp.selector)) 1160 } 1161 } 1162 } 1163 1164 func (fp *PolicyTemplateSource_FieldTerminalPath) ClearValueRaw(item proto.Message) { 1165 fp.ClearValue(item.(*Policy_TemplateSource)) 1166 } 1167 1168 // IsLeaf - whether field path is holds simple value 1169 func (fp *PolicyTemplateSource_FieldTerminalPath) IsLeaf() bool { 1170 return fp.selector == PolicyTemplateSource_FieldPathSelectorTemplate || 1171 fp.selector == PolicyTemplateSource_FieldPathSelectorUpdatedFields 1172 } 1173 1174 func (fp *PolicyTemplateSource_FieldTerminalPath) SplitIntoTerminalIPaths() []gotenobject.FieldPath { 1175 return []gotenobject.FieldPath{fp} 1176 } 1177 1178 func (fp *PolicyTemplateSource_FieldTerminalPath) WithIValue(value interface{}) PolicyTemplateSource_FieldPathValue { 1179 switch fp.selector { 1180 case PolicyTemplateSource_FieldPathSelectorTemplate: 1181 return &PolicyTemplateSource_FieldTerminalPathValue{PolicyTemplateSource_FieldTerminalPath: *fp, value: value.(*policy_template.Reference)} 1182 case PolicyTemplateSource_FieldPathSelectorUpdatedFields: 1183 return &PolicyTemplateSource_FieldTerminalPathValue{PolicyTemplateSource_FieldTerminalPath: *fp, value: value.(*fieldmaskpb.FieldMask)} 1184 default: 1185 panic(fmt.Sprintf("Invalid selector for Policy_TemplateSource: %d", fp.selector)) 1186 } 1187 } 1188 1189 func (fp *PolicyTemplateSource_FieldTerminalPath) WithRawIValue(value interface{}) gotenobject.FieldPathValue { 1190 return fp.WithIValue(value) 1191 } 1192 1193 func (fp *PolicyTemplateSource_FieldTerminalPath) WithIArrayOfValues(values interface{}) PolicyTemplateSource_FieldPathArrayOfValues { 1194 fpaov := &PolicyTemplateSource_FieldTerminalPathArrayOfValues{PolicyTemplateSource_FieldTerminalPath: *fp} 1195 switch fp.selector { 1196 case PolicyTemplateSource_FieldPathSelectorTemplate: 1197 return &PolicyTemplateSource_FieldTerminalPathArrayOfValues{PolicyTemplateSource_FieldTerminalPath: *fp, values: values.([]*policy_template.Reference)} 1198 case PolicyTemplateSource_FieldPathSelectorUpdatedFields: 1199 return &PolicyTemplateSource_FieldTerminalPathArrayOfValues{PolicyTemplateSource_FieldTerminalPath: *fp, values: values.([]*fieldmaskpb.FieldMask)} 1200 default: 1201 panic(fmt.Sprintf("Invalid selector for Policy_TemplateSource: %d", fp.selector)) 1202 } 1203 return fpaov 1204 } 1205 1206 func (fp *PolicyTemplateSource_FieldTerminalPath) WithRawIArrayOfValues(values interface{}) gotenobject.FieldPathArrayOfValues { 1207 return fp.WithIArrayOfValues(values) 1208 } 1209 1210 func (fp *PolicyTemplateSource_FieldTerminalPath) WithIArrayItemValue(value interface{}) PolicyTemplateSource_FieldPathArrayItemValue { 1211 switch fp.selector { 1212 default: 1213 panic(fmt.Sprintf("Invalid selector for Policy_TemplateSource: %d", fp.selector)) 1214 } 1215 } 1216 1217 func (fp *PolicyTemplateSource_FieldTerminalPath) WithRawIArrayItemValue(value interface{}) gotenobject.FieldPathArrayItemValue { 1218 return fp.WithIArrayItemValue(value) 1219 } 1220 1221 // PolicyTemplateSource_FieldPathValue allows storing values for TemplateSource fields according to their type 1222 type PolicyTemplateSource_FieldPathValue interface { 1223 PolicyTemplateSource_FieldPath 1224 gotenobject.FieldPathValue 1225 SetTo(target **Policy_TemplateSource) 1226 CompareWith(*Policy_TemplateSource) (cmp int, comparable bool) 1227 } 1228 1229 func ParsePolicyTemplateSource_FieldPathValue(pathStr, valueStr string) (PolicyTemplateSource_FieldPathValue, error) { 1230 fp, err := ParsePolicyTemplateSource_FieldPath(pathStr) 1231 if err != nil { 1232 return nil, err 1233 } 1234 fpv, err := gotenobject.ParseFieldPathValue(fp, valueStr) 1235 if err != nil { 1236 return nil, status.Errorf(codes.InvalidArgument, "error parsing TemplateSource field path value from %s: %v", valueStr, err) 1237 } 1238 return fpv.(PolicyTemplateSource_FieldPathValue), nil 1239 } 1240 1241 func MustParsePolicyTemplateSource_FieldPathValue(pathStr, valueStr string) PolicyTemplateSource_FieldPathValue { 1242 fpv, err := ParsePolicyTemplateSource_FieldPathValue(pathStr, valueStr) 1243 if err != nil { 1244 panic(err) 1245 } 1246 return fpv 1247 } 1248 1249 type PolicyTemplateSource_FieldTerminalPathValue struct { 1250 PolicyTemplateSource_FieldTerminalPath 1251 value interface{} 1252 } 1253 1254 var _ PolicyTemplateSource_FieldPathValue = (*PolicyTemplateSource_FieldTerminalPathValue)(nil) 1255 1256 // GetRawValue returns raw value stored under selected path for 'TemplateSource' as interface{} 1257 func (fpv *PolicyTemplateSource_FieldTerminalPathValue) GetRawValue() interface{} { 1258 return fpv.value 1259 } 1260 func (fpv *PolicyTemplateSource_FieldTerminalPathValue) AsTemplateValue() (*policy_template.Reference, bool) { 1261 res, ok := fpv.value.(*policy_template.Reference) 1262 return res, ok 1263 } 1264 func (fpv *PolicyTemplateSource_FieldTerminalPathValue) AsUpdatedFieldsValue() (*fieldmaskpb.FieldMask, bool) { 1265 res, ok := fpv.value.(*fieldmaskpb.FieldMask) 1266 return res, ok 1267 } 1268 1269 // SetTo stores value for selected field for object TemplateSource 1270 func (fpv *PolicyTemplateSource_FieldTerminalPathValue) SetTo(target **Policy_TemplateSource) { 1271 if *target == nil { 1272 *target = new(Policy_TemplateSource) 1273 } 1274 switch fpv.selector { 1275 case PolicyTemplateSource_FieldPathSelectorTemplate: 1276 (*target).Template = fpv.value.(*policy_template.Reference) 1277 case PolicyTemplateSource_FieldPathSelectorUpdatedFields: 1278 (*target).UpdatedFields = fpv.value.(*fieldmaskpb.FieldMask) 1279 default: 1280 panic(fmt.Sprintf("Invalid selector for Policy_TemplateSource: %d", fpv.selector)) 1281 } 1282 } 1283 1284 func (fpv *PolicyTemplateSource_FieldTerminalPathValue) SetToRaw(target proto.Message) { 1285 typedObject := target.(*Policy_TemplateSource) 1286 fpv.SetTo(&typedObject) 1287 } 1288 1289 // CompareWith compares value in the 'PolicyTemplateSource_FieldTerminalPathValue' with the value under path in 'Policy_TemplateSource'. 1290 func (fpv *PolicyTemplateSource_FieldTerminalPathValue) CompareWith(source *Policy_TemplateSource) (int, bool) { 1291 switch fpv.selector { 1292 case PolicyTemplateSource_FieldPathSelectorTemplate: 1293 leftValue := fpv.value.(*policy_template.Reference) 1294 rightValue := source.GetTemplate() 1295 if leftValue == nil { 1296 if rightValue != nil { 1297 return -1, true 1298 } 1299 return 0, true 1300 } 1301 if rightValue == nil { 1302 return 1, true 1303 } 1304 if leftValue.String() == rightValue.String() { 1305 return 0, true 1306 } else if leftValue.String() < rightValue.String() { 1307 return -1, true 1308 } else { 1309 return 1, true 1310 } 1311 case PolicyTemplateSource_FieldPathSelectorUpdatedFields: 1312 return 0, false 1313 default: 1314 panic(fmt.Sprintf("Invalid selector for Policy_TemplateSource: %d", fpv.selector)) 1315 } 1316 } 1317 1318 func (fpv *PolicyTemplateSource_FieldTerminalPathValue) CompareWithRaw(source proto.Message) (int, bool) { 1319 return fpv.CompareWith(source.(*Policy_TemplateSource)) 1320 } 1321 1322 // PolicyTemplateSource_FieldPathArrayItemValue allows storing single item in Path-specific values for TemplateSource according to their type 1323 // Present only for array (repeated) types. 1324 type PolicyTemplateSource_FieldPathArrayItemValue interface { 1325 gotenobject.FieldPathArrayItemValue 1326 PolicyTemplateSource_FieldPath 1327 ContainsValue(*Policy_TemplateSource) bool 1328 } 1329 1330 // ParsePolicyTemplateSource_FieldPathArrayItemValue parses string and JSON-encoded value to its Value 1331 func ParsePolicyTemplateSource_FieldPathArrayItemValue(pathStr, valueStr string) (PolicyTemplateSource_FieldPathArrayItemValue, error) { 1332 fp, err := ParsePolicyTemplateSource_FieldPath(pathStr) 1333 if err != nil { 1334 return nil, err 1335 } 1336 fpaiv, err := gotenobject.ParseFieldPathArrayItemValue(fp, valueStr) 1337 if err != nil { 1338 return nil, status.Errorf(codes.InvalidArgument, "error parsing TemplateSource field path array item value from %s: %v", valueStr, err) 1339 } 1340 return fpaiv.(PolicyTemplateSource_FieldPathArrayItemValue), nil 1341 } 1342 1343 func MustParsePolicyTemplateSource_FieldPathArrayItemValue(pathStr, valueStr string) PolicyTemplateSource_FieldPathArrayItemValue { 1344 fpaiv, err := ParsePolicyTemplateSource_FieldPathArrayItemValue(pathStr, valueStr) 1345 if err != nil { 1346 panic(err) 1347 } 1348 return fpaiv 1349 } 1350 1351 type PolicyTemplateSource_FieldTerminalPathArrayItemValue struct { 1352 PolicyTemplateSource_FieldTerminalPath 1353 value interface{} 1354 } 1355 1356 var _ PolicyTemplateSource_FieldPathArrayItemValue = (*PolicyTemplateSource_FieldTerminalPathArrayItemValue)(nil) 1357 1358 // GetRawValue returns stored element value for array in object Policy_TemplateSource as interface{} 1359 func (fpaiv *PolicyTemplateSource_FieldTerminalPathArrayItemValue) GetRawItemValue() interface{} { 1360 return fpaiv.value 1361 } 1362 1363 func (fpaiv *PolicyTemplateSource_FieldTerminalPathArrayItemValue) GetSingle(source *Policy_TemplateSource) (interface{}, bool) { 1364 return nil, false 1365 } 1366 1367 func (fpaiv *PolicyTemplateSource_FieldTerminalPathArrayItemValue) GetSingleRaw(source proto.Message) (interface{}, bool) { 1368 return fpaiv.GetSingle(source.(*Policy_TemplateSource)) 1369 } 1370 1371 // Contains returns a boolean indicating if value that is being held is present in given 'TemplateSource' 1372 func (fpaiv *PolicyTemplateSource_FieldTerminalPathArrayItemValue) ContainsValue(source *Policy_TemplateSource) bool { 1373 slice := fpaiv.PolicyTemplateSource_FieldTerminalPath.Get(source) 1374 for _, v := range slice { 1375 if asProtoMsg, ok := fpaiv.value.(proto.Message); ok { 1376 if proto.Equal(asProtoMsg, v.(proto.Message)) { 1377 return true 1378 } 1379 } else if reflect.DeepEqual(v, fpaiv.value) { 1380 return true 1381 } 1382 } 1383 return false 1384 } 1385 1386 // PolicyTemplateSource_FieldPathArrayOfValues allows storing slice of values for TemplateSource fields according to their type 1387 type PolicyTemplateSource_FieldPathArrayOfValues interface { 1388 gotenobject.FieldPathArrayOfValues 1389 PolicyTemplateSource_FieldPath 1390 } 1391 1392 func ParsePolicyTemplateSource_FieldPathArrayOfValues(pathStr, valuesStr string) (PolicyTemplateSource_FieldPathArrayOfValues, error) { 1393 fp, err := ParsePolicyTemplateSource_FieldPath(pathStr) 1394 if err != nil { 1395 return nil, err 1396 } 1397 fpaov, err := gotenobject.ParseFieldPathArrayOfValues(fp, valuesStr) 1398 if err != nil { 1399 return nil, status.Errorf(codes.InvalidArgument, "error parsing TemplateSource field path array of values from %s: %v", valuesStr, err) 1400 } 1401 return fpaov.(PolicyTemplateSource_FieldPathArrayOfValues), nil 1402 } 1403 1404 func MustParsePolicyTemplateSource_FieldPathArrayOfValues(pathStr, valuesStr string) PolicyTemplateSource_FieldPathArrayOfValues { 1405 fpaov, err := ParsePolicyTemplateSource_FieldPathArrayOfValues(pathStr, valuesStr) 1406 if err != nil { 1407 panic(err) 1408 } 1409 return fpaov 1410 } 1411 1412 type PolicyTemplateSource_FieldTerminalPathArrayOfValues struct { 1413 PolicyTemplateSource_FieldTerminalPath 1414 values interface{} 1415 } 1416 1417 var _ PolicyTemplateSource_FieldPathArrayOfValues = (*PolicyTemplateSource_FieldTerminalPathArrayOfValues)(nil) 1418 1419 func (fpaov *PolicyTemplateSource_FieldTerminalPathArrayOfValues) GetRawValues() (values []interface{}) { 1420 switch fpaov.selector { 1421 case PolicyTemplateSource_FieldPathSelectorTemplate: 1422 for _, v := range fpaov.values.([]*policy_template.Reference) { 1423 values = append(values, v) 1424 } 1425 case PolicyTemplateSource_FieldPathSelectorUpdatedFields: 1426 for _, v := range fpaov.values.([]*fieldmaskpb.FieldMask) { 1427 values = append(values, v) 1428 } 1429 } 1430 return 1431 } 1432 func (fpaov *PolicyTemplateSource_FieldTerminalPathArrayOfValues) AsTemplateArrayOfValues() ([]*policy_template.Reference, bool) { 1433 res, ok := fpaov.values.([]*policy_template.Reference) 1434 return res, ok 1435 } 1436 func (fpaov *PolicyTemplateSource_FieldTerminalPathArrayOfValues) AsUpdatedFieldsArrayOfValues() ([]*fieldmaskpb.FieldMask, bool) { 1437 res, ok := fpaov.values.([]*fieldmaskpb.FieldMask) 1438 return res, ok 1439 }