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