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