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