github.com/cloudwan/edgelq-sdk@v1.15.4/monitoring/resources/v4/notification/notification.pb.parentname.go (about) 1 // Code generated by protoc-gen-goten-resource 2 // Resource: Notification 3 // DO NOT EDIT!!! 4 5 package notification 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 alert "github.com/cloudwan/edgelq-sdk/monitoring/resources/v4/alert" 25 alerting_condition "github.com/cloudwan/edgelq-sdk/monitoring/resources/v4/alerting_condition" 26 alerting_policy "github.com/cloudwan/edgelq-sdk/monitoring/resources/v4/alerting_policy" 27 common "github.com/cloudwan/edgelq-sdk/monitoring/resources/v4/common" 28 notification_channel "github.com/cloudwan/edgelq-sdk/monitoring/resources/v4/notification_channel" 29 project "github.com/cloudwan/edgelq-sdk/monitoring/resources/v4/project" 30 meta "github.com/cloudwan/goten-sdk/types/meta" 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 _ = &alert.Alert{} 49 _ = &alerting_condition.AlertingCondition{} 50 _ = &alerting_policy.AlertingPolicy{} 51 _ = &common.LabelDescriptor{} 52 _ = ¬ification_channel.NotificationChannel{} 53 _ = &project.Project{} 54 _ = &meta.Meta{} 55 ) 56 57 var parentRegexPath_Project_Region_AlertingPolicy = regexp.MustCompile("^projects/(?P<project_id>-|[\\w][\\w.-]{0,127})/regions/(?P<region_id>-|[a-z][a-z0-9\\-]{0,28}[a-z0-9])/alertingPolicies/(?P<alerting_policy_id>-|[\\w][\\w.-]{0,127})$") 58 59 type ParentName struct { 60 NamePattern 61 ProjectId string `firestore:"projectId"` 62 RegionId string `firestore:"regionId"` 63 AlertingPolicyId string `firestore:"alertingPolicyId"` 64 } 65 66 func ParseParentName(name string) (*ParentName, error) { 67 var matches []string 68 if matches = parentRegexPath_Project_Region_AlertingPolicy.FindStringSubmatch(name); matches != nil { 69 return NewNameBuilder(). 70 SetProjectId(matches[1]). 71 SetRegionId(matches[2]). 72 SetAlertingPolicyId(matches[3]). 73 Parent(), nil 74 } 75 76 return nil, status.Errorf(codes.InvalidArgument, "unable to parse '%s' as Notification parent name", name) 77 } 78 79 func MustParseParentName(name string) *ParentName { 80 result, err := ParseParentName(name) 81 if err != nil { 82 panic(err) 83 } 84 return result 85 } 86 87 func (name *ParentName) SetFromSegments(segments gotenresource.NameSegments) error { 88 if len(segments) == 3 && segments[0].CollectionLowerJson == "projects" && segments[1].CollectionLowerJson == "regions" && segments[2].CollectionLowerJson == "alertingPolicies" { 89 name.Pattern = NamePattern_Project_Region_AlertingPolicy 90 name.ProjectId = segments[0].Id 91 name.RegionId = segments[1].Id 92 name.AlertingPolicyId = segments[2].Id 93 return nil 94 } 95 return status.Errorf(codes.InvalidArgument, "unable to use segments %s to form Notification parent name", segments) 96 } 97 98 func (name *ParentName) GetAlertingPolicyName() *alerting_policy.Name { 99 if name == nil { 100 return nil 101 } 102 103 switch name.Pattern { 104 case NamePattern_Project_Region_AlertingPolicy: 105 return alerting_policy.NewNameBuilder(). 106 SetId(name.AlertingPolicyId). 107 SetProjectId(name.ProjectId). 108 SetRegionId(name.RegionId). 109 Name() 110 default: 111 return nil 112 } 113 } 114 115 func (name *ParentName) IsSpecified() bool { 116 if name == nil || name.Pattern == "" { 117 return false 118 } 119 switch name.Pattern { 120 case NamePattern_Project_Region_AlertingPolicy: 121 return name.ProjectId != "" && name.RegionId != "" && name.AlertingPolicyId != "" 122 } 123 return false 124 } 125 126 func (name *ParentName) IsFullyQualified() bool { 127 if name == nil || name.Pattern == "" { 128 return false 129 } 130 131 switch name.Pattern { 132 case NamePattern_Project_Region_AlertingPolicy: 133 return name.ProjectId != "" && name.ProjectId != gotenresource.WildcardId && name.RegionId != "" && name.RegionId != gotenresource.WildcardId && name.AlertingPolicyId != "" && name.AlertingPolicyId != gotenresource.WildcardId 134 } 135 136 return false 137 } 138 139 func (name *ParentName) FullyQualifiedName() (string, error) { 140 if !name.IsFullyQualified() { 141 return "", status.Errorf(codes.InvalidArgument, "Parent name for Notification is not fully qualified") 142 } 143 return fmt.Sprintf("//monitoring.edgelq.com/%s", name.String()), nil 144 } 145 146 func (name *ParentName) GetResourceDescriptor() gotenresource.Descriptor { 147 return descriptor 148 } 149 150 func (name *ParentName) GetPattern() gotenresource.NamePattern { 151 if name == nil { 152 return "" 153 } 154 return name.Pattern 155 } 156 157 func (name *ParentName) GetIdParts() map[string]string { 158 if name != nil { 159 return map[string]string{ 160 "projectId": name.ProjectId, 161 "regionId": name.RegionId, 162 "alertingPolicyId": name.AlertingPolicyId, 163 } 164 } 165 return map[string]string{ 166 "projectId": "", 167 "regionId": "", 168 "alertingPolicyId": "", 169 } 170 } 171 172 func (name *ParentName) GetSegments() gotenresource.NameSegments { 173 if name == nil { 174 return nil 175 } 176 177 switch name.Pattern { 178 case NamePattern_Project_Region_AlertingPolicy: 179 return gotenresource.NameSegments{ 180 gotenresource.NameSegment{ 181 CollectionLowerJson: "projects", 182 Id: name.ProjectId, 183 }, 184 gotenresource.NameSegment{ 185 CollectionLowerJson: "regions", 186 Id: name.RegionId, 187 }, 188 gotenresource.NameSegment{ 189 CollectionLowerJson: "alertingPolicies", 190 Id: name.AlertingPolicyId, 191 }, 192 } 193 } 194 return nil 195 } 196 197 func (name *ParentName) GetIParentName() gotenresource.Name { 198 return nil 199 } 200 201 func (name *ParentName) GetIUnderlyingParentName() gotenresource.Name { 202 return nil 203 } 204 205 func (name *ParentName) String() string { 206 if name == nil { 207 return "<nil>" 208 } 209 210 if valueStr, err := name.ProtoString(); err != nil { 211 panic(err) 212 } else { 213 return valueStr 214 } 215 } 216 217 func (name *ParentName) DescendsFrom(ancestor string) bool { 218 if name == nil { 219 return false 220 } 221 222 switch name.Pattern { 223 case NamePattern_Project_Region_AlertingPolicy: 224 return ancestor == "projects" || ancestor == "regions" || ancestor == "alertingPolicies" 225 } 226 227 return false 228 } 229 230 func (name *ParentName) AsReference() *ParentReference { 231 return &ParentReference{ParentName: *name} 232 } 233 234 func (name *ParentName) AsRawReference() gotenresource.Reference { 235 return name.AsReference() 236 } 237 238 // implement methods required by protobuf-go library for string-struct conversion 239 240 func (name *ParentName) ProtoString() (string, error) { 241 if name == nil { 242 return "", nil 243 } 244 switch name.Pattern { 245 case NamePattern_Project_Region_AlertingPolicy: 246 return "projects/" + name.ProjectId + "/regions/" + name.RegionId + "/alertingPolicies/" + name.AlertingPolicyId, nil 247 } 248 return "", nil 249 } 250 251 func (name *ParentName) ParseProtoString(data string) error { 252 parsed, err := ParseParentName(data) 253 if err != nil { 254 return err 255 } 256 *name = *parsed 257 return nil 258 } 259 260 // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface) 261 func (name *ParentName) GotenEqual(other interface{}) bool { 262 if other == nil { 263 return name == nil 264 } 265 other1, ok := other.(*ParentName) 266 if !ok { 267 other2, ok := other.(ParentName) 268 if ok { 269 other1 = &other2 270 } else { 271 return false 272 } 273 } 274 if other1 == nil { 275 return name == nil 276 } else if name == nil { 277 return false 278 } 279 if name.ProjectId != other1.ProjectId { 280 return false 281 } 282 if name.RegionId != other1.RegionId { 283 return false 284 } 285 if name.AlertingPolicyId != other1.AlertingPolicyId { 286 return false 287 } 288 if name.Pattern != other1.Pattern { 289 return false 290 } 291 292 return true 293 } 294 295 // Matches is same as GotenEqual, but also will accept "other" if name is wildcard. 296 func (name *ParentName) Matches(other interface{}) bool { 297 if other == nil { 298 return name == nil 299 } 300 other1, ok := other.(*ParentName) 301 if !ok { 302 other2, ok := other.(ParentName) 303 if ok { 304 other1 = &other2 305 } else { 306 return false 307 } 308 } 309 if other1 == nil { 310 return name == nil 311 } else if name == nil { 312 return false 313 } 314 315 if name.Pattern != other1.Pattern { 316 return false 317 } 318 switch name.Pattern { 319 case NamePattern_Project_Region_AlertingPolicy: 320 if name.ProjectId != other1.ProjectId && 321 name.ProjectId != gotenresource.WildcardId { 322 return false 323 } 324 if name.RegionId != other1.RegionId && 325 name.RegionId != gotenresource.WildcardId { 326 return false 327 } 328 if name.AlertingPolicyId != other1.AlertingPolicyId && 329 name.AlertingPolicyId != gotenresource.WildcardId { 330 return false 331 } 332 } 333 334 return true 335 } 336 337 // implement CustomTypeCliValue method 338 func (name *ParentName) SetFromCliFlag(raw string) error { 339 parsedName, err := ParseParentName(raw) 340 if err != nil { 341 return err 342 } 343 *name = *parsedName 344 return nil 345 } 346 347 type ParentReference struct { 348 ParentName 349 alertingPolicy *alerting_policy.AlertingPolicy 350 } 351 352 func MakeParentReference(name *ParentName) (*ParentReference, error) { 353 return &ParentReference{ 354 ParentName: *name, 355 }, nil 356 } 357 358 func ParseParentReference(name string) (*ParentReference, error) { 359 parsedName, err := ParseParentName(name) 360 if err != nil { 361 return nil, err 362 } 363 return MakeParentReference(parsedName) 364 } 365 366 func MustParseParentReference(name string) *ParentReference { 367 result, err := ParseParentReference(name) 368 if err != nil { 369 panic(err) 370 } 371 return result 372 } 373 func (ref *ParentReference) GetAlertingPolicyReference() *alerting_policy.Reference { 374 if ref == nil { 375 return nil 376 } 377 378 switch ref.Pattern { 379 case NamePattern_Project_Region_AlertingPolicy: 380 return alerting_policy.NewNameBuilder(). 381 SetId(ref.AlertingPolicyId). 382 SetProjectId(ref.ProjectId). 383 SetRegionId(ref.RegionId). 384 Reference() 385 default: 386 return nil 387 } 388 } 389 390 func (ref *ParentReference) GetUnderlyingReference() gotenresource.Reference { 391 if ref == nil { 392 return nil 393 } 394 alertingPolicyRef := ref.GetAlertingPolicyReference() 395 if alertingPolicyRef != nil { 396 return alertingPolicyRef 397 } 398 399 return nil 400 } 401 402 func (ref *ParentReference) ResolveRaw(res gotenresource.Resource) error { 403 switch typedRes := res.(type) { 404 case *alerting_policy.AlertingPolicy: 405 if name := ref.GetAlertingPolicyName(); name == nil { 406 return status.Errorf(codes.InvalidArgument, "cannot set AlertingPolicy as parent of Notification, because pattern does not match") 407 } 408 ref.alertingPolicy = typedRes 409 return nil 410 default: 411 return status.Errorf(codes.Internal, "Invalid parent type for Notification, got %s", reflect.TypeOf(res).Elem().Name()) 412 } 413 } 414 415 func (ref *ParentReference) Resolved() bool { 416 if name := ref.GetAlertingPolicyName(); name != nil { 417 return ref.alertingPolicy != nil 418 } 419 return true 420 } 421 422 func (ref *ParentReference) ClearCached() { 423 ref.alertingPolicy = nil 424 } 425 426 func (ref *ParentReference) GetAlertingPolicy() *alerting_policy.AlertingPolicy { 427 if ref == nil { 428 return nil 429 } 430 return ref.alertingPolicy 431 } 432 433 func (ref *ParentReference) GetRawResource() gotenresource.Resource { 434 if name := ref.ParentName.GetAlertingPolicyName(); name != nil { 435 return ref.alertingPolicy 436 } 437 return nil 438 } 439 440 func (ref *ParentReference) IsFullyQualified() bool { 441 if ref == nil { 442 return false 443 } 444 return ref.ParentName.IsFullyQualified() 445 } 446 447 func (ref *ParentReference) IsSpecified() bool { 448 if ref == nil { 449 return false 450 } 451 return ref.ParentName.IsSpecified() 452 } 453 454 func (ref *ParentReference) GetResourceDescriptor() gotenresource.Descriptor { 455 return descriptor 456 } 457 458 func (ref *ParentReference) GetPattern() gotenresource.NamePattern { 459 if ref == nil { 460 return "" 461 } 462 return ref.Pattern 463 } 464 465 func (ref *ParentReference) GetIdParts() map[string]string { 466 if ref != nil { 467 return ref.ParentName.GetIdParts() 468 } 469 return map[string]string{ 470 "projectId": "", 471 "regionId": "", 472 "alertingPolicyId": "", 473 } 474 } 475 476 func (ref *ParentReference) GetSegments() gotenresource.NameSegments { 477 if ref != nil { 478 return ref.ParentName.GetSegments() 479 } 480 return nil 481 } 482 483 func (ref *ParentReference) GetIParentName() gotenresource.Name { 484 return nil 485 } 486 487 func (ref *ParentReference) GetIUnderlyingParentName() gotenresource.Name { 488 return nil 489 } 490 491 func (ref *ParentReference) String() string { 492 if ref == nil { 493 return "<nil>" 494 } 495 return ref.ParentName.String() 496 } 497 498 // implement methods required by protobuf-go library for string-struct conversion 499 500 func (ref *ParentReference) ProtoString() (string, error) { 501 if ref == nil { 502 return "", nil 503 } 504 return ref.ParentName.ProtoString() 505 } 506 507 func (ref *ParentReference) ParseProtoString(data string) error { 508 parsed, err := ParseParentReference(data) 509 if err != nil { 510 return err 511 } 512 *ref = *parsed 513 return nil 514 } 515 516 // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface) 517 func (ref *ParentReference) GotenEqual(other interface{}) bool { 518 if other == nil { 519 return ref == nil 520 } 521 other1, ok := other.(*ParentReference) 522 if !ok { 523 other2, ok := other.(ParentReference) 524 if ok { 525 other1 = &other2 526 } else { 527 return false 528 } 529 } 530 if other1 == nil { 531 return ref == nil 532 } else if ref == nil { 533 return false 534 } 535 if ref.alertingPolicy != other1.alertingPolicy { 536 return false 537 } 538 539 return ref.ParentName.GotenEqual(other1.ParentName) 540 } 541 542 // Matches is same as GotenEqual, but also will accept "other" if name is wildcard. 543 func (name *ParentReference) Matches(other interface{}) bool { 544 if other == nil { 545 return name == nil 546 } 547 other1, ok := other.(*ParentReference) 548 if !ok { 549 other2, ok := other.(ParentReference) 550 if ok { 551 other1 = &other2 552 } else { 553 return false 554 } 555 } 556 if other1 == nil { 557 return name == nil 558 } else if name == nil { 559 return false 560 } 561 return name.ParentName.Matches(&other1.ParentName) 562 } 563 564 // implement CustomTypeCliValue method 565 func (ref *ParentReference) SetFromCliFlag(raw string) error { 566 parsedRef, err := ParseParentReference(raw) 567 if err != nil { 568 return err 569 } 570 *ref = *parsedRef 571 return nil 572 }