github.com/cloudwan/edgelq-sdk@v1.15.4/monitoring/resources/v4/alert/alert.pb.name.go (about) 1 // Code generated by protoc-gen-goten-resource 2 // Resource: Alert 3 // DO NOT EDIT!!! 4 5 package alert 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 alerting_condition "github.com/cloudwan/edgelq-sdk/monitoring/resources/v4/alerting_condition" 25 common "github.com/cloudwan/edgelq-sdk/monitoring/resources/v4/common" 26 meta "github.com/cloudwan/goten-sdk/types/meta" 27 ) 28 29 // ensure the imports are used 30 var ( 31 _ = codes.NotFound 32 _ = new(fmt.Stringer) 33 _ = new(proto.Message) 34 _ = status.Status{} 35 _ = url.URL{} 36 _ = strings.Builder{} 37 38 _ = new(goten.GotenMessage) 39 _ = new(gotenresource.ListQuery) 40 ) 41 42 // make sure we're using proto imports 43 var ( 44 _ = &alerting_condition.AlertingCondition{} 45 _ = &common.LabelDescriptor{} 46 _ = &meta.Meta{} 47 ) 48 49 var alert_RegexpId = regexp.MustCompile("^(?P<alert_id>[a-zA-Z0-9_.:-]{1,128})$") 50 var regexPath_Project_Region_AlertingPolicy_AlertingCondition = regexp.MustCompile("^projects/(?P<project_id>-|[\\w][\\w.-]{0,127})/regions/(?P<region_id>-|[a-z][a-z0-9\\-]{0,28}[a-z0-9])/alertingPolicies/(?P<alerting_policy_id>-|[\\w][\\w.-]{0,127})/alertingConditions/(?P<alerting_condition_id>-|[\\w][\\w.-]{0,127})/alerts/(?P<alert_id>-|[a-zA-Z0-9_.:-]{1,128})$") 51 52 func (r *Alert) MaybePopulateDefaults() error { 53 alertInterface := interface{}(r) 54 if defaulter, ok := alertInterface.(goten.Defaulter); ok { 55 return defaulter.PopulateDefaults() 56 } 57 return nil 58 } 59 60 type Name struct { 61 ParentName 62 AlertId string `firestore:"alertId"` 63 } 64 65 func ParseName(name string) (*Name, error) { 66 var matches []string 67 if matches = regexPath_Project_Region_AlertingPolicy_AlertingCondition.FindStringSubmatch(name); matches != nil { 68 return NewNameBuilder(). 69 SetProjectId(matches[1]). 70 SetRegionId(matches[2]). 71 SetAlertingPolicyId(matches[3]). 72 SetAlertingConditionId(matches[4]). 73 SetId(matches[5]). 74 Name(), nil 75 } 76 77 return nil, status.Errorf(codes.InvalidArgument, "unable to parse '%s' as Alert name", name) 78 } 79 80 func MustParseName(name string) *Name { 81 result, err := ParseName(name) 82 if err != nil { 83 panic(err) 84 } 85 return result 86 } 87 88 func ParseNameOrId(nameOrId string) (*Name, error) { 89 name, err := ParseName(nameOrId) 90 if err == nil { 91 return name, err 92 } 93 if alert_RegexpId.MatchString(nameOrId) { 94 return &Name{AlertId: nameOrId}, nil 95 } else { 96 return nil, fmt.Errorf("unable to parse '%s' as Alert name or id", nameOrId) 97 } 98 } 99 100 func (name *Name) SetFromSegments(segments gotenresource.NameSegments) error { 101 if len(segments) == 0 { 102 return status.Errorf(codes.InvalidArgument, "No segments given for Alert name") 103 } 104 if err := name.ParentName.SetFromSegments(segments[:len(segments)-1]); err != nil { 105 return err 106 } 107 if segments[len(segments)-1].CollectionLowerJson != "alerts" { 108 return status.Errorf(codes.InvalidArgument, "unable to use segments %s to form Alert name", segments) 109 } 110 name.AlertId = segments[len(segments)-1].Id 111 return nil 112 } 113 114 func (name *Name) GetAlertingConditionName() *alerting_condition.Name { 115 if name == nil { 116 return nil 117 } 118 return name.ParentName.GetAlertingConditionName() 119 } 120 121 func (name *Name) IsSpecified() bool { 122 if name == nil || name.Pattern == "" || name.AlertId == "" { 123 return false 124 } 125 return name.ParentName.IsSpecified() 126 } 127 128 func (name *Name) IsFullyQualified() bool { 129 if name == nil { 130 return false 131 } 132 if name.ParentName.IsFullyQualified() == false { 133 return false 134 } 135 if name.AlertId == "" || name.AlertId == gotenresource.WildcardId { 136 return false 137 } 138 return true 139 } 140 141 func (name *Name) FullyQualifiedName() (string, error) { 142 if !name.IsFullyQualified() { 143 return "", status.Errorf(codes.InvalidArgument, "Name for Alert is not fully qualified") 144 } 145 return fmt.Sprintf("//monitoring.edgelq.com/%s", name.String()), nil 146 } 147 148 func (name *Name) String() string { 149 if name == nil { 150 return "<nil>" 151 } 152 if valueStr, err := name.ProtoString(); err != nil { 153 panic(err) 154 } else { 155 return valueStr 156 } 157 } 158 159 func (name *Name) AsReference() *Reference { 160 return &Reference{Name: *name} 161 } 162 163 func (name *Name) AsRawReference() gotenresource.Reference { 164 return name.AsReference() 165 } 166 167 func (name *Name) GetResourceDescriptor() gotenresource.Descriptor { 168 return descriptor 169 } 170 171 func (name *Name) GetPattern() gotenresource.NamePattern { 172 if name == nil { 173 return "" 174 } 175 return name.Pattern 176 } 177 178 func (name *Name) GetIdParts() map[string]string { 179 if name != nil { 180 return map[string]string{ 181 "projectId": name.ProjectId, 182 "regionId": name.RegionId, 183 "alertingPolicyId": name.AlertingPolicyId, 184 "alertingConditionId": name.AlertingConditionId, 185 "alertId": name.AlertId, 186 } 187 } 188 return map[string]string{ 189 "projectId": "", 190 "regionId": "", 191 "alertingPolicyId": "", 192 "alertingConditionId": "", 193 "alertId": "", 194 } 195 } 196 197 func (name *Name) GetSegments() gotenresource.NameSegments { 198 if name == nil || name.Pattern == "" { 199 return nil 200 } 201 segments := name.ParentName.GetSegments() 202 return append(segments, gotenresource.NameSegment{ 203 CollectionLowerJson: "alerts", 204 Id: name.AlertId, 205 }) 206 } 207 208 func (name *Name) GetIParentName() gotenresource.Name { 209 if name == nil { 210 return (*ParentName)(nil) 211 } 212 return &name.ParentName 213 } 214 215 func (name *Name) GetIUnderlyingParentName() gotenresource.Name { 216 if parentName := name.GetAlertingConditionName(); parentName != nil { 217 return parentName 218 } 219 return nil 220 } 221 222 // implement methods required by protobuf-go library for string-struct conversion 223 224 func (name *Name) ProtoString() (string, error) { 225 if name == nil { 226 return "", nil 227 } 228 result := "" 229 parentPrefix, err := name.ParentName.ProtoString() 230 if err != nil { 231 return "", err 232 } 233 if parentPrefix != "" { 234 result += parentPrefix + "/" 235 } 236 result += "alerts/" + name.AlertId 237 return result, nil 238 } 239 240 func (name *Name) ParseProtoString(data string) error { 241 parsed, err := ParseName(data) 242 if err != nil { 243 return err 244 } 245 *name = *parsed 246 return nil 247 } 248 249 // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface) 250 func (name *Name) GotenEqual(other interface{}) bool { 251 if other == nil { 252 return name == nil 253 } 254 other1, ok := other.(*Name) 255 if !ok { 256 other2, ok := other.(Name) 257 if ok { 258 other1 = &other2 259 } else { 260 return false 261 } 262 } 263 if other1 == nil { 264 return name == nil 265 } else if name == nil { 266 return false 267 } 268 if name.ParentName.GotenEqual(other1.ParentName) == false { 269 return false 270 } 271 if name.AlertId != other1.AlertId { 272 return false 273 } 274 275 return true 276 } 277 278 // Matches is same as GotenEqual, but also will accept "other" if name is wildcard. 279 func (name *Name) Matches(other interface{}) bool { 280 if other == nil { 281 return name == nil 282 } 283 other1, ok := other.(*Name) 284 if !ok { 285 other2, ok := other.(Name) 286 if ok { 287 other1 = &other2 288 } else { 289 return false 290 } 291 } 292 if other1 == nil { 293 return name == nil 294 } else if name == nil { 295 return false 296 } 297 if name.ParentName.Matches(other1.ParentName) == false { 298 return false 299 } 300 if name.AlertId != other1.AlertId { 301 return name.AlertId == gotenresource.WildcardId 302 } 303 304 return true 305 } 306 307 // implement CustomTypeCliValue method 308 func (name *Name) SetFromCliFlag(raw string) error { 309 parsedName, err := ParseName(raw) 310 if err != nil { 311 return err 312 } 313 *name = *parsedName 314 return nil 315 } 316 317 type Reference struct { 318 Name 319 alert *Alert 320 } 321 322 func MakeReference(name *Name, alert *Alert) (*Reference, error) { 323 return &Reference{ 324 Name: *name, 325 alert: alert, 326 }, nil 327 } 328 329 func ParseReference(name string) (*Reference, error) { 330 parsedName, err := ParseName(name) 331 if err != nil { 332 return nil, err 333 } 334 return MakeReference(parsedName, nil) 335 } 336 337 func MustParseReference(name string) *Reference { 338 result, err := ParseReference(name) 339 if err != nil { 340 panic(err) 341 } 342 return result 343 } 344 345 func (ref *Reference) Resolve(resolved *Alert) { 346 ref.alert = resolved 347 } 348 349 func (ref *Reference) ResolveRaw(res gotenresource.Resource) error { 350 if res == nil { 351 ref.Resolve(nil) 352 return nil 353 } 354 if typedRes, ok := res.(*Alert); ok { 355 ref.Resolve(typedRes) 356 return nil 357 } 358 return status.Errorf(codes.Internal, "Invalid resource type for Alert: %s", reflect.TypeOf(res).Elem().Name()) 359 } 360 361 func (ref *Reference) Resolved() bool { 362 return ref != nil && ref.alert != nil 363 } 364 365 func (ref *Reference) ClearCached() { 366 ref.alert = nil 367 } 368 369 func (ref *Reference) GetAlert() *Alert { 370 if ref == nil { 371 return nil 372 } 373 return ref.alert 374 } 375 376 func (ref *Reference) GetRawResource() gotenresource.Resource { 377 if ref == nil { 378 return (*Alert)(nil) 379 } 380 return ref.alert 381 } 382 383 func (ref *Reference) IsFullyQualified() bool { 384 if ref == nil { 385 return false 386 } 387 return ref.Name.IsFullyQualified() 388 } 389 390 func (ref *Reference) IsSpecified() bool { 391 if ref == nil { 392 return false 393 } 394 return ref.Name.IsSpecified() 395 } 396 397 func (ref *Reference) FullyQualifiedName() (string, error) { 398 if !ref.IsFullyQualified() { 399 return "", status.Errorf(codes.InvalidArgument, "Name for Alert is not fully qualified") 400 } 401 return fmt.Sprintf("//monitoring.edgelq.com/%s", ref.String()), nil 402 } 403 404 func (ref *Reference) GetResourceDescriptor() gotenresource.Descriptor { 405 return descriptor 406 } 407 408 func (ref *Reference) GetPattern() gotenresource.NamePattern { 409 if ref == nil { 410 return "" 411 } 412 return ref.Pattern 413 } 414 415 func (ref *Reference) GetIdParts() map[string]string { 416 if ref != nil { 417 return ref.Name.GetIdParts() 418 } 419 return map[string]string{ 420 "projectId": "", 421 "regionId": "", 422 "alertingPolicyId": "", 423 "alertingConditionId": "", 424 "alertId": "", 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 }