18
18
19
19
namespace Surfnet \StepupMiddleware \MiddlewareBundle \Console \Command ;
20
20
21
+ use Doctrine \DBAL \Connection ;
22
+ use Exception ;
21
23
use Rhumsaa \Uuid \Uuid ;
24
+ use Surfnet \StepupMiddleware \CommandHandlingBundle \EventHandling \BufferedEventBus ;
22
25
use Surfnet \StepupMiddleware \CommandHandlingBundle \Identity \Command \BootstrapIdentityWithYubikeySecondFactorCommand
23
26
as BootstrapIdentityWithYubikeySecondFactorIdentityCommand ;
24
27
use Surfnet \StepupMiddleware \CommandHandlingBundle \Pipeline \Pipeline ;
25
28
use Symfony \Component \Console \Command \Command ;
26
- use Symfony \Component \Console \Input \InputArgument ;
27
29
use Symfony \Component \Console \Input \InputInterface ;
28
30
use Symfony \Component \Console \Input \InputOption ;
29
31
use Symfony \Component \Console \Output \OutputInterface ;
@@ -35,11 +37,23 @@ final class BootstrapIdentityWithYubikeySecondFactorCommand extends Command
35
37
*/
36
38
private $ pipeline ;
37
39
38
- public function __construct (Pipeline $ pipeline )
40
+ /**
41
+ * @var BufferedEventBus
42
+ */
43
+ private $ eventBus ;
44
+
45
+ /**
46
+ * @var Connection
47
+ */
48
+ private $ middlewareConnection ;
49
+
50
+ public function __construct (Pipeline $ pipeline , BufferedEventBus $ eventBus , Connection $ middlewareConnection )
39
51
{
40
52
parent ::__construct (null );
41
53
42
54
$ this ->pipeline = $ pipeline ;
55
+ $ this ->eventBus = $ eventBus ;
56
+ $ this ->middlewareConnection = $ middlewareConnection ;
43
57
}
44
58
45
59
@@ -71,11 +85,26 @@ protected function execute(InputInterface $input, OutputInterface $output)
71
85
$ command ->secondFactorId = (string ) Uuid::uuid4 ();
72
86
$ command ->yubikeyPublicId = $ input ->getOption ('yubikey ' );
73
87
74
- $ command = $ this ->pipeline ->process ($ command );
88
+ $ this ->middlewareConnection ->beginTransaction ();
89
+
90
+ try {
91
+ $ command = $ this ->pipeline ->process ($ command );
92
+ $ this ->eventBus ->flush ();
93
+
94
+ $ this ->middlewareConnection ->commit ();
95
+ } catch (Exception $ e ) {
96
+ $ output ->writeln (sprintf (
97
+ '<error>An Error occurred when trying to bootstrap the identity: "%s"</error> ' ,
98
+ $ e ->getMessage ()
99
+ ));
100
+
101
+ $ this ->middlewareConnection ->rollBack ();
102
+ throw $ e ;
103
+ }
75
104
76
105
$ output ->writeln (
77
106
sprintf (
78
- 'Successfully created identity with UUID %s and second factor with UUID %s ' ,
107
+ '<info> Successfully created identity with UUID %s and second factor with UUID %s</info> ' ,
79
108
$ command ->identityId ,
80
109
$ command ->secondFactorId
81
110
)
0 commit comments