github.com/cloudwan/edgelq-sdk@v1.15.4/alerting/resources/v1/alert/alert.pb.parentname.go (about) 1 // Code generated by protoc-gen-goten-resource 2 // Resource: Alert 3 // DO NOT EDIT!!! 4 5 package alert 6 7 import ( 8 "fmt" 9 "net/url" 10 "reflect" 11 "regexp" 12 "strings" 13 14 "google.golang.org/grpc/codes" 15 "google.golang.org/grpc/status" 16 "google.golang.org/protobuf/proto" 17 18 "github.com/cloudwan/goten-sdk/runtime/goten" 19 gotenresource "github.com/cloudwan/goten-sdk/runtime/resource" 20 ) 21 22 // proto imports 23 import ( 24 rcommon "github.com/cloudwan/edgelq-sdk/alerting/resources/v1/common" 25 log_condition "github.com/cloudwan/edgelq-sdk/alerting/resources/v1/log_condition" 26 notification_channel "github.com/cloudwan/edgelq-sdk/alerting/resources/v1/notification_channel" 27 ts_condition "github.com/cloudwan/edgelq-sdk/alerting/resources/v1/ts_condition" 28 meta "github.com/cloudwan/goten-sdk/types/meta" 29 durationpb "google.golang.org/protobuf/types/known/durationpb" 30 timestamppb "google.golang.org/protobuf/types/known/timestamppb" 31 ) 32 33 // ensure the imports are used 34 var ( 35 _ = codes.NotFound 36 _ = new(fmt.Stringer) 37 _ = new(proto.Message) 38 _ = status.Status{} 39 _ = url.URL{} 40 _ = strings.Builder{} 41 42 _ = new(goten.GotenMessage) 43 _ = new(gotenresource.ListQuery) 44 ) 45 46 // make sure we're using proto imports 47 var ( 48 _ = &log_condition.LogCondition{} 49 _ = ¬ification_channel.NotificationChannel{} 50 _ = &rcommon.LogCndSpec{} 51 _ = &ts_condition.TsCondition{} 52 _ = &durationpb.Duration{} 53 _ = ×tamppb.Timestamp{} 54 _ = &meta.Meta{} 55 ) 56 57 var parentRegexPath_Project_Policy_TsCondition_Region = regexp.MustCompile("^projects/(?P<project_id>-|[\\w][\\w.-]{0,127})/policies/(?P<policy_id>-|[\\w][\\w.-]{0,127})/tsConditions/(?P<ts_condition_id>-|[\\w][\\w.-]{0,127})/regions/(?P<region_id>-|[a-z][a-z0-9\\-]{0,28}[a-z0-9])$") 58 var parentRegexPath_Project_Policy_LogCondition_Region = regexp.MustCompile("^projects/(?P<project_id>-|[\\w][\\w.-]{0,127})/policies/(?P<policy_id>-|[\\w][\\w.-]{0,127})/logConditions/(?P<log_condition_id>-|[\\w][\\w.-]{0,127})/regions/(?P<region_id>-|[a-z][a-z0-9\\-]{0,28}[a-z0-9])$") 59 60 type ParentName struct { 61 NamePattern 62 ProjectId string `firestore:"projectId"` 63 PolicyId string `firestore:"policyId"` 64 TsConditionId string `firestore:"tsConditionId"` 65 RegionId string `firestore:"regionId"` 66 LogConditionId string `firestore:"logConditionId"` 67 } 68 69 func ParseParentName(name string) (*ParentName, error) { 70 var matches []string 71 if matches = parentRegexPath_Project_Policy_TsCondition_Region.FindStringSubmatch(name); matches != nil { 72 return NewNameBuilder(). 73 SetProjectId(matches[1]). 74 SetPolicyId(matches[2]). 75 SetTsConditionId(matches[3]). 76 SetRegionId(matches[4]). 77 Parent(), nil 78 } 79 if matches = parentRegexPath_Project_Policy_LogCondition_Region.FindStringSubmatch(name); matches != nil { 80 return NewNameBuilder(). 81 SetProjectId(matches[1]). 82 SetPolicyId(matches[2]). 83 SetLogConditionId(matches[3]). 84 SetRegionId(matches[4]). 85 Parent(), nil 86 } 87 88 return nil, status.Errorf(codes.InvalidArgument, "unable to parse '%s' as Alert parent name", name) 89 } 90 91 func MustParseParentName(name string) *ParentName { 92 result, err := ParseParentName(name) 93 if err != nil { 94 panic(err) 95 } 96 return result 97 } 98 99 func (name *ParentName) SetFromSegments(segments gotenresource.NameSegments) error { 100 if len(segments) == 4 && segments[0].CollectionLowerJson == "projects" && segments[1].CollectionLowerJson == "policies" && segments[2].CollectionLowerJson == "tsConditions" && segments[3].CollectionLowerJson == "regions" { 101 name.Pattern = NamePattern_Project_Policy_TsCondition_Region 102 name.ProjectId = segments[0].Id 103 name.PolicyId = segments[1].Id 104 name.TsConditionId = segments[2].Id 105 name.RegionId = segments[3].Id 106 return nil 107 } else if len(segments) == 4 && segments[0].CollectionLowerJson == "projects" && segments[1].CollectionLowerJson == "policies" && segments[2].CollectionLowerJson == "logConditions" && segments[3].CollectionLowerJson == "regions" { 108 name.Pattern = NamePattern_Project_Policy_LogCondition_Region 109 name.ProjectId = segments[0].Id 110 name.PolicyId = segments[1].Id 111 name.LogConditionId = segments[2].Id 112 name.RegionId = segments[3].Id 113 return nil 114 } 115 return status.Errorf(codes.InvalidArgument, "unable to use segments %s to form Alert parent name", segments) 116 } 117 118 func (name *ParentName) GetTsConditionName() *ts_condition.Name { 119 if name == nil { 120 return nil 121 } 122 123 switch name.Pattern { 124 case NamePattern_Project_Policy_TsCondition_Region: 125 return ts_condition.NewNameBuilder(). 126 SetId(name.TsConditionId). 127 SetProjectId(name.ProjectId). 128 SetPolicyId(name.PolicyId). 129 Name() 130 default: 131 return nil 132 } 133 } 134 135 func (name *ParentName) GetLogConditionName() *log_condition.Name { 136 if name == nil { 137 return nil 138 } 139 140 switch name.Pattern { 141 case NamePattern_Project_Policy_LogCondition_Region: 142 return log_condition.NewNameBuilder(). 143 SetId(name.LogConditionId). 144 SetProjectId(name.ProjectId). 145 SetPolicyId(name.PolicyId). 146 Name() 147 default: 148 return nil 149 } 150 } 151 152 func (name *ParentName) IsSpecified() bool { 153 if name == nil || name.Pattern == "" { 154 return false 155 } 156 switch name.Pattern { 157 case NamePattern_Project_Policy_TsCondition_Region: 158 return name.ProjectId != "" && name.PolicyId != "" && name.TsConditionId != "" && name.RegionId != "" 159 case NamePattern_Project_Policy_LogCondition_Region: 160 return name.ProjectId != "" && name.PolicyId != "" && name.LogConditionId != "" && name.RegionId != "" 161 } 162 return false 163 } 164 165 func (name *ParentName) IsFullyQualified() bool { 166 if name == nil || name.Pattern == "" { 167 return false 168 } 169 170 switch name.Pattern { 171 case NamePattern_Project_Policy_TsCondition_Region: 172 return name.ProjectId != "" && name.ProjectId != gotenresource.WildcardId && name.PolicyId != "" && name.PolicyId != gotenresource.WildcardId && name.TsConditionId != "" && name.TsConditionId != gotenresource.WildcardId && name.RegionId != "" && name.RegionId != gotenresource.WildcardId 173 case NamePattern_Project_Policy_LogCondition_Region: 174 return name.ProjectId != "" && name.ProjectId != gotenresource.WildcardId && name.PolicyId != "" && name.PolicyId != gotenresource.WildcardId && name.LogConditionId != "" && name.LogConditionId != gotenresource.WildcardId && name.RegionId != "" && name.RegionId != gotenresource.WildcardId 175 } 176 177 return false 178 } 179 180 func (name *ParentName) FullyQualifiedName() (string, error) { 181 if !name.IsFullyQualified() { 182 return "", status.Errorf(codes.InvalidArgument, "Parent name for Alert is not fully qualified") 183 } 184 return fmt.Sprintf("//alerting.edgelq.com/%s", name.String()), nil 185 } 186 187 func (name *ParentName) GetResourceDescriptor() gotenresource.Descriptor { 188 return descriptor 189 } 190 191 func (name *ParentName) GetPattern() gotenresource.NamePattern { 192 if name == nil { 193 return "" 194 } 195 return name.Pattern 196 } 197 198 func (name *ParentName) GetIdParts() map[string]string { 199 if name != nil { 200 return map[string]string{ 201 "projectId": name.ProjectId, 202 "policyId": name.PolicyId, 203 "tsConditionId": name.TsConditionId, 204 "regionId": name.RegionId, 205 "logConditionId": name.LogConditionId, 206 } 207 } 208 return map[string]string{ 209 "projectId": "", 210 "policyId": "", 211 "tsConditionId": "", 212 "regionId": "", 213 "logConditionId": "", 214 } 215 } 216 217 func (name *ParentName) GetSegments() gotenresource.NameSegments { 218 if name == nil { 219 return nil 220 } 221 222 switch name.Pattern { 223 case NamePattern_Project_Policy_TsCondition_Region: 224 return gotenresource.NameSegments{ 225 gotenresource.NameSegment{ 226 CollectionLowerJson: "projects", 227 Id: name.ProjectId, 228 }, 229 gotenresource.NameSegment{ 230 CollectionLowerJson: "policies", 231 Id: name.PolicyId, 232 }, 233 gotenresource.NameSegment{ 234 CollectionLowerJson: "tsConditions", 235 Id: name.TsConditionId, 236 }, 237 gotenresource.NameSegment{ 238 CollectionLowerJson: "regions", 239 Id: name.RegionId, 240 }, 241 } 242 case NamePattern_Project_Policy_LogCondition_Region: 243 return gotenresource.NameSegments{ 244 gotenresource.NameSegment{ 245 CollectionLowerJson: "projects", 246 Id: name.ProjectId, 247 }, 248 gotenresource.NameSegment{ 249 CollectionLowerJson: "policies", 250 Id: name.PolicyId, 251 }, 252 gotenresource.NameSegment{ 253 CollectionLowerJson: "logConditions", 254 Id: name.LogConditionId, 255 }, 256 gotenresource.NameSegment{ 257 CollectionLowerJson: "regions", 258 Id: name.RegionId, 259 }, 260 } 261 } 262 return nil 263 } 264 265 func (name *ParentName) GetIParentName() gotenresource.Name { 266 return nil 267 } 268 269 func (name *ParentName) GetIUnderlyingParentName() gotenresource.Name { 270 return nil 271 } 272 273 func (name *ParentName) String() string { 274 if name == nil { 275 return "<nil>" 276 } 277 278 if valueStr, err := name.ProtoString(); err != nil { 279 panic(err) 280 } else { 281 return valueStr 282 } 283 } 284 285 func (name *ParentName) DescendsFrom(ancestor string) bool { 286 if name == nil { 287 return false 288 } 289 290 switch name.Pattern { 291 case NamePattern_Project_Policy_TsCondition_Region: 292 return ancestor == "projects" || ancestor == "policies" || ancestor == "tsConditions" || ancestor == "regions" 293 case NamePattern_Project_Policy_LogCondition_Region: 294 return ancestor == "projects" || ancestor == "policies" || ancestor == "logConditions" || ancestor == "regions" 295 } 296 297 return false 298 } 299 300 func (name *ParentName) AsReference() *ParentReference { 301 return &ParentReference{ParentName: *name} 302 } 303 304 func (name *ParentName) AsRawReference() gotenresource.Reference { 305 return name.AsReference() 306 } 307 308 // implement methods required by protobuf-go library for string-struct conversion 309 310 func (name *ParentName) ProtoString() (string, error) { 311 if name == nil { 312 return "", nil 313 } 314 switch name.Pattern { 315 case NamePattern_Project_Policy_TsCondition_Region: 316 return "projects/" + name.ProjectId + "/policies/" + name.PolicyId + "/tsConditions/" + name.TsConditionId + "/regions/" + name.RegionId, nil 317 case NamePattern_Project_Policy_LogCondition_Region: 318 return "projects/" + name.ProjectId + "/policies/" + name.PolicyId + "/logConditions/" + name.LogConditionId + "/regions/" + name.RegionId, nil 319 } 320 return "", nil 321 } 322 323 func (name *ParentName) ParseProtoString(data string) error { 324 parsed, err := ParseParentName(data) 325 if err != nil { 326 return err 327 } 328 *name = *parsed 329 return nil 330 } 331 332 // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface) 333 func (name *ParentName) GotenEqual(other interface{}) bool { 334 if other == nil { 335 return name == nil 336 } 337 other1, ok := other.(*ParentName) 338 if !ok { 339 other2, ok := other.(ParentName) 340 if ok { 341 other1 = &other2 342 } else { 343 return false 344 } 345 } 346 if other1 == nil { 347 return name == nil 348 } else if name == nil { 349 return false 350 } 351 if name.ProjectId != other1.ProjectId { 352 return false 353 } 354 if name.PolicyId != other1.PolicyId { 355 return false 356 } 357 if name.TsConditionId != other1.TsConditionId { 358 return false 359 } 360 if name.RegionId != other1.RegionId { 361 return false 362 } 363 if name.LogConditionId != other1.LogConditionId { 364 return false 365 } 366 if name.Pattern != other1.Pattern { 367 return false 368 } 369 370 return true 371 } 372 373 // Matches is same as GotenEqual, but also will accept "other" if name is wildcard. 374 func (name *ParentName) Matches(other interface{}) bool { 375 if other == nil { 376 return name == nil 377 } 378 other1, ok := other.(*ParentName) 379 if !ok { 380 other2, ok := other.(ParentName) 381 if ok { 382 other1 = &other2 383 } else { 384 return false 385 } 386 } 387 if other1 == nil { 388 return name == nil 389 } else if name == nil { 390 return false 391 } 392 393 if name.Pattern != other1.Pattern { 394 return false 395 } 396 switch name.Pattern { 397 case NamePattern_Project_Policy_TsCondition_Region: 398 if name.ProjectId != other1.ProjectId && 399 name.ProjectId != gotenresource.WildcardId { 400 return false 401 } 402 if name.PolicyId != other1.PolicyId && 403 name.PolicyId != gotenresource.WildcardId { 404 return false 405 } 406 if name.TsConditionId != other1.TsConditionId && 407 name.TsConditionId != gotenresource.WildcardId { 408 return false 409 } 410 if name.RegionId != other1.RegionId && 411 name.RegionId != gotenresource.WildcardId { 412 return false 413 } 414 case NamePattern_Project_Policy_LogCondition_Region: 415 if name.ProjectId != other1.ProjectId && 416 name.ProjectId != gotenresource.WildcardId { 417 return false 418 } 419 if name.PolicyId != other1.PolicyId && 420 name.PolicyId != gotenresource.WildcardId { 421 return false 422 } 423 if name.LogConditionId != other1.LogConditionId && 424 name.LogConditionId != gotenresource.WildcardId { 425 return false 426 } 427 if name.RegionId != other1.RegionId && 428 name.RegionId != gotenresource.WildcardId { 429 return false 430 } 431 } 432 433 return true 434 } 435 436 // implement CustomTypeCliValue method 437 func (name *ParentName) SetFromCliFlag(raw string) error { 438 parsedName, err := ParseParentName(raw) 439 if err != nil { 440 return err 441 } 442 *name = *parsedName 443 return nil 444 } 445 446 type ParentReference struct { 447 ParentName 448 tsCondition *ts_condition.TsCondition 449 logCondition *log_condition.LogCondition 450 } 451 452 func MakeParentReference(name *ParentName) (*ParentReference, error) { 453 return &ParentReference{ 454 ParentName: *name, 455 }, nil 456 } 457 458 func ParseParentReference(name string) (*ParentReference, error) { 459 parsedName, err := ParseParentName(name) 460 if err != nil { 461 return nil, err 462 } 463 return MakeParentReference(parsedName) 464 } 465 466 func MustParseParentReference(name string) *ParentReference { 467 result, err := ParseParentReference(name) 468 if err != nil { 469 panic(err) 470 } 471 return result 472 } 473 func (ref *ParentReference) GetTsConditionReference() *ts_condition.Reference { 474 if ref == nil { 475 return nil 476 } 477 478 switch ref.Pattern { 479 case NamePattern_Project_Policy_TsCondition_Region: 480 return ts_condition.NewNameBuilder(). 481 SetId(ref.TsConditionId). 482 SetProjectId(ref.ProjectId). 483 SetPolicyId(ref.PolicyId). 484 Reference() 485 default: 486 return nil 487 } 488 } 489 func (ref *ParentReference) GetLogConditionReference() *log_condition.Reference { 490 if ref == nil { 491 return nil 492 } 493 494 switch ref.Pattern { 495 case NamePattern_Project_Policy_LogCondition_Region: 496 return log_condition.NewNameBuilder(). 497 SetId(ref.LogConditionId). 498 SetProjectId(ref.ProjectId). 499 SetPolicyId(ref.PolicyId). 500 Reference() 501 default: 502 return nil 503 } 504 } 505 506 func (ref *ParentReference) GetUnderlyingReference() gotenresource.Reference { 507 if ref == nil { 508 return nil 509 } 510 tsConditionRef := ref.GetTsConditionReference() 511 if tsConditionRef != nil { 512 return tsConditionRef 513 } 514 logConditionRef := ref.GetLogConditionReference() 515 if logConditionRef != nil { 516 return logConditionRef 517 } 518 519 return nil 520 } 521 522 func (ref *ParentReference) ResolveRaw(res gotenresource.Resource) error { 523 switch typedRes := res.(type) { 524 case *ts_condition.TsCondition: 525 if name := ref.GetTsConditionName(); name == nil { 526 return status.Errorf(codes.InvalidArgument, "cannot set TsCondition as parent of Alert, because pattern does not match") 527 } 528 ref.tsCondition = typedRes 529 return nil 530 case *log_condition.LogCondition: 531 if name := ref.GetLogConditionName(); name == nil { 532 return status.Errorf(codes.InvalidArgument, "cannot set LogCondition as parent of Alert, because pattern does not match") 533 } 534 ref.logCondition = typedRes 535 return nil 536 default: 537 return status.Errorf(codes.Internal, "Invalid parent type for Alert, got %s", reflect.TypeOf(res).Elem().Name()) 538 } 539 } 540 541 func (ref *ParentReference) Resolved() bool { 542 if name := ref.GetTsConditionName(); name != nil { 543 return ref.tsCondition != nil 544 } 545 if name := ref.GetLogConditionName(); name != nil { 546 return ref.logCondition != nil 547 } 548 return true 549 } 550 551 func (ref *ParentReference) ClearCached() { 552 ref.tsCondition = nil 553 ref.logCondition = nil 554 } 555 556 func (ref *ParentReference) GetTsCondition() *ts_condition.TsCondition { 557 if ref == nil { 558 return nil 559 } 560 return ref.tsCondition 561 } 562 func (ref *ParentReference) GetLogCondition() *log_condition.LogCondition { 563 if ref == nil { 564 return nil 565 } 566 return ref.logCondition 567 } 568 569 func (ref *ParentReference) GetRawResource() gotenresource.Resource { 570 if name := ref.ParentName.GetTsConditionName(); name != nil { 571 return ref.tsCondition 572 } 573 if name := ref.ParentName.GetLogConditionName(); name != nil { 574 return ref.logCondition 575 } 576 return nil 577 } 578 579 func (ref *ParentReference) IsFullyQualified() bool { 580 if ref == nil { 581 return false 582 } 583 return ref.ParentName.IsFullyQualified() 584 } 585 586 func (ref *ParentReference) IsSpecified() bool { 587 if ref == nil { 588 return false 589 } 590 return ref.ParentName.IsSpecified() 591 } 592 593 func (ref *ParentReference) GetResourceDescriptor() gotenresource.Descriptor { 594 return descriptor 595 } 596 597 func (ref *ParentReference) GetPattern() gotenresource.NamePattern { 598 if ref == nil { 599 return "" 600 } 601 return ref.Pattern 602 } 603 604 func (ref *ParentReference) GetIdParts() map[string]string { 605 if ref != nil { 606 return ref.ParentName.GetIdParts() 607 } 608 return map[string]string{ 609 "projectId": "", 610 "policyId": "", 611 "tsConditionId": "", 612 "regionId": "", 613 "logConditionId": "", 614 } 615 } 616 617 func (ref *ParentReference) GetSegments() gotenresource.NameSegments { 618 if ref != nil { 619 return ref.ParentName.GetSegments() 620 } 621 return nil 622 } 623 624 func (ref *ParentReference) GetIParentName() gotenresource.Name { 625 return nil 626 } 627 628 func (ref *ParentReference) GetIUnderlyingParentName() gotenresource.Name { 629 return nil 630 } 631 632 func (ref *ParentReference) String() string { 633 if ref == nil { 634 return "<nil>" 635 } 636 return ref.ParentName.String() 637 } 638 639 // implement methods required by protobuf-go library for string-struct conversion 640 641 func (ref *ParentReference) ProtoString() (string, error) { 642 if ref == nil { 643 return "", nil 644 } 645 return ref.ParentName.ProtoString() 646 } 647 648 func (ref *ParentReference) ParseProtoString(data string) error { 649 parsed, err := ParseParentReference(data) 650 if err != nil { 651 return err 652 } 653 *ref = *parsed 654 return nil 655 } 656 657 // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface) 658 func (ref *ParentReference) GotenEqual(other interface{}) bool { 659 if other == nil { 660 return ref == nil 661 } 662 other1, ok := other.(*ParentReference) 663 if !ok { 664 other2, ok := other.(ParentReference) 665 if ok { 666 other1 = &other2 667 } else { 668 return false 669 } 670 } 671 if other1 == nil { 672 return ref == nil 673 } else if ref == nil { 674 return false 675 } 676 if ref.tsCondition != other1.tsCondition { 677 return false 678 } 679 if ref.logCondition != other1.logCondition { 680 return false 681 } 682 683 return ref.ParentName.GotenEqual(other1.ParentName) 684 } 685 686 // Matches is same as GotenEqual, but also will accept "other" if name is wildcard. 687 func (name *ParentReference) Matches(other interface{}) bool { 688 if other == nil { 689 return name == nil 690 } 691 other1, ok := other.(*ParentReference) 692 if !ok { 693 other2, ok := other.(ParentReference) 694 if ok { 695 other1 = &other2 696 } else { 697 return false 698 } 699 } 700 if other1 == nil { 701 return name == nil 702 } else if name == nil { 703 return false 704 } 705 return name.ParentName.Matches(&other1.ParentName) 706 } 707 708 // implement CustomTypeCliValue method 709 func (ref *ParentReference) SetFromCliFlag(raw string) error { 710 parsedRef, err := ParseParentReference(raw) 711 if err != nil { 712 return err 713 } 714 *ref = *parsedRef 715 return nil 716 }