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