github.com/cloudwan/edgelq-sdk@v1.15.4/logging/resources/v1/log/log.pb.parentname.go (about) 1 // Code generated by protoc-gen-goten-resource 2 // Resource: Log 3 // DO NOT EDIT!!! 4 5 package log 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 iam_organization "github.com/cloudwan/edgelq-sdk/iam/resources/v1/organization" 25 iam_project "github.com/cloudwan/edgelq-sdk/iam/resources/v1/project" 26 bucket "github.com/cloudwan/edgelq-sdk/logging/resources/v1/bucket" 27 log_descriptor "github.com/cloudwan/edgelq-sdk/logging/resources/v1/log_descriptor" 28 meta_service "github.com/cloudwan/goten-sdk/meta-service/resources/v1/service" 29 meta "github.com/cloudwan/goten-sdk/types/meta" 30 anypb "google.golang.org/protobuf/types/known/anypb" 31 structpb "google.golang.org/protobuf/types/known/structpb" 32 timestamppb "google.golang.org/protobuf/types/known/timestamppb" 33 ) 34 35 // ensure the imports are used 36 var ( 37 _ = codes.NotFound 38 _ = new(fmt.Stringer) 39 _ = new(proto.Message) 40 _ = status.Status{} 41 _ = url.URL{} 42 _ = strings.Builder{} 43 44 _ = new(goten.GotenMessage) 45 _ = new(gotenresource.ListQuery) 46 ) 47 48 // make sure we're using proto imports 49 var ( 50 _ = &iam_organization.Organization{} 51 _ = &iam_project.Project{} 52 _ = &bucket.Bucket{} 53 _ = &log_descriptor.LogDescriptor{} 54 _ = &anypb.Any{} 55 _ = &structpb.Struct{} 56 _ = ×tamppb.Timestamp{} 57 _ = &meta_service.Service{} 58 _ = &meta.Meta{} 59 ) 60 61 var parentRegexPath_Project = regexp.MustCompile("^projects/(?P<project_id>-|[\\w][\\w.-]{0,127})$") 62 var parentRegexPath_Organization = regexp.MustCompile("^organizations/(?P<organization_id>-|[\\w][\\w.-]{0,127})$") 63 var parentRegexPath_Service = regexp.MustCompile("^services/(?P<service_id>-|[a-z][a-z0-9\\-.]{0,28}[a-z0-9])$") 64 var parentRegexPath_Project_Region_Bucket = regexp.MustCompile("^projects/(?P<project_id>-|[\\w][\\w.-]{0,127})/regions/(?P<region_id>-|[a-z][a-z0-9\\-]{0,28}[a-z0-9])/buckets/(?P<bucket_id>-|[\\w./-]{2,128})$") 65 var parentRegexPath_Organization_Region_Bucket = regexp.MustCompile("^organizations/(?P<organization_id>-|[\\w][\\w.-]{0,127})/regions/(?P<region_id>-|[a-z][a-z0-9\\-]{0,28}[a-z0-9])/buckets/(?P<bucket_id>-|[\\w./-]{2,128})$") 66 var parentRegexPath_Service_Region_Bucket = regexp.MustCompile("^services/(?P<service_id>-|[a-z][a-z0-9\\-.]{0,28}[a-z0-9])/regions/(?P<region_id>-|[a-z][a-z0-9\\-]{0,28}[a-z0-9])/buckets/(?P<bucket_id>-|[\\w./-]{2,128})$") 67 68 type ParentName struct { 69 NamePattern 70 ProjectId string `firestore:"projectId"` 71 OrganizationId string `firestore:"organizationId"` 72 ServiceId string `firestore:"serviceId"` 73 RegionId string `firestore:"regionId"` 74 BucketId string `firestore:"bucketId"` 75 } 76 77 func ParseParentName(name string) (*ParentName, error) { 78 var matches []string 79 if matches = parentRegexPath_Project.FindStringSubmatch(name); matches != nil { 80 return NewNameBuilder(). 81 SetProjectId(matches[1]). 82 Parent(), nil 83 } 84 if matches = parentRegexPath_Organization.FindStringSubmatch(name); matches != nil { 85 return NewNameBuilder(). 86 SetOrganizationId(matches[1]). 87 Parent(), nil 88 } 89 if matches = parentRegexPath_Service.FindStringSubmatch(name); matches != nil { 90 return NewNameBuilder(). 91 SetServiceId(matches[1]). 92 Parent(), nil 93 } 94 if matches = parentRegexPath_Project_Region_Bucket.FindStringSubmatch(name); matches != nil { 95 return NewNameBuilder(). 96 SetProjectId(matches[1]). 97 SetRegionId(matches[2]). 98 SetBucketId(matches[3]). 99 Parent(), nil 100 } 101 if matches = parentRegexPath_Organization_Region_Bucket.FindStringSubmatch(name); matches != nil { 102 return NewNameBuilder(). 103 SetOrganizationId(matches[1]). 104 SetRegionId(matches[2]). 105 SetBucketId(matches[3]). 106 Parent(), nil 107 } 108 if matches = parentRegexPath_Service_Region_Bucket.FindStringSubmatch(name); matches != nil { 109 return NewNameBuilder(). 110 SetServiceId(matches[1]). 111 SetRegionId(matches[2]). 112 SetBucketId(matches[3]). 113 Parent(), nil 114 } 115 116 return nil, status.Errorf(codes.InvalidArgument, "unable to parse '%s' as Log parent name", name) 117 } 118 119 func MustParseParentName(name string) *ParentName { 120 result, err := ParseParentName(name) 121 if err != nil { 122 panic(err) 123 } 124 return result 125 } 126 127 func (name *ParentName) SetFromSegments(segments gotenresource.NameSegments) error { 128 if len(segments) == 1 && segments[0].CollectionLowerJson == "projects" { 129 name.Pattern = NamePattern_Project 130 name.ProjectId = segments[0].Id 131 return nil 132 } else if len(segments) == 1 && segments[0].CollectionLowerJson == "organizations" { 133 name.Pattern = NamePattern_Organization 134 name.OrganizationId = segments[0].Id 135 return nil 136 } else if len(segments) == 1 && segments[0].CollectionLowerJson == "services" { 137 name.Pattern = NamePattern_Service 138 name.ServiceId = segments[0].Id 139 return nil 140 } else if len(segments) == 3 && segments[0].CollectionLowerJson == "projects" && segments[1].CollectionLowerJson == "regions" && segments[2].CollectionLowerJson == "buckets" { 141 name.Pattern = NamePattern_Project_Region_Bucket 142 name.ProjectId = segments[0].Id 143 name.RegionId = segments[1].Id 144 name.BucketId = segments[2].Id 145 return nil 146 } else if len(segments) == 3 && segments[0].CollectionLowerJson == "organizations" && segments[1].CollectionLowerJson == "regions" && segments[2].CollectionLowerJson == "buckets" { 147 name.Pattern = NamePattern_Organization_Region_Bucket 148 name.OrganizationId = segments[0].Id 149 name.RegionId = segments[1].Id 150 name.BucketId = segments[2].Id 151 return nil 152 } else if len(segments) == 3 && segments[0].CollectionLowerJson == "services" && segments[1].CollectionLowerJson == "regions" && segments[2].CollectionLowerJson == "buckets" { 153 name.Pattern = NamePattern_Service_Region_Bucket 154 name.ServiceId = segments[0].Id 155 name.RegionId = segments[1].Id 156 name.BucketId = segments[2].Id 157 return nil 158 } 159 return status.Errorf(codes.InvalidArgument, "unable to use segments %s to form Log parent name", segments) 160 } 161 162 func (name *ParentName) GetProjectName() *iam_project.Name { 163 if name == nil { 164 return nil 165 } 166 167 switch name.Pattern { 168 case NamePattern_Project: 169 return iam_project.NewNameBuilder(). 170 SetId(name.ProjectId). 171 Name() 172 default: 173 return nil 174 } 175 } 176 177 func (name *ParentName) GetOrganizationName() *iam_organization.Name { 178 if name == nil { 179 return nil 180 } 181 182 switch name.Pattern { 183 case NamePattern_Organization: 184 return iam_organization.NewNameBuilder(). 185 SetId(name.OrganizationId). 186 Name() 187 default: 188 return nil 189 } 190 } 191 192 func (name *ParentName) GetServiceName() *meta_service.Name { 193 if name == nil { 194 return nil 195 } 196 197 switch name.Pattern { 198 case NamePattern_Service: 199 return meta_service.NewNameBuilder(). 200 SetId(name.ServiceId). 201 Name() 202 default: 203 return nil 204 } 205 } 206 207 func (name *ParentName) GetBucketName() *bucket.Name { 208 if name == nil { 209 return nil 210 } 211 212 switch name.Pattern { 213 case NamePattern_Project_Region_Bucket: 214 return bucket.NewNameBuilder(). 215 SetId(name.BucketId). 216 SetProjectId(name.ProjectId). 217 SetRegionId(name.RegionId). 218 SetOrganizationId(name.OrganizationId). 219 SetServiceId(name.ServiceId). 220 Name() 221 case NamePattern_Organization_Region_Bucket: 222 return bucket.NewNameBuilder(). 223 SetId(name.BucketId). 224 SetProjectId(name.ProjectId). 225 SetRegionId(name.RegionId). 226 SetOrganizationId(name.OrganizationId). 227 SetServiceId(name.ServiceId). 228 Name() 229 case NamePattern_Service_Region_Bucket: 230 return bucket.NewNameBuilder(). 231 SetId(name.BucketId). 232 SetProjectId(name.ProjectId). 233 SetRegionId(name.RegionId). 234 SetOrganizationId(name.OrganizationId). 235 SetServiceId(name.ServiceId). 236 Name() 237 default: 238 return nil 239 } 240 } 241 242 func (name *ParentName) IsSpecified() bool { 243 if name == nil || name.Pattern == "" { 244 return false 245 } 246 switch name.Pattern { 247 case NamePattern_Project: 248 return name.ProjectId != "" 249 case NamePattern_Organization: 250 return name.OrganizationId != "" 251 case NamePattern_Service: 252 return name.ServiceId != "" 253 case NamePattern_Project_Region_Bucket: 254 return name.ProjectId != "" && name.RegionId != "" && name.BucketId != "" 255 case NamePattern_Organization_Region_Bucket: 256 return name.OrganizationId != "" && name.RegionId != "" && name.BucketId != "" 257 case NamePattern_Service_Region_Bucket: 258 return name.ServiceId != "" && name.RegionId != "" && name.BucketId != "" 259 } 260 return false 261 } 262 263 func (name *ParentName) IsFullyQualified() bool { 264 if name == nil || name.Pattern == "" { 265 return false 266 } 267 268 switch name.Pattern { 269 case NamePattern_Project: 270 return name.ProjectId != "" && name.ProjectId != gotenresource.WildcardId 271 case NamePattern_Organization: 272 return name.OrganizationId != "" && name.OrganizationId != gotenresource.WildcardId 273 case NamePattern_Service: 274 return name.ServiceId != "" && name.ServiceId != gotenresource.WildcardId 275 case NamePattern_Project_Region_Bucket: 276 return name.ProjectId != "" && name.ProjectId != gotenresource.WildcardId && name.RegionId != "" && name.RegionId != gotenresource.WildcardId && name.BucketId != "" && name.BucketId != gotenresource.WildcardId 277 case NamePattern_Organization_Region_Bucket: 278 return name.OrganizationId != "" && name.OrganizationId != gotenresource.WildcardId && name.RegionId != "" && name.RegionId != gotenresource.WildcardId && name.BucketId != "" && name.BucketId != gotenresource.WildcardId 279 case NamePattern_Service_Region_Bucket: 280 return name.ServiceId != "" && name.ServiceId != gotenresource.WildcardId && name.RegionId != "" && name.RegionId != gotenresource.WildcardId && name.BucketId != "" && name.BucketId != gotenresource.WildcardId 281 } 282 283 return false 284 } 285 286 func (name *ParentName) FullyQualifiedName() (string, error) { 287 if !name.IsFullyQualified() { 288 return "", status.Errorf(codes.InvalidArgument, "Parent name for Log is not fully qualified") 289 } 290 return fmt.Sprintf("//logging.edgelq.com/%s", name.String()), nil 291 } 292 293 func (name *ParentName) GetResourceDescriptor() gotenresource.Descriptor { 294 return descriptor 295 } 296 297 func (name *ParentName) GetPattern() gotenresource.NamePattern { 298 if name == nil { 299 return "" 300 } 301 return name.Pattern 302 } 303 304 func (name *ParentName) GetIdParts() map[string]string { 305 if name != nil { 306 return map[string]string{ 307 "projectId": name.ProjectId, 308 "organizationId": name.OrganizationId, 309 "serviceId": name.ServiceId, 310 "regionId": name.RegionId, 311 "bucketId": name.BucketId, 312 } 313 } 314 return map[string]string{ 315 "projectId": "", 316 "organizationId": "", 317 "serviceId": "", 318 "regionId": "", 319 "bucketId": "", 320 } 321 } 322 323 func (name *ParentName) GetSegments() gotenresource.NameSegments { 324 if name == nil { 325 return nil 326 } 327 328 switch name.Pattern { 329 case NamePattern_Project: 330 return gotenresource.NameSegments{ 331 gotenresource.NameSegment{ 332 CollectionLowerJson: "projects", 333 Id: name.ProjectId, 334 }, 335 } 336 case NamePattern_Organization: 337 return gotenresource.NameSegments{ 338 gotenresource.NameSegment{ 339 CollectionLowerJson: "organizations", 340 Id: name.OrganizationId, 341 }, 342 } 343 case NamePattern_Service: 344 return gotenresource.NameSegments{ 345 gotenresource.NameSegment{ 346 CollectionLowerJson: "services", 347 Id: name.ServiceId, 348 }, 349 } 350 case NamePattern_Project_Region_Bucket: 351 return gotenresource.NameSegments{ 352 gotenresource.NameSegment{ 353 CollectionLowerJson: "projects", 354 Id: name.ProjectId, 355 }, 356 gotenresource.NameSegment{ 357 CollectionLowerJson: "regions", 358 Id: name.RegionId, 359 }, 360 gotenresource.NameSegment{ 361 CollectionLowerJson: "buckets", 362 Id: name.BucketId, 363 }, 364 } 365 case NamePattern_Organization_Region_Bucket: 366 return gotenresource.NameSegments{ 367 gotenresource.NameSegment{ 368 CollectionLowerJson: "organizations", 369 Id: name.OrganizationId, 370 }, 371 gotenresource.NameSegment{ 372 CollectionLowerJson: "regions", 373 Id: name.RegionId, 374 }, 375 gotenresource.NameSegment{ 376 CollectionLowerJson: "buckets", 377 Id: name.BucketId, 378 }, 379 } 380 case NamePattern_Service_Region_Bucket: 381 return gotenresource.NameSegments{ 382 gotenresource.NameSegment{ 383 CollectionLowerJson: "services", 384 Id: name.ServiceId, 385 }, 386 gotenresource.NameSegment{ 387 CollectionLowerJson: "regions", 388 Id: name.RegionId, 389 }, 390 gotenresource.NameSegment{ 391 CollectionLowerJson: "buckets", 392 Id: name.BucketId, 393 }, 394 } 395 } 396 return nil 397 } 398 399 func (name *ParentName) GetIParentName() gotenresource.Name { 400 return nil 401 } 402 403 func (name *ParentName) GetIUnderlyingParentName() gotenresource.Name { 404 return nil 405 } 406 407 func (name *ParentName) String() string { 408 if name == nil { 409 return "<nil>" 410 } 411 412 if valueStr, err := name.ProtoString(); err != nil { 413 panic(err) 414 } else { 415 return valueStr 416 } 417 } 418 419 func (name *ParentName) DescendsFrom(ancestor string) bool { 420 if name == nil { 421 return false 422 } 423 424 switch name.Pattern { 425 case NamePattern_Project: 426 return ancestor == "projects" 427 case NamePattern_Organization: 428 return ancestor == "organizations" 429 case NamePattern_Service: 430 return ancestor == "services" 431 case NamePattern_Project_Region_Bucket: 432 return ancestor == "projects" || ancestor == "regions" || ancestor == "buckets" 433 case NamePattern_Organization_Region_Bucket: 434 return ancestor == "organizations" || ancestor == "regions" || ancestor == "buckets" 435 case NamePattern_Service_Region_Bucket: 436 return ancestor == "services" || ancestor == "regions" || ancestor == "buckets" 437 } 438 439 return false 440 } 441 442 func (name *ParentName) AsReference() *ParentReference { 443 return &ParentReference{ParentName: *name} 444 } 445 446 func (name *ParentName) AsRawReference() gotenresource.Reference { 447 return name.AsReference() 448 } 449 450 // implement methods required by protobuf-go library for string-struct conversion 451 452 func (name *ParentName) ProtoString() (string, error) { 453 if name == nil { 454 return "", nil 455 } 456 switch name.Pattern { 457 case NamePattern_Project: 458 return "projects/" + name.ProjectId, nil 459 case NamePattern_Organization: 460 return "organizations/" + name.OrganizationId, nil 461 case NamePattern_Service: 462 return "services/" + name.ServiceId, nil 463 case NamePattern_Project_Region_Bucket: 464 return "projects/" + name.ProjectId + "/regions/" + name.RegionId + "/buckets/" + name.BucketId, nil 465 case NamePattern_Organization_Region_Bucket: 466 return "organizations/" + name.OrganizationId + "/regions/" + name.RegionId + "/buckets/" + name.BucketId, nil 467 case NamePattern_Service_Region_Bucket: 468 return "services/" + name.ServiceId + "/regions/" + name.RegionId + "/buckets/" + name.BucketId, nil 469 } 470 return "", nil 471 } 472 473 func (name *ParentName) ParseProtoString(data string) error { 474 parsed, err := ParseParentName(data) 475 if err != nil { 476 return err 477 } 478 *name = *parsed 479 return nil 480 } 481 482 // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface) 483 func (name *ParentName) GotenEqual(other interface{}) bool { 484 if other == nil { 485 return name == nil 486 } 487 other1, ok := other.(*ParentName) 488 if !ok { 489 other2, ok := other.(ParentName) 490 if ok { 491 other1 = &other2 492 } else { 493 return false 494 } 495 } 496 if other1 == nil { 497 return name == nil 498 } else if name == nil { 499 return false 500 } 501 if name.ProjectId != other1.ProjectId { 502 return false 503 } 504 if name.OrganizationId != other1.OrganizationId { 505 return false 506 } 507 if name.ServiceId != other1.ServiceId { 508 return false 509 } 510 if name.RegionId != other1.RegionId { 511 return false 512 } 513 if name.BucketId != other1.BucketId { 514 return false 515 } 516 if name.Pattern != other1.Pattern { 517 return false 518 } 519 520 return true 521 } 522 523 // Matches is same as GotenEqual, but also will accept "other" if name is wildcard. 524 func (name *ParentName) Matches(other interface{}) bool { 525 if other == nil { 526 return name == nil 527 } 528 other1, ok := other.(*ParentName) 529 if !ok { 530 other2, ok := other.(ParentName) 531 if ok { 532 other1 = &other2 533 } else { 534 return false 535 } 536 } 537 if other1 == nil { 538 return name == nil 539 } else if name == nil { 540 return false 541 } 542 543 if name.Pattern != other1.Pattern { 544 return false 545 } 546 switch name.Pattern { 547 case NamePattern_Project: 548 if name.ProjectId != other1.ProjectId && 549 name.ProjectId != gotenresource.WildcardId { 550 return false 551 } 552 case NamePattern_Organization: 553 if name.OrganizationId != other1.OrganizationId && 554 name.OrganizationId != gotenresource.WildcardId { 555 return false 556 } 557 case NamePattern_Service: 558 if name.ServiceId != other1.ServiceId && 559 name.ServiceId != gotenresource.WildcardId { 560 return false 561 } 562 case NamePattern_Project_Region_Bucket: 563 if name.ProjectId != other1.ProjectId && 564 name.ProjectId != gotenresource.WildcardId { 565 return false 566 } 567 if name.RegionId != other1.RegionId && 568 name.RegionId != gotenresource.WildcardId { 569 return false 570 } 571 if name.BucketId != other1.BucketId && 572 name.BucketId != gotenresource.WildcardId { 573 return false 574 } 575 case NamePattern_Organization_Region_Bucket: 576 if name.OrganizationId != other1.OrganizationId && 577 name.OrganizationId != gotenresource.WildcardId { 578 return false 579 } 580 if name.RegionId != other1.RegionId && 581 name.RegionId != gotenresource.WildcardId { 582 return false 583 } 584 if name.BucketId != other1.BucketId && 585 name.BucketId != gotenresource.WildcardId { 586 return false 587 } 588 case NamePattern_Service_Region_Bucket: 589 if name.ServiceId != other1.ServiceId && 590 name.ServiceId != gotenresource.WildcardId { 591 return false 592 } 593 if name.RegionId != other1.RegionId && 594 name.RegionId != gotenresource.WildcardId { 595 return false 596 } 597 if name.BucketId != other1.BucketId && 598 name.BucketId != gotenresource.WildcardId { 599 return false 600 } 601 } 602 603 return true 604 } 605 606 // implement CustomTypeCliValue method 607 func (name *ParentName) SetFromCliFlag(raw string) error { 608 parsedName, err := ParseParentName(raw) 609 if err != nil { 610 return err 611 } 612 *name = *parsedName 613 return nil 614 } 615 616 type ParentReference struct { 617 ParentName 618 project *iam_project.Project 619 organization *iam_organization.Organization 620 service *meta_service.Service 621 bucket *bucket.Bucket 622 } 623 624 func MakeParentReference(name *ParentName) (*ParentReference, error) { 625 return &ParentReference{ 626 ParentName: *name, 627 }, nil 628 } 629 630 func ParseParentReference(name string) (*ParentReference, error) { 631 parsedName, err := ParseParentName(name) 632 if err != nil { 633 return nil, err 634 } 635 return MakeParentReference(parsedName) 636 } 637 638 func MustParseParentReference(name string) *ParentReference { 639 result, err := ParseParentReference(name) 640 if err != nil { 641 panic(err) 642 } 643 return result 644 } 645 func (ref *ParentReference) GetProjectReference() *iam_project.Reference { 646 if ref == nil { 647 return nil 648 } 649 650 switch ref.Pattern { 651 case NamePattern_Project: 652 return iam_project.NewNameBuilder(). 653 SetId(ref.ProjectId). 654 Reference() 655 default: 656 return nil 657 } 658 } 659 func (ref *ParentReference) GetOrganizationReference() *iam_organization.Reference { 660 if ref == nil { 661 return nil 662 } 663 664 switch ref.Pattern { 665 case NamePattern_Organization: 666 return iam_organization.NewNameBuilder(). 667 SetId(ref.OrganizationId). 668 Reference() 669 default: 670 return nil 671 } 672 } 673 func (ref *ParentReference) GetServiceReference() *meta_service.Reference { 674 if ref == nil { 675 return nil 676 } 677 678 switch ref.Pattern { 679 case NamePattern_Service: 680 return meta_service.NewNameBuilder(). 681 SetId(ref.ServiceId). 682 Reference() 683 default: 684 return nil 685 } 686 } 687 func (ref *ParentReference) GetBucketReference() *bucket.Reference { 688 if ref == nil { 689 return nil 690 } 691 692 switch ref.Pattern { 693 case NamePattern_Project_Region_Bucket: 694 return bucket.NewNameBuilder(). 695 SetId(ref.BucketId). 696 SetProjectId(ref.ProjectId). 697 SetRegionId(ref.RegionId). 698 SetOrganizationId(ref.OrganizationId). 699 SetServiceId(ref.ServiceId). 700 Reference() 701 case NamePattern_Organization_Region_Bucket: 702 return bucket.NewNameBuilder(). 703 SetId(ref.BucketId). 704 SetProjectId(ref.ProjectId). 705 SetRegionId(ref.RegionId). 706 SetOrganizationId(ref.OrganizationId). 707 SetServiceId(ref.ServiceId). 708 Reference() 709 case NamePattern_Service_Region_Bucket: 710 return bucket.NewNameBuilder(). 711 SetId(ref.BucketId). 712 SetProjectId(ref.ProjectId). 713 SetRegionId(ref.RegionId). 714 SetOrganizationId(ref.OrganizationId). 715 SetServiceId(ref.ServiceId). 716 Reference() 717 default: 718 return nil 719 } 720 } 721 722 func (ref *ParentReference) GetUnderlyingReference() gotenresource.Reference { 723 if ref == nil { 724 return nil 725 } 726 projectRef := ref.GetProjectReference() 727 if projectRef != nil { 728 return projectRef 729 } 730 organizationRef := ref.GetOrganizationReference() 731 if organizationRef != nil { 732 return organizationRef 733 } 734 serviceRef := ref.GetServiceReference() 735 if serviceRef != nil { 736 return serviceRef 737 } 738 bucketRef := ref.GetBucketReference() 739 if bucketRef != nil { 740 return bucketRef 741 } 742 743 return nil 744 } 745 746 func (ref *ParentReference) ResolveRaw(res gotenresource.Resource) error { 747 switch typedRes := res.(type) { 748 case *iam_project.Project: 749 if name := ref.GetProjectName(); name == nil { 750 return status.Errorf(codes.InvalidArgument, "cannot set Project as parent of Log, because pattern does not match") 751 } 752 ref.project = typedRes 753 return nil 754 case *iam_organization.Organization: 755 if name := ref.GetOrganizationName(); name == nil { 756 return status.Errorf(codes.InvalidArgument, "cannot set Organization as parent of Log, because pattern does not match") 757 } 758 ref.organization = typedRes 759 return nil 760 case *meta_service.Service: 761 if name := ref.GetServiceName(); name == nil { 762 return status.Errorf(codes.InvalidArgument, "cannot set Service as parent of Log, because pattern does not match") 763 } 764 ref.service = typedRes 765 return nil 766 case *bucket.Bucket: 767 if name := ref.GetBucketName(); name == nil { 768 return status.Errorf(codes.InvalidArgument, "cannot set Bucket as parent of Log, because pattern does not match") 769 } 770 ref.bucket = typedRes 771 return nil 772 default: 773 return status.Errorf(codes.Internal, "Invalid parent type for Log, got %s", reflect.TypeOf(res).Elem().Name()) 774 } 775 } 776 777 func (ref *ParentReference) Resolved() bool { 778 if name := ref.GetProjectName(); name != nil { 779 return ref.project != nil 780 } 781 if name := ref.GetOrganizationName(); name != nil { 782 return ref.organization != nil 783 } 784 if name := ref.GetServiceName(); name != nil { 785 return ref.service != nil 786 } 787 if name := ref.GetBucketName(); name != nil { 788 return ref.bucket != nil 789 } 790 return true 791 } 792 793 func (ref *ParentReference) ClearCached() { 794 ref.project = nil 795 ref.organization = nil 796 ref.service = nil 797 ref.bucket = nil 798 } 799 800 func (ref *ParentReference) GetProject() *iam_project.Project { 801 if ref == nil { 802 return nil 803 } 804 return ref.project 805 } 806 func (ref *ParentReference) GetOrganization() *iam_organization.Organization { 807 if ref == nil { 808 return nil 809 } 810 return ref.organization 811 } 812 func (ref *ParentReference) GetService() *meta_service.Service { 813 if ref == nil { 814 return nil 815 } 816 return ref.service 817 } 818 func (ref *ParentReference) GetBucket() *bucket.Bucket { 819 if ref == nil { 820 return nil 821 } 822 return ref.bucket 823 } 824 825 func (ref *ParentReference) GetRawResource() gotenresource.Resource { 826 if name := ref.ParentName.GetProjectName(); name != nil { 827 return ref.project 828 } 829 if name := ref.ParentName.GetOrganizationName(); name != nil { 830 return ref.organization 831 } 832 if name := ref.ParentName.GetServiceName(); name != nil { 833 return ref.service 834 } 835 if name := ref.ParentName.GetBucketName(); name != nil { 836 return ref.bucket 837 } 838 return nil 839 } 840 841 func (ref *ParentReference) IsFullyQualified() bool { 842 if ref == nil { 843 return false 844 } 845 return ref.ParentName.IsFullyQualified() 846 } 847 848 func (ref *ParentReference) IsSpecified() bool { 849 if ref == nil { 850 return false 851 } 852 return ref.ParentName.IsSpecified() 853 } 854 855 func (ref *ParentReference) GetResourceDescriptor() gotenresource.Descriptor { 856 return descriptor 857 } 858 859 func (ref *ParentReference) GetPattern() gotenresource.NamePattern { 860 if ref == nil { 861 return "" 862 } 863 return ref.Pattern 864 } 865 866 func (ref *ParentReference) GetIdParts() map[string]string { 867 if ref != nil { 868 return ref.ParentName.GetIdParts() 869 } 870 return map[string]string{ 871 "projectId": "", 872 "organizationId": "", 873 "serviceId": "", 874 "regionId": "", 875 "bucketId": "", 876 } 877 } 878 879 func (ref *ParentReference) GetSegments() gotenresource.NameSegments { 880 if ref != nil { 881 return ref.ParentName.GetSegments() 882 } 883 return nil 884 } 885 886 func (ref *ParentReference) GetIParentName() gotenresource.Name { 887 return nil 888 } 889 890 func (ref *ParentReference) GetIUnderlyingParentName() gotenresource.Name { 891 return nil 892 } 893 894 func (ref *ParentReference) String() string { 895 if ref == nil { 896 return "<nil>" 897 } 898 return ref.ParentName.String() 899 } 900 901 // implement methods required by protobuf-go library for string-struct conversion 902 903 func (ref *ParentReference) ProtoString() (string, error) { 904 if ref == nil { 905 return "", nil 906 } 907 return ref.ParentName.ProtoString() 908 } 909 910 func (ref *ParentReference) ParseProtoString(data string) error { 911 parsed, err := ParseParentReference(data) 912 if err != nil { 913 return err 914 } 915 *ref = *parsed 916 return nil 917 } 918 919 // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface) 920 func (ref *ParentReference) GotenEqual(other interface{}) bool { 921 if other == nil { 922 return ref == nil 923 } 924 other1, ok := other.(*ParentReference) 925 if !ok { 926 other2, ok := other.(ParentReference) 927 if ok { 928 other1 = &other2 929 } else { 930 return false 931 } 932 } 933 if other1 == nil { 934 return ref == nil 935 } else if ref == nil { 936 return false 937 } 938 if ref.project != other1.project { 939 return false 940 } 941 if ref.organization != other1.organization { 942 return false 943 } 944 if ref.service != other1.service { 945 return false 946 } 947 if ref.bucket != other1.bucket { 948 return false 949 } 950 951 return ref.ParentName.GotenEqual(other1.ParentName) 952 } 953 954 // Matches is same as GotenEqual, but also will accept "other" if name is wildcard. 955 func (name *ParentReference) Matches(other interface{}) bool { 956 if other == nil { 957 return name == nil 958 } 959 other1, ok := other.(*ParentReference) 960 if !ok { 961 other2, ok := other.(ParentReference) 962 if ok { 963 other1 = &other2 964 } else { 965 return false 966 } 967 } 968 if other1 == nil { 969 return name == nil 970 } else if name == nil { 971 return false 972 } 973 return name.ParentName.Matches(&other1.ParentName) 974 } 975 976 // implement CustomTypeCliValue method 977 func (ref *ParentReference) SetFromCliFlag(raw string) error { 978 parsedRef, err := ParseParentReference(raw) 979 if err != nil { 980 return err 981 } 982 *ref = *parsedRef 983 return nil 984 }