@@ -59,11 +59,37 @@ public function registerDaemonConfig(array $daemonConfigParams, bool $defaultDae
59
59
#[PasswordConfirmationRequired]
60
60
public function updateDaemonConfig (string $ name , array $ daemonConfigParams ): Response {
61
61
$ daemonConfig = $ this ->daemonConfigService ->getDaemonConfigByName ($ name );
62
+
63
+ // Safely check if "haproxy_password" exists before accessing it
64
+ $ haproxyPassword = $ daemonConfigParams ['deploy_config ' ]['haproxy_password ' ] ?? null ;
65
+
66
+ // Restore the original password if "dummySecret123" is provided
67
+ if ($ haproxyPassword === 'dummySecret123 ' ) {
68
+ $ daemonConfigParams ['deploy_config ' ]['haproxy_password ' ] = $ daemonConfig ->getDeployConfig ()['haproxy_password ' ] ?? "" ;
69
+ }
70
+
71
+ // Create and update DaemonConfig instance
62
72
$ updatedDaemonConfig = new DaemonConfig ($ daemonConfigParams );
63
73
$ updatedDaemonConfig ->setId ($ daemonConfig ->getId ());
64
74
$ updatedDaemonConfig = $ this ->daemonConfigService ->updateDaemonConfig ($ updatedDaemonConfig );
75
+
76
+ // Check if update was successful before proceeding
77
+ if ($ updatedDaemonConfig === null ) {
78
+ return new JSONResponse ([
79
+ 'success ' => false ,
80
+ 'daemonConfig ' => null ,
81
+ ]);
82
+ }
83
+
84
+ // Mask the password with "dummySecret123" if it is set
85
+ $ updatedDeployConfig = $ updatedDaemonConfig ->getDeployConfig ();
86
+ if (!empty ($ updatedDeployConfig ['haproxy_password ' ] ?? null )) {
87
+ $ updatedDeployConfig ['haproxy_password ' ] = 'dummySecret123 ' ;
88
+ $ updatedDaemonConfig ->setDeployConfig ($ updatedDeployConfig );
89
+ }
90
+
65
91
return new JSONResponse ([
66
- 'success ' => $ updatedDaemonConfig !== null ,
92
+ 'success ' => true ,
67
93
'daemonConfig ' => $ updatedDaemonConfig ,
68
94
]);
69
95
}
@@ -98,6 +124,23 @@ public function verifyDaemonConnection(string $name): Response {
98
124
}
99
125
100
126
public function checkDaemonConnection (array $ daemonParams ): Response {
127
+ // Safely check if "haproxy_password" exists before accessing it
128
+ // note: UI passes here 'deploy_config' instead of 'deployConfig'
129
+ $ haproxyPassword = $ daemonParams ['deploy_config ' ]['haproxy_password ' ] ?? null ;
130
+
131
+ if ($ haproxyPassword === 'dummySecret123 ' ) {
132
+ // If the secret is "dummySecret123" we check if such record is present in DB
133
+ $ daemonConfig = $ this ->daemonConfigService ->getDaemonConfigByName ($ daemonParams ['name ' ]);
134
+ if ($ daemonConfig !== null ) {
135
+ $ haproxyPasswordDB = $ daemonConfig ->getDeployConfig ()['haproxy_password ' ] ?? "" ;
136
+ if ($ haproxyPasswordDB ) {
137
+ // if there is a record in the DB and there is a password,
138
+ // then we request it from the DB instead of the “masked” one
139
+ $ daemonParams ['deploy_config ' ]['haproxy_password ' ] = $ haproxyPasswordDB ;
140
+ }
141
+ }
142
+ }
143
+
101
144
$ daemonConfig = new DaemonConfig ([
102
145
'name ' => $ daemonParams ['name ' ],
103
146
'display_name ' => $ daemonParams ['display_name ' ],
0 commit comments