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