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