Skip to content

Commit 3ffd55b

Browse files
authored
Merge pull request #3 from itk-dev/feature/os2web_key_digital_post
Updated digital post handler
2 parents 1e60744 + c0c053e commit 3ffd55b

File tree

16 files changed

+293
-86
lines changed

16 files changed

+293
-86
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa
1313

1414
- [#101](https://github.com/OS2Forms/os2forms/pull/101)
1515
- Added support for `os2web_key` in Digital post
16+
- Switched from saving settings in key value store to config, i.e
17+
the module needs to be reconfigured.
1618
- Added support for `os2web_key` in Fasit handler.
1719
- Switched from saving settings in key value store to config, i.e
1820
the module needs to be reconfigured.

composer.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"itk-dev/serviceplatformen": "^1.5",
6060
"mglaman/composer-drupal-lenient": "^1.0",
6161
"os2web/os2web_audit": "^0.1.6",
62-
"os2web/os2web_datalookup": "dev-feature/os2web_key as 2.0.0",
62+
"os2web/os2web_datalookup": "^2.0",
6363
"os2web/os2web_key": "^1.0",
6464
"os2web/os2web_nemlogin": "^1.0",
6565
"os2web/os2web_simplesaml": "dev-master",
@@ -81,10 +81,6 @@
8181
"wsdltophp/packagegenerator": "^4.0"
8282
},
8383
"repositories": {
84-
"os2web/os2web_datalookup": {
85-
"type": "vcs",
86-
"url": "https://github.com/itk-dev/os2web_datalookup"
87-
},
8884
"drupal": {
8985
"type": "composer",
9086
"url": "https://packages.drupal.org/8"

modules/os2forms_digital_post/drush.services.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

modules/os2forms_digital_post/os2forms_digital_post.services.yml

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,64 +8,29 @@ services:
88
arguments: [ 'webform_submission' ]
99

1010
Drupal\os2forms_digital_post\Helper\Settings:
11-
arguments:
12-
- "@config.factory"
13-
- "@key.repository"
11+
autowire: true
1412

1513
Drupal\os2forms_digital_post\Helper\CertificateLocatorHelper:
16-
arguments:
17-
- "@Drupal\\os2forms_digital_post\\Helper\\Settings"
18-
- "@key.repository"
14+
autowire: true
1915

2016
Drupal\os2forms_digital_post\Helper\MeMoHelper:
21-
arguments:
22-
- "@Drupal\\os2forms_digital_post\\Helper\\Settings"
23-
- "@plugin.manager.element_info"
24-
- "@webform.token_manager"
17+
autowire: true
2518

2619
Drupal\os2forms_digital_post\Helper\ForsendelseHelper:
27-
arguments:
28-
- "@Drupal\\os2forms_digital_post\\Helper\\Settings"
29-
- "@plugin.manager.element_info"
30-
- "@webform.token_manager"
20+
autowire: true
3121

3222
Drupal\os2forms_digital_post\Helper\DigitalPostHelper:
33-
arguments:
34-
- "@Drupal\\os2forms_digital_post\\Helper\\Settings"
35-
- "@Drupal\\os2web_key\\KeyHelper"
36-
- "@plugin.manager.os2web_datalookup"
37-
- "@Drupal\\os2forms_digital_post\\Helper\\MeMoHelper"
38-
- "@Drupal\\os2forms_digital_post\\Helper\\ForsendelseHelper"
39-
- "@Drupal\\os2forms_digital_post\\Helper\\BeskedfordelerHelper"
40-
- "@logger.channel.os2forms_digital_post"
41-
- "@logger.channel.os2forms_digital_post_submission"
42-
- "@os2web_audit.logger"
23+
autowire: true
4324

4425
Drupal\os2forms_digital_post\Helper\WebformHelperSF1601:
45-
arguments:
46-
- "@Drupal\\os2forms_digital_post\\Helper\\Settings"
47-
- "@entity_type.manager"
48-
- "@plugin.manager.os2web_datalookup"
49-
- "@Drupal\\os2forms_digital_post\\Helper\\MeMoHelper"
50-
- "@Drupal\\os2forms_digital_post\\Helper\\ForsendelseHelper"
51-
- "@Drupal\\os2forms_digital_post\\Helper\\BeskedfordelerHelper"
52-
- "@logger.channel.os2forms_digital_post"
53-
- "@logger.channel.os2forms_digital_post_submission"
54-
- "@Drupal\\os2forms_digital_post\\Helper\\DigitalPostHelper"
26+
autowire: true
5527

5628
Drupal\os2forms_digital_post\Helper\SF1461Helper:
5729

5830
Drupal\os2forms_digital_post\EventSubscriber\BeskedfordelerEventSubscriber:
59-
arguments:
60-
- '@Drupal\os2forms_digital_post\Helper\BeskedfordelerHelper'
61-
- '@Drupal\beskedfordeler\Helper\MessageHelper'
62-
- '@Drupal\os2forms_digital_post\Helper\WebformHelperSF1601'
63-
- '@logger.channel.os2forms_digital_post'
31+
autowire: true
6432
tags:
6533
- { name: 'event_subscriber' }
6634

6735
Drupal\os2forms_digital_post\Helper\BeskedfordelerHelper:
68-
arguments:
69-
- '@database'
70-
- '@Drupal\os2forms_digital_post\Helper\MeMoHelper'
71-
- '@logger.channel.os2forms_digital_post'
36+
autowire: true

modules/os2forms_digital_post/src/Commands/DigitalPostTestCommands.php renamed to modules/os2forms_digital_post/src/Drush/Commands/DigitalPostTestCommands.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22

3-
namespace Drupal\os2forms_digital_post\Commands;
3+
namespace Drupal\os2forms_digital_post\Drush\Commands;
44

55
use Drupal\Component\Serialization\Yaml;
6+
use Drupal\Core\DependencyInjection\AutowireTrait;
67
use Drupal\Core\Utility\Token;
78
use Drupal\entity_print\Plugin\EntityPrintPluginManagerInterface;
89
use Drupal\os2forms_digital_post\Helper\DigitalPostHelper;
@@ -12,19 +13,22 @@
1213
use ItkDev\Serviceplatformen\Service\SF1601\SF1601;
1314
use Symfony\Component\Console\Exception\InvalidArgumentException;
1415
use Symfony\Component\Console\Style\SymfonyStyle;
16+
use Symfony\Component\DependencyInjection\Attribute\Autowire;
1517
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
1618

1719
/**
1820
* Test commands for digital post.
1921
*/
20-
class DigitalPostTestCommands extends DrushCommands {
22+
final class DigitalPostTestCommands extends DrushCommands {
23+
use AutowireTrait;
2124

2225
/**
2326
* Constructor.
2427
*/
2528
public function __construct(
2629
private readonly DigitalPostHelper $digitalPostHelper,
2730
private readonly Token $token,
31+
#[Autowire(service: 'plugin.manager.entity_print.print_engine')]
2832
private readonly EntityPrintPluginManagerInterface $entityPrintPluginManager,
2933
private readonly Settings $digitalPostSettings,
3034
) {

modules/os2forms_digital_post/src/EventSubscriber/BeskedfordelerEventSubscriber.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Drupal\os2forms_digital_post\Helper\BeskedfordelerHelper;
99
use Drupal\os2forms_digital_post\Helper\WebformHelperSF1601;
1010
use Psr\Log\LoggerInterface;
11+
use Symfony\Component\DependencyInjection\Attribute\Autowire;
1112

1213
/**
1314
* Event subscriber for PostStatusBeskedModtagEvent.
@@ -23,6 +24,7 @@ public function __construct(
2324
private readonly BeskedfordelerHelper $beskedfordelerHelper,
2425
private readonly MessageHelper $messageHelper,
2526
private readonly WebformHelperSF1601 $webformHelper,
27+
#[Autowire(service: 'logger.channel.os2forms_digital_post')]
2628
LoggerInterface $logger,
2729
) {
2830
parent::__construct($logger);

modules/os2forms_digital_post/src/Form/SettingsForm.php

Lines changed: 140 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Drupal\Core\StringTranslation\StringTranslationTrait;
1212
use Drupal\Core\StringTranslation\TranslatableMarkup;
1313
use Drupal\Core\Url;
14+
use Drupal\os2forms_digital_post\Helper\CertificateLocatorHelper;
1415
use Drupal\os2forms_digital_post\Helper\Settings;
1516
use Symfony\Component\DependencyInjection\ContainerInterface;
1617

@@ -134,17 +135,127 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
134135
'#type' => 'fieldset',
135136
'#title' => $this->t('Certificate'),
136137
'#tree' => TRUE,
138+
];
139+
140+
$form[Settings::CERTIFICATE][Settings::CERTIFICATE_PROVIDER] = [
141+
'#type' => 'select',
142+
'#title' => $this->t('Provider'),
143+
'#options' => [
144+
Settings::PROVIDER_TYPE_FORM => $this->t('Form'),
145+
Settings::PROVIDER_TYPE_KEY => $this->t('Key'),
146+
],
147+
'#default_value' => $this->settings->getEditableValue([Settings::CERTIFICATE, Settings::CERTIFICATE_PROVIDER]) ?? Settings::PROVIDER_TYPE_FORM,
148+
'#description' => $this->t('Specifies which provider to use'),
149+
];
150+
151+
$form[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_TYPE] = [
152+
'#type' => 'select',
153+
'#title' => $this->t('Certificate locator type'),
154+
'#options' => [
155+
CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT => $this->t('Azure key vault'),
156+
CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM => $this->t('File system'),
157+
],
158+
'#default_value' => $this->settings->getEditableValue([
159+
Settings::CERTIFICATE,
160+
CertificateLocatorHelper::LOCATOR_TYPE,
161+
]) ?? NULL,
162+
'#states' => [
163+
'visible' => [':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_FORM]],
164+
],
165+
'#description' => $this->t('Specifies which locator to use'),
166+
];
137167

138-
Settings::KEY => [
139-
'#type' => 'key_select',
140-
'#key_filters' => [
141-
'type' => 'os2web_key_certificate',
168+
$form[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT] = [
169+
'#type' => 'fieldset',
170+
'#title' => $this->t('Azure key vault'),
171+
'#states' => [
172+
'visible' => [
173+
':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_FORM],
174+
':input[name="certificate[locator_type]"]' => ['value' => CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT],
175+
],
176+
],
177+
];
178+
179+
$settings = [
180+
CertificateLocatorHelper::LOCATOR_AZURE_KEY_VAULT_TENANT_ID => ['title' => $this->t('Tenant id')],
181+
CertificateLocatorHelper::LOCATOR_AZURE_KEY_VAULT_APPLICATION_ID => ['title' => $this->t('Application id')],
182+
CertificateLocatorHelper::LOCATOR_AZURE_KEY_VAULT_CLIENT_SECRET => ['title' => $this->t('Client secret')],
183+
CertificateLocatorHelper::LOCATOR_AZURE_KEY_VAULT_NAME => ['title' => $this->t('Name')],
184+
CertificateLocatorHelper::LOCATOR_AZURE_KEY_VAULT_SECRET => ['title' => $this->t('Secret')],
185+
CertificateLocatorHelper::LOCATOR_AZURE_KEY_VAULT_VERSION => ['title' => $this->t('Version')],
186+
];
187+
188+
foreach ($settings as $key => $info) {
189+
$form[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT][$key] = [
190+
'#type' => 'textfield',
191+
'#title' => $info['title'],
192+
'#default_value' => $this->settings->getEditableValue([
193+
Settings::CERTIFICATE,
194+
CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT,
195+
$key,
196+
]) ?? NULL,
197+
'#states' => [
198+
'required' => [
199+
':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_FORM],
200+
':input[name="certificate[locator_type]"]' => ['value' => CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT],
201+
],
202+
],
203+
];
204+
}
205+
206+
$form[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM] = [
207+
'#type' => 'fieldset',
208+
'#title' => $this->t('File system'),
209+
'#states' => [
210+
'visible' => [
211+
':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_FORM],
212+
':input[name="certificate[locator_type]"]' => ['value' => CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM],
142213
],
143-
'#key_description' => FALSE,
144-
'#title' => $this->t('Key'),
145-
'#default_value' => $this->settings->getEditableValue([Settings::CERTIFICATE, Settings::KEY]),
146-
'#required' => TRUE,
147-
'#description' => $this->createDescription([Settings::CERTIFICATE, Settings::KEY]),
214+
],
215+
216+
CertificateLocatorHelper::LOCATOR_FILE_SYSTEM_PATH => [
217+
'#type' => 'textfield',
218+
'#title' => $this->t('Path'),
219+
'#default_value' => $this->settings->getEditableValue([
220+
Settings::CERTIFICATE,
221+
CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM,
222+
CertificateLocatorHelper::LOCATOR_FILE_SYSTEM_PATH,
223+
]) ?? NULL,
224+
'#states' => [
225+
'required' => [
226+
':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_FORM],
227+
':input[name="certificate[locator_type]"]' => ['value' => CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM],
228+
],
229+
],
230+
],
231+
];
232+
233+
$form[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_PASSPHRASE] = [
234+
'#type' => 'textfield',
235+
'#title' => $this->t('Passphrase'),
236+
'#default_value' => $this->settings->getEditableValue([
237+
Settings::CERTIFICATE,
238+
CertificateLocatorHelper::LOCATOR_PASSPHRASE,
239+
]) ?? '',
240+
'#states' => [
241+
'visible' => [
242+
':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_FORM],
243+
],
244+
],
245+
];
246+
247+
$form[Settings::CERTIFICATE][Settings::PROVIDER_TYPE_KEY] = [
248+
'#type' => 'key_select',
249+
'#key_filters' => [
250+
'type' => 'os2web_key_certificate',
251+
],
252+
'#key_description' => FALSE,
253+
'#title' => $this->t('Key'),
254+
'#default_value' => $this->settings->getEditableValue([Settings::CERTIFICATE, Settings::PROVIDER_TYPE_KEY]),
255+
'#description' => $this->createDescription([Settings::CERTIFICATE, Settings::PROVIDER_TYPE_KEY]),
256+
'#states' => [
257+
'visible' => [':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_KEY]],
258+
'required' => [':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_KEY]],
148259
],
149260
];
150261

@@ -179,6 +290,26 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
179290
return $form;
180291
}
181292

293+
/**
294+
* {@inheritdoc}
295+
*
296+
* @phpstan-param array<string, mixed> $form
297+
*/
298+
public function validateForm(array &$form, FormStateInterface $form_state): void {
299+
$values = $form_state->getValues();
300+
301+
if (Settings::PROVIDER_TYPE_FORM === $values[Settings::CERTIFICATE][Settings::CERTIFICATE_PROVIDER]) {
302+
if (CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM === $values[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_TYPE]) {
303+
$path = $values[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM][CertificateLocatorHelper::LOCATOR_FILE_SYSTEM_PATH] ?? NULL;
304+
if (!file_exists($path)) {
305+
$form_state->setErrorByName('certificate][file_system][path', $this->t('Invalid certificate path: %path', ['%path' => $path]));
306+
}
307+
}
308+
}
309+
310+
parent::validateForm($form, $form_state);
311+
}
312+
182313
/**
183314
* {@inheritdoc}
184315
*

modules/os2forms_digital_post/src/Helper/AbstractMessageHelper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Drupal\webform_attachment\Element\WebformAttachmentBase;
1313
use ItkDev\Serviceplatformen\Service\SF1601\Serializer;
1414
use Oio\Fjernprint\ForsendelseI;
15+
use Symfony\Component\DependencyInjection\Attribute\Autowire;
1516

1617
/**
1718
* Abstract message helper.
@@ -23,6 +24,7 @@ abstract class AbstractMessageHelper {
2324
*/
2425
public function __construct(
2526
readonly protected Settings $settings,
27+
#[Autowire(service: 'plugin.manager.element_info')]
2628
readonly protected ElementInfoManager $elementInfoManager,
2729
readonly protected WebformTokenManagerInterface $webformTokenManager,
2830
) {

modules/os2forms_digital_post/src/Helper/BeskedfordelerHelper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Drupal\webform\WebformSubmissionInterface;
1010
use Psr\Log\LoggerAwareTrait;
1111
use Psr\Log\LoggerInterface;
12+
use Symfony\Component\DependencyInjection\Attribute\Autowire;
1213

1314
/**
1415
* Beskedfordeler helper.
@@ -24,6 +25,7 @@ class BeskedfordelerHelper {
2425
public function __construct(
2526
private readonly Connection $database,
2627
private readonly MeMoHelper $meMoHelper,
28+
#[Autowire(service: 'logger.channel.os2forms_digital_post')]
2729
LoggerInterface $logger,
2830
) {
2931
$this->setLogger($logger);

0 commit comments

Comments
 (0)