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