-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: using denylist from edge-gateway (#126)
- Loading branch information
Showing
17 changed files
with
216 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ on: | |
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
name: Test | ||
name: Lint | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: pnpm/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ on: | |
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
name: Test | ||
name: Lint | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: pnpm/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ on: | |
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
name: Test | ||
name: Lint | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: pnpm/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import pRetry from 'p-retry' | ||
export const GOOGLE_EVALUATE = 'google-evaluate' | ||
|
||
/** | ||
* Get the threats we have stored in KV. | ||
* | ||
* @param {string} cid | ||
* @param {import('../env').Env} env | ||
*/ | ||
async function getEvaluateResult (cid, env) { | ||
const resultKey = `${cid}/${GOOGLE_EVALUATE}` | ||
const datastore = env.CID_VERIFIER_RESULTS | ||
if (!datastore) { | ||
throw new Error('db not ready') | ||
} | ||
|
||
return await pRetry( | ||
() => datastore.get(resultKey), | ||
{ retries: 5 } | ||
) | ||
} | ||
|
||
/** | ||
* Get the threats we have stored in KV. | ||
* | ||
* @param {string} cid | ||
* @param {import('../env').Env} env | ||
*/ | ||
export async function getStoredThreats (cid, env) { | ||
const evaluateResult = await getEvaluateResult(cid, env) | ||
if (evaluateResult) { | ||
// @ts-ignore | ||
return JSON.parse(evaluateResult)?.scores?.filter(score => !env.GOOGLE_EVALUATE_SAFE_CONFIDENCE_LEVELS.includes(score.confidenceLevel)).map(score => score.threatType) | ||
} | ||
return [] | ||
} | ||
|
||
/** | ||
* Get verification results from Google Evaluate API. | ||
* | ||
* Also returns any lock results if we have in progress evaluate requests. | ||
* | ||
* @param {string} cid | ||
* @param {import('../env').Env} env | ||
*/ | ||
export async function getResults (cid, env) { | ||
const datastore = env.CID_VERIFIER_RESULTS | ||
if (!datastore) { | ||
throw new Error('CID_VERIFIER_RESULTS db not ready') | ||
} | ||
|
||
return (await datastore.list({ prefix: cid }))?.keys?.reduce((acc, key) => { | ||
// @ts-ignore | ||
acc[key?.name] = key?.metadata?.value | ||
return acc | ||
}, {}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.