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