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