@aikidosec/ci-api-client 1.0.9 → 1.0.11

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/.env CHANGED
@@ -1 +1,3 @@
1
1
  AIKIDO_API=https://app.aikido.dev
2
+ AIKIDO_US_API=https://app.us.aikido.dev
3
+ AIKIDO_ME_API=https://app.me.aikido.dev
package/lib/aikidoApi.js CHANGED
@@ -1,7 +1,16 @@
1
1
  import axios from 'axios';
2
2
  import { getApiKey } from './configuration.js';
3
3
  import { outputDebug } from './output.js';
4
- const getApiUrl = () => process.env.AIKIDO_API || 'https://app.aikido.dev';
4
+ const getApiUrl = () => {
5
+ const apiKey = getApiKey();
6
+ if (apiKey.startsWith('AIK_CI_US_')) {
7
+ return process.env.AIKIDO_US_API || 'https://app.us.aikido.dev';
8
+ }
9
+ if (apiKey.startsWith('AIK_CI_ME_')) {
10
+ return process.env.AIKIDO_ME_API || 'https://app.me.aikido.dev';
11
+ }
12
+ return process.env.AIKIDO_API || 'https://app.aikido.dev';
13
+ };
5
14
  const getApiHeaders = () => ({
6
15
  'Content-Type': 'application/json',
7
16
  'X-AIK-API-SECRET': getApiKey(),
@@ -1,7 +1,7 @@
1
1
  import { Argument } from 'commander';
2
2
  import { setApiKey } from '../configuration.js';
3
3
  import { outputError, outputLog } from '../output.js';
4
- const API_KEY_REGEX = /^AIK_CI_[a-zA-Z0-9]{64}$/g;
4
+ const API_KEY_REGEX = /^(?:AIK_CI_|AIK_CI_US_|AIK_CI_ME_)[A-Za-z0-9]{64}$/;
5
5
  function cli(apiKey) {
6
6
  const isValidApiKey = API_KEY_REGEX.test(apiKey) || apiKey.trim().length === 128;
7
7
  if (apiKey && !isValidApiKey) {
@@ -118,7 +118,7 @@ export const scan = async ({ repoId, baseCommitId, headCommitId, branchName, opt
118
118
  pollStatus();
119
119
  };
120
120
  const parseCliOptions = (userCliOptions) => {
121
- const apiOptions = { version: '1.0.9' };
121
+ const apiOptions = { version: '1.0.11' };
122
122
  const cliOptions = { pollInterval: 5 };
123
123
  if (userCliOptions.pullRequestTitle) {
124
124
  apiOptions.pull_request_metadata = {
@@ -120,7 +120,7 @@ export const scan = async ({ repoId, commitId, options, pollInterval = 10, onSta
120
120
  pollStatus();
121
121
  };
122
122
  const parseCliOptions = (userCliOptions) => {
123
- const apiOptions = { version: '1.0.9' };
123
+ const apiOptions = { version: '1.0.11' };
124
124
  const cliOptions = { pollInterval: 10 };
125
125
  if (userCliOptions.pullRequestTitle) {
126
126
  apiOptions.pull_request_metadata = {
package/lib/index.js CHANGED
@@ -11,7 +11,7 @@ export const program = new Command();
11
11
  program
12
12
  .name('Aikido API Client')
13
13
  .description('CLI api client to easily integrate the Aikido public CI API into custom deploy scripts')
14
- .version('1.0.9');
14
+ .version('1.0.11');
15
15
  apiKey.cliSetup(program);
16
16
  scan.cliSetup(program);
17
17
  scanRelease.cliSetup(program);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aikidosec/ci-api-client",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "CLI api client to easily integrate the Aikido public CI API into custom deploy scripts",
5
5
  "license": "MIT",
6
6
  "author": "Bert Devriese <bert@builtinbruges.com>",
package/src/aikidoApi.ts CHANGED
@@ -2,7 +2,19 @@ import axios from 'axios';
2
2
  import { getApiKey } from './configuration.js';
3
3
  import { outputDebug } from './output.js';
4
4
 
5
- const getApiUrl = () => process.env.AIKIDO_API || 'https://app.aikido.dev';
5
+ const getApiUrl = () => {
6
+ const apiKey = getApiKey();
7
+
8
+ if (apiKey.startsWith('AIK_CI_US_')) {
9
+ return process.env.AIKIDO_US_API || 'https://app.us.aikido.dev';
10
+ }
11
+
12
+ if (apiKey.startsWith('AIK_CI_ME_')) {
13
+ return process.env.AIKIDO_ME_API || 'https://app.me.aikido.dev';
14
+ }
15
+
16
+ return process.env.AIKIDO_API || 'https://app.aikido.dev';
17
+ };
6
18
  const getApiHeaders = () => ({
7
19
  'Content-Type': 'application/json',
8
20
  'X-AIK-API-SECRET': getApiKey(),
@@ -2,7 +2,7 @@ import { Argument, Command } from 'commander';
2
2
  import { setApiKey } from '../configuration.js';
3
3
  import { outputError, outputLog } from '../output.js';
4
4
 
5
- const API_KEY_REGEX = /^AIK_CI_[a-zA-Z0-9]{64}$/g;
5
+ const API_KEY_REGEX = /^(?:AIK_CI_|AIK_CI_US_|AIK_CI_ME_)[A-Za-z0-9]{64}$/;
6
6
 
7
7
  function cli(apiKey: string): void {
8
8
  const isValidApiKey =
@@ -245,7 +245,7 @@ export const scan = async ({
245
245
  const parseCliOptions = (userCliOptions: TScanUserCliOptions) => {
246
246
  // Version provided to the API corresponds with the version in package.json
247
247
  // of the cli client
248
- const apiOptions: TScanApiOptions = { version: '1.0.9' };
248
+ const apiOptions: TScanApiOptions = { version: '1.0.11' };
249
249
  const cliOptions: TScanCliOptions = { pollInterval: 5 };
250
250
 
251
251
  if (userCliOptions.pullRequestTitle) {
@@ -70,7 +70,6 @@ async function cli(
70
70
  options: TScanUserCliOptions,
71
71
  command: string
72
72
  ) {
73
-
74
73
  const apiKey = getApiKey();
75
74
 
76
75
  if (!apiKey) {
@@ -145,12 +144,10 @@ async function cli(
145
144
  loader?.fail();
146
145
 
147
146
  if (error.response?.status && error.response?.status === 404) {
148
- if(error.response?.data?.reason_phrase) {
147
+ if (error.response?.data?.reason_phrase) {
149
148
  outputError(error.response?.data?.reason_phrase);
150
149
  } else {
151
- outputError(
152
- 'Please verify your repository id or commit SHA'
153
- );
150
+ outputError('Please verify your repository id or commit SHA');
154
151
  }
155
152
  } else {
156
153
  outputHttpError(error);
@@ -194,7 +191,6 @@ export const scan = async ({
194
191
  // Initialize a scan and call onStartComplete, onStartFail
195
192
  // handlers where needed
196
193
  try {
197
-
198
194
  result = await startScan({
199
195
  is_release_gating: true,
200
196
  head_commit_id: commitId,
@@ -243,7 +239,7 @@ export const scan = async ({
243
239
  const parseCliOptions = (userCliOptions: TScanUserCliOptions) => {
244
240
  // Version provided to the API corresponds with the version in package.json
245
241
  // of the cli client
246
- const apiOptions: TScanApiOptions = { version: '1.0.9' };
242
+ const apiOptions: TScanApiOptions = { version: '1.0.11' };
247
243
  const cliOptions: TScanCliOptions = { pollInterval: 10 };
248
244
 
249
245
  if (userCliOptions.pullRequestTitle) {
@@ -312,12 +308,9 @@ export const cliSetup = (program: Command) =>
312
308
  ).argRequired()
313
309
  )
314
310
  .addArgument(
315
- new Argument(
316
- '<commit_id>',
317
- 'The commit you want to scan'
318
- )
319
- .argRequired()
320
- .argParser(validateCommitId)
311
+ new Argument('<commit_id>', 'The commit you want to scan')
312
+ .argRequired()
313
+ .argParser(validateCommitId)
321
314
  )
322
315
  .addOption(
323
316
  new Option(
@@ -356,7 +349,7 @@ export const cliSetup = (program: Command) =>
356
349
  '--base-branch <branchname>',
357
350
  'Base branch for the release gated scan.'
358
351
  )
359
- )
352
+ )
360
353
  .description('Run a release scan of an Aikido repo.')
361
354
  .action(cli);
362
355
 
package/src/index.ts CHANGED
@@ -20,7 +20,7 @@ program
20
20
  .description(
21
21
  'CLI api client to easily integrate the Aikido public CI API into custom deploy scripts'
22
22
  )
23
- .version('1.0.9');
23
+ .version('1.0.11');
24
24
 
25
25
  // Load in all app commands and set them up in the `program` instance
26
26
  apiKey.cliSetup(program);
@@ -57,7 +57,7 @@ program
57
57
  program
58
58
  .option('--plain-output', 'Disables the formatting on output')
59
59
  .on('option:plain-output', function () {
60
- chalk.level = 0 // Disables all formatting for chalk
60
+ chalk.level = 0; // Disables all formatting for chalk
61
61
  });
62
62
 
63
63
  // Add global option "--apikey"