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