feat: add logging to openpgp profiles

This commit is contained in:
Yarmo Mackenbach 2023-09-22 09:48:55 +02:00
parent a812bb0866
commit 09d2292557
No known key found for this signature in database
GPG key ID: 3C57D093219103A3
2 changed files with 30 additions and 3 deletions

View file

@ -62,7 +62,7 @@ app.use((req, res, next) => {
httpContext.set('requestPath', req.path) httpContext.set('requestPath', req.path)
httpContext.set('requestIp', req.ip) httpContext.set('requestIp', req.ip)
logger.info(`Handle a request`, logger.info('Handle a request',
{ component: 'http_server', action: 'request' }) { component: 'http_server', action: 'request' })
next() next()

View file

@ -46,6 +46,9 @@ if (process.env.ENABLE_EXPERIMENTAL_CACHE) {
const fetchWKD = (id) => { const fetchWKD = (id) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
(async () => { (async () => {
logger.debug('Fetching an OpenPGP profile via WKD',
{ component: 'wkd_profile_fetcher', action: 'start', profile_id: id })
let publicKey = null let publicKey = null
let profile = null let profile = null
let fetchURL = null let fetchURL = null
@ -83,7 +86,10 @@ const fetchWKD = (id) => {
return null return null
} }
}) })
} catch (e) { } catch (errorAdvanced) {
logger.debug('Failed to fetch an OpenPGP profile via WKD (advanced URL)',
{ component: 'hkp_profile_fetcher', action: 'failure', profile_id: id, error: errorAdvanced.message })
try { try {
plaintext = await got(urlDirect).then((response) => { plaintext = await got(urlDirect).then((response) => {
if (response.statusCode === 200) { if (response.statusCode === 200) {
@ -93,7 +99,10 @@ const fetchWKD = (id) => {
return null return null
} }
}) })
} catch (error) { } catch (errorDirect) {
logger.debug('Failed to fetch an OpenPGP profile via WKD (direct URL)',
{ component: 'hkp_profile_fetcher', action: 'failure', profile_id: id, error: errorDirect.message })
return reject(new Error('No public keys could be fetched using WKD')) return reject(new Error('No public keys could be fetched using WKD'))
} }
} }
@ -107,6 +116,9 @@ const fetchWKD = (id) => {
binaryKey: plaintext binaryKey: plaintext
}) })
} catch (error) { } catch (error) {
logger.debug('Failed to fetch an OpenPGP profile via WKD (reading key)',
{ component: 'hkp_profile_fetcher', action: 'failure', profile_id: id, error: error.message })
return reject(new Error('No public keys could be read from the data fetched using WKD')) return reject(new Error('No public keys could be read from the data fetched using WKD'))
} }
@ -117,6 +129,9 @@ const fetchWKD = (id) => {
try { try {
profile = await doipjs.openpgp.parsePublicKey(publicKey) profile = await doipjs.openpgp.parsePublicKey(publicKey)
} catch (error) { } catch (error) {
logger.debug('Failed to fetch an OpenPGP profile via WKD (parsing key)',
{ component: 'hkp_profile_fetcher', action: 'failure', profile_id: id, error: error.message })
return reject(new Error('No public keys could be fetched using WKD')) return reject(new Error('No public keys could be fetched using WKD'))
} }
@ -132,6 +147,9 @@ const fetchWKD = (id) => {
{ component: 'openpgp_cache', action: 'store_wkd' }) { component: 'openpgp_cache', action: 'store_wkd' })
} }
logger.debug('Fetched an OpenPGP profile via WKD',
{ component: 'wkd_profile_fetcher', action: 'done', profile_id: id })
resolve(profile) resolve(profile)
})() })()
}) })
@ -140,6 +158,9 @@ const fetchWKD = (id) => {
const fetchHKP = (id, keyserverDomain) => { const fetchHKP = (id, keyserverDomain) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
(async () => { (async () => {
logger.debug('Fetching an OpenPGP profile via HKP',
{ component: 'hkp_profile_fetcher', action: 'start', profile_id: id, keyserver_domain: keyserverDomain || '' })
let profile = null let profile = null
let fetchURL = null let fetchURL = null
@ -174,6 +195,9 @@ const fetchHKP = (id, keyserverDomain) => {
try { try {
profile = await doipjs.openpgp.fetchHKP(query, keyserverDomainNormalized) profile = await doipjs.openpgp.fetchHKP(query, keyserverDomainNormalized)
} catch (error) { } catch (error) {
logger.debug('Failed to fetch an OpenPGP profile via HKP',
{ component: 'hkp_profile_fetcher', action: 'failure', profile_id: id, keyserver_domain: keyserverDomain || '', error: error.message })
profile = null profile = null
} }
} }
@ -193,6 +217,9 @@ const fetchHKP = (id, keyserverDomain) => {
{ component: 'openpgp_cache', action: 'store_hkp' }) { component: 'openpgp_cache', action: 'store_hkp' })
} }
logger.debug('Fetched an OpenPGP profile via HKP',
{ component: 'hkp_profile_fetcher', action: 'done', profile_id: id, keyserver_domain: keyserverDomain || '' })
resolve(profile) resolve(profile)
})() })()
}) })