github.com/cloudwan/edgelq-sdk@v1.15.4/audit/resources/v1/resource_change_log/resource_change_log.pb.parentname.go (about) 1 // Code generated by protoc-gen-goten-resource 2 // Resource: ResourceChangeLog 3 // DO NOT EDIT!!! 4 5 package resource_change_log 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 common "github.com/cloudwan/edgelq-sdk/audit/resources/v1/common" 25 iam_organization "github.com/cloudwan/edgelq-sdk/iam/resources/v1/organization" 26 iam_project "github.com/cloudwan/edgelq-sdk/iam/resources/v1/project" 27 meta_service "github.com/cloudwan/goten-sdk/meta-service/resources/v1/service" 28 meta "github.com/cloudwan/goten-sdk/types/meta" 29 anypb "google.golang.org/protobuf/types/known/anypb" 30 fieldmaskpb "google.golang.org/protobuf/types/known/fieldmaskpb" 31 timestamppb "google.golang.org/protobuf/types/known/timestamppb" 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 _ = &common.Authentication{} 50 _ = &iam_organization.Organization{} 51 _ = &iam_project.Project{} 52 _ = &anypb.Any{} 53 _ = &fieldmaskpb.FieldMask{} 54 _ = ×tamppb.Timestamp{} 55 _ = &meta_service.Service{} 56 _ = &meta.Meta{} 57 ) 58 59 var parentRegexPath_Project = regexp.MustCompile("^projects/(?P<project_id>-|[\\w][\\w.-]{0,127})$") 60 var parentRegexPath_Organization = regexp.MustCompile("^organizations/(?P<organization_id>-|[\\w][\\w.-]{0,127})$") 61 var parentRegexPath_Service = regexp.MustCompile("^services/(?P<service_id>-|[a-z][a-z0-9\\-.]{0,28}[a-z0-9])$") 62 63 type ParentName struct { 64 NamePattern 65 ProjectId string `firestore:"projectId"` 66 OrganizationId string `firestore:"organizationId"` 67 ServiceId string `firestore:"serviceId"` 68 } 69 70 func ParseParentName(name string) (*ParentName, error) { 71 var matches []string 72 if matches = parentRegexPath_Project.FindStringSubmatch(name); matches != nil { 73 return NewNameBuilder(). 74 SetProjectId(matches[1]). 75 Parent(), nil 76 } 77 if matches = parentRegexPath_Organization.FindStringSubmatch(name); matches != nil { 78 return NewNameBuilder(). 79 SetOrganizationId(matches[1]). 80 Parent(), nil 81 } 82 if matches = parentRegexPath_Service.FindStringSubmatch(name); matches != nil { 83 return NewNameBuilder(). 84 SetServiceId(matches[1]). 85 Parent(), nil 86 } 87 88 return nil, status.Errorf(codes.InvalidArgument, "unable to parse '%s' as ResourceChangeLog parent name", name) 89 } 90 91 func MustParseParentName(name string) *ParentName { 92 result, err := ParseParentName(name) 93 if err != nil { 94 panic(err) 95 } 96 return result 97 } 98 99 func (name *ParentName) SetFromSegments(segments gotenresource.NameSegments) error { 100 if len(segments) == 1 && segments[0].CollectionLowerJson == "projects" { 101 name.Pattern = NamePattern_Project 102 name.ProjectId = segments[0].Id 103 return nil 104 } else if len(segments) == 1 && segments[0].CollectionLowerJson == "organizations" { 105 name.Pattern = NamePattern_Organization 106 name.OrganizationId = segments[0].Id 107 return nil 108 } else if len(segments) == 1 && segments[0].CollectionLowerJson == "services" { 109 name.Pattern = NamePattern_Service 110 name.ServiceId = segments[0].Id 111 return nil 112 } 113 return status.Errorf(codes.InvalidArgument, "unable to use segments %s to form ResourceChangeLog parent name", segments) 114 } 115 116 func (name *ParentName) GetProjectName() *iam_project.Name { 117 if name == nil { 118 return nil 119 } 120 121 switch name.Pattern { 122 case NamePattern_Project: 123 return iam_project.NewNameBuilder(). 124 SetId(name.ProjectId). 125 Name() 126 default: 127 return nil 128 } 129 } 130 131 func (name *ParentName) GetOrganizationName() *iam_organization.Name { 132 if name == nil { 133 return nil 134 } 135 136 switch name.Pattern { 137 case NamePattern_Organization: 138 return iam_organization.NewNameBuilder(). 139 SetId(name.OrganizationId). 140 Name() 141 default: 142 return nil 143 } 144 } 145 146 func (name *ParentName) GetServiceName() *meta_service.Name { 147 if name == nil { 148 return nil 149 } 150 151 switch name.Pattern { 152 case NamePattern_Service: 153 return meta_service.NewNameBuilder(). 154 SetId(name.ServiceId). 155 Name() 156 default: 157 return nil 158 } 159 } 160 161 func (name *ParentName) IsSpecified() bool { 162 if name == nil || name.Pattern == "" { 163 return false 164 } 165 switch name.Pattern { 166 case NamePattern_Project: 167 return name.ProjectId != "" 168 case NamePattern_Organization: 169 return name.OrganizationId != "" 170 case NamePattern_Service: 171 return name.ServiceId != "" 172 } 173 return false 174 } 175 176 func (name *ParentName) IsFullyQualified() bool { 177 if name == nil || name.Pattern == "" { 178 return false 179 } 180 181 switch name.Pattern { 182 case NamePattern_Project: 183 return name.ProjectId != "" && name.ProjectId != gotenresource.WildcardId 184 case NamePattern_Organization: 185 return name.OrganizationId != "" && name.OrganizationId != gotenresource.WildcardId 186 case NamePattern_Service: 187 return name.ServiceId != "" && name.ServiceId != gotenresource.WildcardId 188 } 189 190 return false 191 } 192 193 func (name *ParentName) FullyQualifiedName() (string, error) { 194 if !name.IsFullyQualified() { 195 return "", status.Errorf(codes.InvalidArgument, "Parent name for ResourceChangeLog is not fully qualified") 196 } 197 return fmt.Sprintf("//audit.edgelq.com/%s", name.String()), nil 198 } 199 200 func (name *ParentName) GetResourceDescriptor() gotenresource.Descriptor { 201 return descriptor 202 } 203 204 func (name *ParentName) GetPattern() gotenresource.NamePattern { 205 if name == nil { 206 return "" 207 } 208 return name.Pattern 209 } 210 211 func (name *ParentName) GetIdParts() map[string]string { 212 if name != nil { 213 return map[string]string{ 214 "projectId": name.ProjectId, 215 "organizationId": name.OrganizationId, 216 "serviceId": name.ServiceId, 217 } 218 } 219 return map[string]string{ 220 "projectId": "", 221 "organizationId": "", 222 "serviceId": "", 223 } 224 } 225 226 func (name *ParentName) GetSegments() gotenresource.NameSegments { 227 if name == nil { 228 return nil 229 } 230 231 switch name.Pattern { 232 case NamePattern_Project: 233 return gotenresource.NameSegments{ 234 gotenresource.NameSegment{ 235 CollectionLowerJson: "projects", 236 Id: name.ProjectId, 237 }, 238 } 239 case NamePattern_Organization: 240 return gotenresource.NameSegments{ 241 gotenresource.NameSegment{ 242 CollectionLowerJson: "organizations", 243 Id: name.OrganizationId, 244 }, 245 } 246 case NamePattern_Service: 247 return gotenresource.NameSegments{ 248 gotenresource.NameSegment{ 249 CollectionLowerJson: "services", 250 Id: name.ServiceId, 251 }, 252 } 253 } 254 return nil 255 } 256 257 func (name *ParentName) GetIParentName() gotenresource.Name { 258 return nil 259 } 260 261 func (name *ParentName) GetIUnderlyingParentName() gotenresource.Name { 262 return nil 263 } 264 265 func (name *ParentName) String() string { 266 if name == nil { 267 return "<nil>" 268 } 269 270 if valueStr, err := name.ProtoString(); err != nil { 271 panic(err) 272 } else { 273 return valueStr 274 } 275 } 276 277 func (name *ParentName) DescendsFrom(ancestor string) bool { 278 if name == nil { 279 return false 280 } 281 282 switch name.Pattern { 283 case NamePattern_Project: 284 return ancestor == "projects" 285 case NamePattern_Organization: 286 return ancestor == "organizations" 287 case NamePattern_Service: 288 return ancestor == "services" 289 } 290 291 return false 292 } 293 294 func (name *ParentName) AsReference() *ParentReference { 295 return &ParentReference{ParentName: *name} 296 } 297 298 func (name *ParentName) AsRawReference() gotenresource.Reference { 299 return name.AsReference() 300 } 301 302 // implement methods required by protobuf-go library for string-struct conversion 303 304 func (name *ParentName) ProtoString() (string, error) { 305 if name == nil { 306 return "", nil 307 } 308 switch name.Pattern { 309 case NamePattern_Project: 310 return "projects/" + name.ProjectId, nil 311 case NamePattern_Organization: 312 return "organizations/" + name.OrganizationId, nil 313 case NamePattern_Service: 314 return "services/" + name.ServiceId, nil 315 } 316 return "", nil 317 } 318 319 func (name *ParentName) ParseProtoString(data string) error { 320 parsed, err := ParseParentName(data) 321 if err != nil { 322 return err 323 } 324 *name = *parsed 325 return nil 326 } 327 328 // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface) 329 func (name *ParentName) GotenEqual(other interface{}) bool { 330 if other == nil { 331 return name == nil 332 } 333 other1, ok := other.(*ParentName) 334 if !ok { 335 other2, ok := other.(ParentName) 336 if ok { 337 other1 = &other2 338 } else { 339 return false 340 } 341 } 342 if other1 == nil { 343 return name == nil 344 } else if name == nil { 345 return false 346 } 347 if name.ProjectId != other1.ProjectId { 348 return false 349 } 350 if name.OrganizationId != other1.OrganizationId { 351 return false 352 } 353 if name.ServiceId != other1.ServiceId { 354 return false 355 } 356 if name.Pattern != other1.Pattern { 357 return false 358 } 359 360 return true 361 } 362 363 // Matches is same as GotenEqual, but also will accept "other" if name is wildcard. 364 func (name *ParentName) Matches(other interface{}) bool { 365 if other == nil { 366 return name == nil 367 } 368 other1, ok := other.(*ParentName) 369 if !ok { 370 other2, ok := other.(ParentName) 371 if ok { 372 other1 = &other2 373 } else { 374 return false 375 } 376 } 377 if other1 == nil { 378 return name == nil 379 } else if name == nil { 380 return false 381 } 382 383 if name.Pattern != other1.Pattern { 384 return false 385 } 386 switch name.Pattern { 387 case NamePattern_Project: 388 if name.ProjectId != other1.ProjectId && 389 name.ProjectId != gotenresource.WildcardId { 390 return false 391 } 392 case NamePattern_Organization: 393 if name.OrganizationId != other1.OrganizationId && 394 name.OrganizationId != gotenresource.WildcardId { 395 return false 396 } 397 case NamePattern_Service: 398 if name.ServiceId != other1.ServiceId && 399 name.ServiceId != gotenresource.WildcardId { 400 return false 401 } 402 } 403 404 return true 405 } 406 407 // implement CustomTypeCliValue method 408 func (name *ParentName) SetFromCliFlag(raw string) error { 409 parsedName, err := ParseParentName(raw) 410 if err != nil { 411 return err 412 } 413 *name = *parsedName 414 return nil 415 } 416 417 type ParentReference struct { 418 ParentName 419 project *iam_project.Project 420 organization *iam_organization.Organization 421 service *meta_service.Service 422 } 423 424 func MakeParentReference(name *ParentName) (*ParentReference, error) { 425 return &ParentReference{ 426 ParentName: *name, 427 }, nil 428 } 429 430 func ParseParentReference(name string) (*ParentReference, error) { 431 parsedName, err := ParseParentName(name) 432 if err != nil { 433 return nil, err 434 } 435 return MakeParentReference(parsedName) 436 } 437 438 func MustParseParentReference(name string) *ParentReference { 439 result, err := ParseParentReference(name) 440 if err != nil { 441 panic(err) 442 } 443 return result 444 } 445 func (ref *ParentReference) GetProjectReference() *iam_project.Reference { 446 if ref == nil { 447 return nil 448 } 449 450 switch ref.Pattern { 451 case NamePattern_Project: 452 return iam_project.NewNameBuilder(). 453 SetId(ref.ProjectId). 454 Reference() 455 default: 456 return nil 457 } 458 } 459 func (ref *ParentReference) GetOrganizationReference() *iam_organization.Reference { 460 if ref == nil { 461 return nil 462 } 463 464 switch ref.Pattern { 465 case NamePattern_Organization: 466 return iam_organization.NewNameBuilder(). 467 SetId(ref.OrganizationId). 468 Reference() 469 default: 470 return nil 471 } 472 } 473 func (ref *ParentReference) GetServiceReference() *meta_service.Reference { 474 if ref == nil { 475 return nil 476 } 477 478 switch ref.Pattern { 479 case NamePattern_Service: 480 return meta_service.NewNameBuilder(). 481 SetId(ref.ServiceId). 482 Reference() 483 default: 484 return nil 485 } 486 } 487 488 func (ref *ParentReference) GetUnderlyingReference() gotenresource.Reference { 489 if ref == nil { 490 return nil 491 } 492 projectRef := ref.GetProjectReference() 493 if projectRef != nil { 494 return projectRef 495 } 496 organizationRef := ref.GetOrganizationReference() 497 if organizationRef != nil { 498 return organizationRef 499 } 500 serviceRef := ref.GetServiceReference() 501 if serviceRef != nil { 502 return serviceRef 503 } 504 505 return nil 506 } 507 508 func (ref *ParentReference) ResolveRaw(res gotenresource.Resource) error { 509 switch typedRes := res.(type) { 510 case *iam_project.Project: 511 if name := ref.GetProjectName(); name == nil { 512 return status.Errorf(codes.InvalidArgument, "cannot set Project as parent of ResourceChangeLog, because pattern does not match") 513 } 514 ref.project = typedRes 515 return nil 516 case *iam_organization.Organization: 517 if name := ref.GetOrganizationName(); name == nil { 518 return status.Errorf(codes.InvalidArgument, "cannot set Organization as parent of ResourceChangeLog, because pattern does not match") 519 } 520 ref.organization = typedRes 521 return nil 522 case *meta_service.Service: 523 if name := ref.GetServiceName(); name == nil { 524 return status.Errorf(codes.InvalidArgument, "cannot set Service as parent of ResourceChangeLog, because pattern does not match") 525 } 526 ref.service = typedRes 527 return nil 528 default: 529 return status.Errorf(codes.Internal, "Invalid parent type for ResourceChangeLog, got %s", reflect.TypeOf(res).Elem().Name()) 530 } 531 } 532 533 func (ref *ParentReference) Resolved() bool { 534 if name := ref.GetProjectName(); name != nil { 535 return ref.project != nil 536 } 537 if name := ref.GetOrganizationName(); name != nil { 538 return ref.organization != nil 539 } 540 if name := ref.GetServiceName(); name != nil { 541 return ref.service != nil 542 } 543 return true 544 } 545 546 func (ref *ParentReference) ClearCached() { 547 ref.project = nil 548 ref.organization = nil 549 ref.service = nil 550 } 551 552 func (ref *ParentReference) GetProject() *iam_project.Project { 553 if ref == nil { 554 return nil 555 } 556 return ref.project 557 } 558 func (ref *ParentReference) GetOrganization() *iam_organization.Organization { 559 if ref == nil { 560 return nil 561 } 562 return ref.organization 563 } 564 func (ref *ParentReference) GetService() *meta_service.Service { 565 if ref == nil { 566 return nil 567 } 568 return ref.service 569 } 570 571 func (ref *ParentReference) GetRawResource() gotenresource.Resource { 572 if name := ref.ParentName.GetProjectName(); name != nil { 573 return ref.project 574 } 575 if name := ref.ParentName.GetOrganizationName(); name != nil { 576 return ref.organization 577 } 578 if name := ref.ParentName.GetServiceName(); name != nil { 579 return ref.service 580 } 581 return nil 582 } 583 584 func (ref *ParentReference) IsFullyQualified() bool { 585 if ref == nil { 586 return false 587 } 588 return ref.ParentName.IsFullyQualified() 589 } 590 591 func (ref *ParentReference) IsSpecified() bool { 592 if ref == nil { 593 return false 594 } 595 return ref.ParentName.IsSpecified() 596 } 597 598 func (ref *ParentReference) GetResourceDescriptor() gotenresource.Descriptor { 599 return descriptor 600 } 601 602 func (ref *ParentReference) GetPattern() gotenresource.NamePattern { 603 if ref == nil { 604 return "" 605 } 606 return ref.Pattern 607 } 608 609 func (ref *ParentReference) GetIdParts() map[string]string { 610 if ref != nil { 611 return ref.ParentName.GetIdParts() 612 } 613 return map[string]string{ 614 "projectId": "", 615 "organizationId": "", 616 "serviceId": "", 617 } 618 } 619 620 func (ref *ParentReference) GetSegments() gotenresource.NameSegments { 621 if ref != nil { 622 return ref.ParentName.GetSegments() 623 } 624 return nil 625 } 626 627 func (ref *ParentReference) GetIParentName() gotenresource.Name { 628 return nil 629 } 630 631 func (ref *ParentReference) GetIUnderlyingParentName() gotenresource.Name { 632 return nil 633 } 634 635 func (ref *ParentReference) String() string { 636 if ref == nil { 637 return "<nil>" 638 } 639 return ref.ParentName.String() 640 } 641 642 // implement methods required by protobuf-go library for string-struct conversion 643 644 func (ref *ParentReference) ProtoString() (string, error) { 645 if ref == nil { 646 return "", nil 647 } 648 return ref.ParentName.ProtoString() 649 } 650 651 func (ref *ParentReference) ParseProtoString(data string) error { 652 parsed, err := ParseParentReference(data) 653 if err != nil { 654 return err 655 } 656 *ref = *parsed 657 return nil 658 } 659 660 // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface) 661 func (ref *ParentReference) GotenEqual(other interface{}) bool { 662 if other == nil { 663 return ref == nil 664 } 665 other1, ok := other.(*ParentReference) 666 if !ok { 667 other2, ok := other.(ParentReference) 668 if ok { 669 other1 = &other2 670 } else { 671 return false 672 } 673 } 674 if other1 == nil { 675 return ref == nil 676 } else if ref == nil { 677 return false 678 } 679 if ref.project != other1.project { 680 return false 681 } 682 if ref.organization != other1.organization { 683 return false 684 } 685 if ref.service != other1.service { 686 return false 687 } 688 689 return ref.ParentName.GotenEqual(other1.ParentName) 690 } 691 692 // Matches is same as GotenEqual, but also will accept "other" if name is wildcard. 693 func (name *ParentReference) Matches(other interface{}) bool { 694 if other == nil { 695 return name == nil 696 } 697 other1, ok := other.(*ParentReference) 698 if !ok { 699 other2, ok := other.(ParentReference) 700 if ok { 701 other1 = &other2 702 } else { 703 return false 704 } 705 } 706 if other1 == nil { 707 return name == nil 708 } else if name == nil { 709 return false 710 } 711 return name.ParentName.Matches(&other1.ParentName) 712 } 713 714 // implement CustomTypeCliValue method 715 func (ref *ParentReference) SetFromCliFlag(raw string) error { 716 parsedRef, err := ParseParentReference(raw) 717 if err != nil { 718 return err 719 } 720 *ref = *parsedRef 721 return nil 722 }