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