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