File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace EE \Migration ;
4+
5+ use EE ;
6+ use EE \Migration \Base ;
7+
8+ class GenerateDefaultSelfSignedCert extends Base {
9+
10+ private $ certs_dir ;
11+ private $ key_path ;
12+ private $ crt_path ;
13+
14+ public function __construct () {
15+ parent ::__construct ();
16+ $ this ->certs_dir = EE_ROOT_DIR . '/services/nginx-proxy/certs ' ;
17+ $ this ->key_path = $ this ->certs_dir . '/default.key ' ;
18+ $ this ->crt_path = $ this ->certs_dir . '/default.crt ' ;
19+ }
20+
21+ /**
22+ * Generate default self-signed cert if not present.
23+ * @throws EE\ExitException
24+ */
25+ public function up () {
26+ if ( $ this ->fs ->exists ( $ this ->key_path ) && $ this ->fs ->exists ( $ this ->crt_path ) ) {
27+ EE ::debug ( 'Default self-signed cert already exists. Skipping generation. ' );
28+
29+ return ;
30+ }
31+ EE ::debug ( 'Generating default self-signed cert (default.key, default.crt) with CN=default using internal logic ' );
32+ $ self_signed = new \EE \Site \Type \Site_Self_signed ();
33+ $ self_signed ->create_certificate ( 'default ' );
34+ EE ::debug ( 'Self-signed cert generation complete using internal logic. ' );
35+ }
36+
37+ /**
38+ * Remove default self-signed cert (for rollback).
39+ * @throws EE\ExitException
40+ */
41+ public function down () {
42+ if ( $ this ->fs ->exists ( $ this ->key_path ) ) {
43+ $ this ->fs ->remove ( $ this ->key_path );
44+ }
45+ if ( $ this ->fs ->exists ( $ this ->crt_path ) ) {
46+ $ this ->fs ->remove ( $ this ->crt_path );
47+ }
48+ EE ::debug ( 'Removed default self-signed cert (default.key, default.crt) ' );
49+ }
50+ }
You can’t perform that action at this time.
0 commit comments