@agilecustoms/envctl 1.14.0 → 1.15.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.
|
@@ -2,7 +2,7 @@ import { BusinessException, KnownException, NotFoundException } from '../excepti
|
|
|
2
2
|
import { logger } from '../logger.js';
|
|
3
3
|
import { EnvStatus } from '../model/index.js';
|
|
4
4
|
import { toLocalTime } from '../util.js';
|
|
5
|
-
import { HttpClient
|
|
5
|
+
import { HttpClient } from './HttpClient.js';
|
|
6
6
|
export class EnvApiClient {
|
|
7
7
|
httpClient;
|
|
8
8
|
constructor(httpClient) {
|
|
@@ -33,7 +33,7 @@ export class EnvApiClient {
|
|
|
33
33
|
}
|
|
34
34
|
throw error;
|
|
35
35
|
}
|
|
36
|
-
return
|
|
36
|
+
return this.httpClient.getUrl(`/public/env/${env.key}/extend?token=${result.token}`);
|
|
37
37
|
}
|
|
38
38
|
async create(env) {
|
|
39
39
|
let result;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { BusinessException, HttpException, NotFoundException } from '../exceptions.js';
|
|
1
|
+
import { BusinessException, HttpException, KnownException, NotFoundException } from '../exceptions.js';
|
|
2
2
|
import { logger } from '../logger.js';
|
|
3
|
+
import { DEFAULT_HOST } from '../service/ConfigService.js';
|
|
3
4
|
import { ConfigService } from '../service/index.js';
|
|
4
|
-
const HOST = 'cli.maintenance.agilecustoms.com';
|
|
5
|
-
export function toUrl(path) {
|
|
6
|
-
return `https://${HOST}/env-api${path}`;
|
|
7
|
-
}
|
|
8
5
|
export class HttpClient {
|
|
9
6
|
version;
|
|
10
7
|
commandId;
|
|
@@ -26,8 +23,12 @@ export class HttpClient {
|
|
|
26
23
|
}
|
|
27
24
|
return await this.fetch(path, options);
|
|
28
25
|
}
|
|
26
|
+
getUrl(path) {
|
|
27
|
+
const host = this.configService.getHost();
|
|
28
|
+
return `https://${host}/env-api${path}`;
|
|
29
|
+
}
|
|
29
30
|
async fetch(path, options = {}) {
|
|
30
|
-
const url =
|
|
31
|
+
const url = this.getUrl(path);
|
|
31
32
|
const headers = new Headers(options.headers);
|
|
32
33
|
headers.set('x-command-id', this.commandId);
|
|
33
34
|
headers.set('x-client-version', this.version);
|
|
@@ -44,6 +45,15 @@ export class HttpClient {
|
|
|
44
45
|
response = await fetch(url, options);
|
|
45
46
|
}
|
|
46
47
|
catch (error) {
|
|
48
|
+
if (error.cause && error.cause.errno == -3008) {
|
|
49
|
+
const host = error.cause.hostname;
|
|
50
|
+
if (host == DEFAULT_HOST) {
|
|
51
|
+
throw new KnownException('Can not reach backend. Network issue?');
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
throw new KnownException('Unresolvable hostname ' + error.cause.hostname);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
47
57
|
throw new Error('Error (network?) making the request:', { cause: error });
|
|
48
58
|
}
|
|
49
59
|
const contentType = response.headers?.get('Content-Type') || '';
|
package/dist/index.js
CHANGED
|
@@ -15,7 +15,8 @@ const program = new Command();
|
|
|
15
15
|
program
|
|
16
16
|
.name('envctl')
|
|
17
17
|
.description('CLI to manage environments')
|
|
18
|
-
.version(pkg.version)
|
|
18
|
+
.version(pkg.version, '', 'Output the version number')
|
|
19
|
+
.helpOption('-h, --help', 'Display help for command')
|
|
19
20
|
.option('--verbose', 'Verbose output (w/ debug logs)');
|
|
20
21
|
configure(program, configService);
|
|
21
22
|
createEphemeral(program, configService, envService);
|
|
@@ -3,6 +3,7 @@ import * as os from 'node:os';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { KnownException } from '../exceptions.js';
|
|
5
5
|
const CONFIG_DIR = path.join(os.homedir(), '.envctl');
|
|
6
|
+
export const DEFAULT_HOST = 'cli.maintenance.agilecustoms.com';
|
|
6
7
|
var EnvKey;
|
|
7
8
|
(function (EnvKey) {
|
|
8
9
|
EnvKey["API_KEY"] = "ENVCTL_API_KEY";
|
|
@@ -18,21 +19,23 @@ export class ConfigService {
|
|
|
18
19
|
config;
|
|
19
20
|
constructor() {
|
|
20
21
|
}
|
|
21
|
-
loadConfig(profile) {
|
|
22
|
+
loadConfig(profile, failOnMissingCustomProfile = true) {
|
|
22
23
|
if (this.config)
|
|
23
24
|
throw new Error('load config second time?');
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
25
|
+
const customProfile = profile || env(EnvKey.PROFILE);
|
|
26
|
+
profile = customProfile || 'default';
|
|
27
27
|
const configPath = path.join(CONFIG_DIR, `${profile}.json`);
|
|
28
28
|
if (fs.existsSync(configPath)) {
|
|
29
29
|
const data = fs.readFileSync(configPath, 'utf-8');
|
|
30
30
|
this.config = JSON.parse(data);
|
|
31
31
|
}
|
|
32
|
+
else if (customProfile && failOnMissingCustomProfile) {
|
|
33
|
+
throw new KnownException(`Profile ${customProfile} doesn't exist`);
|
|
34
|
+
}
|
|
32
35
|
return this.config;
|
|
33
36
|
}
|
|
34
37
|
saveConfig(profile, config) {
|
|
35
|
-
const mergedConfig = { ...this.loadConfig(profile), ...config };
|
|
38
|
+
const mergedConfig = { ...this.loadConfig(profile, false), ...config };
|
|
36
39
|
const data = JSON.stringify(mergedConfig, null, 2);
|
|
37
40
|
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
38
41
|
const configPath = path.join(CONFIG_DIR, `${profile}.json`);
|
|
@@ -61,4 +64,7 @@ export class ConfigService {
|
|
|
61
64
|
getVarEphemeral() {
|
|
62
65
|
return this.config?.varEphemeral;
|
|
63
66
|
}
|
|
67
|
+
getHost() {
|
|
68
|
+
return this.config?.host || DEFAULT_HOST;
|
|
69
|
+
}
|
|
64
70
|
}
|