@adinsure-ops/ops-cli 5.2.1 → 5.3.0

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.
Files changed (40) hide show
  1. package/README.md +123 -9
  2. package/lib/commands/config/get.d.ts +11 -0
  3. package/lib/commands/config/get.js +40 -0
  4. package/lib/commands/config/list.d.ts +8 -0
  5. package/lib/commands/config/list.js +26 -0
  6. package/lib/commands/config/set.d.ts +12 -0
  7. package/lib/commands/config/set.js +60 -0
  8. package/lib/commands/config/unset.d.ts +11 -0
  9. package/lib/commands/config/unset.js +42 -0
  10. package/lib/commands/download/client.d.ts +11 -3
  11. package/lib/commands/download/client.js +52 -8
  12. package/lib/commands/download/identity-server.d.ts +11 -3
  13. package/lib/commands/download/identity-server.js +53 -8
  14. package/lib/commands/download/jmeter.d.ts +1 -1
  15. package/lib/commands/download/jmeter.js +13 -3
  16. package/lib/commands/download/keycloak-scim.d.ts +1 -1
  17. package/lib/commands/download/keycloak-scim.js +13 -3
  18. package/lib/commands/download/platform.d.ts +11 -3
  19. package/lib/commands/download/platform.js +53 -8
  20. package/lib/commands/download/scheduler.d.ts +11 -3
  21. package/lib/commands/download/scheduler.js +52 -8
  22. package/lib/commands/download/server.d.ts +11 -3
  23. package/lib/commands/download/server.js +53 -9
  24. package/lib/commands/download/signalr.d.ts +11 -3
  25. package/lib/commands/download/signalr.js +52 -8
  26. package/lib/commands/download/studio.d.ts +11 -3
  27. package/lib/commands/download/studio.js +52 -8
  28. package/lib/commands/login.d.ts +9 -0
  29. package/lib/commands/login.js +60 -1
  30. package/lib/commands/login.ru.d.ts +12 -0
  31. package/lib/commands/login.ru.js +42 -0
  32. package/lib/commands/npm/check-publish.js +1 -1
  33. package/lib/lib/config.d.ts +10 -0
  34. package/lib/lib/config.js +33 -0
  35. package/lib/lib/yarnrc.d.ts +22 -0
  36. package/lib/lib/yarnrc.js +40 -0
  37. package/lib/security/context.d.ts +22 -0
  38. package/lib/security/context.js +113 -0
  39. package/oclif.manifest.json +415 -152
  40. package/package.json +1 -1
@@ -6,10 +6,12 @@ import fs from 'fs-extra';
6
6
  import os from 'os';
7
7
  import path from 'path';
8
8
  import CommandBase from '../../command.base.js';
9
+ import OpsConfig from '../../lib/config.js';
9
10
  class DownloadIdentityServer extends CommandBase {
10
11
  constructor() {
11
12
  super(...arguments);
12
- this.url = 'https://ops.adinsure.com/api/storage/binaries/';
13
+ this.url_azure = 'https://ops.adinsure.com/api/storage/binaries/';
14
+ this.url_gitlabru = 'https://gitlabru.adacta-fintech.ru/api/v4/projects/2/packages/generic';
13
15
  }
14
16
  /**
15
17
  * Get unique Identity Server zip by specified version
@@ -17,9 +19,9 @@ class DownloadIdentityServer extends CommandBase {
17
19
  * @returns {Promise<AxiosResponse<any, any>>}
18
20
  */
19
21
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
- downloadFile(version) {
22
+ downloadFileFromAzure(version) {
21
23
  return __awaiter(this, void 0, void 0, function* () {
22
- return axios.get(`${this.url}/AdInsure-identityServer-${version}.zip`, {
24
+ return axios.get(`${this.url_azure}/AdInsure-identityServer-${version}.zip`, {
23
25
  headers: {
24
26
  Authorization: 'Bearer ' + (yield this.security.getToken()),
25
27
  'Content-Type': 'application/octet-stream',
@@ -28,6 +30,24 @@ class DownloadIdentityServer extends CommandBase {
28
30
  });
29
31
  });
30
32
  }
33
+ /**
34
+ * Get unique Identity Server zip by specified version
35
+ * @param {string} version The version of Identity Server
36
+ * @returns {Promise<AxiosResponse<any, any>>}
37
+ */
38
+ //eslint-disable-next-line @typescript-eslint/no-explicit-any
39
+ downloadFileFromGitLabRu(version) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const packageName = 'AdInsure-identityServer';
42
+ const fileName = `${packageName}-${version}.zip`;
43
+ return axios.get(`${this.url_gitlabru}/${packageName}/${version}/${fileName}`, {
44
+ headers: {
45
+ 'PRIVATE-TOKEN': this.security.getTokenRu(),
46
+ },
47
+ responseType: 'arraybuffer',
48
+ });
49
+ });
50
+ }
31
51
  run() {
32
52
  const _super = Object.create(null, {
33
53
  run: { get: () => super.run }
@@ -35,12 +55,33 @@ class DownloadIdentityServer extends CommandBase {
35
55
  return __awaiter(this, void 0, void 0, function* () {
36
56
  _super.run.call(this);
37
57
  const { flags } = yield this.parse(DownloadIdentityServer);
38
- const basePath = flags.output.charAt(0) === '~' ? os.homedir() + flags.output.split('~')[1] : flags.output;
58
+ let outputDir = flags.output;
59
+ // If the user didn't change the output (default is './'), try to get the default from config.
60
+ if (!outputDir) {
61
+ // If the user didn't provide the output flag, try to get the default from config.
62
+ const config = new OpsConfig(this.security.getConfigPath());
63
+ const defaultFolder = config.get('download_folder');
64
+ outputDir = defaultFolder || './'; // no flag -> DEFAULT output is "./"
65
+ }
66
+ // Expand tilde if present
67
+ const basePath = outputDir.charAt(0) === '~'
68
+ ? os.homedir() + outputDir.split('~')[1]
69
+ : outputDir;
39
70
  const filename = `AdInsure-identityServer-${flags.version}.zip`;
40
71
  const filePath = path.resolve(basePath, filename);
41
72
  ux.action.start(`Downloading AdInsure Identity Server version ${flags.version} to ${filePath}`, undefined, { stdout: true });
42
73
  try {
43
- const file = yield this.downloadFile(flags.version);
74
+ var file;
75
+ if (!flags.source) {
76
+ const config = new OpsConfig(this.security.getConfigPath());
77
+ flags.source = config.get('endpoint') || 'azure'; // no flag -> DEFAULT source is azure
78
+ }
79
+ if (flags.source === 'azure') {
80
+ file = yield this.downloadFileFromAzure(flags.version);
81
+ }
82
+ else {
83
+ file = yield this.downloadFileFromGitLabRu(flags.version);
84
+ }
44
85
  const writeStream = fs.createWriteStream(filePath);
45
86
  writeStream.write(file.data, 'binary');
46
87
  writeStream.on('finish', () => {
@@ -52,10 +93,10 @@ class DownloadIdentityServer extends CommandBase {
52
93
  catch (error) {
53
94
  switch (error.statusCode) {
54
95
  case 404: {
55
- this.error('Does not exists.', { exit: 1 });
96
+ this.error('Does not exist.', { exit: 1 });
56
97
  }
57
98
  case 400: {
58
- this.error('Try refreshing your login credentials with "ops login".', { exit: 1 });
99
+ this.error('Try refreshing your login credentials with "ops login" or "ops login:ru".', { exit: 1 });
59
100
  }
60
101
  default: {
61
102
  this.error(error.message);
@@ -71,6 +112,11 @@ DownloadIdentityServer.examples = [
71
112
  `$ ops download:identity-server -v 3.0.3 -o ~/Downloads`,
72
113
  ];
73
114
  DownloadIdentityServer.flags = {
115
+ source: Flags.string({
116
+ char: 's',
117
+ description: '[default: azure] artifact source, configurable with config:set endpoint <option>',
118
+ options: ['azure', 'gitlabru'],
119
+ }),
74
120
  version: Flags.string({
75
121
  char: 'v',
76
122
  description: 'version we want to download',
@@ -79,7 +125,6 @@ DownloadIdentityServer.flags = {
79
125
  output: Flags.string({
80
126
  char: 'o',
81
127
  description: 'output directory',
82
- default: './',
83
128
  }),
84
129
  };
85
130
  export default DownloadIdentityServer;
@@ -5,7 +5,7 @@ export default class DownloadJmeter extends CommandBase<typeof DownloadJmeter> {
5
5
  static usage: string;
6
6
  static examples: string[];
7
7
  static flags: {
8
- output: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
8
+ output: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
9
9
  };
10
10
  private readonly url;
11
11
  downloadFile(): Promise<AxiosResponse<any, any>>;
@@ -6,6 +6,7 @@ import fs from 'fs-extra';
6
6
  import os from 'os';
7
7
  import path from 'path';
8
8
  import CommandBase from '../../command.base.js';
9
+ import OpsConfig from '../../lib/config.js';
9
10
  class DownloadJmeter extends CommandBase {
10
11
  constructor() {
11
12
  super(...arguments);
@@ -30,7 +31,17 @@ class DownloadJmeter extends CommandBase {
30
31
  return __awaiter(this, void 0, void 0, function* () {
31
32
  _super.run.call(this);
32
33
  const { flags } = yield this.parse(DownloadJmeter);
33
- const basePath = flags.output.charAt(0) === '~' ? os.homedir() + flags.output.split('~')[1] : flags.output;
34
+ let outputDir = flags.output;
35
+ if (!outputDir) {
36
+ // If the user didn't provide the output flag, try to get the default from config.
37
+ const config = new OpsConfig(this.security.getConfigPath());
38
+ const defaultFolder = config.get('download_folder');
39
+ outputDir = defaultFolder || './'; // no flag -> DEFAULT output is "./"
40
+ }
41
+ // Expand tilde if present
42
+ const basePath = outputDir.charAt(0) === '~'
43
+ ? os.homedir() + outputDir.split('~')[1]
44
+ : outputDir;
34
45
  const filename = `jmeter-artifacts.zip`;
35
46
  const filePath = path.resolve(basePath, filename);
36
47
  ux.action.start(`Downloading jmeter examples to ${filePath}`, undefined, { stdout: true });
@@ -47,7 +58,7 @@ class DownloadJmeter extends CommandBase {
47
58
  catch (error) {
48
59
  switch (error.statusCode) {
49
60
  case 404: {
50
- this.error('Does not exists.', { exit: 1 });
61
+ this.error('Does not exist.', { exit: 1 });
51
62
  }
52
63
  case 400: {
53
64
  this.error('Try refreshing your login credentials with "ops login".', { exit: 1 });
@@ -69,7 +80,6 @@ DownloadJmeter.flags = {
69
80
  output: Flags.string({
70
81
  char: 'o',
71
82
  description: 'output directory',
72
- default: './',
73
83
  }),
74
84
  };
75
85
  export default DownloadJmeter;
@@ -6,7 +6,7 @@ export default class DownloadKeycloak extends CommandBase<typeof DownloadKeycloa
6
6
  static examples: string[];
7
7
  static flags: {
8
8
  version: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
9
- output: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
9
+ output: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
10
  };
11
11
  private readonly url;
12
12
  downloadFile(version: string): Promise<AxiosResponse<any, any>>;
@@ -6,6 +6,7 @@ import fs from 'fs-extra';
6
6
  import os from 'os';
7
7
  import path from 'path';
8
8
  import CommandBase from '../../command.base.js';
9
+ import OpsConfig from '../../lib/config.js';
9
10
  class DownloadKeycloak extends CommandBase {
10
11
  constructor() {
11
12
  super(...arguments);
@@ -30,7 +31,17 @@ class DownloadKeycloak extends CommandBase {
30
31
  return __awaiter(this, void 0, void 0, function* () {
31
32
  _super.run.call(this);
32
33
  const { flags } = yield this.parse(DownloadKeycloak);
33
- const basePath = flags.output.charAt(0) === '~' ? os.homedir() + flags.output.split('~')[1] : flags.output;
34
+ let outputDir = flags.output;
35
+ if (!outputDir) {
36
+ // If the user didn't provide the output flag, try to get the default from config.
37
+ const config = new OpsConfig(this.security.getConfigPath());
38
+ const defaultFolder = config.get('download_folder');
39
+ outputDir = defaultFolder || './'; // no flag -> DEFAULT output is "./"
40
+ }
41
+ // Expand tilde if present
42
+ const basePath = outputDir.charAt(0) === '~'
43
+ ? os.homedir() + outputDir.split('~')[1]
44
+ : outputDir;
34
45
  const filename = `Keycloak-scim-${flags.version}.zip`;
35
46
  const filePath = path.resolve(basePath, filename);
36
47
  ux.action.start(`Downloading Keycloack version ${flags.version} to ${filePath}`, undefined, { stdout: true });
@@ -47,7 +58,7 @@ class DownloadKeycloak extends CommandBase {
47
58
  catch (error) {
48
59
  switch (error.statusCode) {
49
60
  case 404: {
50
- this.error('Does not exists.', { exit: 1 });
61
+ this.error('Does not exist.', { exit: 1 });
51
62
  }
52
63
  case 400: {
53
64
  this.error('Try refreshing your login credentials with "ops login".', { exit: 1 });
@@ -74,7 +85,6 @@ DownloadKeycloak.flags = {
74
85
  output: Flags.string({
75
86
  char: 'o',
76
87
  description: 'output directory',
77
- default: './',
78
88
  }),
79
89
  };
80
90
  export default DownloadKeycloak;
@@ -6,15 +6,23 @@ export default class DownloadPlatform extends CommandBase<typeof DownloadPlatfor
6
6
  static usage: string;
7
7
  static examples: string[];
8
8
  static flags: {
9
+ source: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
9
10
  version: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
- output: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
+ output: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
12
  };
12
- private readonly url;
13
+ private readonly url_azure;
14
+ private readonly url_gitlabru;
13
15
  /**
14
16
  * Get unique AdInsure Platform zip by specified version
15
17
  * @param {string} version The version of AdInsure Platform
16
18
  * @returns {Promise<AxiosResponse<any, any>>}
17
19
  */
18
- downloadFile(version: string): Promise<AxiosResponse<any, any>>;
20
+ downloadFileFromAzure(version: string): Promise<AxiosResponse<any, any>>;
21
+ /**
22
+ * Get unique AdInsure Platform zip by specified version
23
+ * @param {string} version The version of AdInsure Platform
24
+ * @returns {Promise<AxiosResponse<any, any>>}
25
+ */
26
+ downloadFileFromGitLabRu(version: string): Promise<AxiosResponse<any>>;
19
27
  run(): Promise<void>;
20
28
  }
@@ -6,10 +6,12 @@ import fs from 'fs-extra';
6
6
  import os from 'os';
7
7
  import path from 'path';
8
8
  import CommandBase from '../../command.base.js';
9
+ import OpsConfig from '../../lib/config.js';
9
10
  class DownloadPlatform extends CommandBase {
10
11
  constructor() {
11
12
  super(...arguments);
12
- this.url = 'https://ops.adinsure.com/api/storage/binaries/';
13
+ this.url_azure = 'https://ops.adinsure.com/api/storage/binaries/';
14
+ this.url_gitlabru = 'https://gitlabru.adacta-fintech.ru/api/v4/projects/2/packages/generic';
13
15
  }
14
16
  /**
15
17
  * Get unique AdInsure Platform zip by specified version
@@ -17,9 +19,9 @@ class DownloadPlatform extends CommandBase {
17
19
  * @returns {Promise<AxiosResponse<any, any>>}
18
20
  */
19
21
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
- downloadFile(version) {
22
+ downloadFileFromAzure(version) {
21
23
  return __awaiter(this, void 0, void 0, function* () {
22
- return axios.get(`${this.url}/AdInsure-${version}.zip`, {
24
+ return axios.get(`${this.url_azure}/AdInsure-${version}.zip`, {
23
25
  headers: {
24
26
  Authorization: 'Bearer ' + (yield this.security.getToken()),
25
27
  'Content-Type': 'application/octet-stream',
@@ -28,6 +30,24 @@ class DownloadPlatform extends CommandBase {
28
30
  });
29
31
  });
30
32
  }
33
+ /**
34
+ * Get unique AdInsure Platform zip by specified version
35
+ * @param {string} version The version of AdInsure Platform
36
+ * @returns {Promise<AxiosResponse<any, any>>}
37
+ */
38
+ //eslint-disable-next-line @typescript-eslint/no-explicit-any
39
+ downloadFileFromGitLabRu(version) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const packageName = 'AdInsure';
42
+ const fileName = `${packageName}-${version}.zip`;
43
+ return axios.get(`${this.url_gitlabru}/${packageName}/${version}/${fileName}`, {
44
+ headers: {
45
+ 'PRIVATE-TOKEN': this.security.getTokenRu(),
46
+ },
47
+ responseType: 'arraybuffer',
48
+ });
49
+ });
50
+ }
31
51
  run() {
32
52
  const _super = Object.create(null, {
33
53
  run: { get: () => super.run }
@@ -35,12 +55,33 @@ class DownloadPlatform extends CommandBase {
35
55
  return __awaiter(this, void 0, void 0, function* () {
36
56
  _super.run.call(this);
37
57
  const { flags } = yield this.parse(DownloadPlatform);
38
- const basePath = flags.output.charAt(0) === '~' ? os.homedir() + flags.output.split('~')[1] : flags.output;
58
+ let outputDir = flags.output;
59
+ // If the user didn't change the output (default is './'), try to get the default from config.
60
+ if (!outputDir) {
61
+ // If the user didn't provide the output flag, try to get the default from config.
62
+ const config = new OpsConfig(this.security.getConfigPath());
63
+ const defaultFolder = config.get('download_folder');
64
+ outputDir = defaultFolder || './'; // no flag -> DEFAULT output is "./"
65
+ }
66
+ // Expand tilde if present
67
+ const basePath = outputDir.charAt(0) === '~'
68
+ ? os.homedir() + outputDir.split('~')[1]
69
+ : outputDir;
39
70
  const filename = `AdInsure-${flags.version}.zip`;
40
71
  const filePath = path.resolve(basePath, filename);
41
72
  ux.action.start(`Downloading AdInsure Platform version ${flags.version} to ${filePath}`, undefined, { stdout: true });
42
73
  try {
43
- const file = yield this.downloadFile(flags.version);
74
+ var file;
75
+ if (!flags.source) {
76
+ const config = new OpsConfig(this.security.getConfigPath());
77
+ flags.source = config.get('endpoint') || 'azure'; // no flag -> DEFAULT source is azure
78
+ }
79
+ if (flags.source === 'azure') {
80
+ file = yield this.downloadFileFromAzure(flags.version);
81
+ }
82
+ else {
83
+ file = yield this.downloadFileFromGitLabRu(flags.version);
84
+ }
44
85
  const writeStream = fs.createWriteStream(filePath);
45
86
  writeStream.write(file.data, 'binary');
46
87
  writeStream.on('finish', () => {
@@ -52,10 +93,10 @@ class DownloadPlatform extends CommandBase {
52
93
  catch (error) {
53
94
  switch (error.statusCode) {
54
95
  case 404: {
55
- this.error('Does not exists.', { exit: 1 });
96
+ this.error('Does not exist.', { exit: 1 });
56
97
  }
57
98
  case 400: {
58
- this.error('Try refreshing your login credentials with "ops login".', { exit: 1 });
99
+ this.error('Try refreshing your login credentials with "ops login" or "ops login:ru".', { exit: 1 });
59
100
  }
60
101
  default: {
61
102
  this.error(error.message);
@@ -72,6 +113,11 @@ DownloadPlatform.examples = [
72
113
  `$ ops download -v 6.0.0 -o ~/Downloads`,
73
114
  ];
74
115
  DownloadPlatform.flags = {
116
+ source: Flags.string({
117
+ char: 's',
118
+ description: '[default: azure] artifact source, configurable with config:set endpoint <option>',
119
+ options: ['azure', 'gitlabru'],
120
+ }),
75
121
  version: Flags.string({
76
122
  char: 'v',
77
123
  description: 'version we want to download',
@@ -80,7 +126,6 @@ DownloadPlatform.flags = {
80
126
  output: Flags.string({
81
127
  char: 'o',
82
128
  description: 'output directory',
83
- default: './',
84
129
  }),
85
130
  };
86
131
  export default DownloadPlatform;
@@ -5,15 +5,23 @@ export default class DownloadScheduler extends CommandBase<typeof DownloadSchedu
5
5
  static usage: string;
6
6
  static examples: string[];
7
7
  static flags: {
8
+ source: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
8
9
  version: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
9
- output: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
+ output: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
11
  };
11
- private readonly url;
12
+ private readonly url_azure;
13
+ private readonly url_gitlabru;
12
14
  /**
13
15
  * Get unique AdInsureScheduler zip by specified version
14
16
  * @param {string} version The version of AdInsureScheduler
15
17
  * @returns {Promise<AxiosResponse<any, any>>}
16
18
  */
17
- downloadFile(version: string): Promise<AxiosResponse<any, any>>;
19
+ downloadFileFromAzure(version: string): Promise<AxiosResponse<any, any>>;
20
+ /**
21
+ * Get unique AdInsureScheduler zip by specified version
22
+ * @param {string} version The version of AdInsureScheduler
23
+ * @returns {Promise<AxiosResponse<any, any>>}
24
+ */
25
+ downloadFileFromGitLabRu(version: string): Promise<AxiosResponse<any>>;
18
26
  run(): Promise<void>;
19
27
  }
@@ -6,10 +6,12 @@ import fs from 'fs-extra';
6
6
  import os from 'os';
7
7
  import path from 'path';
8
8
  import CommandBase from '../../command.base.js';
9
+ import OpsConfig from '../../lib/config.js';
9
10
  class DownloadScheduler extends CommandBase {
10
11
  constructor() {
11
12
  super(...arguments);
12
- this.url = 'https://ops.adinsure.com/api/storage/binaries/';
13
+ this.url_azure = 'https://ops.adinsure.com/api/storage/binaries/';
14
+ this.url_gitlabru = 'https://gitlabru.adacta-fintech.ru/api/v4/projects/2/packages/generic';
13
15
  }
14
16
  /**
15
17
  * Get unique AdInsureScheduler zip by specified version
@@ -17,9 +19,9 @@ class DownloadScheduler extends CommandBase {
17
19
  * @returns {Promise<AxiosResponse<any, any>>}
18
20
  */
19
21
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
- downloadFile(version) {
22
+ downloadFileFromAzure(version) {
21
23
  return __awaiter(this, void 0, void 0, function* () {
22
- return axios.get(`${this.url}/AdInsureScheduler-${version}.zip`, {
24
+ return axios.get(`${this.url_azure}/AdInsureScheduler-${version}.zip`, {
23
25
  headers: {
24
26
  Authorization: 'Bearer ' + (yield this.security.getToken()),
25
27
  'Content-Type': 'application/octet-stream',
@@ -28,6 +30,24 @@ class DownloadScheduler extends CommandBase {
28
30
  });
29
31
  });
30
32
  }
33
+ /**
34
+ * Get unique AdInsureScheduler zip by specified version
35
+ * @param {string} version The version of AdInsureScheduler
36
+ * @returns {Promise<AxiosResponse<any, any>>}
37
+ */
38
+ //eslint-disable-next-line @typescript-eslint/no-explicit-any
39
+ downloadFileFromGitLabRu(version) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const packageName = 'AdInsureScheduler';
42
+ const fileName = `${packageName}-${version}.zip`;
43
+ return axios.get(`${this.url_gitlabru}/${packageName}/${version}/${fileName}`, {
44
+ headers: {
45
+ 'PRIVATE-TOKEN': this.security.getTokenRu(),
46
+ },
47
+ responseType: 'arraybuffer',
48
+ });
49
+ });
50
+ }
31
51
  run() {
32
52
  const _super = Object.create(null, {
33
53
  run: { get: () => super.run }
@@ -35,12 +55,32 @@ class DownloadScheduler extends CommandBase {
35
55
  return __awaiter(this, void 0, void 0, function* () {
36
56
  _super.run.call(this);
37
57
  const { flags } = yield this.parse(DownloadScheduler);
38
- const basePath = flags.output.charAt(0) === '~' ? os.homedir() + flags.output.split('~')[1] : flags.output;
58
+ let outputDir = flags.output;
59
+ if (!outputDir) {
60
+ // If the user didn't provide the output flag, try to get the default from config.
61
+ const config = new OpsConfig(this.security.getConfigPath());
62
+ const defaultFolder = config.get('download_folder');
63
+ outputDir = defaultFolder || './'; // no flag -> DEFAULT output is "./"
64
+ }
65
+ // Expand tilde if present
66
+ const basePath = outputDir.charAt(0) === '~'
67
+ ? os.homedir() + outputDir.split('~')[1]
68
+ : outputDir;
39
69
  const filename = `AdInsureScheduler-${flags.version}.zip`;
40
70
  const filePath = path.resolve(basePath, filename);
41
71
  ux.action.start(`Downloading AdInsure Scheduler version ${flags.version} to ${filePath}`, undefined, { stdout: true });
42
72
  try {
43
- const file = yield this.downloadFile(flags.version);
73
+ var file;
74
+ if (!flags.source) {
75
+ const config = new OpsConfig(this.security.getConfigPath());
76
+ flags.source = config.get('endpoint') || 'azure'; // no flag -> DEFAULT source is azure
77
+ }
78
+ if (flags.source === 'azure') {
79
+ file = yield this.downloadFileFromAzure(flags.version);
80
+ }
81
+ else {
82
+ file = yield this.downloadFileFromGitLabRu(flags.version);
83
+ }
44
84
  const writeStream = fs.createWriteStream(filePath);
45
85
  writeStream.write(file.data, 'binary');
46
86
  writeStream.on('finish', () => {
@@ -52,10 +92,10 @@ class DownloadScheduler extends CommandBase {
52
92
  catch (error) {
53
93
  switch (error.statusCode) {
54
94
  case 404: {
55
- this.error('Does not exists.', { exit: 1 });
95
+ this.error('Does not exist.', { exit: 1 });
56
96
  }
57
97
  case 400: {
58
- this.error('Try refreshing your login credentials with "ops login".', { exit: 1 });
98
+ this.error('Try refreshing your login credentials with "ops login" or "ops login:ru".', { exit: 1 });
59
99
  }
60
100
  default: {
61
101
  this.error(error.message);
@@ -71,6 +111,11 @@ DownloadScheduler.examples = [
71
111
  `$ ops download:scheduler -v 3.2.0 -o ~/Downloads`,
72
112
  ];
73
113
  DownloadScheduler.flags = {
114
+ source: Flags.string({
115
+ char: 's',
116
+ description: '[default: azure] artifact source, configurable with config:set endpoint <option>',
117
+ options: ['azure', 'gitlabru'],
118
+ }),
74
119
  version: Flags.string({
75
120
  char: 'v',
76
121
  description: 'version we want to download',
@@ -79,7 +124,6 @@ DownloadScheduler.flags = {
79
124
  output: Flags.string({
80
125
  char: 'o',
81
126
  description: 'output directory',
82
- default: './',
83
127
  }),
84
128
  };
85
129
  export default DownloadScheduler;
@@ -5,15 +5,23 @@ export default class DownloadServer extends CommandBase<typeof DownloadServer> {
5
5
  static usage: string;
6
6
  static examples: string[];
7
7
  static flags: {
8
+ source: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
8
9
  version: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
9
- output: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
+ output: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
11
  };
11
- private readonly url;
12
+ private readonly url_azure;
13
+ private readonly url_gitlabru;
12
14
  /**
13
15
  * Get unique AdInsure Server zip by specified version
14
16
  * @param {string} version The version of AdInsure Server
15
17
  * @returns {Promise<AxiosResponse<any, any>>}
16
18
  */
17
- downloadFile(version: string): Promise<AxiosResponse<any, any>>;
19
+ downloadFileFromAzure(version: string): Promise<AxiosResponse<any, any>>;
20
+ /**
21
+ * Get unique AdInsure Server zip by specified version
22
+ * @param {string} version The version of AdInsure Server
23
+ * @returns {Promise<AxiosResponse<any, any>>}
24
+ */
25
+ downloadFileFromGitLabRu(version: string): Promise<AxiosResponse<any>>;
18
26
  run(): Promise<void>;
19
27
  }