Skip to content

Commit

Permalink
Merge pull request #520 from SSWConsulting/show-top-scans-and-fix-docker
Browse files Browse the repository at this point in the history
Added option to show all scans and Fixed docker image
  • Loading branch information
tombui99 authored Jul 5, 2023
2 parents 0f592f4 + b2ae234 commit cb7824e
Show file tree
Hide file tree
Showing 8 changed files with 485 additions and 526 deletions.
6 changes: 3 additions & 3 deletions api/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const {
removeAlertEmailAddress,
} = require('./commands');
const {
getSummary,
getPersonalSummary,
getAllPublicSummary,
getSummaryById,
getConfig,
Expand Down Expand Up @@ -134,11 +134,11 @@ app.delete('/deletealertemailaddress', async (req, res) =>
res.json(await removeAlertEmailAddress(req.body.api, req.body.rowkey)));

app.get('/scanresult/:api', async (req, res) => {
res.json(await getSummary(req.params.api));
res.json(await getPersonalSummary(req.params.api, req.query.showAll));
});

app.get('/allscans', async (req, res) => {
res.json(await getAllPublicSummary());
res.json(await getAllPublicSummary(req.query.showAll));
});

app.get('/viewsource', async (req, res) => {
Expand Down
36 changes: 26 additions & 10 deletions api/functions/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,44 @@ exports.getHTMLHintRulesByRunId = async (runId) => {
return null;
};

exports.getSummary = (api) =>
exports.getPersonalSummary = (api, showAll) =>
new Promise(async (resolve) => {
const entity = new TableClient(azureUrl, TABLE.Scans, credential).listEntities({
queryOptions: { filter: odata`PartitionKey eq ${api}` }
});
let result = []
for await (const item of entity) {
result.push(item);
if (showAll === 'true') {
let result = []
for await (const item of entity) {
result.push(item);
}
resolve(result)
} else {
const iterator = entity.byPage({ maxPageSize: 500 });
for await (const item of iterator) {
resolve(item)
break;
}
}
resolve(result)
});

exports.getAllPublicSummary = () =>
exports.getAllPublicSummary = (showAll) =>
new Promise(async (resolve) => {
const entity = new TableClient(azureUrl, TABLE.Scans, credential).listEntities({
queryOptions: { filter: odata`isPrivate eq ${false}` }
});
let result = []
for await (const item of entity) {
result.push(item);
if (showAll === 'true') {
let result = []
for await (const item of entity) {
result.push(item);
}
resolve(result)
} else {
const iterator = entity.byPage({ maxPageSize: 500 });
for await (const item of iterator) {
resolve(item)
break;
}
}
resolve(result)
});

exports.getSummaryById = async (runId) =>
Expand Down
9 changes: 4 additions & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ RUN npm install -g puppeteer
# Setup a user to avoid doing everything as root
RUN groupadd --system lhci && \
useradd --system --create-home --gid lhci lhci && \
mkdir --parents /home/lhci/reports && \
mkdir --parents /home/lhci/app && \
mkdir --parents /home/lhci/app/src && \
chown --recursive lhci:lhci /home/lhci

RUN cd /home/lhci/reports && npm link puppeteer
RUN cd /home/lhci/app/src && npm link puppeteer
USER lhci

WORKDIR /home/lhci/app
Expand All @@ -61,6 +62,4 @@ COPY --from=builder /go/bin/sswlinkauditor /home/lhci/app/sswlinkauditor
# main nodejs app
COPY --from=nodeBuilder /usr/src/app /home/lhci/app

CMD [ "lhci", "--help" ]

ENTRYPOINT ["node","."]
ENTRYPOINT ["node","."]
2 changes: 1 addition & 1 deletion docker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const main = async () => {
writeLog(`start lighthouse`);
try {
const rs = execSync(
`./node_modules/.bin/lhci collect --url="${options.url}"`
`./node_modules/.bin/lhci collect --url="${options.url}" -n 1`
).toString();
writeLog(`lighthouse check finished`, rs);
} catch (e) {
Expand Down
Loading

0 comments on commit cb7824e

Please sign in to comment.