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