Skip to content

Commit 8716e51

Browse files
committed
reflect changes in cli also
1 parent 2f1088d commit 8716e51

3 files changed

Lines changed: 50 additions & 29 deletions

File tree

packages/flowtest-cli/bin/index.js

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ const argv = yargs(hideBin(process.argv))
5656
});
5757
},
5858
async (argv) => {
59-
console.log(`Reading file: ${argv.file}`);
6059
if (argv.file.toLowerCase().endsWith(`.flow`)) {
6160
let content = undefined;
6261
try {
@@ -79,9 +78,9 @@ const argv = yargs(hideBin(process.argv))
7978
argv.env ? getEnvVariables(argv.env) : {},
8079
logger,
8180
);
82-
console.log(chalk.yellow('Running Flow \n'));
81+
console.log(chalk.blue('Running Flow \n'));
8382
console.log(
84-
chalk.blue(
83+
chalk.yellow(
8584
'Right now CLI commands must be run from root directory of collection. We will gradually add support to run commands from anywhere inside the collection. \n',
8685
),
8786
);
@@ -109,27 +108,43 @@ const argv = yargs(hideBin(process.argv))
109108
};
110109
const accessId = process.env.FLOWTEST_ACCESS_ID;
111110
const accessKey = process.env.FLOWTEST_ACCESS_KEY;
112-
try {
113-
const response = await axiosClient.post('/upload', data, {
114-
headers: {
115-
'Content-Type': 'application/json',
116-
'x-access-id': accessId,
117-
'x-access-key': accessKey,
118-
},
119-
});
120-
console.log(chalk.bold('Flow Scan: ') + chalk.dim(`${baseUrl}/scan/${response.data.data[0].id}`));
121-
} catch (error) {
122-
if (error?.response) {
123-
if (error.response?.status >= 400 && error.response?.status < 500) {
124-
console.log(chalk.red(` ${JSON.stringify(error.response?.data)}`));
125-
}
111+
if (!accessId || accessId.trim() === '' || !accessKey || accessKey.trim() === '') {
112+
console.log(chalk.red(` ✕ `) + chalk.dim('Unable to upload flow scan'));
113+
console.log(
114+
chalk.yellow(`Failed to detect access key pairs. Make sure to set environment variables properly.`),
115+
);
116+
console.log(chalk.yellow(` export FLOWTEST_ACCESS_ID="<<FLOWTEST_ACCESS_ID>>"`));
117+
console.log(chalk.yellow(` export FLOWTEST_ACCESS_KEY="<<FLOWTEST_ACCESS_KEY>>"`));
118+
} else {
119+
try {
120+
const response = await axiosClient.post('/upload', data, {
121+
headers: {
122+
'Content-Type': 'application/json',
123+
'x-access-id': accessId,
124+
'x-access-key': accessKey,
125+
},
126+
});
127+
console.log(chalk.bold('Flow Scan: ') + chalk.dim(`${baseUrl}/scan/${response.data.data[0].id}`));
128+
} catch (error) {
129+
if (error?.response) {
130+
if (error.response?.status >= 400 && error.response?.status < 500) {
131+
console.log(chalk.red(` ${JSON.stringify(error.response?.data)}`));
132+
}
126133

127-
if (error.response?.status === 500) {
128-
console.log(chalk.red(' Internal Server Error'));
134+
if (error.response?.status === 500) {
135+
console.log(chalk.red(' Internal Server Error'));
136+
}
129137
}
138+
console.log(chalk.red(` ✕ `) + chalk.dim('Unable to upload flow scan'));
130139
}
131-
console.log(chalk.red(` ✕ `) + chalk.dim('Unable to upload flow scan'));
132140
}
141+
} else {
142+
console.log('\n');
143+
console.log(
144+
chalk.yellow(
145+
'Enable flow scans today to get more value our of your APIs. Get your access key pairs at https://flowtest-ai.vercel.app/ \n',
146+
),
147+
);
133148
}
134149

135150
process.exit(1);

packages/flowtest-cli/graph/compute/authnode.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,33 @@ const chalk = require('chalk');
44
const { LogLevel } = require('../GraphLogger');
55

66
class authNode extends Node {
7-
constructor(auth, envVariables, logger) {
7+
constructor(nodeData, envVariables, logger) {
88
super('authNode');
9-
(this.auth = auth), (this.envVariables = envVariables);
9+
(this.nodeData = nodeData), (this.envVariables = envVariables);
1010
this.logger = logger;
1111
}
1212

1313
evaluate() {
1414
//console.log('Evaluating an auth node');
15-
if (this.auth.type === 'basic-auth') {
15+
if (this.nodeData.type === 'basic-auth') {
1616
console.log(chalk.green(` ✓ `) + chalk.dim('.....setting basic authentication'));
1717
this.logger.add(LogLevel.INFO, '', { type: 'authNode', data: { authType: 'Basic Authentication' } });
18-
this.auth.username = computeVariables(this.auth.username, this.envVariables);
19-
this.auth.password = computeVariables(this.auth.password, this.envVariables);
18+
const username = computeVariables(this.nodeData.username, this.envVariables);
19+
const password = computeVariables(this.nodeData.password, this.envVariables);
2020

21-
return this.auth;
21+
return {
22+
type: 'basic-auth',
23+
username,
24+
password,
25+
};
2226
} else if (this.auth.type === 'no-auth') {
2327
console.log(chalk.green(` ✓ `) + chalk.dim('.....using no authentication'));
2428
this.logger.add(LogLevel.INFO, '', { type: 'authNode', data: { authType: 'No Authentication' } });
25-
return this.auth;
29+
return {
30+
type: 'no-auth',
31+
};
2632
} else {
27-
throw Error(`auth type: ${this.auth.type} is not valid`);
33+
throw Error(`auth type: ${this.nodeData.type} is not valid`);
2834
}
2935
}
3036
}

packages/flowtest-cli/graph/compute/requestnode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class requestNode extends Node {
161161
headers: request.headers,
162162
// form data obj gets serialized here so that it can be sent over wire
163163
// otherwise ipc communication errors out
164-
data: JSON.parse(JSON.stringify(request.data)),
164+
data: request.data ? JSON.parse(JSON.stringify(request.data)) : request.data,
165165
};
166166

167167
const result = await axios({

0 commit comments

Comments
 (0)