@agilecustoms/envctl 0.37.2 → 0.38.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.
@@ -1,11 +1,7 @@
1
- import aws4 from 'aws4';
2
1
  import { BusinessException, HttpException, NotFoundException } from '../exceptions.js';
3
- const HOST = 'env-api.maintenance.agilecustoms.com';
2
+ const HOST = 'cli.maintenance.agilecustoms.com';
4
3
  export class HttpClient {
5
- awsCredsHelper;
6
- constructor(awsCredsHelper) {
7
- this.awsCredsHelper = awsCredsHelper;
8
- }
4
+ constructor() { }
9
5
  async post(path, body, options = {}) {
10
6
  options.method = 'POST';
11
7
  if (body) {
@@ -19,19 +15,7 @@ export class HttpClient {
19
15
  return await this.fetch(path, options);
20
16
  }
21
17
  async fetch(path, options = {}) {
22
- const awsCreds = await this.awsCredsHelper.getCredentials();
23
- const requestOptions = {
24
- method: options.method,
25
- body: options.body,
26
- headers: (options.headers ?? {}),
27
- host: HOST,
28
- service: 'execute-api',
29
- path,
30
- };
31
- const signedOptions = aws4.sign(requestOptions, awsCreds);
32
- const signedHeaders = signedOptions.headers;
33
- const url = `https://${HOST}${path}`;
34
- options.headers = signedHeaders;
18
+ const url = `https://${HOST}/env-api${path}`;
35
19
  let response;
36
20
  try {
37
21
  response = await fetch(url, options);
@@ -135,7 +135,7 @@ export class TerraformAdapter {
135
135
  const keyValue = arg.slice(5);
136
136
  const eqIndex = keyValue.indexOf('=');
137
137
  if (eqIndex === -1) {
138
- console.log('terraform var argument is not in key=value format:', arg);
138
+ console.error('Terraform var argument is not in key=value format:', arg);
139
139
  return;
140
140
  }
141
141
  const key = keyValue.slice(0, eqIndex);
@@ -1,5 +1,5 @@
1
1
  import { Command } from 'commander';
2
- import { awsCredsHelper, envService } from '../container.js';
2
+ import { envService } from '../container.js';
3
3
  import { _keys } from './_keys.js';
4
4
  import { wrap } from './_utils.js';
5
5
  export function deploy(program) {
@@ -12,7 +12,6 @@ export function deploy(program) {
12
12
  .action(wrap(handler));
13
13
  }
14
14
  async function handler(tfArgs, options) {
15
- await awsCredsHelper.ensureCredentials();
16
15
  const { cwd } = options;
17
16
  await envService.deploy(tfArgs, cwd);
18
17
  }
@@ -1,5 +1,5 @@
1
1
  import { Command } from 'commander';
2
- import { awsCredsHelper, envService } from '../container.js';
2
+ import { envService } from '../container.js';
3
3
  import { _keys } from './_keys.js';
4
4
  import { wrap } from './_utils.js';
5
5
  export function plan(program) {
@@ -13,7 +13,6 @@ export function plan(program) {
13
13
  .action(wrap(handler));
14
14
  }
15
15
  async function handler(tfArgs, options) {
16
- await awsCredsHelper.ensureCredentials();
17
16
  const { cwd } = options;
18
17
  await envService.plan(tfArgs, cwd);
19
18
  }
package/dist/container.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { S3Backend } from './backend/S3Backend.js';
2
- import { AwsCredsHelper } from './client/AwsCredsHelper.js';
3
2
  import { CliHelper, EnvApiClient, HttpClient, TerraformAdapter } from './client/index.js';
4
3
  import { ProcessRunner } from './client/ProcessRunner.js';
5
4
  import { ConfigService, EnvService } from './service/index.js';
@@ -7,15 +6,14 @@ import { LocalStateService } from './service/LocalStateService.js';
7
6
  import { LogService } from './service/LogService.js';
8
7
  const cliHelper = new CliHelper();
9
8
  const configService = new ConfigService();
10
- const awsCredsHelper = new AwsCredsHelper();
11
9
  const backends = [
12
10
  new S3Backend()
13
11
  ];
14
- const httpClient = new HttpClient(awsCredsHelper);
12
+ const httpClient = new HttpClient();
15
13
  const envApiClient = new EnvApiClient(httpClient);
16
14
  const processRunner = new ProcessRunner();
17
15
  const terraformAdapter = new TerraformAdapter(processRunner, cliHelper, backends);
18
16
  const localStateService = new LocalStateService();
19
17
  const envService = new EnvService(cliHelper, envApiClient, terraformAdapter, localStateService);
20
18
  const logService = new LogService(envApiClient, terraformAdapter, processRunner);
21
- export { awsCredsHelper, configService, envService, logService };
19
+ export { configService, envService, logService };
@@ -86,7 +86,7 @@ export class EnvService {
86
86
  }
87
87
  async lockTerraform(env, cwd, newEnv = false) {
88
88
  const config = this.localStateService.load(cwd);
89
- console.log('validate terraform.tfstate file');
89
+ console.log('Validate terraform.tfstate file');
90
90
  const stateFileContent = this.terraformAdapter.getTerraformBackend(cwd).validateAndGetStateFileContent();
91
91
  const stateHash = this.localStateService.hash(stateFileContent);
92
92
  if (config.stateHash !== stateHash || newEnv) {
@@ -31,16 +31,16 @@ export class LocalStateService {
31
31
  this.config = config;
32
32
  return;
33
33
  }
34
- console.log('local state file version mismatch, re-initializing');
34
+ console.log('Local state file version mismatch, re-initializing');
35
35
  this.createEmptyConfig(filePath);
36
36
  }
37
37
  load(cwd) {
38
38
  if (this.config)
39
39
  return this.config;
40
- console.log('load local state config');
40
+ console.log('Load local state config');
41
41
  const filePath = this.filePath(cwd);
42
42
  if (!fs.existsSync(filePath)) {
43
- console.warn('local state file does not exist, must have been accidentally deleted, re-initializing');
43
+ console.warn('Local state file does not exist, must have been accidentally deleted, re-initializing');
44
44
  return this.createEmptyConfig(filePath);
45
45
  }
46
46
  const data = fs.readFileSync(filePath, 'utf-8');
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.37.2",
4
+ "version": "0.38.0",
5
5
  "author": "Alex Chekulaev",
6
6
  "type": "module",
7
7
  "engines": {
@@ -55,16 +55,12 @@
55
55
  "run-ephemeral-destroy": "tsc --sourceMap true && npm run run -- destroy --cwd ../tt-gitops --force -var-file=versions.tfvars"
56
56
  },
57
57
  "dependencies": {
58
- "@aws-sdk/client-sts": "^3.716.0",
59
- "@aws-sdk/credential-providers": "^3.716.0",
60
- "aws4": "^1.13.2",
61
58
  "commander": "^14.0.0",
62
59
  "inquirer": "^13.0.0",
63
60
  "update-notifier": "^7.3.1"
64
61
  },
65
62
  "devDependencies": {
66
63
  "@stylistic/eslint-plugin": "^5.0.0",
67
- "@types/aws4": "^1.11.6",
68
64
  "@types/node": "^22.10.2",
69
65
  "@types/update-notifier": "^6.0.8",
70
66
  "@vitest/coverage-v8": "^4.0.0",
@@ -1,36 +0,0 @@
1
- import { fromEnv, fromNodeProviderChain } from '@aws-sdk/credential-providers';
2
- import { CredentialsProviderError } from '@smithy/property-provider';
3
- import { KnownException } from '../exceptions.js';
4
- export class AwsCredsHelper {
5
- creds;
6
- async ensureCredentials() {
7
- await this.getCredentials(true);
8
- }
9
- async getCredentials(printLogs = false) {
10
- if (!this.creds) {
11
- if (printLogs) {
12
- console.log('Fetching AWS credentials...');
13
- }
14
- this.creds = await this._getCredentials();
15
- }
16
- return this.creds;
17
- }
18
- async _getCredentials() {
19
- let identityProvider;
20
- if (process.env.CI) {
21
- identityProvider = fromEnv();
22
- }
23
- else {
24
- identityProvider = fromNodeProviderChain();
25
- }
26
- try {
27
- return await identityProvider();
28
- }
29
- catch (error) {
30
- if (error instanceof CredentialsProviderError) {
31
- throw new KnownException(error.message, { cause: error });
32
- }
33
- throw new Error('Unknown error fetching credentials:', { cause: error });
34
- }
35
- }
36
- }