@aikidosec/ci-api-client
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -0,0 +0,0 @@ # Contributing to aikido-api-client |
@@ -13,3 +13,3 @@ #!/usr/bin/env node | ||
.description('CLI api client to easily integrate the Aikido public CI API into custom deploy scripts') | ||
.version('1.0.3'); | ||
.version('1.0.4'); | ||
apiKey.cliSetup(program); | ||
@@ -16,0 +16,0 @@ scan.cliSetup(program); |
@@ -20,26 +20,20 @@ import ora from 'ora'; | ||
export const outputHttpError = (axiosError) => { | ||
if (axiosError.code === 'ECONNREFUSED') { | ||
outputError(`Could not connect to Aikido API (${axiosError.message}). Please verify your network settings`); | ||
outputDebug(axiosError); | ||
if (axiosError.isAxiosError) { | ||
if (axiosError.response) { | ||
const statusStr = `${axiosError.response.status} ${axiosError.response.statusText}`; | ||
switch (axiosError.response.status) { | ||
case 401: | ||
return outputError(`${statusStr}: The provided api key is most likely no longer valid and has been rotated or revoked. Visit https://app.aikido.dev/settings/integrations/continuous-integration to generate a new key.`); | ||
case 403: | ||
return outputError(`${statusStr}: Could not authenticate with the Aikido API. Please verify your Aikdio API key.`); | ||
case 500: | ||
return outputError(`${statusStr}: Something went wrong contacting the Aikido API. Please try again later.`); | ||
default: | ||
return outputError(`${statusStr}: ${axiosError.response.data ?? ''} Please contact us if this problem persists.`); | ||
} | ||
} | ||
return outputError(`${axiosError.name}: ${axiosError.message}`); | ||
} | ||
else if (axiosError.response?.status && | ||
axiosError.response?.status === 401) { | ||
outputError('Request failed. The provided api key is most likely no longer valid and has been rotated or revoked. Visit https://app.aikido.dev/settings/integrations/continuous-integration to generate a new key.'); | ||
} | ||
else if (axiosError.response?.status && | ||
axiosError.response?.status === 403) { | ||
outputError('Could not authenticate with the Aikido API. Please verify your Aikdio API key.'); | ||
} | ||
else if (axiosError.response?.status && | ||
axiosError.response?.status === 500) { | ||
outputError('Something went wrong contacting the Aikido API.'); | ||
} | ||
const statusStr = axiosError.response?.status | ||
? ` (${axiosError.response?.status})` | ||
: ''; | ||
if (axiosError.response) { | ||
outputDebug(axiosError.response?.status); | ||
outputDebug(axiosError.response?.headers); | ||
outputDebug(axiosError.response?.data); | ||
} | ||
outputError(`Something unexpected went wrong${statusStr}... Please contact us if this problem persists.`); | ||
return outputError('Unexpected error occurred. Please contact us if this problem persists.'); | ||
}; | ||
@@ -46,0 +40,0 @@ export const startSpinner = (message) => { |
{ | ||
"name": "@aikidosec/ci-api-client", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "CLI api client to easily integrate the Aikido public CI API into custom deploy scripts", | ||
"license": "MIT", | ||
"author": "Bert Devriese <bert@builtinbruges.com>", | ||
"private": false, | ||
"type": "module", | ||
@@ -21,3 +22,6 @@ "main": "lib/index.js", | ||
"local-rm": "yarn global remove aikido-api-client", | ||
"format": "prettier --write 'src/**/*.ts'" | ||
"format": "prettier --write 'src/**/*.ts'", | ||
"//": { | ||
"refresh": "rm -rf ./node_modules ./yarn.lock && yarn" | ||
} | ||
}, | ||
@@ -47,4 +51,3 @@ "dependencies": { | ||
"cli" | ||
], | ||
"packageManager": "yarn@4.1.1" | ||
} | ||
] | ||
} |
@@ -0,0 +0,0 @@ # Aikido Security CI API client |
@@ -0,0 +0,0 @@ # Releasing |
@@ -0,0 +0,0 @@ import axios from 'axios'; |
@@ -8,3 +8,4 @@ import { Argument, Command } from 'commander'; | ||
function cli(apiKey: string): void { | ||
const isValidApiKey = API_KEY_REGEX.test(apiKey) || apiKey.trim().length === 128; | ||
const isValidApiKey = | ||
API_KEY_REGEX.test(apiKey) || apiKey.trim().length === 128; | ||
if (apiKey && !isValidApiKey) { | ||
@@ -11,0 +12,0 @@ outputError('That does not seem right, please verify your api key'); |
@@ -0,0 +0,0 @@ import chalk from 'chalk'; |
@@ -0,0 +0,0 @@ import { Argument, Command, InvalidArgumentError, Option } from 'commander'; |
@@ -0,0 +0,0 @@ import Configstore from 'configstore'; |
@@ -22,3 +22,3 @@ #!/usr/bin/env node | ||
) | ||
.version('1.0.3'); | ||
.version('1.0.4'); | ||
@@ -25,0 +25,0 @@ // Load in all app commands and set them up in the `program` instance |
@@ -33,39 +33,34 @@ import ora, { Ora } from 'ora'; | ||
export const outputHttpError = (axiosError: AxiosError): void => { | ||
if (axiosError.code === 'ECONNREFUSED') { | ||
outputError( | ||
`Could not connect to Aikido API (${axiosError.message}). Please verify your network settings` | ||
); | ||
} else if ( | ||
axiosError.response?.status && | ||
axiosError.response?.status === 401 | ||
) { | ||
outputError( | ||
'Request failed. The provided api key is most likely no longer valid and has been rotated or revoked. Visit https://app.aikido.dev/settings/integrations/continuous-integration to generate a new key.' | ||
); | ||
} else if ( | ||
axiosError.response?.status && | ||
axiosError.response?.status === 403 | ||
) { | ||
outputError( | ||
'Could not authenticate with the Aikido API. Please verify your Aikdio API key.' | ||
); | ||
} else if ( | ||
axiosError.response?.status && | ||
axiosError.response?.status === 500 | ||
) { | ||
outputError('Something went wrong contacting the Aikido API.'); | ||
} | ||
outputDebug(axiosError); | ||
const statusStr = axiosError.response?.status | ||
? ` (${axiosError.response?.status})` | ||
: ''; | ||
if (axiosError.isAxiosError) { | ||
if (axiosError.response) { | ||
const statusStr = `${axiosError.response.status} ${axiosError.response.statusText}`; | ||
switch (axiosError.response.status) { | ||
case 401: | ||
return outputError( | ||
`${statusStr}: The provided api key is most likely no longer valid and has been rotated or revoked. Visit https://app.aikido.dev/settings/integrations/continuous-integration to generate a new key.` | ||
); | ||
case 403: | ||
return outputError( | ||
`${statusStr}: Could not authenticate with the Aikido API. Please verify your Aikdio API key.` | ||
); | ||
case 500: | ||
return outputError( | ||
`${statusStr}: Something went wrong contacting the Aikido API. Please try again later.` | ||
); | ||
default: | ||
return outputError( | ||
`${statusStr}: ${ | ||
axiosError.response.data ?? '' | ||
} Please contact us if this problem persists.` | ||
); | ||
} | ||
} | ||
if (axiosError.response) { | ||
outputDebug(axiosError.response?.status); | ||
outputDebug(axiosError.response?.headers); | ||
outputDebug(axiosError.response?.data); | ||
return outputError(`${axiosError.name}: ${axiosError.message}`); | ||
} | ||
outputError( | ||
`Something unexpected went wrong${statusStr}... Please contact us if this problem persists.` | ||
return outputError( | ||
'Unexpected error occurred. Please contact us if this problem persists.' | ||
); | ||
@@ -72,0 +67,0 @@ }; |
@@ -0,0 +0,0 @@ { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
59114
30
1416