Merge pull request #7 from emizzle/fix/readme
fix: README and env variable warning update
This commit is contained in:
commit
5c2056a438
|
@ -16,7 +16,7 @@ MYTHX_USERNAME="<mythx-username>"
|
|||
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 User ID (assigned by MythX API to any registered user);
|
||||
|
|
56
mythx.js
56
mythx.js
|
@ -27,39 +27,39 @@ async function analyse(contracts, cfg, embark) {
|
|||
|
||||
if (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
|
||||
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 Ð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(
|
||||
{
|
||||
clientToolName: "embark-mythx",
|
||||
password: process.env.MYTHX_PASSWORD,
|
||||
ethAddress: process.env.MYTHX_USERNAME,
|
||||
})
|
||||
|
||||
{
|
||||
clientToolName: "embark-mythx",
|
||||
password: process.env.MYTHX_PASSWORD,
|
||||
ethAddress: process.env.MYTHX_USERNAME,
|
||||
})
|
||||
|
||||
// Filter contracts based on parameter choice
|
||||
let toSubmit = { "contracts": {}, "sources": contracts.sources };
|
||||
if(!("ignore" in embark.pluginConfig)) {
|
||||
if (!("ignore" in embark.pluginConfig)) {
|
||||
embark.pluginConfig.ignore = []
|
||||
}
|
||||
|
||||
for (let [filename, contractObjects] of Object.entries(contracts.contracts)) {
|
||||
for (let [contractName, contract] of Object.entries(contractObjects)) {
|
||||
if(!("contracts" in cfg)) {
|
||||
if (!("contracts" in cfg)) {
|
||||
if (embark.pluginConfig.ignore.indexOf(contractName) == -1) {
|
||||
if(!toSubmit.contracts[filename]) {
|
||||
if (!toSubmit.contracts[filename]) {
|
||||
toSubmit.contracts[filename] = {}
|
||||
}
|
||||
toSubmit.contracts[filename][contractName] = contract;
|
||||
}
|
||||
} else {
|
||||
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][contractName] = contract;
|
||||
|
@ -67,9 +67,9 @@ async function analyse(contracts, cfg, embark) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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.");
|
||||
return 0;
|
||||
}
|
||||
|
@ -85,12 +85,12 @@ async function getStatus(uuid, embark) {
|
|||
|
||||
// Connect to MythX via armlet
|
||||
const armletClient = new armlet.Client(
|
||||
{
|
||||
clientToolName: "embark-mythx",
|
||||
password: process.env.MYTHX_PASSWORD,
|
||||
ethAddress: process.env.MYTHX_USERNAME,
|
||||
})
|
||||
|
||||
{
|
||||
clientToolName: "embark-mythx",
|
||||
password: process.env.MYTHX_PASSWORD,
|
||||
ethAddress: process.env.MYTHX_USERNAME,
|
||||
})
|
||||
|
||||
try {
|
||||
const results = await armletClient.getIssues(uuid);
|
||||
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 results = await asyncPool(limit, contracts, async buildObj => {
|
||||
|
||||
|
||||
const obj = new MythXIssues(buildObj, config);
|
||||
|
||||
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.analysisMode = config.full ? "full" : "quick";
|
||||
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.
|
||||
try {
|
||||
//TODO: Call analyze/analyzeWithStatus asynchronously
|
||||
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;
|
||||
|
||||
if (status.status === 'Error') {
|
||||
|
@ -133,7 +133,7 @@ const doAnalysis = async (armletClient, config, contracts, contractNames = null,
|
|||
} else {
|
||||
obj.setIssues(issues);
|
||||
}
|
||||
|
||||
|
||||
return [null, obj];
|
||||
} catch (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')
|
||||
|| errStr.includes('Timeout reached after')) {
|
||||
|| errStr.includes('Timeout reached after')) {
|
||||
return [(buildObj.contractName + ": ").yellow + errStr, null];
|
||||
} else {
|
||||
return [(buildObj.contractName + ": ").red + errStr, null];
|
||||
|
@ -157,7 +157,7 @@ const doAnalysis = async (armletClient, config, contracts, contractNames = null,
|
|||
});
|
||||
|
||||
return results.reduce((accum, curr) => {
|
||||
const [ err, obj ] = curr;
|
||||
const [err, obj] = curr;
|
||||
if (err) {
|
||||
accum.errors.push(err);
|
||||
} else if (obj) {
|
||||
|
@ -172,7 +172,7 @@ function ghettoReport(logger, results) {
|
|||
results.forEach(ele => {
|
||||
issuesCount += ele.issues.length;
|
||||
});
|
||||
|
||||
|
||||
if (issuesCount === 0) {
|
||||
logger.info('No issues found');
|
||||
return 0;
|
||||
|
@ -180,7 +180,7 @@ function ghettoReport(logger, results) {
|
|||
for (const group of results) {
|
||||
logger.info(group.sourceList.join(', ').underline);
|
||||
for (const issue of group.issues) {
|
||||
logger.info(yaml.safeDump(issue, {'skipInvalid': true}));
|
||||
logger.info(yaml.safeDump(issue, { 'skipInvalid': true }));
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
|
|
Loading…
Reference in New Issue