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