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