github.com/cloudwan/edgelq-sdk@v1.15.4/limits/resources/v1/plan_assignment/plan_assignment.pb.parentname.go (about) 1 // Code generated by protoc-gen-goten-resource 2 // Resource: PlanAssignment 3 // DO NOT EDIT!!! 4 5 package plan_assignment 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 accepted_plan "github.com/cloudwan/edgelq-sdk/limits/resources/v1/accepted_plan" 27 common "github.com/cloudwan/edgelq-sdk/limits/resources/v1/common" 28 plan "github.com/cloudwan/edgelq-sdk/limits/resources/v1/plan" 29 meta_service "github.com/cloudwan/goten-sdk/meta-service/resources/v1/service" 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 _ = &iam_organization.Organization{} 49 _ = &iam_project.Project{} 50 _ = &accepted_plan.AcceptedPlan{} 51 _ = &common.RegionalPlanAssignment{} 52 _ = &plan.Plan{} 53 _ = &meta_service.Service{} 54 _ = &meta.Meta{} 55 ) 56 57 var parentRegexPath_Service = regexp.MustCompile("^services/(?P<service_id>-|[a-z][a-z0-9\\-.]{0,28}[a-z0-9])$") 58 var parentRegexPath_Project = regexp.MustCompile("^projects/(?P<project_id>-|[\\w][\\w.-]{0,127})$") 59 var parentRegexPath_Organization = regexp.MustCompile("^organizations/(?P<organization_id>-|[\\w][\\w.-]{0,127})$") 60 61 type ParentName struct { 62 NamePattern 63 ServiceId string `firestore:"serviceId"` 64 ProjectId string `firestore:"projectId"` 65 OrganizationId string `firestore:"organizationId"` 66 } 67 68 func ParseParentName(name string) (*ParentName, error) { 69 var matches []string 70 if matches = parentRegexPath_Service.FindStringSubmatch(name); matches != nil { 71 return NewNameBuilder(). 72 SetServiceId(matches[1]). 73 Parent(), nil 74 } 75 if matches = parentRegexPath_Project.FindStringSubmatch(name); matches != nil { 76 return NewNameBuilder(). 77 SetProjectId(matches[1]). 78 Parent(), nil 79 } 80 if matches = parentRegexPath_Organization.FindStringSubmatch(name); matches != nil { 81 return NewNameBuilder(). 82 SetOrganizationId(matches[1]). 83 Parent(), nil 84 } 85 86 return nil, status.Errorf(codes.InvalidArgument, "unable to parse '%s' as PlanAssignment parent name", name) 87 } 88 89 func MustParseParentName(name string) *ParentName { 90 result, err := ParseParentName(name) 91 if err != nil { 92 panic(err) 93 } 94 return result 95 } 96 97 func (name *ParentName) SetFromSegments(segments gotenresource.NameSegments) error { 98 if len(segments) == 1 && segments[0].CollectionLowerJson == "services" { 99 name.Pattern = NamePattern_Service 100 name.ServiceId = segments[0].Id 101 return nil 102 } else if len(segments) == 1 && segments[0].CollectionLowerJson == "projects" { 103 name.Pattern = NamePattern_Project 104 name.ProjectId = segments[0].Id 105 return nil 106 } else if len(segments) == 1 && segments[0].CollectionLowerJson == "organizations" { 107 name.Pattern = NamePattern_Organization 108 name.OrganizationId = segments[0].Id 109 return nil 110 } 111 return status.Errorf(codes.InvalidArgument, "unable to use segments %s to form PlanAssignment parent name", segments) 112 } 113 114 func (name *ParentName) GetServiceName() *meta_service.Name { 115 if name == nil { 116 return nil 117 } 118 119 switch name.Pattern { 120 case NamePattern_Service: 121 return meta_service.NewNameBuilder(). 122 SetId(name.ServiceId). 123 Name() 124 default: 125 return nil 126 } 127 } 128 129 func (name *ParentName) GetProjectName() *iam_project.Name { 130 if name == nil { 131 return nil 132 } 133 134 switch name.Pattern { 135 case NamePattern_Project: 136 return iam_project.NewNameBuilder(). 137 SetId(name.ProjectId). 138 Name() 139 default: 140 return nil 141 } 142 } 143 144 func (name *ParentName) GetOrganizationName() *iam_organization.Name { 145 if name == nil { 146 return nil 147 } 148 149 switch name.Pattern { 150 case NamePattern_Organization: 151 return iam_organization.NewNameBuilder(). 152 SetId(name.OrganizationId). 153 Name() 154 default: 155 return nil 156 } 157 } 158 159 func (name *ParentName) IsSpecified() bool { 160 if name == nil || name.Pattern == "" { 161 return false 162 } 163 switch name.Pattern { 164 case NamePattern_Service: 165 return name.ServiceId != "" 166 case NamePattern_Project: 167 return name.ProjectId != "" 168 case NamePattern_Organization: 169 return name.OrganizationId != "" 170 } 171 return false 172 } 173 174 func (name *ParentName) IsFullyQualified() bool { 175 if name == nil || name.Pattern == "" { 176 return false 177 } 178 179 switch name.Pattern { 180 case NamePattern_Service: 181 return name.ServiceId != "" && name.ServiceId != gotenresource.WildcardId 182 case NamePattern_Project: 183 return name.ProjectId != "" && name.ProjectId != gotenresource.WildcardId 184 case NamePattern_Organization: 185 return name.OrganizationId != "" && name.OrganizationId != gotenresource.WildcardId 186 } 187 188 return false 189 } 190 191 func (name *ParentName) FullyQualifiedName() (string, error) { 192 if !name.IsFullyQualified() { 193 return "", status.Errorf(codes.InvalidArgument, "Parent name for PlanAssignment is not fully qualified") 194 } 195 return fmt.Sprintf("//limits.edgelq.com/%s", name.String()), nil 196 } 197 198 func (name *ParentName) GetResourceDescriptor() gotenresource.Descriptor { 199 return descriptor 200 } 201 202 func (name *ParentName) GetPattern() gotenresource.NamePattern { 203 if name == nil { 204 return "" 205 } 206 return name.Pattern 207 } 208 209 func (name *ParentName) GetIdParts() map[string]string { 210 if name != nil { 211 return map[string]string{ 212 "serviceId": name.ServiceId, 213 "projectId": name.ProjectId, 214 "organizationId": name.OrganizationId, 215 } 216 } 217 return map[string]string{ 218 "serviceId": "", 219 "projectId": "", 220 "organizationId": "", 221 } 222 } 223 224 func (name *ParentName) GetSegments() gotenresource.NameSegments { 225 if name == nil { 226 return nil 227 } 228 229 switch name.Pattern { 230 case NamePattern_Service: 231 return gotenresource.NameSegments{ 232 gotenresource.NameSegment{ 233 CollectionLowerJson: "services", 234 Id: name.ServiceId, 235 }, 236 } 237 case NamePattern_Project: 238 return gotenresource.NameSegments{ 239 gotenresource.NameSegment{ 240 CollectionLowerJson: "projects", 241 Id: name.ProjectId, 242 }, 243 } 244 case NamePattern_Organization: 245 return gotenresource.NameSegments{ 246 gotenresource.NameSegment{ 247 CollectionLowerJson: "organizations", 248 Id: name.OrganizationId, 249 }, 250 } 251 } 252 return nil 253 } 254 255 func (name *ParentName) GetIParentName() gotenresource.Name { 256 return nil 257 } 258 259 func (name *ParentName) GetIUnderlyingParentName() gotenresource.Name { 260 return nil 261 } 262 263 func (name *ParentName) String() string { 264 if name == nil { 265 return "<nil>" 266 } 267 268 if valueStr, err := name.ProtoString(); err != nil { 269 panic(err) 270 } else { 271 return valueStr 272 } 273 } 274 275 func (name *ParentName) DescendsFrom(ancestor string) bool { 276 if name == nil { 277 return false 278 } 279 280 switch name.Pattern { 281 case NamePattern_Service: 282 return ancestor == "services" 283 case NamePattern_Project: 284 return ancestor == "projects" 285 case NamePattern_Organization: 286 return ancestor == "organizations" 287 } 288 289 return false 290 } 291 292 func (name *ParentName) AsReference() *ParentReference { 293 return &ParentReference{ParentName: *name} 294 } 295 296 func (name *ParentName) AsRawReference() gotenresource.Reference { 297 return name.AsReference() 298 } 299 300 // implement methods required by protobuf-go library for string-struct conversion 301 302 func (name *ParentName) ProtoString() (string, error) { 303 if name == nil { 304 return "", nil 305 } 306 switch name.Pattern { 307 case NamePattern_Service: 308 return "services/" + name.ServiceId, nil 309 case NamePattern_Project: 310 return "projects/" + name.ProjectId, nil 311 case NamePattern_Organization: 312 return "organizations/" + name.OrganizationId, nil 313 } 314 return "", nil 315 } 316 317 func (name *ParentName) ParseProtoString(data string) error { 318 parsed, err := ParseParentName(data) 319 if err != nil { 320 return err 321 } 322 *name = *parsed 323 return nil 324 } 325 326 // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface) 327 func (name *ParentName) GotenEqual(other interface{}) bool { 328 if other == nil { 329 return name == nil 330 } 331 other1, ok := other.(*ParentName) 332 if !ok { 333 other2, ok := other.(ParentName) 334 if ok { 335 other1 = &other2 336 } else { 337 return false 338 } 339 } 340 if other1 == nil { 341 return name == nil 342 } else if name == nil { 343 return false 344 } 345 if name.ServiceId != other1.ServiceId { 346 return false 347 } 348 if name.ProjectId != other1.ProjectId { 349 return false 350 } 351 if name.OrganizationId != other1.OrganizationId { 352 return false 353 } 354 if name.Pattern != other1.Pattern { 355 return false 356 } 357 358 return true 359 } 360 361 // Matches is same as GotenEqual, but also will accept "other" if name is wildcard. 362 func (name *ParentName) Matches(other interface{}) bool { 363 if other == nil { 364 return name == nil 365 } 366 other1, ok := other.(*ParentName) 367 if !ok { 368 other2, ok := other.(ParentName) 369 if ok { 370 other1 = &other2 371 } else { 372 return false 373 } 374 } 375 if other1 == nil { 376 return name == nil 377 } else if name == nil { 378 return false 379 } 380 381 if name.Pattern != other1.Pattern { 382 return false 383 } 384 switch name.Pattern { 385 case NamePattern_Service: 386 if name.ServiceId != other1.ServiceId && 387 name.ServiceId != gotenresource.WildcardId { 388 return false 389 } 390 case NamePattern_Project: 391 if name.ProjectId != other1.ProjectId && 392 name.ProjectId != gotenresource.WildcardId { 393 return false 394 } 395 case NamePattern_Organization: 396 if name.OrganizationId != other1.OrganizationId && 397 name.OrganizationId != gotenresource.WildcardId { 398 return false 399 } 400 } 401 402 return true 403 } 404 405 // implement CustomTypeCliValue method 406 func (name *ParentName) SetFromCliFlag(raw string) error { 407 parsedName, err := ParseParentName(raw) 408 if err != nil { 409 return err 410 } 411 *name = *parsedName 412 return nil 413 } 414 415 type ParentReference struct { 416 ParentName 417 service *meta_service.Service 418 project *iam_project.Project 419 organization *iam_organization.Organization 420 } 421 422 func MakeParentReference(name *ParentName) (*ParentReference, error) { 423 return &ParentReference{ 424 ParentName: *name, 425 }, nil 426 } 427 428 func ParseParentReference(name string) (*ParentReference, error) { 429 parsedName, err := ParseParentName(name) 430 if err != nil { 431 return nil, err 432 } 433 return MakeParentReference(parsedName) 434 } 435 436 func MustParseParentReference(name string) *ParentReference { 437 result, err := ParseParentReference(name) 438 if err != nil { 439 panic(err) 440 } 441 return result 442 } 443 func (ref *ParentReference) GetServiceReference() *meta_service.Reference { 444 if ref == nil { 445 return nil 446 } 447 448 switch ref.Pattern { 449 case NamePattern_Service: 450 return meta_service.NewNameBuilder(). 451 SetId(ref.ServiceId). 452 Reference() 453 default: 454 return nil 455 } 456 } 457 func (ref *ParentReference) GetProjectReference() *iam_project.Reference { 458 if ref == nil { 459 return nil 460 } 461 462 switch ref.Pattern { 463 case NamePattern_Project: 464 return iam_project.NewNameBuilder(). 465 SetId(ref.ProjectId). 466 Reference() 467 default: 468 return nil 469 } 470 } 471 func (ref *ParentReference) GetOrganizationReference() *iam_organization.Reference { 472 if ref == nil { 473 return nil 474 } 475 476 switch ref.Pattern { 477 case NamePattern_Organization: 478 return iam_organization.NewNameBuilder(). 479 SetId(ref.OrganizationId). 480 Reference() 481 default: 482 return nil 483 } 484 } 485 486 func (ref *ParentReference) GetUnderlyingReference() gotenresource.Reference { 487 if ref == nil { 488 return nil 489 } 490 serviceRef := ref.GetServiceReference() 491 if serviceRef != nil { 492 return serviceRef 493 } 494 projectRef := ref.GetProjectReference() 495 if projectRef != nil { 496 return projectRef 497 } 498 organizationRef := ref.GetOrganizationReference() 499 if organizationRef != nil { 500 return organizationRef 501 } 502 503 return nil 504 } 505 506 func (ref *ParentReference) ResolveRaw(res gotenresource.Resource) error { 507 switch typedRes := res.(type) { 508 case *meta_service.Service: 509 if name := ref.GetServiceName(); name == nil { 510 return status.Errorf(codes.InvalidArgument, "cannot set Service as parent of PlanAssignment, because pattern does not match") 511 } 512 ref.service = typedRes 513 return nil 514 case *iam_project.Project: 515 if name := ref.GetProjectName(); name == nil { 516 return status.Errorf(codes.InvalidArgument, "cannot set Project as parent of PlanAssignment, because pattern does not match") 517 } 518 ref.project = typedRes 519 return nil 520 case *iam_organization.Organization: 521 if name := ref.GetOrganizationName(); name == nil { 522 return status.Errorf(codes.InvalidArgument, "cannot set Organization as parent of PlanAssignment, because pattern does not match") 523 } 524 ref.organization = typedRes 525 return nil 526 default: 527 return status.Errorf(codes.Internal, "Invalid parent type for PlanAssignment, got %s", reflect.TypeOf(res).Elem().Name()) 528 } 529 } 530 531 func (ref *ParentReference) Resolved() bool { 532 if name := ref.GetServiceName(); name != nil { 533 return ref.service != nil 534 } 535 if name := ref.GetProjectName(); name != nil { 536 return ref.project != nil 537 } 538 if name := ref.GetOrganizationName(); name != nil { 539 return ref.organization != nil 540 } 541 return true 542 } 543 544 func (ref *ParentReference) ClearCached() { 545 ref.service = nil 546 ref.project = nil 547 ref.organization = nil 548 } 549 550 func (ref *ParentReference) GetService() *meta_service.Service { 551 if ref == nil { 552 return nil 553 } 554 return ref.service 555 } 556 func (ref *ParentReference) GetProject() *iam_project.Project { 557 if ref == nil { 558 return nil 559 } 560 return ref.project 561 } 562 func (ref *ParentReference) GetOrganization() *iam_organization.Organization { 563 if ref == nil { 564 return nil 565 } 566 return ref.organization 567 } 568 569 func (ref *ParentReference) GetRawResource() gotenresource.Resource { 570 if name := ref.ParentName.GetServiceName(); name != nil { 571 return ref.service 572 } 573 if name := ref.ParentName.GetProjectName(); name != nil { 574 return ref.project 575 } 576 if name := ref.ParentName.GetOrganizationName(); name != nil { 577 return ref.organization 578 } 579 return nil 580 } 581 582 func (ref *ParentReference) IsFullyQualified() bool { 583 if ref == nil { 584 return false 585 } 586 return ref.ParentName.IsFullyQualified() 587 } 588 589 func (ref *ParentReference) IsSpecified() bool { 590 if ref == nil { 591 return false 592 } 593 return ref.ParentName.IsSpecified() 594 } 595 596 func (ref *ParentReference) GetResourceDescriptor() gotenresource.Descriptor { 597 return descriptor 598 } 599 600 func (ref *ParentReference) GetPattern() gotenresource.NamePattern { 601 if ref == nil { 602 return "" 603 } 604 return ref.Pattern 605 } 606 607 func (ref *ParentReference) GetIdParts() map[string]string { 608 if ref != nil { 609 return ref.ParentName.GetIdParts() 610 } 611 return map[string]string{ 612 "serviceId": "", 613 "projectId": "", 614 "organizationId": "", 615 } 616 } 617 618 func (ref *ParentReference) GetSegments() gotenresource.NameSegments { 619 if ref != nil { 620 return ref.ParentName.GetSegments() 621 } 622 return nil 623 } 624 625 func (ref *ParentReference) GetIParentName() gotenresource.Name { 626 return nil 627 } 628 629 func (ref *ParentReference) GetIUnderlyingParentName() gotenresource.Name { 630 return nil 631 } 632 633 func (ref *ParentReference) String() string { 634 if ref == nil { 635 return "<nil>" 636 } 637 return ref.ParentName.String() 638 } 639 640 // implement methods required by protobuf-go library for string-struct conversion 641 642 func (ref *ParentReference) ProtoString() (string, error) { 643 if ref == nil { 644 return "", nil 645 } 646 return ref.ParentName.ProtoString() 647 } 648 649 func (ref *ParentReference) ParseProtoString(data string) error { 650 parsed, err := ParseParentReference(data) 651 if err != nil { 652 return err 653 } 654 *ref = *parsed 655 return nil 656 } 657 658 // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface) 659 func (ref *ParentReference) GotenEqual(other interface{}) bool { 660 if other == nil { 661 return ref == nil 662 } 663 other1, ok := other.(*ParentReference) 664 if !ok { 665 other2, ok := other.(ParentReference) 666 if ok { 667 other1 = &other2 668 } else { 669 return false 670 } 671 } 672 if other1 == nil { 673 return ref == nil 674 } else if ref == nil { 675 return false 676 } 677 if ref.service != other1.service { 678 return false 679 } 680 if ref.project != other1.project { 681 return false 682 } 683 if ref.organization != other1.organization { 684 return false 685 } 686 687 return ref.ParentName.GotenEqual(other1.ParentName) 688 } 689 690 // Matches is same as GotenEqual, but also will accept "other" if name is wildcard. 691 func (name *ParentReference) Matches(other interface{}) bool { 692 if other == nil { 693 return name == nil 694 } 695 other1, ok := other.(*ParentReference) 696 if !ok { 697 other2, ok := other.(ParentReference) 698 if ok { 699 other1 = &other2 700 } else { 701 return false 702 } 703 } 704 if other1 == nil { 705 return name == nil 706 } else if name == nil { 707 return false 708 } 709 return name.ParentName.Matches(&other1.ParentName) 710 } 711 712 // implement CustomTypeCliValue method 713 func (ref *ParentReference) SetFromCliFlag(raw string) error { 714 parsedRef, err := ParseParentReference(raw) 715 if err != nil { 716 return err 717 } 718 *ref = *parsedRef 719 return nil 720 }