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