Run prettier

This commit is contained in:
Yarmo Mackenbach 2021-04-19 11:44:30 +02:00
parent 5b35051c7a
commit 802ebb2f4c
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
32 changed files with 349 additions and 286 deletions

View file

@ -1,55 +1,53 @@
---
kind: pipeline
name: build-stable-proxy-container
steps:
- name: build stable proxy container
image: plugins/docker
settings:
username:
from_secret: docker_username
password:
from_secret: docker_password
dockerfile: docker/proxy/Dockerfile
repo: keyoxide/doip-proxy
tags: stable
- name: build tag proxy container
image: plugins/docker
settings:
username:
from_secret: docker_username
password:
from_secret: docker_password
dockerfile: docker/proxy/Dockerfile
repo: keyoxide/doip-proxy
auto_tag: true
- name: build stable proxy container
image: plugins/docker
settings:
username:
from_secret: docker_username
password:
from_secret: docker_password
dockerfile: docker/proxy/Dockerfile
repo: keyoxide/doip-proxy
tags: stable
- name: build tag proxy container
image: plugins/docker
settings:
username:
from_secret: docker_username
password:
from_secret: docker_password
dockerfile: docker/proxy/Dockerfile
repo: keyoxide/doip-proxy
auto_tag: true
trigger:
branch:
- main
event:
- tag
branch:
- main
event:
- tag
---
kind: pipeline
name: build-dev-proxy-container
steps:
- name: build dev proxy container
image: plugins/docker
settings:
username:
from_secret: docker_username
password:
from_secret: docker_password
dockerfile: docker/proxy/Dockerfile
repo: keyoxide/doip-proxy
tags: dev
- name: build dev proxy container
image: plugins/docker
settings:
username:
from_secret: docker_username
password:
from_secret: docker_password
dockerfile: docker/proxy/Dockerfile
repo: keyoxide/doip-proxy
tags: dev
trigger:
branch:
- main
event:
- push
branch:
- main
event:
- push

View file

@ -131,7 +131,9 @@ class Claim {
*/
set uri(uri) {
if (this.state !== E.ClaimState.INIT) {
throw new Error('Cannot change the URI, this claim has already been matched')
throw new Error(
'Cannot change the URI, this claim has already been matched'
)
}
// Verify validity of URI
if (uri && !validUrl.isUri(uri)) {
@ -150,7 +152,9 @@ class Claim {
*/
set fingerprint(fingerprint) {
if (this.state === E.ClaimState.VERIFIED) {
throw new Error('Cannot change the fingerprint, this claim has already been verified')
throw new Error(
'Cannot change the fingerprint, this claim has already been verified'
)
}
this.fingerprint = fingerprint
}
@ -161,7 +165,7 @@ class Claim {
* @param anything - Anything will throw an error
*/
set state(anything) {
throw new Error('Cannot change a claim\'s state')
throw new Error("Cannot change a claim's state")
}
/**
@ -170,7 +174,7 @@ class Claim {
* @param anything - Anything will throw an error
*/
set dataMatches(anything) {
throw new Error('Cannot change a claim\'s dataMatches')
throw new Error("Cannot change a claim's dataMatches")
}
/**
@ -179,7 +183,7 @@ class Claim {
* @param anything - Anything will throw an error
*/
set verification(anything) {
throw new Error('Cannot change a claim\'s verification data')
throw new Error("Cannot change a claim's verification data")
}
/**
@ -210,9 +214,7 @@ class Claim {
this.dataMatches.push(candidate)
} else {
// Set a single candidate and stop
this.dataMatches = [
candidate
]
this.dataMatches = [candidate]
return false
}
@ -262,7 +264,11 @@ class Claim {
if (proofData) {
// Run the verification process
verificationResult = verifications.run(proofData.result, claimData, this.fingerprint)
verificationResult = verifications.run(
proofData.result,
claimData,
this.fingerprint
)
verificationResult.proof = {
fetcher: proofData.fetcher,
viaProxy: proofData.viaProxy,
@ -285,9 +291,7 @@ class Claim {
if (verificationResult.completed) {
// Store the result, keep a single match and stop verifying
this.verification = verificationResult
this.dataMatches = [
claimData
]
this.dataMatches = [claimData]
index = this.dataMatches.length
}
}

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: {
url: `https://dev.to/api/articles/${match[1]}/${match[2]}`,
format: E.ProofFormat.JSON,
}
}
},
},
},
claim: {
format: E.ClaimFormat.MESSAGE,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: {
url: `https://${match[1]}/u/${match[2]}.json`,
format: E.ProofFormat.JSON,
}
}
},
},
},
claim: {
format: E.ClaimFormat.MESSAGE,

View file

@ -42,8 +42,8 @@ const processURI = (uri) => {
format: E.ProofFormat.JSON,
data: {
domain: match[1],
}
}
},
},
},
claim: {
format: E.ClaimFormat.URI,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: {
url: uri,
format: E.ProofFormat.JSON,
}
}
},
},
},
claim: {
format: E.ClaimFormat.FINGERPRINT,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: {
url: `https://${match[1]}/api/v1/repos/${match[2]}/gitea_proof`,
format: E.ProofFormat.JSON,
}
}
},
},
},
claim: {
format: E.ClaimFormat.MESSAGE,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: {
url: `https://api.github.com/gists/${match[2]}`,
format: E.ProofFormat.JSON,
}
}
},
},
},
claim: {
format: E.ClaimFormat.MESSAGE,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: {
domain: match[1],
username: match[2],
}
}
},
},
},
claim: {
format: E.ClaimFormat.MESSAGE,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: {
url: `https://hacker-news.firebaseio.com/v0/user/${match[1]}.json`,
format: E.ProofFormat.JSON,
}
}
},
},
},
claim: {
format: E.ClaimFormat.URI,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: {
domain: match[1],
nick: match[2],
}
}
},
},
},
claim: {
format: E.ClaimFormat.URI,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: {
url: `https://liberapay.com/${match[1]}/public.json`,
format: E.ProofFormat.JSON,
}
}
},
},
},
claim: {
format: E.ClaimFormat.MESSAGE,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: {
url: `https://lobste.rs/u/${match[1]}.json`,
format: E.ProofFormat.JSON,
}
}
},
},
},
claim: {
format: E.ClaimFormat.MESSAGE,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: {
url: uri,
format: E.ProofFormat.JSON,
}
}
},
},
},
claim: {
format: E.ClaimFormat.FINGERPRINT,

View file

@ -57,8 +57,8 @@ const processURI = (uri) => {
data: {
eventId: params['org.keyoxide.e'],
roomId: params['org.keyoxide.r'],
}
}
},
},
},
claim: {
format: E.ClaimFormat.MESSAGE,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: {
url: `${uri}/api/config`,
format: E.ProofFormat.JSON,
}
}
},
},
},
claim: {
format: E.ClaimFormat.FINGERPRINT,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: {
url: `https://www.reddit.com/user/${match[1]}/comments/${match[2]}.json`,
format: E.ProofFormat.JSON,
}
}
},
},
},
claim: {
format: E.ClaimFormat.MESSAGE,

View file

@ -42,8 +42,8 @@ const processURI = (uri) => {
format: E.ProofFormat.TEXT,
data: {
tweetId: match[2],
}
}
},
},
},
claim: {
format: E.ClaimFormat.MESSAGE,

View file

@ -42,9 +42,9 @@ const processURI = (uri) => {
format: E.ProofFormat.TEXT,
data: {
id: `${match[1]}@${match[2]}`,
field: 'note'
}
}
field: 'note',
},
},
},
claim: {
format: E.ClaimFormat.MESSAGE,

View file

@ -15,28 +15,28 @@ limitations under the License.
*/
const E = require('./enums')
const opts = {
const opts = {
proxy: {
hostname: null,
policy: E.ProxyPolicy.NEVER
policy: E.ProxyPolicy.NEVER,
},
claims: {
irc: {
nick: null
nick: null,
},
matrix: {
instance: null,
accessToken: null
accessToken: null,
},
xmpp: {
service: null,
username: null,
password: null
password: null,
},
twitter: {
bearerToken: null
bearerToken: null,
},
}
},
}
exports.opts = opts

View file

@ -13,14 +13,14 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const ProxyPolicy = {
const ProxyPolicy = {
ADAPTIVE: 'adaptive',
ALWAYS: 'always',
NEVER: 'never',
}
Object.freeze(ProxyPolicy)
const Fetcher = {
const Fetcher = {
HTTP: 'http',
DNS: 'dns',
IRC: 'irc',
@ -31,7 +31,7 @@ const Fetcher = {
}
Object.freeze(Fetcher)
const ProofAccess = {
const ProofAccess = {
GENERIC: 0,
NOCORS: 1,
GRANTED: 2,
@ -39,31 +39,31 @@ const ProofAccess = {
}
Object.freeze(ProofAccess)
const ProofFormat = {
const ProofFormat = {
JSON: 'json',
TEXT: 'text',
}
Object.freeze(ProofFormat)
const ClaimFormat = {
const ClaimFormat = {
URI: 0,
FINGERPRINT: 1,
MESSAGE: 2,
}
Object.freeze(ClaimFormat)
const ClaimRelation = {
const ClaimRelation = {
CONTAINS: 0,
EQUALS: 1,
ONEOF: 2,
}
Object.freeze(ClaimRelation)
const VerificationStatus = {
const VerificationStatus = {
INIT: 0,
INPROGRESS: 1,
FAILED: 2,
COMPLETED: 3
COMPLETED: 3,
}
Object.freeze(VerificationStatus)

View file

@ -38,7 +38,9 @@ module.exports.fn = async (data, opts) => {
}
const urlProject = `https://${data.domain}/api/v4/users/${user.id}/projects`
const resProject = await req(urlProject, null, { Accept: 'application/json' })
const resProject = await req(urlProject, null, {
Accept: 'application/json',
})
const jsonProject = await resProject.json()
const project = jsonProject.find((proj) => proj.path === 'gitlab_proof')

View file

@ -32,7 +32,9 @@ module.exports.fn = async (data, opts) => {
try {
validator.isAscii(opts.claims.twitter.bearerToken)
} catch (err) {
throw new Error(`Twitter fetcher was not set up properly (${err.message})`)
throw new Error(
`Twitter fetcher was not set up properly (${err.message})`
)
}
bentReq(

View file

@ -206,8 +206,8 @@ const process = (publicKey) => {
key: {
data: publicKey,
fetchMethod: null,
uri: null
}
uri: null,
},
})
})
}

View file

@ -49,7 +49,9 @@ const handleBrowserRequests = (data, opts) => {
break
case E.ProofAccess.NOCORS:
case E.ProofAccess.SERVER:
throw new Error('Impossible to fetch proof (bad combination of service access and proxy policy)')
throw new Error(
'Impossible to fetch proof (bad combination of service access and proxy policy)'
)
break
default:
throw new Error('Invalid proof access value')
@ -69,7 +71,9 @@ const handleBrowserRequests = (data, opts) => {
return createFallbackRequestPromise(data, opts)
break
case E.ProofAccess.SERVER:
throw new Error('Impossible to fetch proof (bad combination of service access and proxy policy)')
throw new Error(
'Impossible to fetch proof (bad combination of service access and proxy policy)'
)
break
default:
throw new Error('Invalid proof access value')
@ -105,16 +109,17 @@ const handleNodeRequests = (data, opts) => {
const createDefaultRequestPromise = (data, opts) => {
return new Promise((resolve, reject) => {
fetcher[data.proof.request.fetcher].fn(data.proof.request.data, opts)
.then(res => {
fetcher[data.proof.request.fetcher]
.fn(data.proof.request.data, opts)
.then((res) => {
return resolve({
fetcher: data.proof.request.fetcher,
data: data,
viaProxy: false,
result: res
result: res,
})
})
.catch(err => {
.catch((err) => {
return reject(err)
})
})
@ -124,7 +129,11 @@ const createProxyRequestPromise = (data, opts) => {
return new Promise((resolve, reject) => {
let proxyUrl
try {
proxyUrl = utils.generateProxyURL(data.proof.request.fetcher, data.proof.request.data, opts);
proxyUrl = utils.generateProxyURL(
data.proof.request.fetcher,
data.proof.request.data,
opts
)
} catch (err) {
reject(err)
}
@ -132,18 +141,19 @@ const createProxyRequestPromise = (data, opts) => {
const requestData = {
url: proxyUrl,
format: data.proof.request.format,
fetcherTimeout: fetcher[data.proof.request.fetcher].timeout
fetcherTimeout: fetcher[data.proof.request.fetcher].timeout,
}
fetcher.http.fn(requestData, opts)
.then(res => {
fetcher.http
.fn(requestData, opts)
.then((res) => {
return resolve({
fetcher: 'http',
data: data,
viaProxy: true,
result: res
result: res,
})
})
.catch(err => {
.catch((err) => {
return reject(err)
})
})
@ -152,15 +162,15 @@ const createProxyRequestPromise = (data, opts) => {
const createFallbackRequestPromise = (data, opts) => {
return new Promise((resolve, reject) => {
createDefaultRequestPromise(data, opts)
.then(res => {
.then((res) => {
return resolve(res)
})
.catch(err1 => {
.catch((err1) => {
createProxyRequestPromise(data, opts)
.then(res => {
.then((res) => {
return resolve(res)
})
.catch(err2 => {
.catch((err2) => {
return reject([err1, err2])
})
})

View file

@ -21,7 +21,7 @@ const validUrl = require('valid-url')
const jsdom = require('jsdom')
const { client, xml } = require('@xmpp/client')
const debug = require('@xmpp/debug')
const irc = require("irc-upd")
const irc = require('irc-upd')
require('dotenv').config()
const xmpp_service = process.env.XMPP_SERVICE || null
@ -129,28 +129,28 @@ router.get('/get/json/:url', (req, res) => {
bentReq(req.params.url, 'json', {
Accept: 'application/json',
})
.then(async (result) => {
return await result.json()
})
.then(async (result) => {
return res.status(200).json({ url: req.params.url, content: result })
})
.catch((e) => {
return res.status(400).send({ error: e })
})
.then(async (result) => {
return await result.json()
})
.then(async (result) => {
return res.status(200).json({ url: req.params.url, content: result })
})
.catch((e) => {
return res.status(400).send({ error: e })
})
})
router.get('/get/text/:url', (req, res) => {
bentReq(req.params.url)
.then(async (result) => {
return await result.text()
})
.then(async (result) => {
return res.status(200).json({ url: req.params.url, content: result })
})
.catch((e) => {
return res.status(400).send({ error: e })
})
.then(async (result) => {
return await result.text()
})
.then(async (result) => {
return res.status(200).json({ url: req.params.url, content: result })
})
.catch((e) => {
return res.status(400).send({ error: e })
})
})
router.get('/get/dns/:hostname', async (req, res) => {
@ -218,12 +218,15 @@ router.get('/get/xmpp/:xmppid/:xmppdata', async (req, res) => {
break
default:
vcard = dom.window.document.querySelector(req.params.xmppdata).textContent
vcard = dom.window.document.querySelector(req.params.xmppdata)
.textContent
break
}
return res.status(200).json(vcard)
} catch (error) {
return res.status(400).json({ message: 'Request could not be fulfilled', error: error })
return res
.status(400)
.json({ message: 'Request could not be fulfilled', error: error })
}
})
@ -232,19 +235,29 @@ router.get('/get/twitter/:tweetid', async (req, res) => {
return res.status(500).json('Twitter not enabled on server')
}
bentReq(`https://api.twitter.com/1.1/statuses/show.json?id=${req.params.tweetid}`, null, {
Accept: 'application/json',
Authorization: `Bearer ${twitter_bearer_token}`
})
.then(async (data) => {
return await data.json()
})
.then((data) => {
return res.status(200).json({ data: data, message: 'Success', error: {} })
})
.catch((error) => {
return res.status(error.statusCode || 400).json({ data: [], message: 'Request could not be fulfilled', error: error })
})
bentReq(
`https://api.twitter.com/1.1/statuses/show.json?id=${req.params.tweetid}`,
null,
{
Accept: 'application/json',
Authorization: `Bearer ${twitter_bearer_token}`,
}
)
.then(async (data) => {
return await data.json()
})
.then((data) => {
return res.status(200).json({ data: data, message: 'Success', error: {} })
})
.catch((error) => {
return res
.status(error.statusCode || 400)
.json({
data: [],
message: 'Request could not be fulfilled',
error: error,
})
})
})
router.get('/get/matrix/:matrixroomid/:matrixeventid', async (req, res) => {
@ -255,17 +268,23 @@ router.get('/get/matrix/:matrixroomid/:matrixeventid', async (req, res) => {
const url = `https://${matrix_instance}/_matrix/client/r0/rooms/${req.params.matrixroomid}/event/${req.params.matrixeventid}?access_token=${matrix_access_token}`
bentReq(url, null, {
Accept: 'application/json'
})
.then(async (data) => {
return await data.json()
})
.then((data) => {
return res.status(200).json({ data: data, message: 'Success', error: {} })
})
.catch((error) => {
return res.status(error.statusCode || 400).json({ data: [], message: 'Request could not be fulfilled', error: error })
Accept: 'application/json',
})
.then(async (data) => {
return await data.json()
})
.then((data) => {
return res.status(200).json({ data: data, message: 'Success', error: {} })
})
.catch((error) => {
return res
.status(error.statusCode || 400)
.json({
data: [],
message: 'Request could not be fulfilled',
error: error,
})
})
})
router.get('/get/irc/:ircserver/:ircnick', async (req, res) => {
@ -289,15 +308,23 @@ router.get('/get/irc/:ircserver/:ircnick', async (req, res) => {
client.addListener('notice', (nick, to, text, message) => {
if (reKey.test(text)) {
const match = text.match(reKey)
keys.push(match[1]);
keys.push(match[1])
}
if (reEnd.test(text)) {
client.disconnect()
return res.status(200).json({ data: keys, message: 'Success', error: {} })
return res
.status(200)
.json({ data: keys, message: 'Success', error: {} })
}
})
} catch (error) {
return res.status(400).json({ data: [], message: 'Request could not be fulfilled', error: error })
return res
.status(400)
.json({
data: [],
message: 'Request could not be fulfilled',
error: error,
})
}
})

View file

@ -45,7 +45,8 @@ router.get('/', async (req, res) => {
})
// HTTP route
router.get('/get/http',
router.get(
'/get/http',
query('url').isURL(),
query('format').isIn([E.ProofFormat.JSON, E.ProofFormat.TEXT]),
(req, res) => {
@ -54,49 +55,62 @@ router.get('/get/http',
return res.status(400).json({ errors: errors.array() })
}
fetcher
.http.fn(req.query, opts)
.then(result => {
fetcher.http
.fn(req.query, opts)
.then((result) => {
switch (req.query.format) {
case E.ProofFormat.JSON:
return res.status(200).json(result)
break;
break
case E.ProofFormat.TEXT:
return res.status(200).send(result)
break;
break
}
})
.catch(err => {
return res.status(400).json({ errors: err.message ? err.message : err })
})
})
// DNS route
router.get('/get/dns',
query('domain').isFQDN(),
(req, res) => {
const errors = validationResult(req)
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() })
}
fetcher
.dns.fn(req.query, opts)
.then((data) => {
return res.status(200).send(data)
})
.catch((err) => {
return res.status(400).json({ errors: err.message ? err.message : err })
})
}
)
// DNS route
router.get('/get/dns', query('domain').isFQDN(), (req, res) => {
const errors = validationResult(req)
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() })
}
fetcher.dns
.fn(req.query, opts)
.then((data) => {
return res.status(200).send(data)
})
.catch((err) => {
return res.status(400).json({ errors: err.message ? err.message : err })
})
})
// XMPP route
router.get('/get/xmpp',
router.get(
'/get/xmpp',
query('id').isEmail(),
query('field').isIn(['fn','number','userid','url','bday','nickname','note','desc']),
query('field').isIn([
'fn',
'number',
'userid',
'url',
'bday',
'nickname',
'note',
'desc',
]),
async (req, res) => {
if (!opts.claims.xmpp.service || !opts.claims.xmpp.username || !opts.claims.xmpp.password) {
if (
!opts.claims.xmpp.service ||
!opts.claims.xmpp.username ||
!opts.claims.xmpp.password
) {
return res.status(501).json({ errors: 'XMPP not enabled on server' })
}
const errors = validationResult(req)
@ -104,40 +118,40 @@ router.get('/get/xmpp',
return res.status(400).json({ errors: errors.array() })
}
fetcher
.xmpp.fn(req.query, opts)
fetcher.xmpp
.fn(req.query, opts)
.then((data) => {
return res.status(200).send(data)
})
.catch((err) => {
return res.status(400).json({ errors: err.message ? err.message : err })
})
})
}
)
// Twitter route
router.get('/get/twitter',
query('tweetId').isInt(),
async (req, res) => {
if (!opts.claims.twitter.bearerToken) {
return res.status(501).json({ errors: 'Twitter not enabled on server' })
}
const errors = validationResult(req)
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() })
}
router.get('/get/twitter', query('tweetId').isInt(), async (req, res) => {
if (!opts.claims.twitter.bearerToken) {
return res.status(501).json({ errors: 'Twitter not enabled on server' })
}
const errors = validationResult(req)
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() })
}
fetcher
.twitter.fn(req.query, opts)
.then((data) => {
return res.status(200).send(data)
})
.catch((err) => {
return res.status(400).json({ errors: err.message ? err.message : err })
})
fetcher.twitter
.fn(req.query, opts)
.then((data) => {
return res.status(200).send(data)
})
.catch((err) => {
return res.status(400).json({ errors: err.message ? err.message : err })
})
})
// Matrix route
router.get('/get/matrix',
router.get(
'/get/matrix',
query('roomId').isString(),
query('eventId').isString(),
async (req, res) => {
@ -149,40 +163,40 @@ router.get('/get/matrix',
return res.status(400).json({ errors: errors.array() })
}
fetcher
.matrix.fn(req.query, opts)
fetcher.matrix
.fn(req.query, opts)
.then((data) => {
return res.status(200).send(data)
})
.catch((err) => {
return res.status(400).json({ errors: err.message ? err.message : err })
})
})
}
)
// IRC route
router.get('/get/irc',
query('nick').isString(),
async (req, res) => {
if (!opts.claims.irc.nick) {
return res.status(501).json({ errors: 'IRC not enabled on server' })
}
const errors = validationResult(req)
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() })
}
router.get('/get/irc', query('nick').isString(), async (req, res) => {
if (!opts.claims.irc.nick) {
return res.status(501).json({ errors: 'IRC not enabled on server' })
}
const errors = validationResult(req)
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() })
}
fetcher
.irc.fn(req.query, opts)
.then((data) => {
return res.status(200).send(data)
})
.catch((err) => {
return res.status(400).json({ errors: err.message ? err.message : err })
})
fetcher.irc
.fn(req.query, opts)
.then((data) => {
return res.status(200).send(data)
})
.catch((err) => {
return res.status(400).json({ errors: err.message ? err.message : err })
})
})
// Gitlab route
router.get('/get/gitlab',
router.get(
'/get/gitlab',
query('domain').isFQDN(),
query('username').isString(),
async (req, res) => {
@ -191,14 +205,15 @@ router.get('/get/gitlab',
return res.status(400).json({ errors: errors.array() })
}
fetcher
.gitlab.fn(req.query, opts)
fetcher.gitlab
.fn(req.query, opts)
.then((data) => {
return res.status(200).send(data)
})
.catch((err) => {
return res.status(400).json({ errors: err.message ? err.message : err })
})
})
}
)
module.exports = router

View file

@ -28,7 +28,9 @@ app.get('/', (req, res) => {
return res.status(200).json({ message: 'Available endpoints: /api' })
})
app.get('/api', (req, res) => {
return res.status(200).json({ message: 'Available API versions: /api/1, /api/2' })
return res
.status(200)
.json({ message: 'Available API versions: /api/1, /api/2' })
})
app.all('*', (req, res) => {
return res.status(404).json({ message: 'API endpoint not found' })

View file

@ -22,10 +22,12 @@ const process = (signature) => {
let sigData,
result = {
fingerprint: null,
users: [{
userData: {},
claims: [],
}],
users: [
{
userData: {},
claims: [],
},
],
primaryUserIndex: null,
key: {
data: null,
@ -88,7 +90,9 @@ const process = (signature) => {
if (!result.key.data) {
try {
const match = preferredKeyServer.match(/^(.*\:\/\/)?([^/]*)(?:\/)?$/i)
result.key.uri = `hkp:${match[2]}:${issuerKeyId ? issuerKeyId : signersUserId}`
result.key.uri = `hkp:${match[2]}:${
issuerKeyId ? issuerKeyId : signersUserId
}`
result.key.data = await keys.fetch.uri(result.key.uri)
result.key.fetchMethod = 'hkp'
} catch (e) {
@ -99,7 +103,7 @@ const process = (signature) => {
result.fingerprint = result.key.data.keyPacket.getFingerprint()
result.users[0].claims.forEach(claim => {
result.users[0].claims.forEach((claim) => {
claim.fingerprint = result.fingerprint
})
@ -107,7 +111,7 @@ const process = (signature) => {
let userData
if (signersUserId) {
result.key.data.users.forEach(user => {
result.key.data.users.forEach((user) => {
if (user.userId.email == signersUserId) {
userData = user
}

View file

@ -25,13 +25,13 @@ const generateProxyURL = (type, data, opts) => {
let queryStrings = []
Object.keys(data).forEach(key => {
Object.keys(data).forEach((key) => {
queryStrings.push(`${key}=${encodeURIComponent(data[key])}`)
})
return `http://${
opts.proxy.hostname
}/api/2/get/${type}?${queryStrings.join('&')}`
return `http://${opts.proxy.hostname}/api/2/get/${type}?${queryStrings.join(
'&'
)}`
}
const generateClaim = (fingerprint, format) => {

View file

@ -16,12 +16,7 @@ limitations under the License.
const utils = require('./utils')
const E = require('./enums')
const runJSON = (
proofData,
checkPath,
checkClaim,
checkRelation
) => {
const runJSON = (proofData, checkPath, checkClaim, checkRelation) => {
let re
if (!proofData) {
@ -31,7 +26,9 @@ const runJSON = (
if (Array.isArray(proofData)) {
let result = false
proofData.forEach((item, i) => {
if (result) { return }
if (result) {
return
}
result = runJSON(item, checkPath, checkClaim, checkRelation)
})
return result
@ -46,8 +43,10 @@ const runJSON = (
break
case E.ClaimRelation.EQUALS:
return proofData.replace(/\r?\n|\r|\\/g, '').toLowerCase() ==
return (
proofData.replace(/\r?\n|\r|\\/g, '').toLowerCase() ==
checkClaim.toLowerCase()
)
break
case E.ClaimRelation.ONEOF: