@agilecustoms/envctl 1.17.0 → 1.18.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.
@@ -110,7 +110,7 @@ export class Cli {
110
110
  });
111
111
  });
112
112
  }
113
- getKind() {
113
+ getDir() {
114
114
  return path.basename(process.cwd());
115
115
  }
116
116
  async writeInTmpFile(stream, fileName) {
@@ -1,6 +1,5 @@
1
1
  export const _keys = {
2
2
  FORCE: 'Force deletion without confirmation',
3
3
  KEY: 'Environment name/identifier - taken from remote stake key, must be unique for a given customer',
4
- KIND: 'Environment kind',
5
4
  PROFILE: 'Profile to use'
6
5
  };
@@ -5,7 +5,7 @@ import { wrap } from './_utils.js';
5
5
  export function plan(program, configService, envService) {
6
6
  program
7
7
  .command('plan')
8
- .description('High level wrapper for terraform plan. Compliments deploy command: if you plan to deploy env with envctl deploy,'
8
+ .description('High level wrapper for terraform plan. Compliments apply command: if you plan to deploy env with envctl apply,'
9
9
  + ' then it is recommended to do plan with envctl plan to guarantee consistent behavior')
10
10
  .option('--profile <profile>', _keys.PROFILE)
11
11
  .allowUnknownOption(true)
@@ -2,18 +2,18 @@ import * as fs from 'node:fs';
2
2
  import * as os from 'node:os';
3
3
  import path from 'path';
4
4
  import { KnownException } from '../exceptions.js';
5
- const CONFIG_DIR = path.join(os.homedir(), '.envctl');
6
5
  export const DEFAULT_HOST = 'cli.maintenance.agilecustoms.com';
7
- var EnvKey;
6
+ export var EnvKey;
8
7
  (function (EnvKey) {
9
8
  EnvKey["API_KEY"] = "ENVCTL_API_KEY";
9
+ EnvKey["HOME"] = "ENVCTL_HOME";
10
10
  EnvKey["PROFILE"] = "ENVCTL_PROFILE";
11
11
  })(EnvKey || (EnvKey = {}));
12
12
  function env(key) {
13
13
  return process.env[key];
14
14
  }
15
- function isCI() {
16
- return !!process.env['CI'];
15
+ function configDir() {
16
+ return env(EnvKey.HOME) || path.join(os.homedir(), '.envctl');
17
17
  }
18
18
  export class ConfigService {
19
19
  config;
@@ -24,7 +24,7 @@ export class ConfigService {
24
24
  throw new Error('load config second time?');
25
25
  const customProfile = profile || env(EnvKey.PROFILE);
26
26
  profile = customProfile || 'default';
27
- const configPath = path.join(CONFIG_DIR, `${profile}.json`);
27
+ const configPath = path.join(configDir(), `${profile}.json`);
28
28
  if (fs.existsSync(configPath)) {
29
29
  const data = fs.readFileSync(configPath, 'utf-8');
30
30
  this.config = JSON.parse(data);
@@ -37,15 +37,15 @@ export class ConfigService {
37
37
  saveConfig(profile, config) {
38
38
  const mergedConfig = { ...this.loadConfig(profile, false), ...config };
39
39
  const data = JSON.stringify(mergedConfig, null, 2);
40
- fs.mkdirSync(CONFIG_DIR, { recursive: true });
41
- const configPath = path.join(CONFIG_DIR, `${profile}.json`);
40
+ fs.mkdirSync(configDir(), { recursive: true });
41
+ const configPath = path.join(configDir(), `${profile}.json`);
42
42
  fs.writeFileSync(configPath, data);
43
43
  }
44
- init(profile) {
44
+ init(profile = undefined) {
45
45
  this.loadConfig(profile);
46
46
  const apiKey = this.getApiKey();
47
47
  if (!apiKey) {
48
- if (isCI()) {
48
+ if (!!process.env['CI']) {
49
49
  throw new KnownException('API key is missing, set env variable ' + EnvKey.API_KEY);
50
50
  }
51
51
  throw new KnownException('API key is missing, call \'envctl configure\' or set env variable ' + EnvKey.API_KEY);
@@ -27,10 +27,10 @@ export class EnvService extends BaseService {
27
27
  if (env.status !== EnvStatus.Deleting && env.status !== EnvStatus.DeleteError) {
28
28
  logger.info(`Expires at ${toLocalTime(env.ttl)}`);
29
29
  }
30
- if (env.kind) {
31
- const kind = this.cli.getKind();
32
- if (env.kind !== kind) {
33
- logger.warn(`Env ${key} kind (dir-name): ${env.kind} - looks like this env was deployed from a different directory`);
30
+ if (env.dir) {
31
+ const dir = this.cli.getDir();
32
+ if (env.dir !== dir) {
33
+ logger.warn(`Env ${key} was deployed from ${env.dir}`);
34
34
  }
35
35
  }
36
36
  }
@@ -45,13 +45,13 @@ export class EnvService extends BaseService {
45
45
  }
46
46
  return env;
47
47
  }
48
- checkKind(env) {
48
+ checkDir(env) {
49
49
  if (env.ephemeral)
50
50
  return;
51
- if (env.kind) {
52
- const kind = this.cli.getKind();
53
- if (kind !== env.kind) {
54
- throw new KnownException(`Env ${env.key} kind (dir-name): ${env.kind} - make sure you run this command from the same directory`);
51
+ if (env.dir) {
52
+ const dir = this.cli.getDir();
53
+ if (dir !== env.dir) {
54
+ throw new KnownException(`Env ${env.key} was deployed from ${env.dir} - make sure you run this command from the same directory`);
55
55
  }
56
56
  }
57
57
  }
@@ -59,7 +59,7 @@ export class EnvService extends BaseService {
59
59
  const key = this.terraformAdapter.getTerraformBackend().getKey();
60
60
  const env = await this.tryGetEnv(key);
61
61
  if (env) {
62
- this.checkKind(env);
62
+ this.checkDir(env);
63
63
  this.handleDeleteStatuses(env);
64
64
  }
65
65
  const newEnv = env === null;
@@ -116,9 +116,8 @@ export class EnvService extends BaseService {
116
116
  const key = this.terraformAdapter.getTerraformBackend().getKey();
117
117
  let env = await this.tryGetEnv(key);
118
118
  if (env === null) {
119
- const kind = this.cli.getKind();
120
- logger.info(`Inferred kind from directory name: ${kind}`);
121
- const createEnv = { key, kind };
119
+ const dir = this.cli.getDir();
120
+ const createEnv = { key, dir };
122
121
  await this.lockTerraform(createEnv, true);
123
122
  tfArgs = await this.ensurePlan({ key, ephemeral: false }, tfArgs);
124
123
  logger.info('Creating env metadata');
@@ -126,7 +125,7 @@ export class EnvService extends BaseService {
126
125
  await this.runApply(env, tfArgs);
127
126
  return;
128
127
  }
129
- this.checkKind(env);
128
+ this.checkDir(env);
130
129
  this.handleDeleteStatuses(env);
131
130
  const status = env.status;
132
131
  if (status === EnvStatus.Deploying || status === EnvStatus.Updating) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agilecustoms/envctl",
3
- "version": "1.17.0",
3
+ "version": "1.18.1",
4
4
  "description": "node.js CLI client for manage environments",
5
5
  "keywords": [
6
6
  "terraform wrapper",