1 | <?php |
||
15 | class PublishSSL extends Command |
||
16 | { |
||
17 | use ChecksEnv, DiesIfEnvVariableIsnotInstalled; |
||
18 | |||
19 | /** |
||
20 | * Server name |
||
21 | * |
||
22 | * @var String |
||
23 | */ |
||
24 | protected $server; |
||
25 | |||
26 | /** |
||
27 | * Domain |
||
28 | * |
||
29 | * @var String |
||
30 | */ |
||
31 | protected $domain; |
||
32 | |||
33 | /** |
||
34 | * Forge site id. |
||
35 | * |
||
36 | * @var String |
||
37 | */ |
||
38 | protected $site; |
||
39 | |||
40 | /** |
||
41 | * The name and signature of the console command. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $signature = 'publish:ssl {--server=} {--domain=} {--site=}'; |
||
46 | |||
47 | /** |
||
48 | * The console command description. |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $description = 'Obtain lets encrypt certificate'; |
||
53 | |||
54 | /** |
||
55 | * API endpoint URL |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $url; |
||
60 | |||
61 | /** |
||
62 | * Guzzle http client. |
||
63 | * |
||
64 | * @var Client |
||
65 | */ |
||
66 | protected $http; |
||
67 | |||
68 | /** |
||
69 | * Create a new command instance. |
||
70 | * |
||
71 | */ |
||
72 | public function __construct(Client $http) |
||
73 | { |
||
74 | parent::__construct(); |
||
75 | $this->http = $http; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Execute the console command. |
||
80 | * |
||
81 | */ |
||
82 | public function handle() |
||
83 | { |
||
84 | $this->abortCommandExecution(); |
||
85 | $this->info("Obtaining Lets Encrypt Certificate on production..."); |
||
86 | |||
87 | $this->url = $this->obtainAPIURLEndpoint(); |
||
88 | |||
89 | |||
90 | $this->http->post($this->url, |
||
91 | [ |
||
92 | 'form_params' => [ |
||
93 | 'domains' => [$this->domain] |
||
94 | ], |
||
95 | 'headers' => [ |
||
96 | 'X-Requested-With' => 'XMLHttpRequest', |
||
97 | 'Authorization' => 'Bearer ' . fp_env('ACACHA_FORGE_ACCESS_TOKEN') |
||
98 | ] |
||
99 | ] |
||
100 | ); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * Obtain API URL endpoint. |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | protected function obtainAPIURLEndpoint() |
||
114 | |||
115 | /** |
||
116 | * Abort command execution? |
||
117 | */ |
||
118 | protected function abortCommandExecution() |
||
125 | } |
||
126 |