( taskID string, boundChannel string, ingressChannel string, patch *taskpkg.Patch, )
| 461 | } |
| 462 | |
| 463 | func enforceBoundTaskChannel( |
| 464 | taskID string, |
| 465 | boundChannel string, |
| 466 | ingressChannel string, |
| 467 | patch *taskpkg.Patch, |
| 468 | ) error { |
| 469 | trimmedBound := strings.TrimSpace(boundChannel) |
| 470 | if trimmedBound == "" { |
| 471 | return nil |
| 472 | } |
| 473 | if err := ValidateChannel(trimmedBound); err != nil { |
| 474 | if patch != nil && patchAllowsStaleChannelRepair(strings.TrimSpace(ingressChannel), *patch) { |
| 475 | return nil |
| 476 | } |
| 477 | return fmt.Errorf( |
| 478 | "%w: task %q channel %q no longer validates", |
| 479 | ErrTaskChannelStale, |
| 480 | strings.TrimSpace(taskID), |
| 481 | trimmedBound, |
| 482 | ) |
| 483 | } |
| 484 | if trimmedBound != strings.TrimSpace(ingressChannel) { |
| 485 | return fmt.Errorf( |
| 486 | "%w: task %q channel %q does not match ingress channel %q", |
| 487 | ErrTaskChannelMismatch, |
| 488 | strings.TrimSpace(taskID), |
| 489 | trimmedBound, |
| 490 | strings.TrimSpace(ingressChannel), |
| 491 | ) |
| 492 | } |
| 493 | return nil |
| 494 | } |
| 495 | |
| 496 | func patchAllowsStaleChannelRepair(ingressChannel string, patch taskpkg.Patch) bool { |
| 497 | if patch.NetworkChannel == nil { |
no test coverage detected