@bprotsyk/aso-core 2.0.42 → 2.0.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,7 @@ export declare class ServerUtil {
15
15
  sftpConfig: ISFTP;
16
16
  constructor(sftpConfig: ISFTP);
17
17
  connectSSH(): Promise<void>;
18
+ ensureConnected(): Promise<void>;
18
19
  exec(command: string, options?: any): Promise<string>;
19
20
  generateSSHKey(): Promise<string>;
20
21
  createDirectories(): Promise<void>;
@@ -33,9 +33,15 @@ class ServerUtil {
33
33
  password: this.sftpConfig.password,
34
34
  });
35
35
  }
36
+ async ensureConnected() {
37
+ if (!this.ssh.isConnected()) {
38
+ await this.connectSSH(); // Підключення, якщо ще не підключено
39
+ }
40
+ }
36
41
  // Выконує команду або по SSH або локально, повертаючи текст незалежно від результату (помилка чи успіх)
37
42
  async exec(command, options) {
38
- if (this.ssh) {
43
+ await this.ensureConnected();
44
+ if (this.ssh.isConnected()) {
39
45
  return (await this.ssh.execCommand(command, options)).stdout;
40
46
  }
41
47
  else {
@@ -161,16 +167,16 @@ class ServerUtil {
161
167
  }
162
168
  // install certbot
163
169
  async setupCertbot() {
164
- await this.exec(`apt-get install -y certbot python3-certbot-nginx;`);
170
+ await this.ssh.execCommand(`apt-get install -y certbot python3-certbot-nginx;`);
165
171
  return true;
166
172
  }
167
- // creating a SSL certificate
168
173
  async setupSSL(email, host) {
169
- let certbotResponse = await this.exec(`certbot --non-interactive --agree-tos --nginx -m "${email}" -d "${host}"`);
170
- if (certbotResponse.includes(`Some challenges have failed.`)) {
174
+ // Прямий виклик this.ssh.execCommand
175
+ let certbotResponse = await this.ssh.execCommand(`certbot --non-interactive --agree-tos --nginx -m "${email}" -d "${host}"`);
176
+ if (certbotResponse.stdout.includes(`Some challenges have failed.`)) {
171
177
  throw new Error("Certbot encountered an error");
172
178
  }
173
- await this.exec(`echo "0 12 * * * /usr/bin/certbot renew --quiet" | crontab -`);
179
+ await this.ssh.execCommand(`echo "0 12 * * * /usr/bin/certbot renew --quiet" | crontab -`);
174
180
  }
175
181
  // Git
176
182
  async refresh() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bprotsyk/aso-core",
3
- "version": "2.0.42",
3
+ "version": "2.0.44",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "scripts": {
@@ -46,9 +46,17 @@ export class ServerUtil {
46
46
  });
47
47
  }
48
48
 
49
+ async ensureConnected(): Promise<void> {
50
+ if (!this.ssh.isConnected()) {
51
+ await this.connectSSH(); // Підключення, якщо ще не підключено
52
+ }
53
+ }
54
+
55
+
49
56
  // Выконує команду або по SSH або локально, повертаючи текст незалежно від результату (помилка чи успіх)
50
57
  async exec(command: string, options?: any): Promise<string> {
51
- if (this.ssh) {
58
+ await this.ensureConnected();
59
+ if (this.ssh.isConnected()) {
52
60
  return (await this.ssh.execCommand(command, options)).stdout;
53
61
  } else {
54
62
  return await new Promise<string>((resolve) => {
@@ -194,22 +202,26 @@ export class ServerUtil {
194
202
 
195
203
  // install certbot
196
204
  async setupCertbot(): Promise<boolean> {
197
- await this.exec(`apt-get install -y certbot python3-certbot-nginx;`);
205
+ await this.ssh.execCommand(`apt-get install -y certbot python3-certbot-nginx;`);
198
206
 
199
207
  return true;
200
208
  }
201
- // creating a SSL certificate
209
+
202
210
  async setupSSL(email: string, host: string): Promise<void> {
203
- let certbotResponse = await this.exec(
211
+ // Прямий виклик this.ssh.execCommand
212
+ let certbotResponse = await this.ssh.execCommand(
204
213
  `certbot --non-interactive --agree-tos --nginx -m "${email}" -d "${host}"`
205
214
  );
206
- if (certbotResponse.includes(`Some challenges have failed.`)) {
215
+
216
+ if (certbotResponse.stdout.includes(`Some challenges have failed.`)) {
207
217
  throw new Error("Certbot encountered an error");
208
218
  }
209
- await this.exec(
219
+
220
+ await this.ssh.execCommand(
210
221
  `echo "0 12 * * * /usr/bin/certbot renew --quiet" | crontab -`
211
222
  );
212
223
  }
224
+
213
225
 
214
226
  // Git
215
227
  async refresh(): Promise<boolean> {
@@ -349,6 +361,8 @@ export class ServerUtil {
349
361
  async disconnectSSH(): Promise<void> {
350
362
  this.ssh.dispose();
351
363
  }
364
+
365
+
352
366
  }
353
367
 
354
368