Add the Bird Control Plane gateway, signed webhook ingestion, policy-gated writes, fail-closed production auto-activation, and RSA-OAEP bootstrap credential flow.
81 lines
2.6 KiB
PHP
81 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace traits;
|
|
|
|
require_once WD . '/modules/bird/classes/bird_control_plane_contract.php';
|
|
|
|
use bird\classes\bird_control_plane_contract;
|
|
use classes\bird;
|
|
|
|
trait bird_route_helpers_t
|
|
{
|
|
private function normalizeOptionalString(mixed $value): string
|
|
{
|
|
if (!is_scalar($value)) {
|
|
return '';
|
|
}
|
|
$normalized = trim((string)$value);
|
|
if ($normalized === '') {
|
|
return '';
|
|
}
|
|
$lower = strtolower($normalized);
|
|
if ($lower === 'undefined' || $lower === 'null') {
|
|
return '';
|
|
}
|
|
return $normalized;
|
|
}
|
|
|
|
private function getConfiguredWorkspaceId(bird $client): string
|
|
{
|
|
$workspaceConfig = null;
|
|
if (property_exists($client->config, 'workspaceId')) {
|
|
$workspaceConfig = $client->config->workspaceId;
|
|
}
|
|
if (is_object($workspaceConfig) && method_exists($workspaceConfig, 'getVariableValue')) {
|
|
$canonical = $this->normalizeOptionalString($workspaceConfig->getVariableValue());
|
|
if ($canonical !== '') {
|
|
return $canonical;
|
|
}
|
|
}
|
|
|
|
// Backward compatibility with the historical misspelled config key.
|
|
if (property_exists($client->config, 'workplaceId')) {
|
|
$workspaceConfig = $client->config->workplaceId;
|
|
if (is_object($workspaceConfig) && method_exists($workspaceConfig, 'getVariableValue')) {
|
|
return $this->normalizeOptionalString($workspaceConfig->getVariableValue());
|
|
}
|
|
}
|
|
return '';
|
|
}
|
|
|
|
private function getConfiguredChannelId(bird $client): string
|
|
{
|
|
$channelConfig = null;
|
|
if (property_exists($client->config, 'channelId')) {
|
|
$channelConfig = $client->config->channelId;
|
|
}
|
|
if (is_object($channelConfig) && method_exists($channelConfig, 'getVariableValue')) {
|
|
return $this->normalizeOptionalString($channelConfig->getVariableValue());
|
|
}
|
|
return '';
|
|
}
|
|
|
|
/**
|
|
* @return array<int,string>
|
|
*/
|
|
private function getAllowedChannelIds(bird $client): array
|
|
{
|
|
$raw = '';
|
|
if (property_exists($client->config, 'allowed_channel_ids_json')) {
|
|
$config = $client->config->allowed_channel_ids_json;
|
|
if (is_object($config) && method_exists($config, 'getVariableValue')) {
|
|
$raw = trim((string)$config->getVariableValue());
|
|
}
|
|
}
|
|
return bird_control_plane_contract::allowedChannelIds(
|
|
$raw,
|
|
$this->getConfiguredChannelId($client)
|
|
);
|
|
}
|
|
}
|