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