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