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