mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
merge
This commit is contained in:
parent
2d03ae938a
commit
2abf228ca9
@ -26,21 +26,25 @@ export class Client_1_0 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getPublicKey = async (): Promise<string | undefined> => {
|
getPublicKey = async (): Promise<string | undefined> => {
|
||||||
logger.info(`requestGetPublicKey with endpoint='${this.endpoint}'...`)
|
logger.info('Federation: getPublicKey from endpoint', this.endpoint)
|
||||||
try {
|
try {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
const { data, errors, headers, status } = await this.client.rawRequest(getPublicKey, {})
|
const { data } = await this.client.rawRequest(getPublicKey, {})
|
||||||
logger.debug(`Response-Data:`, data, errors, headers, status)
|
|
||||||
if (data) {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||||
logger.debug(`Response-PublicKey:`, data.getPublicKey.publicKey)
|
if (!data?.getPublicKey?.publicKey) {
|
||||||
logger.info(`requestGetPublicKey processed successfully`)
|
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
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access
|
||||||
return data.getPublicKey.publicKey
|
return data.getPublicKey.publicKey
|
||||||
}
|
|
||||||
logger.warn(`requestGetPublicKey processed without response data`)
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new LogError(`Request-Error:`, err)
|
logger.warn('Federation: getPublicKey failed for endpoint', this.endpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
import { IsNull } from '@dbTools/typeorm'
|
import { IsNull } from '@dbTools/typeorm'
|
||||||
import { FederatedCommunity as DbFederatedCommunity } from '@entity/FederatedCommunity'
|
import { FederatedCommunity as DbFederatedCommunity } from '@entity/FederatedCommunity'
|
||||||
|
|
||||||
import { LogError } from '@/server/LogError'
|
|
||||||
import { backendLogger as logger } from '@/server/logger'
|
import { backendLogger as logger } from '@/server/logger'
|
||||||
|
|
||||||
import { Client } from './client/Client'
|
import { Client } from './client/Client'
|
||||||
@ -33,39 +32,24 @@ export async function validateCommunities(): Promise<void> {
|
|||||||
logger.debug('Federation: dbCom', dbCom)
|
logger.debug('Federation: dbCom', dbCom)
|
||||||
const apiValueStrings: string[] = Object.values(ApiVersionType)
|
const apiValueStrings: string[] = Object.values(ApiVersionType)
|
||||||
logger.debug(`suppported ApiVersions=`, apiValueStrings)
|
logger.debug(`suppported ApiVersions=`, apiValueStrings)
|
||||||
if (apiValueStrings.includes(dbCom.apiVersion)) {
|
if (!apiValueStrings.includes(dbCom.apiVersion)) {
|
||||||
logger.debug(
|
logger.warn('Federation: dbCom with unsupported apiVersion', dbCom.endPoint, dbCom.apiVersion)
|
||||||
`Federation: validate publicKey for dbCom: ${dbCom.id} with apiVersion=${dbCom.apiVersion}`,
|
continue
|
||||||
)
|
}
|
||||||
try {
|
try {
|
||||||
const pubKey = await Client.getInstance(dbCom)?.getPublicKey()
|
const client = Client.getInstance(dbCom)
|
||||||
logger.info(
|
const pubKey = await client?.getPublicKey()
|
||||||
'Federation: received publicKey from endpoint',
|
|
||||||
pubKey,
|
|
||||||
`${dbCom.endPoint}/${dbCom.apiVersion}`,
|
|
||||||
)
|
|
||||||
if (pubKey && pubKey === dbCom.publicKey.toString()) {
|
if (pubKey && pubKey === dbCom.publicKey.toString()) {
|
||||||
logger.info(`Federation: matching publicKey: ${pubKey}`)
|
|
||||||
await DbFederatedCommunity.update({ id: dbCom.id }, { verifiedAt: new Date() })
|
await DbFederatedCommunity.update({ id: dbCom.id }, { verifiedAt: new Date() })
|
||||||
logger.debug(`Federation: updated dbCom: ${JSON.stringify(dbCom)}`)
|
|
||||||
} else {
|
} else {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
`Federation: received not matching publicKey -> received: ${
|
'Federation: received not matching publicKey:',
|
||||||
pubKey || 'null'
|
pubKey,
|
||||||
}, expected: ${dbCom.publicKey.toString()} `,
|
dbCom.publicKey.toString(),
|
||||||
)
|
)
|
||||||
// DbCommunity.delete({ id: dbCom.id })
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!(err instanceof LogError)) {
|
|
||||||
logger.error(`Error:`, err)
|
logger.error(`Error:`, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
logger.warn(
|
|
||||||
`Federation: dbCom: ${dbCom.id} with unsupported apiVersion=${dbCom.apiVersion}; supported versions`,
|
|
||||||
apiValueStrings,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user