Add data to API output

This commit is contained in:
Yarmo Mackenbach 2022-09-16 18:57:47 +02:00
parent a5b9eeea8e
commit f3b513a5f5
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
2 changed files with 73 additions and 1 deletions

View file

@ -134,6 +134,16 @@ const apiProfileSchema = {
verification: {
type: "object"
},
summary: {
type: "object",
properties: {
profileName: { type: "string" },
profileURL: { type: "string" },
serviceProviderName: { type: "string" },
isVerificationDone: { type: "boolean" },
isVerified: { type: "boolean" },
}
}
}
}
},
@ -153,6 +163,12 @@ const apiProfileSchema = {
},
},
},
keyoxide: {
type: "object",
properties: {
url: { type: "string" },
}
},
extra: {
type: "object",
properties: {
@ -163,7 +179,7 @@ const apiProfileSchema = {
type: "array"
},
},
required: ["keyData", "extra", "errors"],
required: ["keyData", "keyoxide", "extra", "errors"],
additionalProperties: false
}
@ -237,6 +253,33 @@ const sanitize = (data) => {
return data
}
const addSummaryToClaims = (data) => {
// To be removed when data is added by DOIP library
for (let userIndex = 0; userIndex < data.keyData.users.length; userIndex++) {
const user = data.keyData.users[userIndex]
for (let claimIndex = 0; claimIndex < user.claims.length; claimIndex++) {
const claim = user.claims[claimIndex]
const isVerificationDone = claim.status === "verified"
const isVerified = isVerificationDone ? claim.verification.result : false
const isAmbiguous = isVerified
? false
: claim.matches.length > 1 || claim.matches[0].match.isAmbiguous
data.keyData.users[userIndex].claims[claimIndex].summary = {
profileName: !isAmbiguous ? claim.matches[0].profile.display : claim.uri,
profileURL: !isAmbiguous ? claim.matches[0].profile.uri : "",
serviceProviderName: !isAmbiguous ? claim.matches[0].serviceprovider.name : "",
isVerificationDone: isVerificationDone,
isVerified: isVerified,
}
}
}
return data
}
router.get('/profile/fetch',
check('query').exists(),
check('protocol').optional().toLowerCase().isIn(["hkp", "wkd"]),
@ -292,6 +335,9 @@ router.get('/profile/fetch',
data.errors = [error.message]
}
// Add missing data
data = addSummaryToClaims(data)
let statusCode = 200
if (data.errors.length > 0) {
statusCode = 500
@ -322,6 +368,9 @@ router.get('/profile/verify',
data.errors = [error.message]
}
// Add missing data
data = addSummaryToClaims(data)
let statusCode = 200
if (data.errors.length > 0) {
statusCode = 500

View file

@ -41,9 +41,13 @@ const generateWKDProfile = async (id) => {
keyData.key.data = {}
keyData = processKeyData(keyData)
let keyoxideData = {}
keyoxideData.url = `https://${process.env.DOMAIN}/wkd/${id}`
return {
key: key,
keyData: keyData,
keyoxide: keyoxideData,
extra: await computeExtraData(key, keyData),
errors: []
}
@ -52,6 +56,7 @@ const generateWKDProfile = async (id) => {
return {
key: {},
keyData: {},
keyoxide: {},
extra: {},
errors: [err.message]
}
@ -68,9 +73,17 @@ const generateHKPProfile = async (id, keyserverDomain) => {
keyData.key.data = {}
keyData = processKeyData(keyData)
let keyoxideData = {}
if (!keyserverDomain || keyserverDomain === 'keys.openpgp.org') {
keyoxideData.url = `https://${process.env.DOMAIN}/hkp/${id}`
} else {
keyoxideData.url = `https://${process.env.DOMAIN}/hkp/${keyserverDomain}/${id}`
}
return {
key: key,
keyData: keyData,
keyoxide: keyoxideData,
extra: await computeExtraData(key, keyData),
errors: []
}
@ -79,6 +92,7 @@ const generateHKPProfile = async (id, keyserverDomain) => {
return {
key: {},
keyData: {},
keyoxide: {},
extra: {},
errors: [err.message]
}
@ -94,9 +108,12 @@ const generateSignatureProfile = async (signature) => {
keyData.key.data = {}
keyData = processKeyData(keyData)
let keyoxideData = {}
return {
key: key,
keyData: keyData,
keyoxide: keyoxideData,
extra: await computeExtraData(key, keyData),
errors: []
}
@ -105,6 +122,7 @@ const generateSignatureProfile = async (signature) => {
return {
key: {},
keyData: {},
keyoxide: {},
extra: {},
errors: [err.message]
}
@ -121,9 +139,13 @@ const generateKeybaseProfile = async (username, fingerprint) => {
keyData.key.data = {}
keyData = processKeyData(keyData)
let keyoxideData = {}
keyoxideData.url = `https://${process.env.DOMAIN}/keybase/${username}/${fingerprint}`
return {
key: key,
keyData: keyData,
keyoxide: keyoxideData,
extra: await computeExtraData(key, keyData),
errors: []
}
@ -132,6 +154,7 @@ const generateKeybaseProfile = async (username, fingerprint) => {
return {
key: {},
keyData: {},
keyoxide: {},
extra: {},
errors: [err.message]
}