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