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