You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
3.1 KiB
PHP
95 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Cloud;
|
|
|
|
/**
|
|
* Allow-list of single-dispatch Agent leaf operations whose PHP ledgers may be
|
|
* converged from immutable completion or operation-bound inspection evidence.
|
|
*
|
|
* Aggregate parents are deliberately absent: they never cross the Agent
|
|
* dispatch boundary and must be recomputed from their recovered child jobs.
|
|
*/
|
|
final class CloudOperationRecoveryPolicy
|
|
{
|
|
/** @return list<string> */
|
|
public static function kinds(): array
|
|
{
|
|
return self::kindsForModes(['generic']);
|
|
}
|
|
|
|
public static function supports(string $kind): bool
|
|
{
|
|
return (CloudOperationRecoveryContract::OPERATIONS[$kind]['recovery_mode'] ?? null)
|
|
=== 'generic';
|
|
}
|
|
|
|
/** Create-like effects require full guest/artifact absence before release. */
|
|
public static function isCreateLike(string $kind): bool
|
|
{
|
|
return (CloudOperationRecoveryContract::OPERATIONS[$kind]['recovery_mode'] ?? null)
|
|
=== 'create';
|
|
}
|
|
|
|
/** Kinds whose PHP business ledger has an implemented recovery finalizer. */
|
|
public static function supportsLedgerFinalizer(string $kind): bool
|
|
{
|
|
return self::supports($kind) || $kind === 'backup_restore';
|
|
}
|
|
|
|
/** @return list<string> */
|
|
public static function ledgerFinalizerKinds(): array
|
|
{
|
|
return array_values(array_filter(
|
|
self::automaticKinds(),
|
|
self::supportsLedgerFinalizer(...)
|
|
));
|
|
}
|
|
|
|
/** Includes dedicated create inspection, never generic create finalization. */
|
|
public static function automaticKinds(): array
|
|
{
|
|
return self::kindsForModes(['generic', 'create']);
|
|
}
|
|
|
|
public static function identityScope(string $kind): ?string
|
|
{
|
|
$scope = CloudOperationRecoveryContract::OPERATIONS[$kind]['identity_scope'] ?? null;
|
|
return $scope === 'none' ? null : $scope;
|
|
}
|
|
|
|
public static function allowsSystemResolution(string $kind, string $resolution): bool
|
|
{
|
|
return in_array($resolution,
|
|
CloudOperationRecoveryContract::OPERATIONS[$kind]['system_resolutions'] ?? [],
|
|
true);
|
|
}
|
|
|
|
/** Check a rebuilt wire action without replacing its kind-specific evidence checks. */
|
|
public static function allowsAction(string $kind, string $action): bool
|
|
{
|
|
$entry = CloudOperationRecoveryContract::OPERATIONS[$kind] ?? null;
|
|
if ($entry === null || strlen($action) > 128
|
|
|| preg_match('/^[a-z][a-z0-9]*(?:[-:][a-z0-9]+)*$/D', $action) !== 1) {
|
|
return false;
|
|
}
|
|
if (in_array($action, $entry['actions'], true)) {
|
|
return true;
|
|
}
|
|
foreach ($entry['action_patterns'] as $pattern) {
|
|
if (preg_match('~' . $pattern . '~D', $action) === 1) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/** @return list<string> */
|
|
private static function kindsForModes(array $modes): array
|
|
{
|
|
return array_keys(array_filter(
|
|
CloudOperationRecoveryContract::OPERATIONS,
|
|
static fn (array $entry): bool => in_array($entry['recovery_mode'], $modes, true)
|
|
));
|
|
}
|
|
}
|