@agilecustoms/envctl 0.17.0 → 0.18.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.
@@ -4,11 +4,13 @@ import { KnownException } from '../exceptions.js';
4
4
  export class AwsCredsHelper {
5
5
  creds;
6
6
  async ensureCredentials() {
7
- await this.getCredentials();
7
+ await this.getCredentials(true);
8
8
  }
9
- async getCredentials() {
9
+ async getCredentials(printLogs = false) {
10
10
  if (!this.creds) {
11
- console.log('Fetching AWS credentials...');
11
+ if (printLogs) {
12
+ console.log('Fetching AWS credentials...');
13
+ }
12
14
  this.creds = await this._getCredentials();
13
15
  }
14
16
  return this.creds;
@@ -0,0 +1,20 @@
1
+ import { Command } from 'commander';
2
+ import { envCtl } from '../container.js';
3
+ import { _keys } from './_keys.js';
4
+ import { wrap } from './_utils.js';
5
+ export function apiCreateEphemeral(program) {
6
+ program
7
+ .command('api-create-ephemeral')
8
+ .description('Create bare env w/o resources. Used in CI as first step just to pre-generate token for extension')
9
+ .option('--project <project>', _keys.PROJECT)
10
+ .requiredOption('--env <env>', _keys.ENV)
11
+ .requiredOption('--owner <owner>', _keys.OWNER)
12
+ .requiredOption('--size <size>', _keys.SIZE)
13
+ .requiredOption('--type <type>', _keys.TYPE)
14
+ .action(wrap(handler));
15
+ }
16
+ async function handler(options) {
17
+ const { project, env, owner, size, type } = options;
18
+ const token = await envCtl.createEphemeral(project, env, owner, size, type);
19
+ console.log(token);
20
+ }
@@ -1,3 +1,4 @@
1
+ export { apiCreateEphemeral } from './apiCreateEphemeral.js';
1
2
  export { configure } from './configure.js';
2
3
  export { deleteIt } from './delete.js';
3
4
  export { deploy } from './deploy.js';
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { createRequire } from 'module';
3
3
  import { Command } from 'commander';
4
4
  import updateNotifier from 'update-notifier';
5
- import { configure, deleteIt, deploy, destroy, init, plan, status } from './commands/index.js';
5
+ import { apiCreateEphemeral, configure, deleteIt, deploy, destroy, init, plan, status } from './commands/index.js';
6
6
  const require = createRequire(import.meta.url);
7
7
  const pkg = require('../package.json');
8
8
  updateNotifier({ pkg, updateCheckInterval: 0 }).notify();
@@ -11,6 +11,7 @@ program
11
11
  .name('envctl')
12
12
  .description('CLI to manage environments')
13
13
  .version(pkg.version);
14
+ apiCreateEphemeral(program);
14
15
  configure(program);
15
16
  deleteIt(program);
16
17
  deploy(program);
@@ -1,4 +1,5 @@
1
1
  import { KnownException, TerraformInitRequired } from '../exceptions.js';
2
+ import { EnvType, EnvSize } from '../model/index.js';
2
3
  import { EnvSizeAvgTime, EnvStatus } from '../model/index.js';
3
4
  export class EnvCtl {
4
5
  cliHelper;
@@ -98,6 +99,16 @@ export class EnvCtl {
98
99
  }
99
100
  await this.terraformAdapter.plan(envInput, tfArgs, cwd);
100
101
  }
102
+ async createEphemeral(project, envName, owner, size, type) {
103
+ const key = this.key(project, envName);
104
+ const env = await this.envApi.get(key);
105
+ if (env !== null) {
106
+ throw new KnownException(`Env ${key} already exists`);
107
+ }
108
+ const createEnv = { key, ephemeral: true, owner, size, type };
109
+ const newEnv = await this.envApi.create(createEnv);
110
+ return newEnv.token;
111
+ }
101
112
  async deploy(input, tfArgs, cwd) {
102
113
  const { envName, owner, key, env } = await this.tryGetEnv(input);
103
114
  if (env === null) {
@@ -158,7 +169,7 @@ export class EnvCtl {
158
169
  }
159
170
  await this.promptUnlock(env);
160
171
  if (env.status !== EnvStatus.Active) {
161
- throw new KnownException(`Env ${env.key} status is ${env.status}, can not delete`);
172
+ return;
162
173
  }
163
174
  console.log('Deleting env');
164
175
  const statusMessage = await this.envApi.delete(env);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agilecustoms/envctl",
3
3
  "description": "node.js CLI client for manage environments",
4
- "version": "0.17.0",
4
+ "version": "0.18.0",
5
5
  "author": "Alex Chekulaev",
6
6
  "type": "module",
7
7
  "bin": {
@@ -32,7 +32,8 @@
32
32
  "run-plan": "tsc --sourceMap true && npm run run -- plan --size min --cwd ../tt-core",
33
33
  "run-deploy": "tsc --sourceMap true && npm run run -- deploy --size min --cwd ../tt-core",
34
34
  "run-delete": "tsc --sourceMap true && npm run run -- delete --cwd ../tt-core",
35
- "run-destroy": "tsc --sourceMap true && npm run run -- destroy --cwd ../tt-core"
35
+ "run-destroy": "tsc --sourceMap true && npm run run -- destroy --cwd ../tt-core",
36
+ "run-api-create-ephemeral": "tsc --sourceMap true && npm run run -- api-create-ephemeral --env laxa1986 --owner laxa1986 --size min --type dev"
36
37
  },
37
38
  "dependencies": {
38
39
  "@aws-sdk/client-sts": "^3.716.0",