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