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