@agilecustoms/envctl 0.32.9 → 0.33.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.
- package/dist/container.js +1 -1
- package/dist/service/ConfigService.js +5 -6
- package/dist/service/EnvCtl.js +7 -15
- package/package.json +1 -1
package/dist/container.js
CHANGED
|
@@ -13,5 +13,5 @@ const httpClient = new HttpClient(awsCredsHelper);
|
|
|
13
13
|
const envApiClient = new EnvApiClient(httpClient);
|
|
14
14
|
const processRunner = new ProcessRunner();
|
|
15
15
|
const terraformAdapter = new TerraformAdapter(processRunner, cliHelper, backends);
|
|
16
|
-
const envCtl = new EnvCtl(cliHelper, envApiClient, terraformAdapter
|
|
16
|
+
const envCtl = new EnvCtl(cliHelper, envApiClient, terraformAdapter);
|
|
17
17
|
export { awsCredsHelper, configService, envCtl };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
2
|
import * as os from 'node:os';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import { KnownException } from '../exceptions.js';
|
|
5
4
|
const CONFIG_PATH = path.join(os.homedir(), '.envctl', 'config.json');
|
|
6
5
|
export class ConfigService {
|
|
7
6
|
config;
|
|
@@ -23,11 +22,11 @@ export class ConfigService {
|
|
|
23
22
|
}
|
|
24
23
|
return this.config;
|
|
25
24
|
}
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
if (!
|
|
29
|
-
|
|
25
|
+
getApiKey() {
|
|
26
|
+
const apiKey = this.loadConfig()?.apiKey;
|
|
27
|
+
if (!apiKey) {
|
|
28
|
+
return 'api-key';
|
|
30
29
|
}
|
|
31
|
-
return
|
|
30
|
+
return apiKey;
|
|
32
31
|
}
|
|
33
32
|
}
|
package/dist/service/EnvCtl.js
CHANGED
|
@@ -4,12 +4,10 @@ export class EnvCtl {
|
|
|
4
4
|
cliHelper;
|
|
5
5
|
envApi;
|
|
6
6
|
terraformAdapter;
|
|
7
|
-
|
|
8
|
-
constructor(cliHelper, envApi, terraformAdapter, configService) {
|
|
7
|
+
constructor(cliHelper, envApi, terraformAdapter) {
|
|
9
8
|
this.cliHelper = cliHelper;
|
|
10
9
|
this.envApi = envApi;
|
|
11
10
|
this.terraformAdapter = terraformAdapter;
|
|
12
|
-
this.configService = configService;
|
|
13
11
|
}
|
|
14
12
|
getKey(key, cwd) {
|
|
15
13
|
if (!key) {
|
|
@@ -59,10 +57,6 @@ export class EnvCtl {
|
|
|
59
57
|
checkInput(env, cwd) {
|
|
60
58
|
if (env.ephemeral)
|
|
61
59
|
return;
|
|
62
|
-
const userName = this.configService.getUserName();
|
|
63
|
-
if (env.owner !== userName) {
|
|
64
|
-
throw new KnownException(`Can not change env owner ${env.owner} -> ${userName}`);
|
|
65
|
-
}
|
|
66
60
|
if (env.kind) {
|
|
67
61
|
const kind = this.cliHelper.getKind(cwd);
|
|
68
62
|
if (kind !== env.kind) {
|
|
@@ -81,7 +75,6 @@ export class EnvCtl {
|
|
|
81
75
|
}
|
|
82
76
|
async plan(tfArgs, cwd) {
|
|
83
77
|
const key = this.terraformAdapter.getTerraformBackend(cwd).getKey();
|
|
84
|
-
const userName = this.configService.getUserName();
|
|
85
78
|
const env = await this.tryGetEnv(key);
|
|
86
79
|
let vars = undefined;
|
|
87
80
|
if (env) {
|
|
@@ -93,7 +86,7 @@ export class EnvCtl {
|
|
|
93
86
|
}
|
|
94
87
|
vars = env.vars;
|
|
95
88
|
}
|
|
96
|
-
const envTerraform = { key, ephemeral: false,
|
|
89
|
+
const envTerraform = { key, ephemeral: false, args: tfArgs, vars };
|
|
97
90
|
await this.terraformAdapter.plan(envTerraform, cwd);
|
|
98
91
|
}
|
|
99
92
|
async createEphemeral(key) {
|
|
@@ -116,8 +109,7 @@ export class EnvCtl {
|
|
|
116
109
|
if (env === null) {
|
|
117
110
|
const kind = this.cliHelper.getKind(cwd);
|
|
118
111
|
console.log(`Inferred kind from directory name: ${kind}`);
|
|
119
|
-
const
|
|
120
|
-
const createEnv = { key, owner: userName, kind };
|
|
112
|
+
const createEnv = { key, kind };
|
|
121
113
|
await this.lockTerraform(createEnv, cwd);
|
|
122
114
|
console.log('Creating env metadata');
|
|
123
115
|
env = await this.envApi.create(createEnv);
|
|
@@ -137,7 +129,7 @@ export class EnvCtl {
|
|
|
137
129
|
return;
|
|
138
130
|
}
|
|
139
131
|
}
|
|
140
|
-
if (env.status === EnvStatus.Active) {
|
|
132
|
+
else if (env.status === EnvStatus.Active) {
|
|
141
133
|
console.log('Env status is ACTIVE\nWill lock for update and run terraform apply (to update resources)');
|
|
142
134
|
await this.envApi.lockForUpdate(env);
|
|
143
135
|
}
|
|
@@ -147,7 +139,7 @@ export class EnvCtl {
|
|
|
147
139
|
async runDeploy(env, key, tfArgs, cwd) {
|
|
148
140
|
console.log('Deploying resources');
|
|
149
141
|
const { ephemeral, vars } = env;
|
|
150
|
-
const envTerraform = { key, ephemeral,
|
|
142
|
+
const envTerraform = { key, ephemeral, args: tfArgs, vars };
|
|
151
143
|
const onDemandVars = {};
|
|
152
144
|
try {
|
|
153
145
|
await this.terraformAdapter.apply(envTerraform, onDemandVars, cwd);
|
|
@@ -214,8 +206,8 @@ export class EnvCtl {
|
|
|
214
206
|
console.log('Lock env to run destroy');
|
|
215
207
|
await this.envApi.lockForUpdate(env);
|
|
216
208
|
}
|
|
217
|
-
const { ephemeral,
|
|
218
|
-
const envTerraform = { key, ephemeral,
|
|
209
|
+
const { ephemeral, vars } = env;
|
|
210
|
+
const envTerraform = { key, ephemeral, args: tfArgs, vars };
|
|
219
211
|
console.log('Destroying env resources');
|
|
220
212
|
await this.terraformAdapter.destroy(envTerraform, force, cwd);
|
|
221
213
|
console.log('Unlock env');
|