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