Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| SigningModePolicy | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| keys | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| get | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign\Service\Policy\Provider\Worker; |
| 10 | |
| 11 | use OCA\Libresign\Service\Policy\Contract\IPolicyDefinition; |
| 12 | use OCA\Libresign\Service\Policy\Contract\IPolicyDefinitionProvider; |
| 13 | use OCA\Libresign\Service\Policy\Model\PolicySpec; |
| 14 | use OCA\Libresign\Service\Policy\Provider\Helper\PolicyKeyNormalizer; |
| 15 | |
| 16 | final class SigningModePolicy implements IPolicyDefinitionProvider { |
| 17 | public const KEY_SIGNING_MODE = 'signing_mode'; |
| 18 | |
| 19 | public const SYSTEM_APP_CONFIG_KEY_SIGNING_MODE = self::KEY_SIGNING_MODE; |
| 20 | |
| 21 | #[\Override] |
| 22 | public function keys(): array { |
| 23 | return [ |
| 24 | self::KEY_SIGNING_MODE, |
| 25 | ]; |
| 26 | } |
| 27 | |
| 28 | #[\Override] |
| 29 | public function get(string|\BackedEnum $policyKey): IPolicyDefinition { |
| 30 | return match (PolicyKeyNormalizer::normalize($policyKey)) { |
| 31 | self::KEY_SIGNING_MODE => new PolicySpec( |
| 32 | key: self::KEY_SIGNING_MODE, |
| 33 | defaultSystemValue: 'sync', |
| 34 | allowedValues: ['sync', 'async'], |
| 35 | normalizer: static fn (mixed $rawValue): string => in_array((string)$rawValue, ['sync', 'async'], true) |
| 36 | ? (string)$rawValue |
| 37 | : 'sync', |
| 38 | appConfigKey: self::SYSTEM_APP_CONFIG_KEY_SIGNING_MODE, |
| 39 | supportsUserPreference: false, |
| 40 | supportsRequestOverride: false, |
| 41 | requestLifecycle: PolicySpec::LIFECYCLE_RUNTIME, |
| 42 | supportedScopes: [PolicySpec::SCOPE_SYSTEM], |
| 43 | compositeChildren: [WorkerConfigPolicy::KEY], |
| 44 | ), |
| 45 | default => throw new \InvalidArgumentException('Unknown policy key: ' . PolicyKeyNormalizer::normalize($policyKey)), |
| 46 | }; |
| 47 | } |
| 48 | } |