mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
remove versioned graphql models
This commit is contained in:
parent
022c3d0173
commit
885834338f
@ -1,12 +1,11 @@
|
||||
import { GraphQLClient, gql } from 'graphql-request'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
// eslint-disable-next-line camelcase
|
||||
import { V1_0_FdCommunity } from '@/federation/graphql/1_0/model/V1_0_FdCommunity'
|
||||
import { Community as DbCommunity } from '@entity/Community'
|
||||
|
||||
// eslint-disable-next-line camelcase
|
||||
export async function requestGetPublicKey(fdCom: V1_0_FdCommunity): Promise<string | undefined> {
|
||||
let endpoint = fdCom.url.endsWith('/') ? fdCom.url : fdCom.url + '/'
|
||||
endpoint = `${endpoint}${fdCom.apiVersion}/getPublicKey`
|
||||
export async function requestGetPublicKey(dbCom: DbCommunity): Promise<string | undefined> {
|
||||
let endpoint = dbCom.endPoint.endsWith('/') ? dbCom.endPoint : dbCom.endPoint + '/'
|
||||
endpoint = `${endpoint}${dbCom.apiVersion}/getPublicKey`
|
||||
logger.info(`requestGetPublicKey with endpoint='${endpoint}'...`)
|
||||
|
||||
const graphQLClient = new GraphQLClient(endpoint, {
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
import { GraphQLClient, gql } from 'graphql-request'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
// eslint-disable-next-line camelcase
|
||||
import { V1_1_FdCommunity } from '@/federation/graphql/1_1/model/V1_1_FdCommunity'
|
||||
import { Community as DbCommunity } from '@entity/Community'
|
||||
|
||||
// eslint-disable-next-line camelcase
|
||||
export async function requestGetPublicKey(fdCom: V1_1_FdCommunity): Promise<string | undefined> {
|
||||
let endpoint = fdCom.url.endsWith('/') ? fdCom.url : fdCom.url + '/'
|
||||
endpoint = `${endpoint}${fdCom.apiVersion}/getPublicKey`
|
||||
export async function requestGetPublicKey(dbCom: DbCommunity): Promise<string | undefined> {
|
||||
let endpoint = dbCom.endPoint.endsWith('/') ? dbCom.endPoint : dbCom.endPoint + '/'
|
||||
endpoint = `${endpoint}${dbCom.apiVersion}/getPublicKey`
|
||||
logger.info(`requestGetPublicKey with endpoint='${endpoint}'...`)
|
||||
|
||||
const graphQLClient = new GraphQLClient(endpoint, {
|
||||
|
||||
@ -1,42 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
import { ObjectType, Field } from 'type-graphql'
|
||||
import { Community as DbCommunity } from '@entity/Community'
|
||||
|
||||
@ObjectType()
|
||||
// eslint-disable-next-line camelcase
|
||||
export class V1_0_FdCommunity {
|
||||
constructor(dbCommunity: DbCommunity) {
|
||||
this.apiVersion = dbCommunity.apiVersion
|
||||
this.createdAt = dbCommunity.createdAt
|
||||
this.id = dbCommunity.id
|
||||
this.lastAnnouncedAt = dbCommunity.lastAnnouncedAt
|
||||
this.publicKey = dbCommunity.publicKey.toString('hex')
|
||||
this.updatedAt = dbCommunity.updatedAt
|
||||
this.url = dbCommunity.endPoint
|
||||
}
|
||||
|
||||
@Field(() => Number, { nullable: true })
|
||||
id: number
|
||||
|
||||
@Field(() => String)
|
||||
publicKey: string
|
||||
|
||||
@Field(() => String)
|
||||
apiVersion: string
|
||||
|
||||
@Field(() => String)
|
||||
url: string
|
||||
|
||||
@Field(() => Date)
|
||||
createdAt: Date
|
||||
|
||||
@Field(() => Date, { nullable: true })
|
||||
lastAnnouncedAt: Date | null
|
||||
|
||||
@Field(() => Date, { nullable: true })
|
||||
verifiedAt: Date | null
|
||||
|
||||
@Field(() => Date, { nullable: true })
|
||||
updatedAt: Date | null
|
||||
}
|
||||
@ -1,42 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
import { ObjectType, Field } from 'type-graphql'
|
||||
import { Community as DbCommunity } from '@entity/Community'
|
||||
|
||||
@ObjectType()
|
||||
// eslint-disable-next-line camelcase
|
||||
export class V1_1_FdCommunity {
|
||||
constructor(dbCommunity: DbCommunity) {
|
||||
this.apiVersion = dbCommunity.apiVersion
|
||||
this.createdAt = dbCommunity.createdAt
|
||||
this.id = dbCommunity.id
|
||||
this.lastAnnouncedAt = dbCommunity.lastAnnouncedAt
|
||||
this.publicKey = dbCommunity.publicKey.toString('hex')
|
||||
this.updatedAt = dbCommunity.updatedAt
|
||||
this.url = dbCommunity.endPoint
|
||||
}
|
||||
|
||||
@Field(() => Number, { nullable: true })
|
||||
id: number
|
||||
|
||||
@Field(() => String)
|
||||
publicKey: string
|
||||
|
||||
@Field(() => String)
|
||||
apiVersion: string
|
||||
|
||||
@Field(() => String)
|
||||
url: string
|
||||
|
||||
@Field(() => Date)
|
||||
createdAt: Date
|
||||
|
||||
@Field(() => Date, { nullable: true })
|
||||
lastAnnouncedAt: Date | null
|
||||
|
||||
@Field(() => Date, { nullable: true })
|
||||
verifiedAt: Date | null
|
||||
|
||||
@Field(() => Date, { nullable: true })
|
||||
updatedAt: Date | null
|
||||
}
|
||||
@ -4,10 +4,6 @@ import { IsNull } from '@dbTools/typeorm'
|
||||
import { requestGetPublicKey as v1_0_requestGetPublicKey } from './client/1_0/FederationClient'
|
||||
// eslint-disable-next-line camelcase
|
||||
import { requestGetPublicKey as v1_1_requestGetPublicKey } from './client/1_1/FederationClient'
|
||||
// eslint-disable-next-line camelcase
|
||||
import { V1_0_FdCommunity } from './graphql/1_0/model/V1_0_FdCommunity'
|
||||
// eslint-disable-next-line camelcase
|
||||
import { V1_1_FdCommunity } from './graphql/1_1/model/V1_1_FdCommunity'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
import { ApiVersionType } from './enum/apiVersionType'
|
||||
|
||||
@ -29,29 +25,22 @@ export async function startValidateCommunities(timerInterval: number): Promise<v
|
||||
if (dbCommunities) {
|
||||
dbCommunities.forEach(async function (dbCom) {
|
||||
logger.debug(`Federation: dbCom: ${JSON.stringify(dbCom)}`)
|
||||
const fdCom = getVersionedFdCommunity(dbCom)
|
||||
if (!fdCom) {
|
||||
logger.warn(
|
||||
`Federation: unsupported ApiVersion ${dbCom.apiVersion} of Community with id= ${dbCom.id}`,
|
||||
)
|
||||
return
|
||||
}
|
||||
const apiValueStrings: string[] = Object.values(ApiVersionType)
|
||||
logger.debug(`suppported ApiVersions=`, apiValueStrings)
|
||||
if (apiValueStrings.includes(fdCom.apiVersion)) {
|
||||
if (apiValueStrings.includes(dbCom.apiVersion)) {
|
||||
logger.debug(
|
||||
`Federation: validate publicKey for dbCom: ${dbCom.id} with apiVersion=${dbCom.apiVersion}`,
|
||||
)
|
||||
const pubKey = await invokeVersionedRequestGetPublicKey(fdCom)
|
||||
const pubKey = await invokeVersionedRequestGetPublicKey(dbCom)
|
||||
logger.debug(`Federation: received publicKey: ${pubKey}`)
|
||||
if (pubKey && pubKey === fdCom.publicKey) {
|
||||
if (pubKey && pubKey === dbCom.publicKey.toString('hex')) {
|
||||
logger.debug(`Federation: matching publicKey: ${pubKey}`)
|
||||
DbCommunity.update({ id: fdCom.id }, { verifiedAt: new Date() })
|
||||
DbCommunity.update({ id: dbCom.id }, { verifiedAt: new Date() })
|
||||
logger.debug(`Federation: updated dbCom: ${JSON.stringify(dbCom)}`)
|
||||
}
|
||||
} else {
|
||||
logger.debug(
|
||||
`Federation: dbCom: ${fdCom.id} with unsupported apiVersion=${fdCom.apiVersion}; supported versions=${apiValueStrings}`,
|
||||
`Federation: dbCom: ${dbCom.id} with unsupported apiVersion=${dbCom.apiVersion}; supported versions=${apiValueStrings}`,
|
||||
)
|
||||
}
|
||||
})
|
||||
@ -66,27 +55,12 @@ function sleep(ms: number) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms))
|
||||
}
|
||||
|
||||
function getVersionedFdCommunity(dbCom: DbCommunity) {
|
||||
async function invokeVersionedRequestGetPublicKey(dbCom: DbCommunity): Promise<string | undefined> {
|
||||
switch (dbCom.apiVersion) {
|
||||
case ApiVersionType.V1_0:
|
||||
// eslint-disable-next-line new-cap
|
||||
return new V1_0_FdCommunity(dbCom)
|
||||
return v1_0_requestGetPublicKey(dbCom)
|
||||
case ApiVersionType.V1_1:
|
||||
// eslint-disable-next-line new-cap
|
||||
return new V1_1_FdCommunity(dbCom)
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
async function invokeVersionedRequestGetPublicKey(
|
||||
// eslint-disable-next-line camelcase
|
||||
fdCom: V1_0_FdCommunity | V1_1_FdCommunity,
|
||||
): Promise<string | undefined> {
|
||||
switch (fdCom.apiVersion) {
|
||||
case ApiVersionType.V1_0:
|
||||
return v1_0_requestGetPublicKey(fdCom)
|
||||
case ApiVersionType.V1_1:
|
||||
return v1_1_requestGetPublicKey(fdCom)
|
||||
return v1_1_requestGetPublicKey(dbCom)
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user