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