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