@agilecustoms/envctl 1.19.2 → 1.20.1

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.
@@ -12,7 +12,7 @@ export function plan(program, configService, envService) {
12
12
  .argument('[args...]')
13
13
  .action(wrap(async (tfArgs, options) => {
14
14
  const { profile } = options;
15
- configService.init(profile);
15
+ configService.init(profile, false);
16
16
  await envService.plan(tfArgs);
17
17
  }));
18
18
  }
package/dist/container.js CHANGED
@@ -6,8 +6,8 @@ import { ConfigService, EnvService, TerraformAdapter } from './service/index.js'
6
6
  import { LocalStateService } from './service/LocalStateService.js';
7
7
  import { LogService } from './service/LogService.js';
8
8
  export function buildContainer(appVersion) {
9
- const cli = new Cli();
10
9
  const configService = new ConfigService();
10
+ const cli = new Cli();
11
11
  const backends = [new S3Backend()];
12
12
  const commandId = randomUUID();
13
13
  const httpClient = new HttpClient(appVersion, commandId, configService);
@@ -15,7 +15,7 @@ export function buildContainer(appVersion) {
15
15
  const localStateService = new LocalStateService();
16
16
  const nonInteractive = !process.stdout.isTTY || process.env.CI === 'true';
17
17
  const terraformAdapter = new TerraformAdapter(Date.now, configService, cli, localStateService, backends, nonInteractive);
18
- const envService = new EnvService(cli, envApiClient, terraformAdapter);
18
+ const envService = new EnvService(configService, cli, envApiClient, terraformAdapter);
19
19
  const logService = new LogService(cli, envApiClient, terraformAdapter);
20
20
  return { configService, envService, logService };
21
21
  }
@@ -41,10 +41,10 @@ export class ConfigService {
41
41
  const configPath = path.join(configDir(), `${profile}.json`);
42
42
  fs.writeFileSync(configPath, data);
43
43
  }
44
- init(profile = undefined) {
44
+ init(profile = undefined, requireApiKey = true) {
45
45
  this.loadConfig(profile);
46
46
  const apiKey = this.getApiKey();
47
- if (!apiKey) {
47
+ if (!apiKey && requireApiKey) {
48
48
  if (!!process.env['CI']) {
49
49
  throw new KnownException('API key is missing, set env variable ' + EnvKey.API_KEY);
50
50
  }
@@ -6,10 +6,12 @@ import { EnvStatus } from '../model/index.js';
6
6
  import { toLocalTime } from '../util.js';
7
7
  import { BaseService } from './BaseService.js';
8
8
  export class EnvService extends BaseService {
9
+ configService;
9
10
  cli;
10
11
  envApi;
11
- constructor(cli, envApi, terraformAdapter) {
12
+ constructor(configService, cli, envApi, terraformAdapter) {
12
13
  super(terraformAdapter);
14
+ this.configService = configService;
13
15
  this.cli = cli;
14
16
  this.envApi = envApi;
15
17
  }
@@ -33,10 +35,13 @@ export class EnvService extends BaseService {
33
35
  }
34
36
  }
35
37
  async tryGetEnv(key) {
38
+ if (this.configService.getApiKey() === undefined) {
39
+ return null;
40
+ }
36
41
  logger.info(`Check if env ${key} already exists`);
37
42
  const env = await this.envApi.get(key);
38
43
  if (env) {
39
- logger.info(`Found ${key} env`);
44
+ logger.info(`Env ${key} status: ${env.status}`);
40
45
  }
41
46
  else {
42
47
  logger.info(`Env ${key} does not exist`);
@@ -68,7 +73,7 @@ export class EnvService extends BaseService {
68
73
  const createEnv = { key };
69
74
  return await this.envApi.createEphemeral(createEnv);
70
75
  }
71
- async lockTerraform(env, newEnv = false) {
76
+ async lockTerraform(env, newEnv) {
72
77
  logger.info('Lock providers');
73
78
  const res = await this.terraformAdapter.lock(newEnv);
74
79
  if (env !== null) {
@@ -106,11 +111,9 @@ export class EnvService extends BaseService {
106
111
  this.handleDeleteStatuses(env);
107
112
  const status = env.status;
108
113
  if (status === EnvStatus.Init || status === EnvStatus.Active) {
109
- logger.info(`Env status is ${status}`);
110
- await this.lockTerraform(env);
111
- if (env.status == EnvStatus.Active) {
112
- logger.info('Will lock for update and run terraform apply (to update resources)');
113
- }
114
+ const newEnv = status === EnvStatus.Init;
115
+ await this.lockTerraform(env, newEnv);
116
+ logger.info('Will lock for update and run terraform apply (to update resources)');
114
117
  await this.envApi.lockForUpdate(env);
115
118
  await this.runApply(env, tfArgs);
116
119
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agilecustoms/envctl",
3
- "version": "1.19.2",
3
+ "version": "1.20.1",
4
4
  "description": "node.js CLI client for manage environments",
5
5
  "keywords": [
6
6
  "terraform wrapper",