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