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