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