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