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