@@ -141,20 +141,11 @@ const internalCertificate = {
141
141
} ) ;
142
142
} )
143
143
. then ( ( in_use_result ) => {
144
- // 3. Generate the LE config
145
- return internalNginx . generateLetsEncryptRequestConfig ( certificate )
146
- . then ( internalNginx . reload )
147
- . then ( ( ) => {
144
+ // Is CloudFlare, no config needed, so skip 3 and 5.
145
+ if ( data . meta . cloudflare_use ) {
146
+ return internalNginx . reload ( ) . then ( ( ) => {
148
147
// 4. Request cert
149
- if ( data . meta . cloudflare_use ) {
150
- return internalCertificate . requestLetsEncryptCloudFlareDnsSsl ( certificate , data . meta . cloudflare_token ) ;
151
- } else {
152
- return internalCertificate . requestLetsEncryptSsl ( certificate ) ;
153
- }
154
- } )
155
- . then ( ( ) => {
156
- // 5. Remove LE config
157
- return internalNginx . deleteLetsEncryptRequestConfig ( certificate ) ;
148
+ return internalCertificate . requestLetsEncryptCloudFlareDnsSsl ( certificate , data . meta . cloudflare_token ) ;
158
149
} )
159
150
. then ( internalNginx . reload )
160
151
. then ( ( ) => {
@@ -166,15 +157,44 @@ const internalCertificate = {
166
157
} )
167
158
. catch ( ( err ) => {
168
159
// In the event of failure, revert things and throw err back
169
- return internalNginx . deleteLetsEncryptRequestConfig ( certificate )
170
- . then ( ( ) => {
171
- return internalCertificate . enableInUseHosts ( in_use_result ) ;
172
- } )
160
+ return internalCertificate . enableInUseHosts ( in_use_result )
173
161
. then ( internalNginx . reload )
174
162
. then ( ( ) => {
175
163
throw err ;
176
164
} ) ;
177
165
} ) ;
166
+ } else {
167
+ // 3. Generate the LE config
168
+ return internalNginx . generateLetsEncryptRequestConfig ( certificate )
169
+ . then ( internalNginx . reload )
170
+ . then ( ( ) => {
171
+ // 4. Request cert
172
+ return internalCertificate . requestLetsEncryptSsl ( certificate ) ;
173
+ } )
174
+ . then ( ( ) => {
175
+ // 5. Remove LE config
176
+ return internalNginx . deleteLetsEncryptRequestConfig ( certificate ) ;
177
+ } )
178
+ . then ( internalNginx . reload )
179
+ . then ( ( ) => {
180
+ // 6. Re-instate previously disabled hosts
181
+ return internalCertificate . enableInUseHosts ( in_use_result ) ;
182
+ } )
183
+ . then ( ( ) => {
184
+ return certificate ;
185
+ } )
186
+ . catch ( ( err ) => {
187
+ // In the event of failure, revert things and throw err back
188
+ return internalNginx . deleteLetsEncryptRequestConfig ( certificate )
189
+ . then ( ( ) => {
190
+ return internalCertificate . enableInUseHosts ( in_use_result ) ;
191
+ } )
192
+ . then ( internalNginx . reload )
193
+ . then ( ( ) => {
194
+ throw err ;
195
+ } ) ;
196
+ } ) ;
197
+ }
178
198
} )
179
199
. then ( ( ) => {
180
200
// At this point, the letsencrypt cert should exist on disk.
@@ -763,26 +783,25 @@ const internalCertificate = {
763
783
let tokenLoc = '~/cloudflare-token' ;
764
784
let storeKey = 'echo "dns_cloudflare_api_token = ' + apiToken + '" > ' + tokenLoc ;
765
785
766
- let cmd = certbot_command + ' certonly --non-interactive ' +
786
+ let cmd =
787
+ storeKey + " && " +
788
+ certbot_command + ' certonly --non-interactive ' +
767
789
'--cert-name "npm-' + certificate . id + '" ' +
768
790
'--agree-tos ' +
769
791
'--email "' + certificate . meta . letsencrypt_email + '" ' +
770
792
'--domains "' + certificate . domain_names . join ( ',' ) + '" ' +
771
- '--dns-cloudflare --dns-cloudflare-credentials ' + tokenLoc + ' ' +
772
- ( le_staging ? '--staging' : '' ) ;
793
+ '--dns-cloudflare --dns-cloudflare-credentials ' + tokenLoc +
794
+ ( le_staging ? ' --staging' : '' )
795
+ + ' && rm ' + tokenLoc ;
773
796
774
797
if ( debug_mode ) {
775
798
logger . info ( 'Command:' , cmd ) ;
776
799
}
777
800
778
- return utils . exec ( storeKey ) . then ( ( result ) => {
779
- utils . exec ( cmd ) . then ( ( result ) => {
780
- utils . exec ( 'rm ' + tokenLoc ) . then ( result => {
781
- logger . success ( result ) ;
782
- return result ;
783
- } ) ;
801
+ return utils . exec ( cmd ) . then ( ( result ) => {
802
+ logger . info ( result ) ;
803
+ return result ;
784
804
} ) ;
785
- } ) ;
786
805
} ,
787
806
788
807
0 commit comments