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