TenantAtlas/apps/platform/app/Services/TenantConfiguration/ExchangePowerShellCommandContract.php
ahmido 9374260ae1 feat: add Exchange PowerShell invocation gate (#498)
## Summary
- Adds the Spec 431 Exchange PowerShell invocation gate and operation registration slice.
- Introduces trusted provider operation start handling and read-only Exchange PowerShell runner abstractions.
- Updates provider capability/readiness evaluation and coverage for Exchange PowerShell invocation safety.

## Verification
- `cd apps/platform && ./vendor/bin/sail artisan test tests/Feature/Providers/ProviderCapabilityEvaluationTest.php tests/Feature/Providers/ProviderOperationCapabilityGateTest.php tests/Feature/TenantConfiguration/Spec431ExchangePowerShellInvocationGateTest.php tests/Unit/Providers/ProviderCapabilityRegistryTest.php tests/Unit/Providers/ProviderOperationStartGateTest.php tests/Unit/Support/TenantConfiguration/Spec430ExchangePowerShellCommandAllowlistTest.php tests/Unit/Support/TenantConfiguration/Spec431ExchangePowerShellOperationRegistrationTest.php tests/Unit/Verification/ManagedEnvironmentPermissionCapabilityMappingTest.php`
- Result: 80 passed, 685 assertions.

## Product Surface / Ops
- Rendered UI surface changed: N/A.
- Filament/Livewire surface changed: N/A.
- Deployment impact: config/runtime service changes only; no migrations, queues, or assets added.

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #498
2026-07-07 15:23:29 +00:00

71 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Services\TenantConfiguration;
use InvalidArgumentException;
final readonly class ExchangePowerShellCommandContract
{
/**
* @param array<string, mixed> $payload
* @param array<string, mixed> $parameters
*/
private function __construct(
private array $payload,
private array $parameters,
) {}
/**
* @param array<string, mixed> $contract
* @param array<string, mixed> $parameters
*/
public static function fromVerifiedArray(
array $contract,
ExchangePowerShellCommandContracts $contracts,
array $parameters = [],
): self {
$validation = $contracts->validateInvocation($contract, $parameters);
if (! $validation['accepted']) {
throw new InvalidArgumentException('Exchange PowerShell command contract was not verified.');
}
$commandName = $contract['command_name'] ?? null;
$canonicalContract = is_string($commandName)
? $contracts->contractForCommandName($commandName)
: null;
if (! is_array($canonicalContract)) {
throw new InvalidArgumentException('Exchange PowerShell command contract was not canonical.');
}
return new self($canonicalContract, $parameters);
}
/**
* @return array<string, mixed>
*/
public function toArray(): array
{
return $this->payload;
}
/**
* @return array<string, mixed>
*/
public function parameters(): array
{
return $this->parameters;
}
/**
* @return list<string>
*/
public function parameterNames(): array
{
return array_values(array_map('strval', array_keys($this->parameters)));
}
}