({
installMethod, tier, current, latest, executionStatus, maintenanceWindow,
}: PolicyInput)
| 40 | * | 'ok'. |
| 41 | */ |
| 42 | export const evaluatePolicy = ({ |
| 43 | installMethod, tier, current, latest, executionStatus, maintenanceWindow, |
| 44 | }: PolicyInput): PolicyResult => { |
| 45 | if (tier === 'off') { |
| 46 | return {canNotify: false, canManual: false, canAuto: false, canAutonomous: false, reason: 'tier-off'}; |
| 47 | } |
| 48 | if (compareSemver(current, latest) >= 0) { |
| 49 | return {canNotify: false, canManual: false, canAuto: false, canAutonomous: false, reason: 'up-to-date'}; |
| 50 | } |
| 51 | |
| 52 | const canNotify = true; |
| 53 | const writable = WRITABLE_METHODS.has(installMethod); |
| 54 | |
| 55 | if (!writable) { |
| 56 | return {canNotify, canManual: false, canAuto: false, canAutonomous: false, reason: 'install-method-not-writable'}; |
| 57 | } |
| 58 | |
| 59 | const terminal = executionStatus === 'rollback-failed'; |
| 60 | const canManual = tier === 'manual' || tier === 'auto' || tier === 'autonomous'; |
| 61 | const canAuto = !terminal && (tier === 'auto' || tier === 'autonomous'); |
| 62 | |
| 63 | let canAutonomous = false; |
| 64 | let windowReason: string | null = null; |
| 65 | if (!terminal && tier === 'autonomous') { |
| 66 | if (maintenanceWindow == null) { |
| 67 | windowReason = 'maintenance-window-missing'; |
| 68 | } else if (parseWindow(maintenanceWindow) == null) { |
| 69 | windowReason = 'maintenance-window-invalid'; |
| 70 | } else { |
| 71 | canAutonomous = true; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | const reason = terminal |
| 76 | ? 'rollback-failed-terminal' |
| 77 | : (windowReason ?? 'ok'); |
| 78 | |
| 79 | return {canNotify, canManual, canAuto, canAutonomous, reason}; |
| 80 | }; |
no test coverage detected