- Issue created by @Antonín Slejška
- 🇩🇪Germany jurgenhaas Gottmadingen
Hey @antonín slejška I've added a referenced issue ✨ Add support for smoke data over the CTI API Active in the crowdsec module and implemented the service that provides you with smoke data for an IP. The issue includes some links which also show you what data you get back. If you need the data in some different format, then let me know, please.
- 🇩🇪Germany Antonín Slejška Hannover
I Integrated the Crowdsec CTI service, but I have not found a way how to inject a service, which possibly does not exist. The following code does work, but it does not apply the Drupal Coding Standards: commit/bcb9fad356f64...
I have tried to decorate the CTI service and make the original service optional. But it did not work.
- 🇩🇪Germany jurgenhaas Gottmadingen
Here is an approach from @berdir who has solved that in one of his projects by altering the service definition: https://git.drupalcode.org/project/entity_reference_revisions/-/blob/8.x...
- Merge request !3Resolve #3507242 "Display information from CrowdSec" → (Merged) created by Antonín Slejška
- 🇩🇪Germany Antonín Slejška Hannover
I have tried to implement it: https://git.drupalcode.org/project/ip_info/-/merge_requests/3/diffs
If the module crowdsec is deactivated, it works (nothing is displayed). If the module is enabled, I get the following error message:TypeError: Drupal\ip_info\Services\CrowdSec::__construct(): Argument #1 ($cti) must be of type Drupal\ip_info\Services\FakeCti, Drupal\crowdsec\Cti given, called in /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 in Drupal\ip_info\Services\CrowdSec->__construct() (line 26 of modules/contrib/ip_info/src/Services/CrowdSec.php).
- 🇩🇪Germany Antonín Slejška Hannover
The following factory service works:
<?php namespace Drupal\ip_info\Services; class CtiFactory { public function getCtiService() { if (\Drupal::hasService('crowdsec.cti')) { return \Drupal::service('crowdsec.cti'); } return new FakeCti(); } }
But when I try to implement the dependency injection, I have the same problems.
- 🇩🇪Germany Antonín Slejška Hannover
It works now. I combine the service provider: https://git.drupalcode.org/project/ip_info/-/merge_requests/3/diffs?file...
with the factory: https://git.drupalcode.org/project/ip_info/-/merge_requests/3/diffs#ae6c... - 🇩🇪Germany Antonín Slejška Hannover
There is just one last problem in the phpstan test:
Parameter $crowdsecCti of method Drupal\ip_info\Services\CtiFactory::__construct() has invalid type Drupal\crowdsec\Cti.
See: https://git.drupalcode.org/project/ip_info/-/jobs/4436363
- 🇩🇪Germany Antonín Slejška Hannover
There is also another way how to create a service with an optional dependency:
https://eiriksm.dev/services-with-optional-dependencies-drupal-8
I think this is a promising approach. -
antonín slejška →
committed f2f53007 on 1.x
Issue #3507242 by antonín slejška, jurgenhaas: Display information from...
-
antonín slejška →
committed f2f53007 on 1.x