mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge branch '2630-feature-federation-implement-a-graphql-endpoint-for-request-getpublickey' into 2730-devops-add-federation-modul-to-deployment-scripts
This commit is contained in:
commit
cf056e7d8c
@ -18,9 +18,13 @@ export async function requestGetPublicKey(dbCom: DbCommunity): Promise<string |
|
||||
}
|
||||
}
|
||||
`
|
||||
const variables = {}
|
||||
|
||||
try {
|
||||
const { data, errors, extensions, headers, status } = await graphQLClient.rawRequest(query)
|
||||
const { data, errors, extensions, headers, status } = await graphQLClient.rawRequest(
|
||||
query,
|
||||
variables,
|
||||
)
|
||||
logger.debug(`Response-Data:`, data, errors, extensions, headers, status)
|
||||
if (data) {
|
||||
logger.debug(`Response-PublicKey:`, data.getPublicKey.publicKey)
|
||||
|
||||
@ -1,8 +1,14 @@
|
||||
import { GraphQLClient } from 'graphql-request'
|
||||
import { PatchedRequestInit } from 'graphql-request/dist/types'
|
||||
|
||||
type ClientInstance = {
|
||||
url: string
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
client: GraphQLGetClient
|
||||
}
|
||||
|
||||
export class GraphQLGetClient extends GraphQLClient {
|
||||
private static instance: GraphQLGetClient
|
||||
private static instanceArray: ClientInstance[] = []
|
||||
|
||||
/**
|
||||
* The Singleton's constructor should always be private to prevent direct
|
||||
@ -20,16 +26,19 @@ export class GraphQLGetClient extends GraphQLClient {
|
||||
* just one instance of each subclass around.
|
||||
*/
|
||||
public static getInstance(url: string): GraphQLGetClient {
|
||||
if (!GraphQLGetClient.instance) {
|
||||
GraphQLGetClient.instance = new GraphQLGetClient(url, {
|
||||
method: 'GET',
|
||||
jsonSerializer: {
|
||||
parse: JSON.parse,
|
||||
stringify: JSON.stringify,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return GraphQLGetClient.instance
|
||||
GraphQLGetClient.instanceArray.forEach(function (instance) {
|
||||
if (instance.url === url) {
|
||||
return instance.client
|
||||
}
|
||||
})
|
||||
const client = new GraphQLGetClient(url, {
|
||||
method: 'GET',
|
||||
jsonSerializer: {
|
||||
parse: JSON.parse,
|
||||
stringify: JSON.stringify,
|
||||
},
|
||||
})
|
||||
GraphQLGetClient.instanceArray.push({ url, client } as ClientInstance)
|
||||
return client
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,17 +40,16 @@ export async function validateCommunities(): Promise<void> {
|
||||
logger.info(
|
||||
`Federation: received publicKey=${pubKey} from endpoint=${dbCom.endPoint}/${dbCom.apiVersion}`,
|
||||
)
|
||||
if (pubKey && pubKey === dbCom.publicKey.toString('hex')) {
|
||||
if (pubKey && pubKey === dbCom.publicKey.toString()) {
|
||||
logger.info(`Federation: matching publicKey: ${pubKey}`)
|
||||
DbCommunity.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}, expected: ${dbCom.publicKey} `,
|
||||
)
|
||||
// DbCommunity.delete({ id: dbCom.id })
|
||||
}
|
||||
/*
|
||||
else {
|
||||
logger.warn(`Federation: received unknown publicKey -> delete dbCom with id=${dbCom.id} `)
|
||||
DbCommunity.delete({ id: dbCom.id })
|
||||
}
|
||||
*/
|
||||
} catch (err) {
|
||||
if (!isLogError(err)) {
|
||||
logger.error(`Error:`, err)
|
||||
|
||||
11
federation/src/graphql/api/1_0/model/GetPublicKeyResult.ts
Normal file
11
federation/src/graphql/api/1_0/model/GetPublicKeyResult.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { Field, ObjectType } from 'type-graphql'
|
||||
|
||||
@ObjectType()
|
||||
export class GetPublicKeyResult {
|
||||
constructor(pubKey: string) {
|
||||
this.publicKey = pubKey
|
||||
}
|
||||
|
||||
@Field(() => String)
|
||||
publicKey: string
|
||||
}
|
||||
18
federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts
Normal file
18
federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Field, ObjectType, Query, Resolver } from 'type-graphql'
|
||||
import { federationLogger as logger } from '@/server/logger'
|
||||
import { Community as DbCommunity } from '@entity/Community'
|
||||
import { GetPublicKeyResult } from '../model/GetPublicKeyResult'
|
||||
|
||||
@Resolver()
|
||||
export class PublicKeyResolver {
|
||||
@Query(() => GetPublicKeyResult)
|
||||
async getPublicKey(): Promise<GetPublicKeyResult> {
|
||||
logger.info(`getPublicKey()...`)
|
||||
const homeCom = await DbCommunity.findOneOrFail({
|
||||
foreign: false,
|
||||
apiVersion: '1_0',
|
||||
})
|
||||
logger.info(`getPublicKey()... with publicKey=${homeCom.publicKey}`)
|
||||
return new GetPublicKeyResult(homeCom.publicKey.toString())
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user