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