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