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