Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/Services/Addons/AddonExecutionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,24 @@ public function execute(ServiceAddonExecution $execution): bool
return $this->finish($execution, AddonExecutionStatus::Failed, null, __('addons.executor.configuration_missing'), null, $attempt, $claimToken);
}

// The add-on names the module it was written for. On a service
// run by another module the same operation and parameter can mean
// something else, so it is not sent there.
$expected = strtolower(trim((string) ($config['module'] ?? '')));
$actual = strtolower(trim((string) ($service->server?->type ?? $service->product?->server_type ?? '')));

if ($expected !== '' && $expected !== $actual) {
return $this->finish(
$execution,
AddonExecutionStatus::Unsupported,
null,
__('addons.executor.module_mismatch', ['expected' => $expected, 'actual' => $actual !== '' ? $actual : '-']),
null,
$attempt,
$claimToken
);
}

$this->assertNoSecrets($config);

$problem = $this->validateCapabilities($module, $config);
Expand Down
1 change: 1 addition & 0 deletions lang/de/addons.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'executor' => [
'service_or_addon_missing' => 'Der Dienst oder das Add-on existiert nicht mehr.',
'module_not_supported' => 'Das Dienstmodul unterstützt die technische Add-on-Ausführung nicht.',
'module_mismatch' => 'Das Add-on ist für das Modul :expected eingerichtet, dieser Dienst läuft aber auf :actual.',
'configuration_missing' => 'Für dieses Add-on fehlt eine vollständige Ausführungskonfiguration.',
'validation_failed' => 'Das Modul hat die Add-on-Konfiguration abgelehnt.',
'operation_failed' => 'Das Modul konnte die Add-on-Operation nicht ausführen.',
Expand Down
1 change: 1 addition & 0 deletions lang/en/addons.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'executor' => [
'service_or_addon_missing' => 'The service or add-on no longer exists.',
'module_not_supported' => 'The service module does not support technical add-on execution.',
'module_mismatch' => 'The add-on is set up for the :expected module, but this service runs on :actual.',
'configuration_missing' => 'This add-on has no complete fulfillment configuration.',
'validation_failed' => 'The module rejected the add-on configuration.',
'operation_failed' => 'The module could not complete the add-on operation.',
Expand Down
1 change: 1 addition & 0 deletions lang/pl/addons.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'executor' => [
'service_or_addon_missing' => 'Usługa lub dodatek już nie istnieją.',
'module_not_supported' => 'Moduł usługi nie obsługuje technicznej realizacji dodatków.',
'module_mismatch' => 'Dodatek jest skonfigurowany dla modułu :expected, a ta usługa działa na :actual.',
'configuration_missing' => 'Ten dodatek nie ma kompletnej konfiguracji realizacji.',
'validation_failed' => 'Moduł odrzucił konfigurację dodatku.',
'operation_failed' => 'Moduł nie mógł wykonać operacji dodatku.',
Expand Down
1 change: 1 addition & 0 deletions lang/tr/addons.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'executor' => [
'service_or_addon_missing' => 'Hizmet veya eklenti artık mevcut değil.',
'module_not_supported' => 'Hizmet modülü teknik eklenti uygulamasını desteklemiyor.',
'module_mismatch' => 'Eklenti :expected modülü için ayarlanmış, ama bu hizmet :actual üzerinde çalışıyor.',
'configuration_missing' => 'Bu eklenti için tam bir uygulama yapılandırması yok.',
'validation_failed' => 'Modül eklenti yapılandırmasını reddetti.',
'operation_failed' => 'Modül eklenti işlemini tamamlayamadı.',
Expand Down
1 change: 1 addition & 0 deletions lang/zh/addons.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'executor' => [
'service_or_addon_missing' => '服务或附加项已不存在。',
'module_not_supported' => '服务模块不支持附加项的技术执行。',
'module_mismatch' => '该附加项是为 :expected 模块设置的,但此服务运行在 :actual 上。',
'configuration_missing' => '此附加项缺少完整的执行配置。',
'validation_failed' => '模块拒绝了附加项配置。',
'operation_failed' => '模块无法完成附加项操作。',
Expand Down
24 changes: 24 additions & 0 deletions tests/Feature/AddonExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,30 @@ function addonTestServiceAddon(
expect($execution->fresh()->status)->toBe(AddonExecutionStatus::Unsupported);
});

it('does not run an add-on set up for another module', function () {
$service = addonTestService();
$addon = addonTestServiceAddon($service, addonTestProductAddon(['fulfillment_module' => 'panelica']));
$executor = app(AddonExecutionService::class);

$execution = $executor->enqueueApply($addon);
$executor->execute($execution);

expect($execution->fresh()->status)->toBe(AddonExecutionStatus::Unsupported)
->and($execution->fresh()->result_message)->toContain('panelica')
->and($service->fresh()->module_data['addon_test']['state']['storage_quota'] ?? null)->toBeNull();
});

it('runs an add-on set up for the service module, whatever the case', function () {
$service = addonTestService();
$addon = addonTestServiceAddon($service, addonTestProductAddon(['fulfillment_module' => 'Addon_Test']));
$executor = app(AddonExecutionService::class);

$execution = $executor->enqueueApply($addon);
$executor->execute($execution);

expect($execution->fresh()->status)->toBe(AddonExecutionStatus::Completed);
});

it('retries a transient module failure with a new attempt record', function () {
$service = addonTestService();
$productAddon = addonTestProductAddon(['options' => ['simulate' => 'fail_once']]);
Expand Down
Loading