Merge pull request #7 from emizzle/fix/readme

fix: README and env variable warning update
This commit is contained in:
semuelle 2020-03-16 13:04:54 +01:00 committed by GitHub
commit 5c2056a438
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 29 deletions

View File

@ -16,7 +16,7 @@ MYTHX_USERNAME="<mythx-username>"
MYTHX_PASSWORD="<password>" MYTHX_PASSWORD="<password>"
``` ```
> **NOTE:** `MYTHX_ETH_ADDRESS` in favour of `MYTHX_USERNAME` and will be removed in future versions. Please update your .env file or your environment variables accordingly. > **NOTE:** `MYTHX_ETH_ADDRESS` has been deprecated in favour of `MYTHX_USERNAME` and will be removed in future versions. Please update your .env file or your environment variables accordingly.
`MYTHX_USERNAME` may be either of: `MYTHX_USERNAME` may be either of:
* MythX User ID (assigned by MythX API to any registered user); * MythX User ID (assigned by MythX API to any registered user);

View File

@ -27,39 +27,39 @@ async function analyse(contracts, cfg, embark) {
if (process.env.MYTHX_ETH_ADDRESS) { if (process.env.MYTHX_ETH_ADDRESS) {
process.env.MYTHX_USERNAME = process.env.MYTHX_ETH_ADDRESS; process.env.MYTHX_USERNAME = process.env.MYTHX_ETH_ADDRESS;
embark.logger.warn("The environment variable MYTHX_ETH_ADDRESS in favour of MYTHX_USERNAME and will be removed in future versions. Please update your .env file or your environment variables accordingly."); embark.logger.warn("The environment variable MYTHX_ETH_ADDRESS has been deprecated in favour of MYTHX_USERNAME and will be removed in future versions. Please update your .env file or your environment variables accordingly.");
} }
// Connect to MythX via armlet // Connect to MythX via armlet
if(!process.env.MYTHX_USERNAME || !process.env.MYTHX_PASSWORD) { if (!process.env.MYTHX_USERNAME || !process.env.MYTHX_PASSWORD) {
throw new Error("Environment variables 'MYTHX_USERNAME' and 'MYTHX_PASSWORD' not found. Place these in a .env file in the root of your &ETH;App, add them in the CLI command, ie 'MYTHX_USERNAME=xyz MYTHX_PASSWORD=123 embark run', or add them to your system's environment variables."); throw new Error("Environment variables 'MYTHX_USERNAME' and 'MYTHX_PASSWORD' not found. Place these in a .env file in the root of your &ETH;App, add them in the CLI command, ie 'MYTHX_USERNAME=xyz MYTHX_PASSWORD=123 embark run', or add them to your system's environment variables.");
} }
const armletClient = new armlet.Client( const armletClient = new armlet.Client(
{ {
clientToolName: "embark-mythx", clientToolName: "embark-mythx",
password: process.env.MYTHX_PASSWORD, password: process.env.MYTHX_PASSWORD,
ethAddress: process.env.MYTHX_USERNAME, ethAddress: process.env.MYTHX_USERNAME,
}) })
// Filter contracts based on parameter choice // Filter contracts based on parameter choice
let toSubmit = { "contracts": {}, "sources": contracts.sources }; let toSubmit = { "contracts": {}, "sources": contracts.sources };
if(!("ignore" in embark.pluginConfig)) { if (!("ignore" in embark.pluginConfig)) {
embark.pluginConfig.ignore = [] embark.pluginConfig.ignore = []
} }
for (let [filename, contractObjects] of Object.entries(contracts.contracts)) { for (let [filename, contractObjects] of Object.entries(contracts.contracts)) {
for (let [contractName, contract] of Object.entries(contractObjects)) { for (let [contractName, contract] of Object.entries(contractObjects)) {
if(!("contracts" in cfg)) { if (!("contracts" in cfg)) {
if (embark.pluginConfig.ignore.indexOf(contractName) == -1) { if (embark.pluginConfig.ignore.indexOf(contractName) == -1) {
if(!toSubmit.contracts[filename]) { if (!toSubmit.contracts[filename]) {
toSubmit.contracts[filename] = {} toSubmit.contracts[filename] = {}
} }
toSubmit.contracts[filename][contractName] = contract; toSubmit.contracts[filename][contractName] = contract;
} }
} else { } else {
if (cfg.contracts.indexOf(contractName) >= 0 && embark.pluginConfig.ignore.indexOf(contractName) == -1) { if (cfg.contracts.indexOf(contractName) >= 0 && embark.pluginConfig.ignore.indexOf(contractName) == -1) {
if(!toSubmit.contracts[filename]) { if (!toSubmit.contracts[filename]) {
toSubmit.contracts[filename] = {} toSubmit.contracts[filename] = {}
} }
toSubmit.contracts[filename][contractName] = contract; toSubmit.contracts[filename][contractName] = contract;
@ -67,9 +67,9 @@ async function analyse(contracts, cfg, embark) {
} }
} }
} }
// Stop here if no contracts are left // Stop here if no contracts are left
if(Object.keys(toSubmit.contracts).length === 0) { if (Object.keys(toSubmit.contracts).length === 0) {
embark.logger.info("No contracts to submit."); embark.logger.info("No contracts to submit.");
return 0; return 0;
} }
@ -85,12 +85,12 @@ async function getStatus(uuid, embark) {
// Connect to MythX via armlet // Connect to MythX via armlet
const armletClient = new armlet.Client( const armletClient = new armlet.Client(
{ {
clientToolName: "embark-mythx", clientToolName: "embark-mythx",
password: process.env.MYTHX_PASSWORD, password: process.env.MYTHX_PASSWORD,
ethAddress: process.env.MYTHX_USERNAME, ethAddress: process.env.MYTHX_USERNAME,
}) })
try { try {
const results = await armletClient.getIssues(uuid); const results = await armletClient.getIssues(uuid);
return ghettoReport(embark.logger, results); return ghettoReport(embark.logger, results);
@ -106,7 +106,7 @@ const doAnalysis = async (armletClient, config, contracts, contractNames = null,
const initialDelay = ('initial-delay' in config) ? config['initial-delay'] * 1000 : undefined; const initialDelay = ('initial-delay' in config) ? config['initial-delay'] * 1000 : undefined;
const results = await asyncPool(limit, contracts, async buildObj => { const results = await asyncPool(limit, contracts, async buildObj => {
const obj = new MythXIssues(buildObj, config); const obj = new MythXIssues(buildObj, config);
let analyzeOpts = { let analyzeOpts = {
@ -118,14 +118,14 @@ const doAnalysis = async (armletClient, config, contracts, contractNames = null,
analyzeOpts.data = mythXUtil.cleanAnalyzeDataEmptyProps(obj.buildObj, config.debug, config.logger.debug); analyzeOpts.data = mythXUtil.cleanAnalyzeDataEmptyProps(obj.buildObj, config.debug, config.logger.debug);
analyzeOpts.data.analysisMode = config.full ? "full" : "quick"; analyzeOpts.data.analysisMode = config.full ? "full" : "quick";
if (config.debug > 1) { if (config.debug > 1) {
config.logger.debug("analyzeOpts: " + `${util.inspect(analyzeOpts, {depth: null})}`); config.logger.debug("analyzeOpts: " + `${util.inspect(analyzeOpts, { depth: null })}`);
} }
// request analysis to armlet. // request analysis to armlet.
try { try {
//TODO: Call analyze/analyzeWithStatus asynchronously //TODO: Call analyze/analyzeWithStatus asynchronously
config.logger.info("Submitting '" + obj.contractName + "' for " + analyzeOpts.data.analysisMode + " analysis...") config.logger.info("Submitting '" + obj.contractName + "' for " + analyzeOpts.data.analysisMode + " analysis...")
const {issues, status} = await armletClient.analyzeWithStatus(analyzeOpts); const { issues, status } = await armletClient.analyzeWithStatus(analyzeOpts);
obj.uuid = status.uuid; obj.uuid = status.uuid;
if (status.status === 'Error') { if (status.status === 'Error') {
@ -133,7 +133,7 @@ const doAnalysis = async (armletClient, config, contracts, contractNames = null,
} else { } else {
obj.setIssues(issues); obj.setIssues(issues);
} }
return [null, obj]; return [null, obj];
} catch (err) { } catch (err) {
//console.log("catch", JSON.stringify(err)); //console.log("catch", JSON.stringify(err));
@ -147,7 +147,7 @@ const doAnalysis = async (armletClient, config, contracts, contractNames = null,
} }
if (errStr.includes('User or default timeout reached after') if (errStr.includes('User or default timeout reached after')
|| errStr.includes('Timeout reached after')) { || errStr.includes('Timeout reached after')) {
return [(buildObj.contractName + ": ").yellow + errStr, null]; return [(buildObj.contractName + ": ").yellow + errStr, null];
} else { } else {
return [(buildObj.contractName + ": ").red + errStr, null]; return [(buildObj.contractName + ": ").red + errStr, null];
@ -157,7 +157,7 @@ const doAnalysis = async (armletClient, config, contracts, contractNames = null,
}); });
return results.reduce((accum, curr) => { return results.reduce((accum, curr) => {
const [ err, obj ] = curr; const [err, obj] = curr;
if (err) { if (err) {
accum.errors.push(err); accum.errors.push(err);
} else if (obj) { } else if (obj) {
@ -172,7 +172,7 @@ function ghettoReport(logger, results) {
results.forEach(ele => { results.forEach(ele => {
issuesCount += ele.issues.length; issuesCount += ele.issues.length;
}); });
if (issuesCount === 0) { if (issuesCount === 0) {
logger.info('No issues found'); logger.info('No issues found');
return 0; return 0;
@ -180,7 +180,7 @@ function ghettoReport(logger, results) {
for (const group of results) { for (const group of results) {
logger.info(group.sourceList.join(', ').underline); logger.info(group.sourceList.join(', ').underline);
for (const issue of group.issues) { for (const issue of group.issues) {
logger.info(yaml.safeDump(issue, {'skipInvalid': true})); logger.info(yaml.safeDump(issue, { 'skipInvalid': true }));
} }
} }
return 1; return 1;