This commit is contained in:
Ulf Gebhardt 2023-05-04 22:53:55 +02:00
parent 2d03ae938a
commit 2abf228ca9
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
2 changed files with 30 additions and 42 deletions

View File

@ -26,21 +26,25 @@ export class Client_1_0 {
}
getPublicKey = async (): Promise<string | undefined> => {
logger.info(`requestGetPublicKey with endpoint='${this.endpoint}'...`)
logger.info('Federation: getPublicKey from endpoint', this.endpoint)
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { data, errors, headers, status } = await this.client.rawRequest(getPublicKey, {})
logger.debug(`Response-Data:`, data, errors, headers, status)
if (data) {
const { data } = await this.client.rawRequest(getPublicKey, {})
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
logger.debug(`Response-PublicKey:`, data.getPublicKey.publicKey)
logger.info(`requestGetPublicKey processed successfully`)
if (!data?.getPublicKey?.publicKey) {
logger.warn('Federation: getPublicKey without response data from endpoint', this.endpoint)
return
}
logger.info(
'Federation: getPublicKey successfull from endpoint',
this.endpoint,
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
data.getPublicKey.publicKey,
)
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access
return data.getPublicKey.publicKey
}
logger.warn(`requestGetPublicKey processed without response data`)
} catch (err) {
throw new LogError(`Request-Error:`, err)
logger.warn('Federation: getPublicKey failed for endpoint', this.endpoint)
}
}
}

View File

@ -3,7 +3,6 @@
import { IsNull } from '@dbTools/typeorm'
import { FederatedCommunity as DbFederatedCommunity } from '@entity/FederatedCommunity'
import { LogError } from '@/server/LogError'
import { backendLogger as logger } from '@/server/logger'
import { Client } from './client/Client'
@ -33,39 +32,24 @@ export async function validateCommunities(): Promise<void> {
logger.debug('Federation: dbCom', dbCom)
const apiValueStrings: string[] = Object.values(ApiVersionType)
logger.debug(`suppported ApiVersions=`, apiValueStrings)
if (apiValueStrings.includes(dbCom.apiVersion)) {
logger.debug(
`Federation: validate publicKey for dbCom: ${dbCom.id} with apiVersion=${dbCom.apiVersion}`,
)
if (!apiValueStrings.includes(dbCom.apiVersion)) {
logger.warn('Federation: dbCom with unsupported apiVersion', dbCom.endPoint, dbCom.apiVersion)
continue
}
try {
const pubKey = await Client.getInstance(dbCom)?.getPublicKey()
logger.info(
'Federation: received publicKey from endpoint',
pubKey,
`${dbCom.endPoint}/${dbCom.apiVersion}`,
)
const client = Client.getInstance(dbCom)
const pubKey = await client?.getPublicKey()
if (pubKey && pubKey === dbCom.publicKey.toString()) {
logger.info(`Federation: matching publicKey: ${pubKey}`)
await DbFederatedCommunity.update({ id: dbCom.id }, { verifiedAt: new Date() })
logger.debug(`Federation: updated dbCom: ${JSON.stringify(dbCom)}`)
} else {
logger.warn(
`Federation: received not matching publicKey -> received: ${
pubKey || 'null'
}, expected: ${dbCom.publicKey.toString()} `,
'Federation: received not matching publicKey:',
pubKey,
dbCom.publicKey.toString(),
)
// DbCommunity.delete({ id: dbCom.id })
}
} catch (err) {
if (!(err instanceof LogError)) {
logger.error(`Error:`, err)
}
}
} else {
logger.warn(
`Federation: dbCom: ${dbCom.id} with unsupported apiVersion=${dbCom.apiVersion}; supported versions`,
apiValueStrings,
)
}
}
}