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