Skip to content

Commit

Permalink
En cours: importation des FI agent
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrelemee committed Jan 24, 2025
1 parent 8a10ecc commit a3c7a78
Show file tree
Hide file tree
Showing 13 changed files with 390 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .docker/proconnect/mock-oidc-provider/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ server.service.once('beforeAuthorizeRedirect', (authorizeRedirectUri, req) => {
console.log(authorizeRedirectUri);
});

server.service.once('beforeUserinfo', (userInfoResponse, req) => {
server.service.addListener('beforeUserinfo', (userInfoResponse, req) => {
userInfoResponse.body = {
sub: 'c1722a03-4172-4015-9f0d-d1995d4cbe5c',
email: 'redacteur@test.fr',
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"nelmio/cors-bundle": "^2.4",
"pentatrion/vite-bundle": "^7.1",
"phpstan/phpdoc-parser": "^1.28",
"ramsey/uuid": "*",
"ramsey/uuid-doctrine": "^2.1",
"sentry/sentry-symfony": "^5.0",
"symfony/apache-pack": "^1.0",
"symfony/asset": "7.2.*",
Expand Down
86 changes: 85 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ doctrine:
text[]: MartinGeorgiev\Doctrine\DBAL\Types\TextArray
jsonb: MartinGeorgiev\Doctrine\DBAL\Types\Jsonb
jsonb[]: MartinGeorgiev\Doctrine\DBAL\Types\JsonbArray
uuid: Ramsey\Uuid\Doctrine\UuidType

profiling_collect_backtrace: '%kernel.debug%'
use_savepoints: true
Expand Down
41 changes: 41 additions & 0 deletions migrations/Version20250123145424.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250123145424 extends AbstractMigration
{
public function getDescription(): string
{
return 'Création de la table agent_fournisseurs_identites';
}

public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE agent_fournisseurs_identites (uid VARCHAR(255) NOT NULL, nom VARCHAR(255) NOT NULL, est_reseau_interne BOOLEAN NOT NULL, est_actif BOOLEAN NOT NULL, url_decouverte VARCHAR(255) NOT NULL, domaines JSON NOT NULL, categorie_agent VARCHAR(255) DEFAULT NULL, PRIMARY KEY(uid))');
$this->addSql('ALTER TABLE agents ADD fournisseur_identite_uid VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE agents DROP fournisseur_identite');
$this->addSql('ALTER TABLE agents ALTER donnes_authentification TYPE TEXT');
$this->addSql('COMMENT ON COLUMN agents.donnes_authentification IS NULL');
$this->addSql('ALTER TABLE agents ADD CONSTRAINT FK_9596AB6E2CCC2389 FOREIGN KEY (fournisseur_identite_uid) REFERENCES agent_fournisseurs_identites (uid) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_9596AB6E2CCC2389 ON agents (fournisseur_identite_uid)');
}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE agents DROP CONSTRAINT FK_9596AB6E2CCC2389');
$this->addSql('DROP TABLE agent_fournisseurs_identites');
$this->addSql('DROP INDEX IDX_9596AB6E2CCC2389');
$this->addSql('ALTER TABLE agents ADD fournisseur_identite VARCHAR(255) NOT NULL');
$this->addSql('ALTER TABLE agents DROP fournisseur_identite_uid');
$this->addSql('ALTER TABLE agents ALTER donnes_authentification TYPE TEXT');
$this->addSql('COMMENT ON COLUMN agents.donnes_authentification IS \'(DC2Type:simple_array)\'');
}
}
69 changes: 69 additions & 0 deletions src/Command/ImporterCatalogueFournisseurIdentiteAgentCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

namespace MonIndemnisationJustice\Command;

use Doctrine\ORM\EntityManagerInterface;
use MonIndemnisationJustice\Entity\FournisseurIdentiteAgent;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

#[AsCommand(name: 'mon_indemnisation:agent:importer_catalogue_fournisseur_identite', description: 'Hello PhpStorm')]
class ImporterCatalogueFournisseurIdentiteAgentCommand extends Command
{
public function __construct(
protected readonly EntityManagerInterface $em,
protected readonly EventDispatcherInterface $eventDispatcher,
) {
parent::__construct();
}

protected function configure(): void
{
$this
->addArgument('path', InputArgument::REQUIRED)
;
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$path = $input->getArgument('path');
if (!filter_var($path, FILTER_VALIDATE_URL) && !is_file($path)) {
$output->writeln("<error>URL ou chemin de fichier inconnu $path</error>");

return Command::FAILURE;
}

$index = 0;
if (($handle = fopen($path, 'r')) !== false) {
while (($data = fgetcsv($handle, 1000, ',')) !== false) {
if ($index++ > 0) {
dump($data);
list($reseau, $uid, $titre, $actif, $urlDecouverte, $listeFQDNs) = $data;

/** @var FournisseurIdentiteAgent $fournisseurIdentite */
$fournisseurIdentite = $this->em->getRepository(FournisseurIdentiteAgent::class)->findOneBy(['uid' => $uid]) ?? (new FournisseurIdentiteAgent())->setUid($uid);

$fournisseurIdentite
->setNom($titre)
->setActif(in_array(strtolower($actif), ['oui', 'true', 1]))
->setUrlDecouverte($urlDecouverte)
->setReseauInterne(FournisseurIdentiteAgent::RESEAU_INTERNE === $reseau)
->setDomaines(explode(',', $listeFQDNs))
;
$this->em->persist($fournisseurIdentite);
}
}
}

fclose($handle);
$this->em->flush();

return Command::SUCCESS;
}
}
62 changes: 0 additions & 62 deletions src/Command/PurgeDatabaseCommand.php

This file was deleted.

28 changes: 18 additions & 10 deletions src/Entity/Agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ class Agent implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\Column(nullable: false)]
protected string $uid;

/**
* Correspond au champs `idp_id` de ProConnect.
*
* La liste des organisations est définie icihttps://grist.numerique.gouv.fr/o/docs/3kQ829mp7bTy/AgentConnect-Configuration-des-Fournisseurs-dIdentite
*/
#[ORM\Column(nullable: false)]
protected string $fournisseurIdentite;

#[ORM\Column(length: 180)]
protected string $email;

Expand All @@ -70,6 +62,15 @@ class Agent implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\Column(type: 'simple_array')]
protected array $roles = [];

/**
* Correspond au champs `idp_id` de ProConnect.
*
* La liste des organisations est définie ici https://grist.numerique.gouv.fr/o/docs/3kQ829mp7bTy/AgentConnect-Configuration-des-Fournisseurs-dIdentite
*/
#[ORM\ManyToOne(targetEntity: FournisseurIdentiteAgent::class)]
#[ORM\JoinColumn(name: 'fournisseur_identite_uid', referencedColumnName: 'uid')]
protected ?FournisseurIdentiteAgent $fournisseurIdentite = null;

public function __construct()
{
}
Expand Down Expand Up @@ -103,9 +104,16 @@ public function setUid(string $uid): Agent
return $this;
}

public function setFournisseurIdentite(string $fournisseurIdentite): Agent
public function getFournisseurIdentite(): FournisseurIdentiteAgent
{
$this->fournisseurIdentite = $fournisseurIdentite;
return $this->fournisseurIdentite;
}

public function setFournisseurIdentite(?FournisseurIdentiteAgent $fournisseurIdentite): Agent
{
if (null !== $fournisseurIdentite) {
$this->fournisseurIdentite = $fournisseurIdentite;
}

return $this;
}
Expand Down
Loading

0 comments on commit a3c7a78

Please sign in to comment.