Add the Bird Control Plane gateway, signed webhook ingestion, policy-gated writes, fail-closed production auto-activation, and RSA-OAEP bootstrap credential flow.
59 lines
2.2 KiB
PHP
59 lines
2.2 KiB
PHP
#!/usr/bin/env php
|
|
<?php
|
|
|
|
if (PHP_SAPI !== 'cli') {
|
|
fwrite(STDERR, "This command is CLI-only.\n");
|
|
exit(2);
|
|
}
|
|
|
|
$command = $argv[1] ?? 'check';
|
|
if (!in_array($command, ['check', 'apply', 'webhooks-check', 'webhooks-apply'], true)) {
|
|
fwrite(
|
|
STDERR,
|
|
"Usage: scripts/bird-control-plane-activate.php check|apply|webhooks-check|webhooks-apply [--yes]\n"
|
|
);
|
|
exit(2);
|
|
}
|
|
if (in_array($command, ['apply', 'webhooks-apply'], true) && ($argv[2] ?? '') !== '--yes') {
|
|
fwrite(STDERR, "Refusing Bird activation without: apply --yes\n");
|
|
exit(2);
|
|
}
|
|
|
|
$appDirectory = __DIR__ . '/../services/nginx/app';
|
|
if (!is_file($appDirectory . '/config.php')) {
|
|
$appDirectory = dirname(__DIR__);
|
|
}
|
|
define('WD', $appDirectory);
|
|
require_once WD . '/vendor/autoload.php';
|
|
require_once WD . '/config.php';
|
|
require_once WD . '/classes/db.php';
|
|
require_once WD . '/modules/bird/classes/bird_control_plane_activator.php';
|
|
require_once WD . '/modules/bird/classes/bird_webhook_subscription_reconciler.php';
|
|
|
|
try {
|
|
$pdo = \classes\db::getPDO();
|
|
if (str_starts_with($command, 'webhooks-')) {
|
|
$reconciler = new \bird\classes\bird_webhook_subscription_reconciler($pdo);
|
|
$organizationId = trim((string)(getenv('BIRD_ORGANIZATION_ID') ?: ''));
|
|
$status = $command === 'webhooks-apply'
|
|
? $reconciler->apply($organizationId)
|
|
: $reconciler->check($organizationId);
|
|
} else {
|
|
$activator = new \bird\classes\bird_control_plane_activator($pdo);
|
|
$status = $command === 'apply' ? $activator->apply([
|
|
'controlPlaneToken' => trim((string)(getenv('BIRD_CONTROL_PLANE_TOKEN') ?: '')),
|
|
'webhookSigningKey' => trim((string)(getenv('BIRD_WEBHOOK_SIGNING_KEY') ?: '')),
|
|
'participantId' => trim((string)(getenv('BIRD_PARTICIPANT_ID') ?: '')),
|
|
]) : $activator->check();
|
|
}
|
|
fwrite(STDOUT, json_encode($status, JSON_UNESCAPED_SLASHES) . PHP_EOL);
|
|
exit(($status['ready'] ?? false) === true ? 0 : 1);
|
|
} catch (Throwable $throwable) {
|
|
error_log('[bird-control-plane-activate] Failed: ' . get_class($throwable));
|
|
fwrite(STDOUT, json_encode([
|
|
'ready' => false,
|
|
'errorCode' => 'bird_activation_failed',
|
|
], JSON_UNESCAPED_SLASHES) . PHP_EOL);
|
|
exit(1);
|
|
}
|