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