mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
rework PR-comments
This commit is contained in:
parent
e3284f4659
commit
70276800e6
@ -10,7 +10,7 @@ Decimal.set({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const constants = {
|
const constants = {
|
||||||
DB_VERSION: '0061-update_communities_table',
|
DB_VERSION: '0060-update_communities_table',
|
||||||
DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0
|
DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0
|
||||||
LOG4JS_CONFIG: 'log4js-config.json',
|
LOG4JS_CONFIG: 'log4js-config.json',
|
||||||
// default log level on production should be info
|
// default log level on production should be info
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { gql } from 'graphql-request'
|
|||||||
import { backendLogger as logger } from '@/server/logger'
|
import { backendLogger as logger } from '@/server/logger'
|
||||||
import { Community as DbCommunity } from '@entity/Community'
|
import { Community as DbCommunity } from '@entity/Community'
|
||||||
import { GraphQLGetClient } from '../GraphQLGetClient'
|
import { GraphQLGetClient } from '../GraphQLGetClient'
|
||||||
|
import LogError from '@/server/LogError'
|
||||||
|
|
||||||
export async function requestGetPublicKey(dbCom: DbCommunity): Promise<string | undefined> {
|
export async function requestGetPublicKey(dbCom: DbCommunity): Promise<string | undefined> {
|
||||||
let endpoint = dbCom.endPoint.endsWith('/') ? dbCom.endPoint : dbCom.endPoint + '/'
|
let endpoint = dbCom.endPoint.endsWith('/') ? dbCom.endPoint : dbCom.endPoint + '/'
|
||||||
@ -18,28 +19,16 @@ export async function requestGetPublicKey(dbCom: DbCommunity): Promise<string |
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
const variables = {}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { data, errors, extensions, headers, status } = await graphQLClient.rawRequest(
|
const { data, errors, extensions, headers, status } = await graphQLClient.rawRequest(query)
|
||||||
query,
|
logger.debug(`Response-Data:`, data, errors, extensions, headers, status)
|
||||||
variables,
|
|
||||||
)
|
|
||||||
logger.debug(
|
|
||||||
`Response-Data: ${JSON.stringify(
|
|
||||||
{ data, errors, extensions, headers, status },
|
|
||||||
undefined,
|
|
||||||
2,
|
|
||||||
)}`,
|
|
||||||
)
|
|
||||||
if (data) {
|
if (data) {
|
||||||
logger.debug(`Response-PublicKey: ${data.getPublicKey.publicKey}`)
|
logger.debug(`Response-PublicKey:`, data.getPublicKey.publicKey)
|
||||||
logger.info(`requestGetPublicKey processed successfully`)
|
logger.info(`requestGetPublicKey processed successfully`)
|
||||||
return data.getPublicKey.publicKey
|
return data.getPublicKey.publicKey
|
||||||
}
|
}
|
||||||
logger.warn(`requestGetPublicKey processed without response data`)
|
logger.warn(`requestGetPublicKey processed without response data`)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(`Request-Error:`, err) // ${JSON.stringify(err)}`)
|
throw new LogError(`Request-Error:`, err)
|
||||||
}
|
}
|
||||||
return undefined
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { gql } from 'graphql-request'
|
|||||||
import { backendLogger as logger } from '@/server/logger'
|
import { backendLogger as logger } from '@/server/logger'
|
||||||
import { Community as DbCommunity } from '@entity/Community'
|
import { Community as DbCommunity } from '@entity/Community'
|
||||||
import { GraphQLGetClient } from '../GraphQLGetClient'
|
import { GraphQLGetClient } from '../GraphQLGetClient'
|
||||||
|
import LogError from '@/server/LogError'
|
||||||
|
|
||||||
export async function requestGetPublicKey(dbCom: DbCommunity): Promise<string | undefined> {
|
export async function requestGetPublicKey(dbCom: DbCommunity): Promise<string | undefined> {
|
||||||
let endpoint = dbCom.endPoint.endsWith('/') ? dbCom.endPoint : dbCom.endPoint + '/'
|
let endpoint = dbCom.endPoint.endsWith('/') ? dbCom.endPoint : dbCom.endPoint + '/'
|
||||||
@ -18,28 +19,16 @@ export async function requestGetPublicKey(dbCom: DbCommunity): Promise<string |
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
const variables = {}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { data, errors, extensions, headers, status } = await graphQLClient.rawRequest(
|
const { data, errors, extensions, headers, status } = await graphQLClient.rawRequest(query)
|
||||||
query,
|
logger.debug(`Response-Data:`, data, errors, extensions, headers, status)
|
||||||
variables,
|
|
||||||
)
|
|
||||||
logger.debug(
|
|
||||||
`Response-Data: ${JSON.stringify(
|
|
||||||
{ data, errors, extensions, headers, status },
|
|
||||||
undefined,
|
|
||||||
2,
|
|
||||||
)}`,
|
|
||||||
)
|
|
||||||
if (data) {
|
if (data) {
|
||||||
logger.debug(`Response-PublicKey: ${data.getPublicKey.publicKey}`)
|
logger.debug(`Response-PublicKey:`, data.getPublicKey.publicKey)
|
||||||
logger.info(`requestGetPublicKey processed successfully`)
|
logger.info(`requestGetPublicKey processed successfully`)
|
||||||
return data.getPublicKey.publicKey
|
return data.getPublicKey.publicKey
|
||||||
}
|
}
|
||||||
logger.warn(`requestGetPublicKey processed without response data`)
|
logger.warn(`requestGetPublicKey processed without response data`)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(`Request-Error:`, err) // ${JSON.stringify(err)}`)
|
throw new LogError(`Request-Error:`, err)
|
||||||
}
|
}
|
||||||
return undefined
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import { requestGetPublicKey as v1_0_requestGetPublicKey } from './client/1_0/Fe
|
|||||||
import { requestGetPublicKey as v1_1_requestGetPublicKey } from './client/1_1/FederationClient'
|
import { requestGetPublicKey as v1_1_requestGetPublicKey } from './client/1_1/FederationClient'
|
||||||
import { backendLogger as logger } from '@/server/logger'
|
import { backendLogger as logger } from '@/server/logger'
|
||||||
import { ApiVersionType } from './enum/apiVersionType'
|
import { ApiVersionType } from './enum/apiVersionType'
|
||||||
|
import LogError from '@/server/LogError'
|
||||||
|
|
||||||
export async function startValidateCommunities(timerInterval: number): Promise<void> {
|
export async function startValidateCommunities(timerInterval: number): Promise<void> {
|
||||||
logger.info(
|
logger.info(
|
||||||
@ -23,21 +24,17 @@ export async function validateCommunities(): Promise<void> {
|
|||||||
.where({ foreign: true, verifiedAt: IsNull() })
|
.where({ foreign: true, verifiedAt: IsNull() })
|
||||||
.orWhere('verified_at < last_announced_at')
|
.orWhere('verified_at < last_announced_at')
|
||||||
.getMany()
|
.getMany()
|
||||||
/*
|
|
||||||
const dbCommunities: DbCommunity[] = await DbCommunity.getRepository().manager.query(
|
|
||||||
'SELECT * FROM `communities` `Community` WHERE (`Community`.`verified_at` IS NULL OR `Community`.`verified_at` < `Community`.`last_announced_at`)',
|
|
||||||
)
|
|
||||||
*/
|
|
||||||
logger.debug(`Federation: found ${dbCommunities.length} dbCommunities`)
|
logger.debug(`Federation: found ${dbCommunities.length} dbCommunities`)
|
||||||
if (dbCommunities) {
|
dbCommunities.forEach(async function (dbCom) {
|
||||||
dbCommunities.forEach(async function (dbCom) {
|
logger.debug(`Federation: dbCom: ${JSON.stringify(dbCom)}`)
|
||||||
logger.debug(`Federation: dbCom: ${JSON.stringify(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.debug(
|
`Federation: validate publicKey for dbCom: ${dbCom.id} with apiVersion=${dbCom.apiVersion}`,
|
||||||
`Federation: validate publicKey for dbCom: ${dbCom.id} with apiVersion=${dbCom.apiVersion}`,
|
)
|
||||||
)
|
try {
|
||||||
const pubKey = await invokeVersionedRequestGetPublicKey(dbCom)
|
const pubKey = await invokeVersionedRequestGetPublicKey(dbCom)
|
||||||
logger.info(
|
logger.info(
|
||||||
`Federation: received publicKey=${pubKey} from endpoint=${dbCom.endPoint}/${dbCom.apiVersion}`,
|
`Federation: received publicKey=${pubKey} from endpoint=${dbCom.endPoint}/${dbCom.apiVersion}`,
|
||||||
@ -53,15 +50,22 @@ export async function validateCommunities(): Promise<void> {
|
|||||||
DbCommunity.delete({ id: dbCom.id })
|
DbCommunity.delete({ id: dbCom.id })
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
} else {
|
} catch (err) {
|
||||||
logger.warn(
|
if (!isLogError(err)) {
|
||||||
`Federation: dbCom: ${dbCom.id} with unsupported apiVersion=${dbCom.apiVersion}; supported versions=${apiValueStrings}`,
|
logger.error(`Error:`, err)
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
})
|
} else {
|
||||||
}
|
logger.warn(
|
||||||
|
`Federation: dbCom: ${dbCom.id} with unsupported apiVersion=${dbCom.apiVersion}; supported versions=${apiValueStrings}`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isLogError(err: any) {
|
||||||
|
return err instanceof LogError
|
||||||
|
}
|
||||||
async function invokeVersionedRequestGetPublicKey(dbCom: DbCommunity): Promise<string | undefined> {
|
async function invokeVersionedRequestGetPublicKey(dbCom: DbCommunity): Promise<string | undefined> {
|
||||||
switch (dbCom.apiVersion) {
|
switch (dbCom.apiVersion) {
|
||||||
case ApiVersionType.V1_0:
|
case ApiVersionType.V1_0:
|
||||||
|
|||||||
@ -1,45 +0,0 @@
|
|||||||
import {
|
|
||||||
BaseEntity,
|
|
||||||
Entity,
|
|
||||||
PrimaryGeneratedColumn,
|
|
||||||
Column,
|
|
||||||
CreateDateColumn,
|
|
||||||
UpdateDateColumn,
|
|
||||||
} from 'typeorm'
|
|
||||||
|
|
||||||
@Entity('communities')
|
|
||||||
export class Community extends BaseEntity {
|
|
||||||
@PrimaryGeneratedColumn('increment', { unsigned: true })
|
|
||||||
id: number
|
|
||||||
|
|
||||||
@Column({ name: 'public_key', type: 'binary', length: 64, default: null, nullable: true })
|
|
||||||
publicKey: Buffer
|
|
||||||
|
|
||||||
@Column({ name: 'api_version', length: 10, nullable: false })
|
|
||||||
apiVersion: string
|
|
||||||
|
|
||||||
@Column({ name: 'end_point', length: 255, nullable: false })
|
|
||||||
endPoint: string
|
|
||||||
|
|
||||||
@Column({ name: 'last_announced_at', type: 'datetime', nullable: false })
|
|
||||||
lastAnnouncedAt: Date
|
|
||||||
|
|
||||||
@Column({ name: 'verified_at', type: 'datetime', nullable: true })
|
|
||||||
verifiedAt: Date
|
|
||||||
|
|
||||||
@CreateDateColumn({
|
|
||||||
name: 'created_at',
|
|
||||||
type: 'datetime',
|
|
||||||
default: () => 'CURRENT_TIMESTAMP(3)',
|
|
||||||
nullable: false,
|
|
||||||
})
|
|
||||||
createdAt: Date
|
|
||||||
|
|
||||||
@UpdateDateColumn({
|
|
||||||
name: 'updated_at',
|
|
||||||
type: 'datetime',
|
|
||||||
onUpdate: 'CURRENT_TIMESTAMP(3)',
|
|
||||||
nullable: true,
|
|
||||||
})
|
|
||||||
updatedAt: Date | null
|
|
||||||
}
|
|
||||||
@ -15,7 +15,7 @@ export class Community extends BaseEntity {
|
|||||||
@Column({ name: 'foreign', type: 'bool', nullable: false, default: true })
|
@Column({ name: 'foreign', type: 'bool', nullable: false, default: true })
|
||||||
foreign: boolean
|
foreign: boolean
|
||||||
|
|
||||||
@Column({ name: 'public_key', type: 'binary', length: 64, default: null, nullable: false })
|
@Column({ name: 'public_key', type: 'binary', length: 64, default: null, nullable: true })
|
||||||
publicKey: Buffer
|
publicKey: Buffer
|
||||||
|
|
||||||
@Column({ name: 'api_version', length: 10, nullable: false })
|
@Column({ name: 'api_version', length: 10, nullable: false })
|
||||||
@ -28,7 +28,7 @@ export class Community extends BaseEntity {
|
|||||||
lastAnnouncedAt: Date
|
lastAnnouncedAt: Date
|
||||||
|
|
||||||
@Column({ name: 'verified_at', type: 'datetime', nullable: true })
|
@Column({ name: 'verified_at', type: 'datetime', nullable: true })
|
||||||
verifiedAt: Date | null
|
verifiedAt: Date
|
||||||
|
|
||||||
@Column({ name: 'last_error_at', type: 'datetime', nullable: true })
|
@Column({ name: 'last_error_at', type: 'datetime', nullable: true })
|
||||||
lastErrorAt: Date
|
lastErrorAt: Date
|
||||||
@ -1 +1 @@
|
|||||||
export { Community } from './0061-update_communities_table/Community'
|
export { Community } from './0060-update_communities_table/Community'
|
||||||
|
|||||||
@ -1,17 +0,0 @@
|
|||||||
/* MIGRATION TO CREATE THE FEDERATION COMMUNITY TABLES
|
|
||||||
*
|
|
||||||
* This migration creates the `community` and 'communityfederation' tables in the `apollo` database (`gradido_community`).
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
||||||
|
|
||||||
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
|
||||||
await queryFn(
|
|
||||||
'ALTER TABLE `communities` ADD COLUMN `verified_at` datetime(3) DEFAULT NULL AFTER `last_announced_at`;',
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
|
||||||
await queryFn('ALTER TABLE `communities` DROP COLUMN `verified_at`;')
|
|
||||||
}
|
|
||||||
@ -13,14 +13,9 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
|||||||
await queryFn(
|
await queryFn(
|
||||||
'ALTER TABLE `communities` ADD COLUMN `foreign` tinyint(4) NOT NULL DEFAULT 1 AFTER `id`;',
|
'ALTER TABLE `communities` ADD COLUMN `foreign` tinyint(4) NOT NULL DEFAULT 1 AFTER `id`;',
|
||||||
)
|
)
|
||||||
await queryFn(
|
|
||||||
'ALTER TABLE `communities` MODIFY COLUMN `public_key` binary(64) NOT NULL AFTER `foreign`;',
|
|
||||||
)
|
|
||||||
/*
|
|
||||||
await queryFn(
|
await queryFn(
|
||||||
'ALTER TABLE `communities` ADD COLUMN `verified_at` datetime(3) AFTER `last_announced_at`;',
|
'ALTER TABLE `communities` ADD COLUMN `verified_at` datetime(3) AFTER `last_announced_at`;',
|
||||||
)
|
)
|
||||||
*/
|
|
||||||
await queryFn(
|
await queryFn(
|
||||||
'ALTER TABLE `communities` ADD COLUMN `last_error_at` datetime(3) AFTER `verified_at`;',
|
'ALTER TABLE `communities` ADD COLUMN `last_error_at` datetime(3) AFTER `verified_at`;',
|
||||||
)
|
)
|
||||||
@ -31,8 +26,7 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
|
|||||||
await queryFn(
|
await queryFn(
|
||||||
'ALTER TABLE `communities` MODIFY COLUMN `last_announced_at` datetime(3) NOT NULL AFTER `end_point`;',
|
'ALTER TABLE `communities` MODIFY COLUMN `last_announced_at` datetime(3) NOT NULL AFTER `end_point`;',
|
||||||
)
|
)
|
||||||
await queryFn('ALTER TABLE `communities` MODIFY COLUMN `public_key` binary(64) AFTER `id`;')
|
|
||||||
await queryFn('ALTER TABLE `communities` DROP COLUMN `foreign`;')
|
await queryFn('ALTER TABLE `communities` DROP COLUMN `foreign`;')
|
||||||
// await queryFn('ALTER TABLE `communities` DROP COLUMN `verified_at`;')
|
await queryFn('ALTER TABLE `communities` DROP COLUMN `verified_at`;')
|
||||||
await queryFn('ALTER TABLE `communities` DROP COLUMN `last_error_at`;')
|
await queryFn('ALTER TABLE `communities` DROP COLUMN `last_error_at`;')
|
||||||
}
|
}
|
||||||
@ -3,7 +3,7 @@ import dotenv from 'dotenv'
|
|||||||
dotenv.config()
|
dotenv.config()
|
||||||
|
|
||||||
const constants = {
|
const constants = {
|
||||||
DB_VERSION: '0061-update_communities_table',
|
DB_VERSION: '0060-update_communities_table',
|
||||||
LOG4JS_CONFIG: 'log4js-config.json',
|
LOG4JS_CONFIG: 'log4js-config.json',
|
||||||
// default log level on production should be info
|
// default log level on production should be info
|
||||||
LOG_LEVEL: process.env.LOG_LEVEL || 'info',
|
LOG_LEVEL: process.env.LOG_LEVEL || 'info',
|
||||||
|
|||||||
@ -11,7 +11,7 @@ Decimal.set({
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const constants = {
|
const constants = {
|
||||||
DB_VERSION: '0059-add_hide_amount_to_users',
|
DB_VERSION: '0060-update_communities_table',
|
||||||
// DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0
|
// DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0
|
||||||
LOG4JS_CONFIG: 'log4js-config.json',
|
LOG4JS_CONFIG: 'log4js-config.json',
|
||||||
// default log level on production should be info
|
// default log level on production should be info
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user