feat(core): add CLI management for tenant system stores
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXC\SystemStore;
|
||||
|
||||
use KTXC\Stores\TenantStore;
|
||||
use KTXF\SystemStore\StoreReference;
|
||||
use KTXF\SystemStore\SystemStoreException;
|
||||
|
||||
/**
|
||||
* Superuser-facing configuration operations for tenant logical stores.
|
||||
*/
|
||||
class SystemStoreConfigurationService
|
||||
{
|
||||
public function __construct(private readonly TenantStore $tenants)
|
||||
{
|
||||
}
|
||||
|
||||
/** @return array<string, StoreReference> */
|
||||
public function list(string $tenantId): array
|
||||
{
|
||||
$tenant = $this->tenants->fetch($tenantId);
|
||||
if ($tenant === null) {
|
||||
throw new SystemStoreException("Tenant '{$tenantId}' was not found");
|
||||
}
|
||||
|
||||
return $tenant->getConfiguration()->stores()->all();
|
||||
}
|
||||
|
||||
public function set(
|
||||
string $tenantId,
|
||||
string $name,
|
||||
string $provider,
|
||||
string|int $service,
|
||||
string $namespace,
|
||||
): StoreReference {
|
||||
self::validateName($name);
|
||||
$reference = new StoreReference($provider, $service, $namespace);
|
||||
|
||||
if (!$this->tenants->storeConfigurationStore($tenantId, $name, $reference->toArray())) {
|
||||
throw new SystemStoreException("Tenant '{$tenantId}' was not found");
|
||||
}
|
||||
|
||||
return $reference;
|
||||
}
|
||||
|
||||
public function remove(string $tenantId, string $name): bool
|
||||
{
|
||||
self::validateName($name);
|
||||
$removed = $this->tenants->removeConfigurationStore($tenantId, $name);
|
||||
if ($removed === null) {
|
||||
throw new SystemStoreException("Tenant '{$tenantId}' was not found");
|
||||
}
|
||||
|
||||
return $removed;
|
||||
}
|
||||
|
||||
private static function validateName(string $name): void
|
||||
{
|
||||
if (preg_match('/^[a-z][a-z0-9-]*$/', $name) !== 1) {
|
||||
throw new \InvalidArgumentException('Logical store names must use lowercase letters, numbers, and hyphens');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user