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