Skip to content

Commit

Permalink
Merge pull request #802 from SSWConsulting/staging
Browse files Browse the repository at this point in the history
Merge Staging to Main
  • Loading branch information
tombui99 authored Nov 29, 2023
2 parents 43adf84 + 8cba888 commit 9dad0dc
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 78 deletions.
73 changes: 35 additions & 38 deletions api/functions/firestore.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
const admin = require('firebase-admin');
const { initializeApp } = require('firebase-admin/app');
const { getFirestore } = require('firebase-admin/firestore');
const { CONSTANTS } = require('./consts');

exports.getUserIdFromApiKey = (api) => {
return admin
.firestore()
.collection(CONSTANTS.users)
.where(CONSTANTS.apiKey, '==', api)
.get()
.then((x) => (x.docs.length === 1 ? x.docs[0].id : null));
initializeApp();
const db = getFirestore();

exports.getUserIdFromApiKey = async (api) => {
const q = db.collection(CONSTANTS.users);
const users = await q.where(CONSTANTS.apiKey, '==', api).limit(1).get();
return users.empty ? null : users.docs[0].id;
};

exports.updateLastBuild = (userId, apikey, runId) => {
return admin
.firestore()
.collection(CONSTANTS.users)
.doc(userId)
.update({
lastBuild: new Date(),
runId,
})
.then(() =>
admin.firestore().collection(CONSTANTS.runs).doc(runId).set({
apikey,
runId,
})
);
exports.updateLastBuild = async (userId, apikey, runId) => {
await db.collection(CONSTANTS.users).doc(userId).set(
{
lastBuild: new Date(),
runId,
},
{ merge: true }
);
await db.collection(CONSTANTS.runs).doc(runId).set(
{
apikey,
runId,
},
{ merge: true }
);
};

exports.getRun = (runId) =>
admin
.firestore()
.collection(CONSTANTS.runs)
.doc(runId)
.get()
.then((doc) => doc.data());
exports.getRun = async (runId) => {
const doc = await db.collection(CONSTANTS.runs).doc(runId).get();
return doc.data();
};

exports.getAlertEmailConfig = () => {
return admin
.firestore()
.collection(CONSTANTS.config)
.doc('alertEmailConfig')
.get()
.then((doc) => doc.data())
};
exports.getAlertEmailConfig = async () => {
const doc = await db
.collection(CONSTANTS.config)
.doc('alertEmailConfig')
.get();
return doc.data();
};
6 changes: 2 additions & 4 deletions api/functions/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const functions = require('firebase-functions');
const express = require('express');
const admin = require('firebase-admin');
const R = require('ramda');
const fetch = require('node-fetch');
const Queue = require('better-queue');
Expand Down Expand Up @@ -55,7 +54,6 @@ const {
} = require('./firestore');

var cors = require('cors');
admin.initializeApp();

const app = express();
// middlewares
Expand Down Expand Up @@ -364,5 +362,5 @@ app.post('/scanresult/:api/:buildId', async (req, res) => {
res.json(runId);
});

exports.api = functions.region('asia-east2').https.onRequest(app);
exports.api2 = functions.region('asia-northeast1').https.onRequest(app);
exports.api = functions.runWith({ timeoutSeconds: 540 }).region('asia-east2').https.onRequest(app);
exports.api2 = functions.runWith({ timeoutSeconds: 540 }).region('asia-northeast1').https.onRequest(app);
92 changes: 75 additions & 17 deletions api/functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"scripts": {
"lint": "eslint .",
"test": "jest",
"serve": "firebase serve --only functions --port 5001",
"serve": "firebase serve -o 0.0.0.0 --only functions --port 5001",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --token $FIREBASETOKEN --only functions",
Expand All @@ -21,7 +21,7 @@
"cors": "^2.8.5",
"dotenv": "^8.6.0",
"express": "^4.18.2",
"firebase-admin": "^11.8.0",
"firebase-admin": "^11.11.1",
"firebase-functions": "^3.24.1",
"node-fetch": "^2.6.11",
"ramda": "^0.27.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import Icon from "../misccomponents/Icon.svelte";
import { htmlHintRules, customHtmlHintRules } from "../../../../docker/rules.js";
import LoadingCircle from "../misccomponents/LoadingCircle.svelte";
import { tooltip } from '../misccomponents/tooltip';
export let errors = [];
export let codeIssues = [];
Expand Down Expand Up @@ -136,7 +137,7 @@
<tr>
<th class="w-2/12 px-4 py-2">Page ({error.pages.length})</th>
<th class="w-9/12 px-4 py-2">Locations (line:col)</th>
<th class="w-1/12 px-4 py-2">Ignore</th>
<th class="w-1/12 px-4 py-2" title="Ignore URL for this rule in future scans" use:tooltip>Ignore</th>
</tr>
</thead>
<tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import { createEventDispatcher } from "svelte";
import Icon from "../misccomponents/Icon.svelte";
import LoadingCircle from "../misccomponents/LoadingCircle.svelte";
import { tooltip } from '../misccomponents/tooltip';
export let errors = [];
export let codeIssues = [];
Expand Down Expand Up @@ -115,7 +116,7 @@
Issues ({Object.keys(url.errors).length})
</th>
<th class="w-9/12 px-4 py-2">Locations</th>
<th class="w-1/12 px-4 py-2">Ignore</th>
<th class="w-1/12 px-4 py-2" title="Ignore rule on this URL in future scans" use:tooltip>Ignore</th>
</tr>
</thead>
<tbody>
Expand Down
31 changes: 16 additions & 15 deletions ui/src/components/misccomponents/TooltipFromAction.svelte
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<script>
export let title;
export let x;
export let y;
export let title;
export let x;
export let y;
</script>
<div style="
top: {y + 5}px;
left: {x + 5}px;">{title}</div>

<div style="top: {y + 5}px; left: {x + 5}px;">
<i class="fa-solid fa-circle-info text-blue-600"></i> {title}
</div>

<style>
div {
border: 1px solid #ddd;
box-shadow: 1px 1px 1px #ddd;
background: white;
border-radius: 4px;
padding: 4px;
position: absolute;
}
</style>
div {
border: 1px solid #ddd;
box-shadow: 1px 1px 1px #ddd;
background: white;
border-radius: 4px;
padding: 4px;
position: absolute;
}
</style>

0 comments on commit 9dad0dc

Please sign in to comment.