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