github.com/cloudwan/edgelq-sdk@v1.15.4/limits/resources/v1alpha2/limit_pool/limit_pool.pb.name.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/v1alpha2/organization" 25 meta_resource "github.com/cloudwan/edgelq-sdk/meta/resources/v1alpha2/resource" 26 meta_service "github.com/cloudwan/edgelq-sdk/meta/resources/v1alpha2/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 limitPool_RegexpId = regexp.MustCompile("^(?P<limit_pool_id>[a-zA-Z0-9-.]{1,128}\\/[a-zA-Z]{1,128})$") 52 var regexPath = regexp.MustCompile("^limitPools/(?P<limit_pool_id>-|[a-zA-Z0-9-.]{1,128}\\/[a-zA-Z]{1,128})$") 53 var regexPath_Organization = regexp.MustCompile("^organizations/(?P<organization_id>-|[\\w][\\w.-]{0,127})/limitPools/(?P<limit_pool_id>-|[a-zA-Z0-9-.]{1,128}\\/[a-zA-Z]{1,128})$") 54 55 func (r *LimitPool) MaybePopulateDefaults() error { 56 limitPoolInterface := interface{}(r) 57 if defaulter, ok := limitPoolInterface.(goten.Defaulter); ok { 58 return defaulter.PopulateDefaults() 59 } 60 return nil 61 } 62 63 type Name struct { 64 ParentName 65 LimitPoolId string `firestore:"limitPoolId"` 66 } 67 68 func ParseName(name string) (*Name, error) { 69 var matches []string 70 if matches = regexPath.FindStringSubmatch(name); matches != nil { 71 return NewNameBuilder(). 72 SetId(matches[1]). 73 Name(), nil 74 } 75 if matches = regexPath_Organization.FindStringSubmatch(name); matches != nil { 76 return NewNameBuilder(). 77 SetOrganizationId(matches[1]). 78 SetId(matches[2]). 79 Name(), nil 80 } 81 82 return nil, status.Errorf(codes.InvalidArgument, "unable to parse '%s' as LimitPool name", name) 83 } 84 85 func MustParseName(name string) *Name { 86 result, err := ParseName(name) 87 if err != nil { 88 panic(err) 89 } 90 return result 91 } 92 93 func ParseNameOrId(nameOrId string) (*Name, error) { 94 name, err := ParseName(nameOrId) 95 if err == nil { 96 return name, err 97 } 98 if limitPool_RegexpId.MatchString(nameOrId) { 99 return &Name{LimitPoolId: nameOrId}, nil 100 } else { 101 return nil, fmt.Errorf("unable to parse '%s' as LimitPool name or id", nameOrId) 102 } 103 } 104 105 func (name *Name) SetFromSegments(segments gotenresource.NameSegments) error { 106 if len(segments) == 0 { 107 return status.Errorf(codes.InvalidArgument, "No segments given for LimitPool name") 108 } 109 if err := name.ParentName.SetFromSegments(segments[:len(segments)-1]); err != nil { 110 return err 111 } 112 if segments[len(segments)-1].CollectionLowerJson != "limitPools" { 113 return status.Errorf(codes.InvalidArgument, "unable to use segments %s to form LimitPool name", segments) 114 } 115 name.LimitPoolId = segments[len(segments)-1].Id 116 return nil 117 } 118 119 func (name *Name) GetOrganizationName() *iam_organization.Name { 120 if name == nil { 121 return nil 122 } 123 return name.ParentName.GetOrganizationName() 124 } 125 126 func (name *Name) IsSpecified() bool { 127 if name == nil || name.Pattern == "" || name.LimitPoolId == "" { 128 return false 129 } 130 return name.ParentName.IsSpecified() 131 } 132 133 func (name *Name) IsFullyQualified() bool { 134 if name == nil { 135 return false 136 } 137 if name.ParentName.IsFullyQualified() == false { 138 return false 139 } 140 if name.LimitPoolId == "" || name.LimitPoolId == gotenresource.WildcardId { 141 return false 142 } 143 return true 144 } 145 146 func (name *Name) FullyQualifiedName() (string, error) { 147 if !name.IsFullyQualified() { 148 return "", status.Errorf(codes.InvalidArgument, "Name for LimitPool is not fully qualified") 149 } 150 return fmt.Sprintf("//limits.edgelq.com/%s", name.String()), nil 151 } 152 153 func (name *Name) String() string { 154 if name == nil { 155 return "<nil>" 156 } 157 if valueStr, err := name.ProtoString(); err != nil { 158 panic(err) 159 } else { 160 return valueStr 161 } 162 } 163 164 func (name *Name) AsReference() *Reference { 165 return &Reference{Name: *name} 166 } 167 168 func (name *Name) AsRawReference() gotenresource.Reference { 169 return name.AsReference() 170 } 171 172 func (name *Name) GetResourceDescriptor() gotenresource.Descriptor { 173 return descriptor 174 } 175 176 func (name *Name) GetPattern() gotenresource.NamePattern { 177 if name == nil { 178 return "" 179 } 180 return name.Pattern 181 } 182 183 func (name *Name) GetIdParts() map[string]string { 184 if name != nil { 185 return map[string]string{ 186 "limitPoolId": name.LimitPoolId, 187 "organizationId": name.OrganizationId, 188 } 189 } 190 return map[string]string{ 191 "limitPoolId": "", 192 "organizationId": "", 193 } 194 } 195 196 func (name *Name) GetSegments() gotenresource.NameSegments { 197 if name == nil || name.Pattern == "" { 198 return nil 199 } 200 segments := name.ParentName.GetSegments() 201 return append(segments, gotenresource.NameSegment{ 202 CollectionLowerJson: "limitPools", 203 Id: name.LimitPoolId, 204 }) 205 } 206 207 func (name *Name) GetIParentName() gotenresource.Name { 208 if name == nil { 209 return (*ParentName)(nil) 210 } 211 return &name.ParentName 212 } 213 214 func (name *Name) GetIUnderlyingParentName() gotenresource.Name { 215 if parentName := name.GetOrganizationName(); parentName != nil { 216 return parentName 217 } 218 return nil 219 } 220 221 // implement methods required by protobuf-go library for string-struct conversion 222 223 func (name *Name) ProtoString() (string, error) { 224 if name == nil { 225 return "", nil 226 } 227 result := "" 228 parentPrefix, err := name.ParentName.ProtoString() 229 if err != nil { 230 return "", err 231 } 232 if parentPrefix != "" { 233 result += parentPrefix + "/" 234 } 235 result += "limitPools/" + name.LimitPoolId 236 return result, nil 237 } 238 239 func (name *Name) ParseProtoString(data string) error { 240 parsed, err := ParseName(data) 241 if err != nil { 242 return err 243 } 244 *name = *parsed 245 return nil 246 } 247 248 // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface) 249 func (name *Name) GotenEqual(other interface{}) bool { 250 if other == nil { 251 return name == nil 252 } 253 other1, ok := other.(*Name) 254 if !ok { 255 other2, ok := other.(Name) 256 if ok { 257 other1 = &other2 258 } else { 259 return false 260 } 261 } 262 if other1 == nil { 263 return name == nil 264 } else if name == nil { 265 return false 266 } 267 if name.ParentName.GotenEqual(other1.ParentName) == false { 268 return false 269 } 270 if name.LimitPoolId != other1.LimitPoolId { 271 return false 272 } 273 274 return true 275 } 276 277 // Matches is same as GotenEqual, but also will accept "other" if name is wildcard. 278 func (name *Name) Matches(other interface{}) bool { 279 if other == nil { 280 return name == nil 281 } 282 other1, ok := other.(*Name) 283 if !ok { 284 other2, ok := other.(Name) 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.ParentName.Matches(other1.ParentName) == false { 297 return false 298 } 299 if name.LimitPoolId != other1.LimitPoolId { 300 return name.LimitPoolId == gotenresource.WildcardId 301 } 302 303 return true 304 } 305 306 // implement CustomTypeCliValue method 307 func (name *Name) SetFromCliFlag(raw string) error { 308 parsedName, err := ParseName(raw) 309 if err != nil { 310 return err 311 } 312 *name = *parsedName 313 return nil 314 } 315 316 type Reference struct { 317 Name 318 limitPool *LimitPool 319 } 320 321 func MakeReference(name *Name, limitPool *LimitPool) (*Reference, error) { 322 return &Reference{ 323 Name: *name, 324 limitPool: limitPool, 325 }, nil 326 } 327 328 func ParseReference(name string) (*Reference, error) { 329 parsedName, err := ParseName(name) 330 if err != nil { 331 return nil, err 332 } 333 return MakeReference(parsedName, nil) 334 } 335 336 func MustParseReference(name string) *Reference { 337 result, err := ParseReference(name) 338 if err != nil { 339 panic(err) 340 } 341 return result 342 } 343 344 func (ref *Reference) Resolve(resolved *LimitPool) { 345 ref.limitPool = resolved 346 } 347 348 func (ref *Reference) ResolveRaw(res gotenresource.Resource) error { 349 if res == nil { 350 ref.Resolve(nil) 351 return nil 352 } 353 if typedRes, ok := res.(*LimitPool); ok { 354 ref.Resolve(typedRes) 355 return nil 356 } 357 return status.Errorf(codes.Internal, "Invalid resource type for LimitPool: %s", reflect.TypeOf(res).Elem().Name()) 358 } 359 360 func (ref *Reference) Resolved() bool { 361 return ref != nil && ref.limitPool != nil 362 } 363 364 func (ref *Reference) ClearCached() { 365 ref.limitPool = nil 366 } 367 368 func (ref *Reference) GetLimitPool() *LimitPool { 369 if ref == nil { 370 return nil 371 } 372 return ref.limitPool 373 } 374 375 func (ref *Reference) GetRawResource() gotenresource.Resource { 376 if ref == nil { 377 return (*LimitPool)(nil) 378 } 379 return ref.limitPool 380 } 381 382 func (ref *Reference) IsFullyQualified() bool { 383 if ref == nil { 384 return false 385 } 386 return ref.Name.IsFullyQualified() 387 } 388 389 func (ref *Reference) IsSpecified() bool { 390 if ref == nil { 391 return false 392 } 393 return ref.Name.IsSpecified() 394 } 395 396 func (ref *Reference) FullyQualifiedName() (string, error) { 397 if !ref.IsFullyQualified() { 398 return "", status.Errorf(codes.InvalidArgument, "Name for LimitPool is not fully qualified") 399 } 400 return fmt.Sprintf("//limits.edgelq.com/%s", ref.String()), nil 401 } 402 403 func (ref *Reference) GetResourceDescriptor() gotenresource.Descriptor { 404 return descriptor 405 } 406 407 func (ref *Reference) GetPattern() gotenresource.NamePattern { 408 if ref == nil { 409 return "" 410 } 411 return ref.Pattern 412 } 413 414 func (ref *Reference) GetIdParts() map[string]string { 415 if ref != nil { 416 return ref.Name.GetIdParts() 417 } 418 return map[string]string{ 419 "limitPoolId": "", 420 "organizationId": "", 421 } 422 } 423 424 func (ref *Reference) GetSegments() gotenresource.NameSegments { 425 if ref != nil { 426 return ref.Name.GetSegments() 427 } 428 return nil 429 } 430 431 func (ref *Reference) GetIParentName() gotenresource.Name { 432 if ref == nil { 433 return (*ParentName)(nil) 434 } 435 return ref.Name.GetIParentName() 436 } 437 438 func (ref *Reference) GetIUnderlyingParentName() gotenresource.Name { 439 if ref != nil { 440 return ref.Name.GetIUnderlyingParentName() 441 } 442 return nil 443 } 444 445 func (ref *Reference) String() string { 446 if ref == nil { 447 return "<nil>" 448 } 449 return ref.Name.String() 450 } 451 452 // implement methods required by protobuf-go library for string-struct conversion 453 454 func (ref *Reference) ProtoString() (string, error) { 455 if ref == nil { 456 return "", nil 457 } 458 return ref.Name.ProtoString() 459 } 460 461 func (ref *Reference) ParseProtoString(data string) error { 462 parsed, err := ParseReference(data) 463 if err != nil { 464 return err 465 } 466 *ref = *parsed 467 return nil 468 } 469 470 // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface) 471 func (ref *Reference) GotenEqual(other interface{}) bool { 472 if other == nil { 473 return ref == nil 474 } 475 other1, ok := other.(*Reference) 476 if !ok { 477 other2, ok := other.(Reference) 478 if ok { 479 other1 = &other2 480 } else { 481 return false 482 } 483 } 484 if other1 == nil { 485 return ref == nil 486 } else if ref == nil { 487 return false 488 } 489 490 return ref.Name.GotenEqual(other1.Name) 491 } 492 493 // Matches is same as GotenEqual, but also will accept "other" if name is wildcard. 494 func (name *Reference) Matches(other interface{}) bool { 495 if other == nil { 496 return name == nil 497 } 498 other1, ok := other.(*Reference) 499 if !ok { 500 other2, ok := other.(Reference) 501 if ok { 502 other1 = &other2 503 } else { 504 return false 505 } 506 } 507 if other1 == nil { 508 return name == nil 509 } else if name == nil { 510 return false 511 } 512 return name.Name.Matches(&other1.Name) 513 } 514 515 // implement CustomTypeCliValue method 516 func (ref *Reference) SetFromCliFlag(raw string) error { 517 parsedRef, err := ParseReference(raw) 518 if err != nil { 519 return err 520 } 521 *ref = *parsedRef 522 return nil 523 }