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