From b70565cabf0d888c4038043cb90262ebdce8f75d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Thu, 26 Jan 2023 00:33:42 +0100 Subject: [PATCH 001/106] remove TestResolvers from previous PR "multiple graphql endpoints" --- .../src/graphql/api/1_0/resolver/Test2Resolver.ts | 12 ------------ .../src/graphql/api/1_0/resolver/TestResolver.ts | 12 ------------ .../src/graphql/api/1_1/resolver/TestResolver.ts | 12 ------------ .../src/graphql/api/2_0/resolver/TestResolver.ts | 12 ------------ 4 files changed, 48 deletions(-) delete mode 100644 federation/src/graphql/api/1_0/resolver/Test2Resolver.ts delete mode 100644 federation/src/graphql/api/1_0/resolver/TestResolver.ts delete mode 100644 federation/src/graphql/api/1_1/resolver/TestResolver.ts delete mode 100644 federation/src/graphql/api/2_0/resolver/TestResolver.ts diff --git a/federation/src/graphql/api/1_0/resolver/Test2Resolver.ts b/federation/src/graphql/api/1_0/resolver/Test2Resolver.ts deleted file mode 100644 index 3388003b8..000000000 --- a/federation/src/graphql/api/1_0/resolver/Test2Resolver.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Query, Resolver } from 'type-graphql' -import { federationLogger as logger } from '@/server/logger' -import { GetTestApiResult } from '../../GetTestApiResult' - -@Resolver() -export class Test2Resolver { - @Query(() => GetTestApiResult) - async test2(): Promise { - logger.info(`test api 2 1_0`) - return new GetTestApiResult('1_0') - } -} diff --git a/federation/src/graphql/api/1_0/resolver/TestResolver.ts b/federation/src/graphql/api/1_0/resolver/TestResolver.ts deleted file mode 100644 index 7291e5ef2..000000000 --- a/federation/src/graphql/api/1_0/resolver/TestResolver.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Field, ObjectType, Query, Resolver } from 'type-graphql' -import { federationLogger as logger } from '@/server/logger' -import { GetTestApiResult } from '../../GetTestApiResult' - -@Resolver() -export class TestResolver { - @Query(() => GetTestApiResult) - async test(): Promise { - logger.info(`test api 1_0`) - return new GetTestApiResult('1_0') - } -} diff --git a/federation/src/graphql/api/1_1/resolver/TestResolver.ts b/federation/src/graphql/api/1_1/resolver/TestResolver.ts deleted file mode 100644 index 8880cad6e..000000000 --- a/federation/src/graphql/api/1_1/resolver/TestResolver.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Field, ObjectType, Query, Resolver } from 'type-graphql' -import { federationLogger as logger } from '@/server/logger' -import { GetTestApiResult } from '../../GetTestApiResult' - -@Resolver() -export class TestResolver { - @Query(() => GetTestApiResult) - async test(): Promise { - logger.info(`test api 1_1`) - return new GetTestApiResult('1_1') - } -} diff --git a/federation/src/graphql/api/2_0/resolver/TestResolver.ts b/federation/src/graphql/api/2_0/resolver/TestResolver.ts deleted file mode 100644 index f50149e33..000000000 --- a/federation/src/graphql/api/2_0/resolver/TestResolver.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Field, ObjectType, Query, Resolver } from 'type-graphql' -import { federationLogger as logger } from '@/server/logger' -import { GetTestApiResult } from '../../GetTestApiResult' - -@Resolver() -export class TestResolver { - @Query(() => GetTestApiResult) - async test(): Promise { - logger.info(`test api 2_0`) - return new GetTestApiResult('2_0') - } -} From a05c2307ee4becd498ec85509d09e213810e5a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Thu, 26 Jan 2023 00:34:45 +0100 Subject: [PATCH 002/106] add columns to communities table --- backend/src/config/index.ts | 2 +- .../Community.ts | 48 +++++++++++++++++++ database/entity/Community.ts | 2 +- .../0060-update_communities_table.ts | 22 +++++++++ federation/src/config/index.ts | 2 +- 5 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 database/entity/0060-update_communities_table/Community.ts create mode 100644 database/migrations/0060-update_communities_table.ts diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index d010b4ab0..3b8d0d1d6 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -10,7 +10,7 @@ Decimal.set({ }) 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 LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info diff --git a/database/entity/0060-update_communities_table/Community.ts b/database/entity/0060-update_communities_table/Community.ts new file mode 100644 index 000000000..3a9082667 --- /dev/null +++ b/database/entity/0060-update_communities_table/Community.ts @@ -0,0 +1,48 @@ +import { + BaseEntity, + Entity, + PrimaryGeneratedColumn, + Column, + CreateDateColumn, + UpdateDateColumn, +} from 'typeorm' + +@Entity('communities') +export class Community extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: number + + @Column({ name: 'foreign', type: 'bool', nullable: false, default: false }) + foreign: boolean + + @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: 'pubkey_verified_at', type: 'datetime', nullable: false }) + pubKeyVerifiedAt: 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 +} diff --git a/database/entity/Community.ts b/database/entity/Community.ts index 457d03eae..80e5ace30 100644 --- a/database/entity/Community.ts +++ b/database/entity/Community.ts @@ -1 +1 @@ -export { Community } from './0058-add_communities_table/Community' +export { Community } from './0060-update_communities_table/Community' diff --git a/database/migrations/0060-update_communities_table.ts b/database/migrations/0060-update_communities_table.ts new file mode 100644 index 000000000..1047481ee --- /dev/null +++ b/database/migrations/0060-update_communities_table.ts @@ -0,0 +1,22 @@ +/* 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>) { + await queryFn( + 'ALTER TABLE `communities` ADD COLUMN `foreign` tinyint(4) NOT NULL DEFAULT 0 AFTER `id`;', + ) + await queryFn( + 'ALTER TABLE `communities` ADD COLUMN `pubkey_verified_at` datetime(3) AFTER `last_announced_at`;', + ) +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + // write downgrade logic as parameter of queryFn + await queryFn('ALTER TABLE communities DROP COLUMN foreign;') + await queryFn('ALTER TABLE communities DROP COLUMN pubkey_verified_at;') +} diff --git a/federation/src/config/index.ts b/federation/src/config/index.ts index c2d81d2c8..2404c610f 100644 --- a/federation/src/config/index.ts +++ b/federation/src/config/index.ts @@ -11,7 +11,7 @@ Decimal.set({ */ 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 LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info From 4e1a6d965e620311c4d2f9678901accaa5299e56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Thu, 26 Jan 2023 00:35:28 +0100 Subject: [PATCH 003/106] create graphql endpoint for GetPublicKey request --- .../api/1_0/model/GetPublicKeyResult.ts | 11 +++++++++++ .../api/1_0/resolver/PublicKeyResolver.ts | 18 ++++++++++++++++++ federation/src/graphql/api/GetTestApiResult.ts | 11 ----------- 3 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 federation/src/graphql/api/1_0/model/GetPublicKeyResult.ts create mode 100644 federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts delete mode 100644 federation/src/graphql/api/GetTestApiResult.ts diff --git a/federation/src/graphql/api/1_0/model/GetPublicKeyResult.ts b/federation/src/graphql/api/1_0/model/GetPublicKeyResult.ts new file mode 100644 index 000000000..1582ad892 --- /dev/null +++ b/federation/src/graphql/api/1_0/model/GetPublicKeyResult.ts @@ -0,0 +1,11 @@ +import { Field, ObjectType } from 'type-graphql' + +@ObjectType() +export class GetPublicKeyResult { + constructor(pubKey: string) { + this.publicKey = pubKey + } + + @Field(() => String) + publicKey: string +} diff --git a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts new file mode 100644 index 000000000..53f0d0bd4 --- /dev/null +++ b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts @@ -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 { + 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()) + } +} diff --git a/federation/src/graphql/api/GetTestApiResult.ts b/federation/src/graphql/api/GetTestApiResult.ts deleted file mode 100644 index 7c8c6c487..000000000 --- a/federation/src/graphql/api/GetTestApiResult.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Field, ObjectType } from 'type-graphql' - -@ObjectType() -export class GetTestApiResult { - constructor(apiVersion: string) { - this.api = apiVersion - } - - @Field(() => String) - api: string -} From ae2097ff71439eab415573420b565c4bf25a321d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Fri, 27 Jan 2023 21:55:43 +0100 Subject: [PATCH 004/106] rename pubkeyVerifiedAt to verifiedAt --- database/entity/0060-update_communities_table/Community.ts | 4 ++-- database/migrations/0060-update_communities_table.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/database/entity/0060-update_communities_table/Community.ts b/database/entity/0060-update_communities_table/Community.ts index 3a9082667..73f098f46 100644 --- a/database/entity/0060-update_communities_table/Community.ts +++ b/database/entity/0060-update_communities_table/Community.ts @@ -27,8 +27,8 @@ export class Community extends BaseEntity { @Column({ name: 'last_announced_at', type: 'datetime', nullable: false }) lastAnnouncedAt: Date - @Column({ name: 'pubkey_verified_at', type: 'datetime', nullable: false }) - pubKeyVerifiedAt: Date + @Column({ name: 'verified_at', type: 'datetime', nullable: false }) + verifiedAt: Date @CreateDateColumn({ name: 'created_at', diff --git a/database/migrations/0060-update_communities_table.ts b/database/migrations/0060-update_communities_table.ts index 1047481ee..1e1b8411e 100644 --- a/database/migrations/0060-update_communities_table.ts +++ b/database/migrations/0060-update_communities_table.ts @@ -11,12 +11,12 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis 'ALTER TABLE `communities` ADD COLUMN `foreign` tinyint(4) NOT NULL DEFAULT 0 AFTER `id`;', ) await queryFn( - 'ALTER TABLE `communities` ADD COLUMN `pubkey_verified_at` datetime(3) AFTER `last_announced_at`;', + 'ALTER TABLE `communities` ADD COLUMN `verified_at` datetime(3) AFTER `last_announced_at`;', ) } export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { // write downgrade logic as parameter of queryFn await queryFn('ALTER TABLE communities DROP COLUMN foreign;') - await queryFn('ALTER TABLE communities DROP COLUMN pubkey_verified_at;') + await queryFn('ALTER TABLE communities DROP COLUMN verified_at;') } From b542f6c81e8a2b1c38e1a394a289851b1b106b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 31 Jan 2023 01:02:20 +0100 Subject: [PATCH 005/106] add column last_error_at --- database/entity/0060-update_communities_table/Community.ts | 3 +++ database/migrations/0060-update_communities_table.ts | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/database/entity/0060-update_communities_table/Community.ts b/database/entity/0060-update_communities_table/Community.ts index 73f098f46..227400fdf 100644 --- a/database/entity/0060-update_communities_table/Community.ts +++ b/database/entity/0060-update_communities_table/Community.ts @@ -30,6 +30,9 @@ export class Community extends BaseEntity { @Column({ name: 'verified_at', type: 'datetime', nullable: false }) verifiedAt: Date + @Column({ name: 'last_error_at', type: 'datetime', nullable: false }) + lastErrorAt: Date + @CreateDateColumn({ name: 'created_at', type: 'datetime', diff --git a/database/migrations/0060-update_communities_table.ts b/database/migrations/0060-update_communities_table.ts index 1e1b8411e..55617fd0a 100644 --- a/database/migrations/0060-update_communities_table.ts +++ b/database/migrations/0060-update_communities_table.ts @@ -13,10 +13,14 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis await queryFn( 'ALTER TABLE `communities` ADD COLUMN `verified_at` datetime(3) AFTER `last_announced_at`;', ) + await queryFn( + 'ALTER TABLE `communities` ADD COLUMN `last_error_at` datetime(3) AFTER `verified_at`;', + ) } export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { // write downgrade logic as parameter of queryFn await queryFn('ALTER TABLE communities DROP COLUMN foreign;') await queryFn('ALTER TABLE communities DROP COLUMN verified_at;') + await queryFn('ALTER TABLE communities DROP COLUMN last_error_at;') } From 72f882add3ffade6dd3c0dd67bca0048a1ad987f Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Tue, 7 Feb 2023 22:34:30 +0100 Subject: [PATCH 006/106] Update database/migrations/0060-update_communities_table.ts Co-authored-by: Moriz Wahl --- database/migrations/0060-update_communities_table.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/0060-update_communities_table.ts b/database/migrations/0060-update_communities_table.ts index 55617fd0a..1804ee6c7 100644 --- a/database/migrations/0060-update_communities_table.ts +++ b/database/migrations/0060-update_communities_table.ts @@ -8,7 +8,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { await queryFn( - 'ALTER TABLE `communities` ADD COLUMN `foreign` tinyint(4) NOT NULL DEFAULT 0 AFTER `id`;', + 'ALTER TABLE `communities` ADD COLUMN `foreign` tinyint(4) NOT NULL DEFAULT 1 AFTER `id`;', ) await queryFn( 'ALTER TABLE `communities` ADD COLUMN `verified_at` datetime(3) AFTER `last_announced_at`;', From fcab712f86468e5a19311f9284acd99a404f3bfd Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Tue, 7 Feb 2023 22:35:12 +0100 Subject: [PATCH 007/106] Update database/entity/0060-update_communities_table/Community.ts Co-authored-by: Moriz Wahl --- database/entity/0060-update_communities_table/Community.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/entity/0060-update_communities_table/Community.ts b/database/entity/0060-update_communities_table/Community.ts index 227400fdf..d764fc98f 100644 --- a/database/entity/0060-update_communities_table/Community.ts +++ b/database/entity/0060-update_communities_table/Community.ts @@ -12,7 +12,7 @@ export class Community extends BaseEntity { @PrimaryGeneratedColumn('increment', { unsigned: true }) id: number - @Column({ name: 'foreign', type: 'bool', nullable: false, default: false }) + @Column({ name: 'foreign', type: 'bool', nullable: false, default: true }) foreign: boolean @Column({ name: 'public_key', type: 'binary', length: 64, default: null, nullable: true }) From 0d6fb2a427f1c294fe2c7cbca0f6f17180a2d6d5 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 16 Feb 2023 19:16:33 +0100 Subject: [PATCH 008/106] started event refactoring on database level --- .../entity/0061-event_refactoring/Event.ts | 82 +++++++++++++++++++ database/entity/Event.ts | 1 + database/entity/EventProtocol.ts | 1 - database/entity/index.ts | 8 +- database/migrations/0061-event_refactoring.ts | 33 ++++++++ 5 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 database/entity/0061-event_refactoring/Event.ts create mode 100644 database/entity/Event.ts delete mode 100644 database/entity/EventProtocol.ts create mode 100644 database/migrations/0061-event_refactoring.ts diff --git a/database/entity/0061-event_refactoring/Event.ts b/database/entity/0061-event_refactoring/Event.ts new file mode 100644 index 000000000..62f517aba --- /dev/null +++ b/database/entity/0061-event_refactoring/Event.ts @@ -0,0 +1,82 @@ +import { Contribution } from '@entity/Contribution' +import { ContributionMessage } from '@entity/ContributionMessage' +import { User } from '@entity/User' +import Decimal from 'decimal.js-light' +import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, Transaction } from 'typeorm' +import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer' + +@Entity('event') +// TODO tablename event_protocol +export class Event extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: number + + @Column({ length: 100, nullable: false, collation: 'utf8mb4_unicode_ci' }) + type: string + + // TODO proper field type + @Column({ name: 'created_at', type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) + createdAt: Date + + // TODO field name user_id + // @Column({ name: 'affected_user_id', unsigned: true, nullable: false }) + // affectedUserId: number + + @ManyToOne(() => User) + @JoinColumn({ name: 'affected_user_id', referencedColumnName: 'id' }) + affectedUser: User | null + + // TODO new column + // TODO potentially save actingRole aswell + // @Column({ name: 'acting_user_id', unsigned: true, nullable: false }) + // actingUserId: number + + @ManyToOne(() => User) + @JoinColumn({ name: 'acting_user_id', referencedColumnName: 'id' }) + actingUser: User | null + + // TODO rename column x_user_id + // @Column({ name: 'involved_user_id', type: 'int', unsigned: true, nullable: true }) + // involvedUserId: number | null + + @ManyToOne(() => User) + @JoinColumn({ name: 'involved_user_id', referencedColumnName: 'id' }) + involvedUser: User | null + + // TODO drop column xCommunityId + + // TODO rename column transaction_id + // @Column({ name: 'involved_transaction_id', type: 'int', unsigned: true, nullable: true }) + // involvedTransactionId: number | null + + @ManyToOne(() => Transaction) + @JoinColumn({ name: 'involved_transaction_id', referencedColumnName: 'id' }) + involvedTransaction: Transaction | null + + // TODO rename column contribution_id + // @Column({ name: 'involved_contribution_id', type: 'int', unsigned: true, nullable: true }) + // involvedContributionId: number | null + + @ManyToOne(() => Contribution) + @JoinColumn({ name: 'involved_contribution_id', referencedColumnName: 'id' }) + involvedContribution: Contribution | null + + // TODO move column + // TODO rename column message_id + // TEST do we need the Id field definition? + // @Column({ name: 'involved_contribution_message_id', type: 'int', unsigned: true, nullable: true }) + // involvedContributionMessageId: number | null + + @ManyToOne(() => ContributionMessage) + @JoinColumn({ name: 'involved_contribution_message_id', referencedColumnName: 'id' }) + involvedContributionMessage: ContributionMessage | null + + @Column({ + type: 'decimal', + precision: 40, + scale: 20, + nullable: true, + transformer: DecimalTransformer, + }) + amount: Decimal | null +} diff --git a/database/entity/Event.ts b/database/entity/Event.ts new file mode 100644 index 000000000..e53085f2f --- /dev/null +++ b/database/entity/Event.ts @@ -0,0 +1 @@ +export { Event } from './0061-event_refactoring/Event' diff --git a/database/entity/EventProtocol.ts b/database/entity/EventProtocol.ts deleted file mode 100644 index 6ebbd3d68..000000000 --- a/database/entity/EventProtocol.ts +++ /dev/null @@ -1 +0,0 @@ -export { EventProtocol } from './0050-add_messageId_to_event_protocol/EventProtocol' diff --git a/database/entity/index.ts b/database/entity/index.ts index a58afb816..2d9d04c3b 100644 --- a/database/entity/index.ts +++ b/database/entity/index.ts @@ -7,21 +7,21 @@ import { TransactionLink } from './TransactionLink' import { User } from './User' import { UserContact } from './UserContact' import { Contribution } from './Contribution' -import { EventProtocol } from './EventProtocol' +import { Event } from './Event' import { ContributionMessage } from './ContributionMessage' import { Community } from './Community' export const entities = [ + Community, Contribution, ContributionLink, + ContributionMessage, + Event, LoginElopageBuys, LoginEmailOptIn, Migration, Transaction, TransactionLink, User, - EventProtocol, - ContributionMessage, UserContact, - Community, ] diff --git a/database/migrations/0061-event_refactoring.ts b/database/migrations/0061-event_refactoring.ts new file mode 100644 index 000000000..a5ce50595 --- /dev/null +++ b/database/migrations/0061-event_refactoring.ts @@ -0,0 +1,33 @@ +/* MIGRATION TO REFACTOR THE EVENT_PROTOCOL TABLE + * + * This migration refactors the `event_protocol` table. + * It renames the table to `event`, introduces new fields and renames others. + */ + +/* 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>) { + await queryFn( + 'ALTER TABLE `communities` MODIFY COLUMN `last_announced_at` datetime(3) AFTER `end_point`;', + ) + await queryFn( + 'ALTER TABLE `communities` ADD COLUMN `foreign` tinyint(4) NOT NULL DEFAULT 1 AFTER `id`;', + ) + await queryFn( + 'ALTER TABLE `communities` ADD COLUMN `verified_at` datetime(3) AFTER `last_announced_at`;', + ) + await queryFn( + 'ALTER TABLE `communities` ADD COLUMN `last_error_at` datetime(3) AFTER `verified_at`;', + ) +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + // write downgrade logic as parameter of queryFn + await queryFn( + 'ALTER TABLE `communities` MODIFY COLUMN `last_announced_at` datetime(3) NOT NULL AFTER `end_point`;', + ) + await queryFn('ALTER TABLE `communities` DROP COLUMN `foreign`;') + await queryFn('ALTER TABLE `communities` DROP COLUMN `verified_at`;') + await queryFn('ALTER TABLE `communities` DROP COLUMN `last_error_at`;') +} From 80a059b94d3cfaf0d33796e36e4f6d4b5b21e1ac Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 17 Feb 2023 11:49:26 +0100 Subject: [PATCH 009/106] properly import entities --- database/entity/0061-event_refactoring/Event.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/database/entity/0061-event_refactoring/Event.ts b/database/entity/0061-event_refactoring/Event.ts index 62f517aba..ca2ab58da 100644 --- a/database/entity/0061-event_refactoring/Event.ts +++ b/database/entity/0061-event_refactoring/Event.ts @@ -1,6 +1,6 @@ -import { Contribution } from '@entity/Contribution' -import { ContributionMessage } from '@entity/ContributionMessage' -import { User } from '@entity/User' +import { Contribution } from '../Contribution' +import { ContributionMessage } from '../ContributionMessage' +import { User } from '../User' import Decimal from 'decimal.js-light' import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, Transaction } from 'typeorm' import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer' From 6d8b11aeb8f3f15ce627e8a5d8c6bcc193c614f7 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 17 Feb 2023 14:47:31 +0100 Subject: [PATCH 010/106] finished up Table definition and migration --- .../entity/0061-event_refactoring/Event.ts | 24 +++-------- database/migrations/0061-event_refactoring.ts | 43 ++++++++++++++----- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/database/entity/0061-event_refactoring/Event.ts b/database/entity/0061-event_refactoring/Event.ts index ca2ab58da..80b4238bb 100644 --- a/database/entity/0061-event_refactoring/Event.ts +++ b/database/entity/0061-event_refactoring/Event.ts @@ -1,12 +1,12 @@ import { Contribution } from '../Contribution' import { ContributionMessage } from '../ContributionMessage' import { User } from '../User' +import { Transaction } from '../Transaction' import Decimal from 'decimal.js-light' -import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, Transaction } from 'typeorm' +import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, ManyToOne, JoinColumn } from 'typeorm' import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer' -@Entity('event') -// TODO tablename event_protocol +@Entity('events') export class Event extends BaseEntity { @PrimaryGeneratedColumn('increment', { unsigned: true }) id: number @@ -14,28 +14,24 @@ export class Event extends BaseEntity { @Column({ length: 100, nullable: false, collation: 'utf8mb4_unicode_ci' }) type: string - // TODO proper field type - @Column({ name: 'created_at', type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) + @CreateDateColumn({ name: 'created_at', type: 'datetime', default: () => 'CURRENT_TIMESTAMP()' , nullable: false }) createdAt: Date - // TODO field name user_id // @Column({ name: 'affected_user_id', unsigned: true, nullable: false }) // affectedUserId: number @ManyToOne(() => User) @JoinColumn({ name: 'affected_user_id', referencedColumnName: 'id' }) - affectedUser: User | null + affectedUser: User - // TODO new column - // TODO potentially save actingRole aswell + // TODO potentially save actingRole as well // @Column({ name: 'acting_user_id', unsigned: true, nullable: false }) // actingUserId: number @ManyToOne(() => User) @JoinColumn({ name: 'acting_user_id', referencedColumnName: 'id' }) - actingUser: User | null + actingUser: User - // TODO rename column x_user_id // @Column({ name: 'involved_user_id', type: 'int', unsigned: true, nullable: true }) // involvedUserId: number | null @@ -43,9 +39,6 @@ export class Event extends BaseEntity { @JoinColumn({ name: 'involved_user_id', referencedColumnName: 'id' }) involvedUser: User | null - // TODO drop column xCommunityId - - // TODO rename column transaction_id // @Column({ name: 'involved_transaction_id', type: 'int', unsigned: true, nullable: true }) // involvedTransactionId: number | null @@ -53,7 +46,6 @@ export class Event extends BaseEntity { @JoinColumn({ name: 'involved_transaction_id', referencedColumnName: 'id' }) involvedTransaction: Transaction | null - // TODO rename column contribution_id // @Column({ name: 'involved_contribution_id', type: 'int', unsigned: true, nullable: true }) // involvedContributionId: number | null @@ -61,8 +53,6 @@ export class Event extends BaseEntity { @JoinColumn({ name: 'involved_contribution_id', referencedColumnName: 'id' }) involvedContribution: Contribution | null - // TODO move column - // TODO rename column message_id // TEST do we need the Id field definition? // @Column({ name: 'involved_contribution_message_id', type: 'int', unsigned: true, nullable: true }) // involvedContributionMessageId: number | null diff --git a/database/migrations/0061-event_refactoring.ts b/database/migrations/0061-event_refactoring.ts index a5ce50595..88874b15e 100644 --- a/database/migrations/0061-event_refactoring.ts +++ b/database/migrations/0061-event_refactoring.ts @@ -8,26 +8,47 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn('RENAME TABLE `event_protocol` TO `events`;') + await queryFn('ALTER TABLE `events` RENAME COLUMN `user_id` TO `affected_user_id`;') + await queryFn( - 'ALTER TABLE `communities` MODIFY COLUMN `last_announced_at` datetime(3) AFTER `end_point`;', + 'ALTER TABLE `events` ADD COLUMN `acting_user_id` int(10) unsigned DEFAULT NULL AFTER `affected_user_id`;', + ) + await queryFn('UPDATE `events` SET `acting_user_id` = `affected_user_id`;') + await queryFn( + 'ALTER TABLE `events` MODIFY COLUMN `acting_user_id` int(10) unsigned NOT NULL AFTER `affected_user_id`;', + ) + + await queryFn('ALTER TABLE `events` RENAME COLUMN `x_user_id` TO `involved_user_id`;') + await queryFn('ALTER TABLE `events` DROP COLUMN `x_community_id`;') + await queryFn('ALTER TABLE `events` RENAME COLUMN `transaction_id` TO `involved_transaction_id`;') + await queryFn( + 'ALTER TABLE `events` RENAME COLUMN `contribution_id` TO `involved_contribution_id`;', ) await queryFn( - 'ALTER TABLE `communities` ADD COLUMN `foreign` tinyint(4) NOT NULL DEFAULT 1 AFTER `id`;', + 'ALTER TABLE `events` MODIFY COLUMN `message_id` int(10) unsigned DEFAULT NULL AFTER `involved_contribution_id`;', ) await queryFn( - 'ALTER TABLE `communities` ADD COLUMN `verified_at` datetime(3) AFTER `last_announced_at`;', - ) - await queryFn( - 'ALTER TABLE `communities` ADD COLUMN `last_error_at` datetime(3) AFTER `verified_at`;', + 'ALTER TABLE `events` RENAME COLUMN `message_id` TO `involved_contribution_message_id`;', ) } export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { - // write downgrade logic as parameter of queryFn await queryFn( - 'ALTER TABLE `communities` MODIFY COLUMN `last_announced_at` datetime(3) NOT NULL AFTER `end_point`;', + 'ALTER TABLE `events` RENAME COLUMN `involved_contribution_message_id` TO `message_id`;', ) - await queryFn('ALTER TABLE `communities` DROP COLUMN `foreign`;') - await queryFn('ALTER TABLE `communities` DROP COLUMN `verified_at`;') - await queryFn('ALTER TABLE `communities` DROP COLUMN `last_error_at`;') + await queryFn( + 'ALTER TABLE `events` MODIFY COLUMN `message_id` int(10) unsigned DEFAULT NULL AFTER `amount`;', + ) + await queryFn( + 'ALTER TABLE `events` RENAME COLUMN `involved_contribution_id` TO `contribution_id`;', + ) + await queryFn('ALTER TABLE `events` RENAME COLUMN `involved_transaction_id` TO `transaction_id`;') + await queryFn( + 'ALTER TABLE `events` ADD COLUMN `x_community_id` int(10) unsigned DEFAULT NULL AFTER `involved_user_id`;', + ) + await queryFn('ALTER TABLE `events` RENAME COLUMN `involved_user_id` TO `x_user_id`;') + await queryFn('ALTER TABLE `events` DROP COLUMN `acting_user_id`;') + await queryFn('ALTER TABLE `events` RENAME COLUMN `affected_user_id` TO `user_id`;') + await queryFn('RENAME TABLE `events` TO `event_protocol`;') } From 5aef000520129810dbf5b2e2964c6e970762ac11 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 17 Feb 2023 14:53:07 +0100 Subject: [PATCH 011/106] lint fixes --- database/entity/0061-event_refactoring/Event.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/database/entity/0061-event_refactoring/Event.ts b/database/entity/0061-event_refactoring/Event.ts index 80b4238bb..5a62fcdc2 100644 --- a/database/entity/0061-event_refactoring/Event.ts +++ b/database/entity/0061-event_refactoring/Event.ts @@ -3,7 +3,15 @@ import { ContributionMessage } from '../ContributionMessage' import { User } from '../User' import { Transaction } from '../Transaction' import Decimal from 'decimal.js-light' -import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, ManyToOne, JoinColumn } from 'typeorm' +import { + BaseEntity, + Entity, + PrimaryGeneratedColumn, + Column, + CreateDateColumn, + ManyToOne, + JoinColumn, +} from 'typeorm' import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer' @Entity('events') @@ -14,7 +22,12 @@ export class Event extends BaseEntity { @Column({ length: 100, nullable: false, collation: 'utf8mb4_unicode_ci' }) type: string - @CreateDateColumn({ name: 'created_at', type: 'datetime', default: () => 'CURRENT_TIMESTAMP()' , nullable: false }) + @CreateDateColumn({ + name: 'created_at', + type: 'datetime', + default: () => 'CURRENT_TIMESTAMP()', + nullable: false, + }) createdAt: Date // @Column({ name: 'affected_user_id', unsigned: true, nullable: false }) From d8f2843a55c8079e6268981f03b0229af6c24025 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 18 Feb 2023 00:11:29 +0100 Subject: [PATCH 012/106] fix database version requirement of dht-node & federation --- dht-node/src/config/index.ts | 2 +- federation/src/config/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dht-node/src/config/index.ts b/dht-node/src/config/index.ts index 8210ddfcc..6ba9493ac 100644 --- a/dht-node/src/config/index.ts +++ b/dht-node/src/config/index.ts @@ -3,7 +3,7 @@ import dotenv from 'dotenv' dotenv.config() const constants = { - DB_VERSION: '0060-update_communities_table', + DB_VERSION: '0061-event_refactoring', LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info LOG_LEVEL: process.env.LOG_LEVEL || 'info', diff --git a/federation/src/config/index.ts b/federation/src/config/index.ts index c8a841315..6b3bf6424 100644 --- a/federation/src/config/index.ts +++ b/federation/src/config/index.ts @@ -11,7 +11,7 @@ Decimal.set({ */ const constants = { - DB_VERSION: '0060-update_communities_table', + DB_VERSION: '0060-0061-event_refactoring', // DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0 LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info From fde67c2c32b61e4cfaec449f641d331aa6410a3f Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 18 Feb 2023 00:12:36 +0100 Subject: [PATCH 013/106] todo event data refactoring --- database/migrations/0061-event_refactoring.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/database/migrations/0061-event_refactoring.ts b/database/migrations/0061-event_refactoring.ts index 88874b15e..2fdc7dcef 100644 --- a/database/migrations/0061-event_refactoring.ts +++ b/database/migrations/0061-event_refactoring.ts @@ -31,6 +31,8 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis await queryFn( 'ALTER TABLE `events` RENAME COLUMN `message_id` TO `involved_contribution_message_id`;', ) + + // TODO insert data based on event type } export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { From 41569ad0f11b91ff8299dde0a255b0c3af2876b7 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 18 Feb 2023 01:08:06 +0100 Subject: [PATCH 014/106] refactor events - first step to get backend working --- backend/src/config/index.ts | 2 +- backend/src/event/Event.ts | 192 ++++++++++-------- .../resolver/ContributionResolver.test.ts | 22 +- .../graphql/resolver/ContributionResolver.ts | 31 ++- .../resolver/TransactionResolver.test.ts | 6 +- .../graphql/resolver/TransactionResolver.ts | 13 +- .../src/graphql/resolver/UserResolver.test.ts | 20 +- backend/src/graphql/resolver/UserResolver.ts | 35 +++- 8 files changed, 182 insertions(+), 139 deletions(-) diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 27b51b47d..961d83219 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -10,7 +10,7 @@ Decimal.set({ }) const constants = { - DB_VERSION: '0060-update_communities_table', + DB_VERSION: '0061-event_refactoring', DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0 LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 8e65d85f2..5ba21fe19 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -1,212 +1,230 @@ -import { EventProtocol as DbEvent } from '@entity/EventProtocol' +import { Event as DbEvent } from '@entity/Event' +import { User as DbUser } from '@entity/User' +import { ContributionMessage as DbContributionMessage } from '@entity/ContributionMessage' +import { Contribution as DbContribution } from '@entity/Contribution' +import { Transaction as DbTransaction } from '@entity/Transaction' import Decimal from 'decimal.js-light' import { EventProtocolType } from './EventProtocolType' export const Event = ( type: EventProtocolType, - userId: number, - xUserId: number | null = null, - xCommunityId: number | null = null, - transactionId: number | null = null, - contributionId: number | null = null, + affectedUser: DbUser, + actingUser: DbUser, + involvedUser: DbUser | null = null, + involvedTransaction: DbTransaction | null = null, + involvedContribution: DbContribution | null = null, + involvedContributionMessage: DbContributionMessage | null = null, amount: Decimal | null = null, - messageId: number | null = null, ): DbEvent => { const event = new DbEvent() event.type = type - event.userId = userId - event.xUserId = xUserId - event.xCommunityId = xCommunityId - event.transactionId = transactionId - event.contributionId = contributionId + event.affectedUser = affectedUser + event.actingUser = actingUser + event.involvedUser = involvedUser + event.involvedTransaction = involvedTransaction + event.involvedContribution = involvedContribution + event.involvedContributionMessage = involvedContributionMessage event.amount = amount - event.messageId = messageId return event } export const EVENT_CONTRIBUTION_CREATE = async ( - userId: number, - contributionId: number, + user: DbUser, + contribution: DbContribution, amount: Decimal, ): Promise => Event( EventProtocolType.CONTRIBUTION_CREATE, - userId, + user, + user, null, null, + contribution, null, - contributionId, amount, ).save() export const EVENT_CONTRIBUTION_DELETE = async ( - userId: number, - contributionId: number, + user: DbUser, + contribution: DbContribution, amount: Decimal, ): Promise => Event( EventProtocolType.CONTRIBUTION_DELETE, - userId, + user, + user, null, null, + contribution, null, - contributionId, amount, ).save() export const EVENT_CONTRIBUTION_UPDATE = async ( - userId: number, - contributionId: number, + user: DbUser, + contribution: DbContribution, amount: Decimal, ): Promise => Event( EventProtocolType.CONTRIBUTION_UPDATE, - userId, + user, + user, null, null, + contribution, null, - contributionId, amount, ).save() +// TODO what was user_id? affected or moderator user? +// await EVENT_ADMIN_CONTRIBUTION_CREATE(moderator.id, contribution.id, amount) export const EVENT_ADMIN_CONTRIBUTION_CREATE = async ( - userId: number, - contributionId: number, + user: DbUser, + moderator: DbUser, + contribution: DbContribution, amount: Decimal, ): Promise => Event( EventProtocolType.ADMIN_CONTRIBUTION_CREATE, - userId, + user, + moderator, null, null, + contribution, null, - contributionId, amount, ).save() +// TODO await EVENT_ADMIN_CONTRIBUTION_UPDATE(emailContact.user.id, contributionToUpdate.id, amount) export const EVENT_ADMIN_CONTRIBUTION_UPDATE = async ( - userId: number, - contributionId: number, + user: DbUser, + moderator: DbUser, + contribution: DbContribution, amount: Decimal, ): Promise => Event( EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, - userId, + user, + moderator, null, null, + contribution, null, - contributionId, amount, ).save() +// TODO await EVENT_ADMIN_CONTRIBUTION_DELETE(contribution.userId, contribution.id, contribution.amount) export const EVENT_ADMIN_CONTRIBUTION_DELETE = async ( - userId: number, - contributionId: number, + user: DbUser, + moderator: DbUser, + contribution: DbContribution, amount: Decimal, ): Promise => Event( EventProtocolType.ADMIN_CONTRIBUTION_DELETE, - userId, + user, + moderator, null, null, + contribution, null, - contributionId, amount, ).save() +// TODO await EVENT_CONTRIBUTION_CONFIRM(user.id, contribution.id, contribution.amount) export const EVENT_CONTRIBUTION_CONFIRM = async ( - userId: number, - contributionId: number, + user: DbUser, + moderator: DbUser, + contribution: DbContribution, amount: Decimal, ): Promise => Event( EventProtocolType.CONTRIBUTION_CONFIRM, - userId, + user, + moderator, null, null, + contribution, null, - contributionId, amount, ).save() +// TODO await EVENT_ADMIN_CONTRIBUTION_DENY( +// contributionToUpdate.userId, +// moderator.id, +// contributionToUpdate.id, +// contributionToUpdate.amount, +// ) +// x User = moderator export const EVENT_ADMIN_CONTRIBUTION_DENY = async ( - userId: number, - xUserId: number, - contributionId: number, + user: DbUser, + moderator: DbUser, + contribution: DbContribution, amount: Decimal, ): Promise => Event( EventProtocolType.ADMIN_CONTRIBUTION_DENY, - userId, - xUserId, + user, + moderator, null, null, - contributionId, + contribution, + null, amount, ).save() export const EVENT_TRANSACTION_SEND = async ( - userId: number, - xUserId: number, - transactionId: number, + user: DbUser, + involvedUser: DbUser, + transaction: DbTransaction, amount: Decimal, ): Promise => Event( EventProtocolType.TRANSACTION_SEND, - userId, - xUserId, + user, + user, + involvedUser, + transaction, null, - transactionId, null, amount, ).save() +// TODO acting user = involved user export const EVENT_TRANSACTION_RECEIVE = async ( - userId: number, - xUserId: number, - transactionId: number, + user: DbUser, + involvedUser: DbUser, + transaction: DbTransaction, amount: Decimal, ): Promise => Event( EventProtocolType.TRANSACTION_RECEIVE, - userId, - xUserId, + user, + involvedUser, + involvedUser, + transaction, null, - transactionId, null, amount, ).save() -export const EVENT_LOGIN = async (userId: number): Promise => - Event(EventProtocolType.LOGIN, userId, null, null, null, null, null, null).save() +export const EVENT_LOGIN = async (user: DbUser): Promise => + Event(EventProtocolType.LOGIN, user, user).save() -export const EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = async ( - userId: number, -): Promise => Event(EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, userId).save() +export const EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = async (user: DbUser): Promise => + Event(EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, user, { id: 0 } as DbUser).save() -export const EVENT_SEND_CONFIRMATION_EMAIL = async (userId: number): Promise => - Event(EventProtocolType.SEND_CONFIRMATION_EMAIL, userId).save() +export const EVENT_SEND_CONFIRMATION_EMAIL = async (user: DbUser): Promise => + Event(EventProtocolType.SEND_CONFIRMATION_EMAIL, user, user).save() -export const EVENT_ADMIN_SEND_CONFIRMATION_EMAIL = async (userId: number): Promise => - Event(EventProtocolType.ADMIN_SEND_CONFIRMATION_EMAIL, userId).save() +export const EVENT_ADMIN_SEND_CONFIRMATION_EMAIL = async ( + user: DbUser, + moderator: DbUser, +): Promise => + Event(EventProtocolType.ADMIN_SEND_CONFIRMATION_EMAIL, user, moderator).save() -/* export const EVENT_REDEEM_REGISTER = async ( - userId: number, - transactionId: number | null = null, - contributionId: number | null = null, -): Promise => - Event( - EventProtocolType.REDEEM_REGISTER, - userId, - null, - null, - transactionId, - contributionId, - ).save() -*/ +export const EVENT_REGISTER = async (user: DbUser): Promise => + Event(EventProtocolType.REGISTER, user, user).save() -export const EVENT_REGISTER = async (userId: number): Promise => - Event(EventProtocolType.REGISTER, userId).save() - -export const EVENT_ACTIVATE_ACCOUNT = async (userId: number): Promise => - Event(EventProtocolType.ACTIVATE_ACCOUNT, userId).save() +export const EVENT_ACTIVATE_ACCOUNT = async (user: DbUser): Promise => + Event(EventProtocolType.ACTIVATE_ACCOUNT, user, user).save() diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index b56180c45..8f2ae3981 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -38,7 +38,7 @@ import { userFactory } from '@/seeds/factory/user' import { creationFactory } from '@/seeds/factory/creation' import { creations } from '@/seeds/creation/index' import { peterLustig } from '@/seeds/users/peter-lustig' -import { EventProtocol } from '@entity/EventProtocol' +import { Event as DbEvent } from '@entity/Event' import { Contribution } from '@entity/Contribution' import { Transaction as DbTransaction } from '@entity/Transaction' import { User } from '@entity/User' @@ -284,7 +284,7 @@ describe('ContributionResolver', () => { }) it('stores the CONTRIBUTION_CREATE event in the database', async () => { - await expect(EventProtocol.find()).resolves.toContainEqual( + await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.CONTRIBUTION_CREATE, amount: expect.decimalEqual(100), @@ -589,7 +589,7 @@ describe('ContributionResolver', () => { variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, }) - await expect(EventProtocol.find()).resolves.toContainEqual( + await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.CONTRIBUTION_UPDATE, amount: expect.decimalEqual(10), @@ -819,7 +819,7 @@ describe('ContributionResolver', () => { }) it('stores the ADMIN_CONTRIBUTION_DENY event in the database', async () => { - await expect(EventProtocol.find()).resolves.toContainEqual( + await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_CONTRIBUTION_DENY, userId: bibi.id, @@ -934,7 +934,7 @@ describe('ContributionResolver', () => { }) it('stores the CONTRIBUTION_DELETE event in the database', async () => { - await expect(EventProtocol.find()).resolves.toContainEqual( + await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.CONTRIBUTION_DELETE, contributionId: contributionToDelete.data.createContribution.id, @@ -2082,7 +2082,7 @@ describe('ContributionResolver', () => { }) it('stores the ADMIN_CONTRIBUTION_CREATE event in the database', async () => { - await expect(EventProtocol.find()).resolves.toContainEqual( + await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_CONTRIBUTION_CREATE, userId: admin.id, @@ -2353,7 +2353,7 @@ describe('ContributionResolver', () => { }) it('stores the ADMIN_CONTRIBUTION_UPDATE event in the database', async () => { - await expect(EventProtocol.find()).resolves.toContainEqual( + await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, userId: admin.id, @@ -2394,7 +2394,7 @@ describe('ContributionResolver', () => { }) it('stores the ADMIN_CONTRIBUTION_UPDATE event in the database', async () => { - await expect(EventProtocol.find()).resolves.toContainEqual( + await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, userId: admin.id, @@ -2573,7 +2573,7 @@ describe('ContributionResolver', () => { }) it('stores the ADMIN_CONTRIBUTION_DELETE event in the database', async () => { - await expect(EventProtocol.find()).resolves.toContainEqual( + await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_CONTRIBUTION_DELETE, userId: admin.id, @@ -2717,7 +2717,7 @@ describe('ContributionResolver', () => { }) it('stores the CONTRIBUTION_CONFIRM event in the database', async () => { - await expect(EventProtocol.find()).resolves.toContainEqual( + await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.CONTRIBUTION_CONFIRM, }), @@ -2749,7 +2749,7 @@ describe('ContributionResolver', () => { }) it('stores the SEND_CONFIRMATION_EMAIL event in the database', async () => { - await expect(EventProtocol.find()).resolves.toContainEqual( + await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.SEND_CONFIRMATION_EMAIL, }), diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index c2f0d7d23..145966f47 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -91,7 +91,7 @@ export class ContributionResolver { logger.trace('contribution to save', contribution) await DbContribution.save(contribution) - await EVENT_CONTRIBUTION_CREATE(user.id, contribution.id, amount) + await EVENT_CONTRIBUTION_CREATE(user, contribution, amount) return new UnconfirmedContribution(contribution, user, creations) } @@ -119,7 +119,7 @@ export class ContributionResolver { contribution.deletedAt = new Date() await contribution.save() - await EVENT_CONTRIBUTION_DELETE(user.id, contribution.id, contribution.amount) + await EVENT_CONTRIBUTION_DELETE(user, contribution, contribution.amount) const res = await contribution.softRemove() return !!res @@ -267,7 +267,7 @@ export class ContributionResolver { contributionToUpdate.updatedAt = new Date() DbContribution.save(contributionToUpdate) - await EVENT_CONTRIBUTION_UPDATE(user.id, contributionId, amount) + await EVENT_CONTRIBUTION_UPDATE(user, contributionToUpdate, amount) return new UnconfirmedContribution(contributionToUpdate, user, creations) } @@ -324,7 +324,7 @@ export class ContributionResolver { await DbContribution.save(contribution) - await EVENT_ADMIN_CONTRIBUTION_CREATE(moderator.id, contribution.id, amount) + await EVENT_ADMIN_CONTRIBUTION_CREATE(emailContact.user, moderator, contribution, amount) return getUserCreation(emailContact.userId, clientTimezoneOffset) } @@ -419,7 +419,12 @@ export class ContributionResolver { result.creation = await getUserCreation(emailContact.user.id, clientTimezoneOffset) - await EVENT_ADMIN_CONTRIBUTION_UPDATE(emailContact.user.id, contributionToUpdate.id, amount) + await EVENT_ADMIN_CONTRIBUTION_UPDATE( + emailContact.user, + moderator, + contributionToUpdate, + amount, + ) return result } @@ -490,7 +495,13 @@ export class ContributionResolver { await contribution.save() const res = await contribution.softRemove() - await EVENT_ADMIN_CONTRIBUTION_DELETE(contribution.userId, contribution.id, contribution.amount) + // TODO allow to query the user with relation + await EVENT_ADMIN_CONTRIBUTION_DELETE( + { id: contribution.userId } as DbUser, + moderator, + contribution, + contribution.amount, + ) sendContributionDeletedEmail({ firstName: user.firstName, @@ -603,7 +614,7 @@ export class ContributionResolver { await queryRunner.release() } - await EVENT_CONTRIBUTION_CONFIRM(user.id, contribution.id, contribution.amount) + await EVENT_CONTRIBUTION_CONFIRM(user, moderatorUser, contribution, contribution.amount) } finally { releaseLock() } @@ -694,9 +705,9 @@ export class ContributionResolver { const res = await contributionToUpdate.save() await EVENT_ADMIN_CONTRIBUTION_DENY( - contributionToUpdate.userId, - moderator.id, - contributionToUpdate.id, + user, + moderator, + contributionToUpdate, contributionToUpdate.amount, ) diff --git a/backend/src/graphql/resolver/TransactionResolver.test.ts b/backend/src/graphql/resolver/TransactionResolver.test.ts index 6751aa6ad..fd4f839b6 100644 --- a/backend/src/graphql/resolver/TransactionResolver.test.ts +++ b/backend/src/graphql/resolver/TransactionResolver.test.ts @@ -14,7 +14,7 @@ import { bobBaumeister } from '@/seeds/users/bob-baumeister' import { garrickOllivander } from '@/seeds/users/garrick-ollivander' import { peterLustig } from '@/seeds/users/peter-lustig' import { stephenHawking } from '@/seeds/users/stephen-hawking' -import { EventProtocol } from '@entity/EventProtocol' +import { Event as DbEvent } from '@entity/Event' import { Transaction } from '@entity/Transaction' import { User } from '@entity/User' import { cleanDB, testEnvironment } from '@test/helpers' @@ -337,7 +337,7 @@ describe('send coins', () => { memo: 'unrepeatable memo', }) - expect(EventProtocol.find()).resolves.toContainEqual( + expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.TRANSACTION_SEND, userId: user[1].id, @@ -354,7 +354,7 @@ describe('send coins', () => { memo: 'unrepeatable memo', }) - expect(EventProtocol.find()).resolves.toContainEqual( + expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.TRANSACTION_RECEIVE, userId: user[0].id, diff --git a/backend/src/graphql/resolver/TransactionResolver.ts b/backend/src/graphql/resolver/TransactionResolver.ts index 9d5a1d38c..f0527ee61 100644 --- a/backend/src/graphql/resolver/TransactionResolver.ts +++ b/backend/src/graphql/resolver/TransactionResolver.ts @@ -138,16 +138,17 @@ export const executeTransaction = async ( logger.info(`commit Transaction successful...`) await EVENT_TRANSACTION_SEND( - transactionSend.userId, - transactionSend.linkedUserId, - transactionSend.id, + sender, + recipient, + transactionSend, + // TODO why mul -1? transactionSend.amount.mul(-1), ) await EVENT_TRANSACTION_RECEIVE( - transactionReceive.userId, - transactionReceive.linkedUserId, - transactionReceive.id, + recipient, + sender, + transactionReceive, transactionReceive.amount, ) } catch (e) { diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index 19eb04b34..a2dd08ea4 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -35,7 +35,7 @@ import { transactionLinkFactory } from '@/seeds/factory/transactionLink' import { ContributionLink } from '@model/ContributionLink' import { TransactionLink } from '@entity/TransactionLink' import { EventProtocolType } from '@/event/EventProtocolType' -import { EventProtocol } from '@entity/EventProtocol' +import { Event as DbEvent } from '@entity/Event' import { validate as validateUUID, version as versionUUID } from 'uuid' import { peterLustig } from '@/seeds/users/peter-lustig' import { UserContact } from '@entity/UserContact' @@ -182,7 +182,7 @@ describe('UserResolver', () => { { email: 'peter@lustig.de' }, { relations: ['user'] }, ) - expect(EventProtocol.find()).resolves.toContainEqual( + expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.REGISTER, userId: userConatct.user.id, @@ -211,7 +211,7 @@ describe('UserResolver', () => { }) it('stores the SEND_CONFIRMATION_EMAIL event in the database', () => { - expect(EventProtocol.find()).resolves.toContainEqual( + expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.SEND_CONFIRMATION_EMAIL, userId: user[0].id, @@ -256,7 +256,7 @@ describe('UserResolver', () => { { email: 'peter@lustig.de' }, { relations: ['user'] }, ) - expect(EventProtocol.find()).resolves.toContainEqual( + expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, userId: userConatct.user.id, @@ -356,7 +356,7 @@ describe('UserResolver', () => { }) it('stores the ACTIVATE_ACCOUNT event in the database', () => { - expect(EventProtocol.find()).resolves.toContainEqual( + expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ACTIVATE_ACCOUNT, userId: user[0].id, @@ -365,7 +365,7 @@ describe('UserResolver', () => { }) it('stores the REDEEM_REGISTER event in the database', () => { - expect(EventProtocol.find()).resolves.toContainEqual( + expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.REDEEM_REGISTER, userId: result.data.createUser.id, @@ -449,7 +449,7 @@ describe('UserResolver', () => { }) it('stores the REDEEM_REGISTER event in the database', async () => { - await expect(EventProtocol.find()).resolves.toContainEqual( + await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.REDEEM_REGISTER, userId: newUser.data.createUser.id, @@ -680,7 +680,7 @@ describe('UserResolver', () => { { email: 'bibi@bloxberg.de' }, { relations: ['user'] }, ) - expect(EventProtocol.find()).resolves.toContainEqual( + expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.LOGIN, userId: userConatct.user.id, @@ -928,7 +928,7 @@ describe('UserResolver', () => { }) it('stores the LOGIN event in the database', () => { - expect(EventProtocol.find()).resolves.toContainEqual( + expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.LOGIN, userId: user[0].id, @@ -1847,7 +1847,7 @@ describe('UserResolver', () => { { email: 'bibi@bloxberg.de' }, { relations: ['user'] }, ) - expect(EventProtocol.find()).resolves.toContainEqual( + expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_SEND_CONFIRMATION_EMAIL, userId: userConatct.user.id, diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index f9617b0df..435ca3c82 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -16,7 +16,9 @@ import { getConnection, getCustomRepository, IsNull, Not } from '@dbTools/typeor import { User as DbUser } from '@entity/User' import { UserContact as DbUserContact } from '@entity/UserContact' import { TransactionLink as DbTransactionLink } from '@entity/TransactionLink' +import { Transaction as DbTransaction } from '@entity/Transaction' import { ContributionLink as DbContributionLink } from '@entity/ContributionLink' +import { Contribution as DbContribution } from '@entity/Contribution' import { UserRepository } from '@repository/User' import { User } from '@model/User' @@ -178,7 +180,7 @@ export class UserResolver { value: encode(dbUser.gradidoID), }) - await EVENT_LOGIN(user.id) + await EVENT_LOGIN(dbUser) logger.info(`successful Login: ${JSON.stringify(user, null, 2)}`) return user } @@ -248,7 +250,7 @@ export class UserResolver { language: foundUser.language, // use language of the emails owner for sending }) - await EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL(foundUser.id) + await EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL(foundUser) logger.info( `sendAccountMultiRegistrationEmail by ${firstName} ${lastName} to ${foundUser.firstName} ${foundUser.lastName} <${email}>`, @@ -266,7 +268,11 @@ export class UserResolver { const gradidoID = await newGradidoID() - const eventRegisterRedeem = Event(EventProtocolType.REDEEM_REGISTER, 0) + const eventRegisterRedeem = Event( + EventProtocolType.REDEEM_REGISTER, + { id: 0 } as DbUser, + { id: 0 } as DbUser, + ) let dbUser = new DbUser() dbUser.gradidoID = gradidoID dbUser.firstName = firstName @@ -283,14 +289,16 @@ export class UserResolver { logger.info('redeemCode found contributionLink=' + contributionLink) if (contributionLink) { dbUser.contributionLinkId = contributionLink.id - eventRegisterRedeem.contributionId = contributionLink.id + // TODO this is so wrong + eventRegisterRedeem.involvedContribution = { id: contributionLink.id } as DbContribution } } else { const transactionLink = await DbTransactionLink.findOne({ code: redeemCode }) logger.info('redeemCode found transactionLink=' + transactionLink) if (transactionLink) { dbUser.referrerId = transactionLink.userId - eventRegisterRedeem.transactionId = transactionLink.id + // TODO this is so wrong + eventRegisterRedeem.involvedTransaction = { id: transactionLink.id } as DbTransaction } } } @@ -329,7 +337,7 @@ export class UserResolver { }) logger.info(`sendAccountActivationEmail of ${firstName}.${lastName} to ${email}`) - await EVENT_SEND_CONFIRMATION_EMAIL(dbUser.id) + await EVENT_SEND_CONFIRMATION_EMAIL(dbUser) if (!emailSent) { logger.debug(`Account confirmation link: ${activationLink}`) @@ -346,10 +354,11 @@ export class UserResolver { logger.info('createUser() successful...') if (redeemCode) { - eventRegisterRedeem.userId = dbUser.id + eventRegisterRedeem.affectedUser = dbUser + eventRegisterRedeem.actingUser = dbUser await eventRegisterRedeem.save() } else { - await EVENT_REGISTER(dbUser.id) + await EVENT_REGISTER(dbUser) } return new User(dbUser) @@ -465,7 +474,7 @@ export class UserResolver { await queryRunner.commitTransaction() logger.info('User and UserContact data written successfully...') - await EVENT_ACTIVATE_ACCOUNT(user.id) + await EVENT_ACTIVATE_ACCOUNT(user) } catch (e) { await queryRunner.rollbackTransaction() throw new LogError('Error on writing User and User Contact data', e) @@ -775,9 +784,13 @@ export class UserResolver { return null } + // TODO this is an admin function - needs refactor @Authorized([RIGHTS.SEND_ACTIVATION_EMAIL]) @Mutation(() => Boolean) - async sendActivationEmail(@Arg('email') email: string): Promise { + async sendActivationEmail( + @Arg('email') email: string, + @Ctx() context: Context, + ): Promise { email = email.trim().toLowerCase() // const user = await dbUser.findOne({ id: emailContact.userId }) const user = await findUserByEmail(email) @@ -802,7 +815,7 @@ export class UserResolver { if (!emailSent) { logger.info(`Account confirmation link: ${activationLink}`) } else { - await EVENT_ADMIN_SEND_CONFIRMATION_EMAIL(user.id) + await EVENT_ADMIN_SEND_CONFIRMATION_EMAIL(user, getUser(context)) } return true From 4e55acebeb0fec2e92a010b109a307e4b26fddd3 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 18 Feb 2023 01:24:48 +0100 Subject: [PATCH 015/106] have explicit reference id columns due to missing foreign keys --- .../entity/0061-event_refactoring/Event.ts | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/database/entity/0061-event_refactoring/Event.ts b/database/entity/0061-event_refactoring/Event.ts index 5a62fcdc2..219861834 100644 --- a/database/entity/0061-event_refactoring/Event.ts +++ b/database/entity/0061-event_refactoring/Event.ts @@ -30,45 +30,46 @@ export class Event extends BaseEntity { }) createdAt: Date - // @Column({ name: 'affected_user_id', unsigned: true, nullable: false }) - // affectedUserId: number + @Column({ name: 'affected_user_id', unsigned: true, nullable: false }) + affectedUserId: number @ManyToOne(() => User) @JoinColumn({ name: 'affected_user_id', referencedColumnName: 'id' }) affectedUser: User // TODO potentially save actingRole as well - // @Column({ name: 'acting_user_id', unsigned: true, nullable: false }) - // actingUserId: number + @Column({ name: 'acting_user_id', unsigned: true, nullable: false }) + actingUserId: number @ManyToOne(() => User) @JoinColumn({ name: 'acting_user_id', referencedColumnName: 'id' }) actingUser: User - // @Column({ name: 'involved_user_id', type: 'int', unsigned: true, nullable: true }) - // involvedUserId: number | null + @Column({ name: 'involved_user_id', type: 'int', unsigned: true, nullable: true }) + involvedUserId: number | null @ManyToOne(() => User) @JoinColumn({ name: 'involved_user_id', referencedColumnName: 'id' }) involvedUser: User | null - // @Column({ name: 'involved_transaction_id', type: 'int', unsigned: true, nullable: true }) - // involvedTransactionId: number | null + @Column({ name: 'involved_transaction_id', type: 'int', unsigned: true, nullable: true }) + involvedTransactionId: number | null @ManyToOne(() => Transaction) @JoinColumn({ name: 'involved_transaction_id', referencedColumnName: 'id' }) involvedTransaction: Transaction | null - // @Column({ name: 'involved_contribution_id', type: 'int', unsigned: true, nullable: true }) - // involvedContributionId: number | null + @Column({ name: 'involved_contribution_id', type: 'int', unsigned: true, nullable: true }) + involvedContributionId: number | null @ManyToOne(() => Contribution) @JoinColumn({ name: 'involved_contribution_id', referencedColumnName: 'id' }) involvedContribution: Contribution | null // TEST do we need the Id field definition? - // @Column({ name: 'involved_contribution_message_id', type: 'int', unsigned: true, nullable: true }) - // involvedContributionMessageId: number | null + // TODO we need proper foreign keys to have things working without the explicit column + @Column({ name: 'involved_contribution_message_id', type: 'int', unsigned: true, nullable: true }) + involvedContributionMessageId: number | null @ManyToOne(() => ContributionMessage) @JoinColumn({ name: 'involved_contribution_message_id', referencedColumnName: 'id' }) From e73c26a1cd045a28c55c9954e63e8346dcc4b983 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 18 Feb 2023 01:31:29 +0100 Subject: [PATCH 016/106] fix transactionResolver tests --- .../graphql/resolver/TransactionResolver.test.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/backend/src/graphql/resolver/TransactionResolver.test.ts b/backend/src/graphql/resolver/TransactionResolver.test.ts index fd4f839b6..6ddbb8191 100644 --- a/backend/src/graphql/resolver/TransactionResolver.test.ts +++ b/backend/src/graphql/resolver/TransactionResolver.test.ts @@ -340,9 +340,10 @@ describe('send coins', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.TRANSACTION_SEND, - userId: user[1].id, - transactionId: transaction[0].id, - xUserId: user[0].id, + affectedUserId: user[1].id, + actingUserId: user[1].id, + involvedUserId: user[0].id, + involvedTransactionId: transaction[0].id, }), ) }) @@ -357,9 +358,10 @@ describe('send coins', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.TRANSACTION_RECEIVE, - userId: user[0].id, - transactionId: transaction[0].id, - xUserId: user[1].id, + affectedUserId: user[0].id, + actingUserId: user[1].id, + involvedUserId: user[1].id, + involvedTransactionId: transaction[0].id, }), ) }) From 08ad0fb1bbe457a6e97836cfa9ead0d9e746af27 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 18 Feb 2023 01:43:27 +0100 Subject: [PATCH 017/106] fix userResolver tests --- .../src/graphql/resolver/UserResolver.test.ts | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index a2dd08ea4..e627f4f0f 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -185,7 +185,8 @@ describe('UserResolver', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.REGISTER, - userId: userConatct.user.id, + affectedUserId: userConatct.user.id, + actingUserId: userConatct.user.id, }), ) }) @@ -214,7 +215,8 @@ describe('UserResolver', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.SEND_CONFIRMATION_EMAIL, - userId: user[0].id, + affectedUserId: user[0].id, + actingUserId: user[0].id, }), ) }) @@ -259,7 +261,8 @@ describe('UserResolver', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, - userId: userConatct.user.id, + affectedUserId: userConatct.user.id, + actingUserId: 0, }), ) }) @@ -359,7 +362,8 @@ describe('UserResolver', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ACTIVATE_ACCOUNT, - userId: user[0].id, + affectedUserId: user[0].id, + actingUserId: user[0].id, }), ) }) @@ -368,8 +372,9 @@ describe('UserResolver', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.REDEEM_REGISTER, - userId: result.data.createUser.id, - contributionId: link.id, + affectedUserId: result.data.createUser.id, + actingUserId: result.data.createUser.id, + involvedContributionId: link.id, }), ) }) @@ -452,7 +457,9 @@ describe('UserResolver', () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.REDEEM_REGISTER, - userId: newUser.data.createUser.id, + affectedUserId: newUser.data.createUser.id, + actingUserId: newUser.data.createUser.id, + involvedTransactionId: transactionLink.id, }), ) }) @@ -683,7 +690,8 @@ describe('UserResolver', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.LOGIN, - userId: userConatct.user.id, + affectedUserId: userConatct.user.id, + actingUserId: userConatct.user.id, }), ) }) @@ -931,7 +939,8 @@ describe('UserResolver', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.LOGIN, - userId: user[0].id, + affectedUserId: user[0].id, + actingUserId: user[0].id, }), ) }) @@ -1850,7 +1859,8 @@ describe('UserResolver', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_SEND_CONFIRMATION_EMAIL, - userId: userConatct.user.id, + affectedUserId: userConatct.user.id, + actingUserId: admin.id, }), ) }) From 8744ff919e21bcdd4757453a71c6db9e23e2af03 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 18 Feb 2023 02:01:31 +0100 Subject: [PATCH 018/106] fix contributionResolver tests --- .../resolver/ContributionResolver.test.ts | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 8f2ae3981..540285c53 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -287,9 +287,10 @@ describe('ContributionResolver', () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.CONTRIBUTION_CREATE, + affectedUserId: bibi.id, + actingUserId: bibi.id, + involvedContributionId: pendingContribution.data.createContribution.id, amount: expect.decimalEqual(100), - contributionId: pendingContribution.data.createContribution.id, - userId: bibi.id, }), ) }) @@ -592,9 +593,10 @@ describe('ContributionResolver', () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.CONTRIBUTION_UPDATE, + affectedUserId: bibi.id, + actingUserId: bibi.id, + involvedContributionId: pendingContribution.data.createContribution.id, amount: expect.decimalEqual(10), - contributionId: pendingContribution.data.createContribution.id, - userId: bibi.id, }), ) }) @@ -822,9 +824,9 @@ describe('ContributionResolver', () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_CONTRIBUTION_DENY, - userId: bibi.id, - xUserId: admin.id, - contributionId: contributionToDeny.data.createContribution.id, + affectedUserId: bibi.id, + actingUserId: admin.id, + involvedContributionId: contributionToDeny.data.createContribution.id, amount: expect.decimalEqual(100), }), ) @@ -937,9 +939,10 @@ describe('ContributionResolver', () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.CONTRIBUTION_DELETE, - contributionId: contributionToDelete.data.createContribution.id, + affectedUserId: bibi.id, + actingUserId: bibi.id, + involvedContributionId: contributionToDelete.data.createContribution.id, amount: expect.decimalEqual(100), - userId: bibi.id, }), ) }) @@ -2085,7 +2088,8 @@ describe('ContributionResolver', () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_CONTRIBUTION_CREATE, - userId: admin.id, + affectedUserId: bibi.id, + actingUserId: admin.id, amount: expect.decimalEqual(200), }), ) @@ -2329,7 +2333,7 @@ describe('ContributionResolver', () => { mutate({ mutation: adminUpdateContribution, variables: { - id: creation ? creation.id : -1, + id: creation?.id, email: 'peter@lustig.de', amount: new Decimal(300), memo: 'Danke Peter!', @@ -2356,7 +2360,8 @@ describe('ContributionResolver', () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, - userId: admin.id, + affectedUserId: creation?.userId, + actingUserId: admin.id, amount: 300, }), ) @@ -2370,7 +2375,7 @@ describe('ContributionResolver', () => { mutate({ mutation: adminUpdateContribution, variables: { - id: creation ? creation.id : -1, + id: creation?.id, email: 'peter@lustig.de', amount: new Decimal(200), memo: 'Das war leider zu Viel!', @@ -2397,7 +2402,8 @@ describe('ContributionResolver', () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, - userId: admin.id, + affectedUserId: creation?.userId, + actingUserId: admin.id, amount: expect.decimalEqual(200), }), ) @@ -2562,7 +2568,7 @@ describe('ContributionResolver', () => { mutate({ mutation: adminDeleteContribution, variables: { - id: creation ? creation.id : -1, + id: creation?.id, }, }), ).resolves.toEqual( @@ -2576,7 +2582,9 @@ describe('ContributionResolver', () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_CONTRIBUTION_DELETE, - userId: admin.id, + affectedUserId: creation?.userId, + actingUserId: admin.id, + involvedContributionId: creation?.id, amount: expect.decimalEqual(200), }), ) From 89435409aff1da7c498d52cfc07e579e38335fa1 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 18 Feb 2023 02:11:03 +0100 Subject: [PATCH 019/106] fix typo --- federation/src/config/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/federation/src/config/index.ts b/federation/src/config/index.ts index 6b3bf6424..52c73ef0a 100644 --- a/federation/src/config/index.ts +++ b/federation/src/config/index.ts @@ -11,7 +11,7 @@ Decimal.set({ */ const constants = { - DB_VERSION: '0060-0061-event_refactoring', + DB_VERSION: '0061-event_refactoring', // DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0 LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info From 56485d2d75fba0ae6e9749b5a77ac4f55b71d0e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 22 Feb 2023 20:43:19 +0100 Subject: [PATCH 020/106] start adding federation to deployment scripts --- deployment/bare_metal/.env.dist | 2 ++ deployment/bare_metal/start.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/deployment/bare_metal/.env.dist b/deployment/bare_metal/.env.dist index 9c9c7ac82..80c1b36a1 100644 --- a/deployment/bare_metal/.env.dist +++ b/deployment/bare_metal/.env.dist @@ -61,6 +61,8 @@ WEBHOOK_ELOPAGE_SECRET=secret # on an hash created from this topic # FEDERATION_DHT_TOPIC=GRADIDO_HUB # FEDERATION_DHT_SEED=64ebcb0e3ad547848fef4197c6e2332f +FEDERATION_CONFIG_VERSION=v1.2023-01-09 +FEDERATION_API=1_0 # database DATABASE_CONFIG_VERSION=v1.2022-03-18 diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 95b89241f..ae98c7e87 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -1,5 +1,18 @@ #!/bin/bash +echo "Before getopt" +for i +do + echo $i +done +args=`getopt b:p: $*` +set -- $args +echo "After getopt" +for i +do + echo "-->$i" +done + # Find current directory & configure paths set -o allexport SCRIPT_PATH=$(realpath $0) @@ -93,10 +106,12 @@ cp -f $PROJECT_ROOT/database/.env $PROJECT_ROOT/database/.env.bak cp -f $PROJECT_ROOT/backend/.env $PROJECT_ROOT/backend/.env.bak cp -f $PROJECT_ROOT/frontend/.env $PROJECT_ROOT/frontend/.env.bak cp -f $PROJECT_ROOT/admin/.env $PROJECT_ROOT/admin/.env.bak +cp -f $PROJECT_ROOT/federation/.env $PROJECT_ROOT/federation/.env.bak envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $PROJECT_ROOT/database/.env.template > $PROJECT_ROOT/database/.env envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $PROJECT_ROOT/backend/.env.template > $PROJECT_ROOT/backend/.env envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $PROJECT_ROOT/frontend/.env.template > $PROJECT_ROOT/frontend/.env envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $PROJECT_ROOT/admin/.env.template > $PROJECT_ROOT/admin/.env +envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $PROJECT_ROOT/federation/.env.template > $PROJECT_ROOT/federation/.env # Install & build database echo 'Updating database' >> $UPDATE_HTML @@ -152,6 +167,19 @@ pm2 delete gradido-admin pm2 start --name gradido-admin "yarn --cwd $PROJECT_ROOT/admin start" -l $GRADIDO_LOG_PATH/pm2.admin.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save +# Install & build federation +echo 'Updating federation' >> $UPDATE_HTML +cd $PROJECT_ROOT/federation +# TODO maybe handle this differently? +unset NODE_ENV +yarn install +yarn build +# TODO maybe handle this differently? +export NODE_ENV=production +pm2 delete gradido-federation +pm2 start --name gradido-federation "yarn --cwd $PROJECT_ROOT/federation start" -l $GRADIDO_LOG_PATH/pm2.federation.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' +pm2 save + # let nginx showing gradido echo 'Configuring nginx to serve gradido again' >> $UPDATE_HTML ln -s /etc/nginx/sites-available/gradido.conf /etc/nginx/sites-enabled/ From c9df716eb38bde05f60a9a2115ceb07e5fc85fe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 22 Feb 2023 22:42:18 +0100 Subject: [PATCH 021/106] add federation-module to deployment script --- deployment/bare_metal/start.sh | 39 +++++++++++++++++++++++----------- federation/src/config/index.ts | 2 +- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index ae98c7e87..8ec4cfc48 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -1,18 +1,25 @@ #!/bin/bash -echo "Before getopt" -for i -do - echo $i -done -args=`getopt b:p: $*` -set -- $args -echo "After getopt" -for i -do - echo "-->$i" +while [ "$#" -gt 0 ]; do + case "$1" in + -a) ARG_API="${2:-1_0}"; shift 2;; + -b) ARG_BRANCH="${2:-master}"; shift 2;; + + --api-version=*) ARG_API="${1#*=}"; shift 1;; + --branch=*) ARG_BRANCH="${1#*=}"; shift 1;; + --api-version|--branch) echo "$1 requires an argument" >&2; exit 1;; + + -*) echo "unknown option: $1" >&2; exit 1;; + *) handle_argument "$1"; shift 1;; + esac done +echo "==================================================" +echo "Arguments:" +echo " -api-version = $ARG_API" +echo " -branch = $ARG_BRANCH" +echo "==================================================" + # Find current directory & configure paths set -o allexport SCRIPT_PATH=$(realpath $0) @@ -76,7 +83,8 @@ echo 'Stopping all Gradido services' >> $UPDATE_HTML pm2 stop all # git -BRANCH=${1:-master} +# BRANCH=${1:-master} +BRANCH=$ARG_BRANCH echo "Starting with git pull - branch:$BRANCH" >> $UPDATE_HTML cd $PROJECT_ROOT # TODO: this overfetches alot, but ensures we can use start.sh with tags @@ -177,6 +185,13 @@ yarn build # TODO maybe handle this differently? export NODE_ENV=production pm2 delete gradido-federation +# set FEDERATION_PORT from ARG_API +port=${ARG_API//_/} +FEDERATION_PORT=$(($FEDERATION_PORT + $port)) +export FEDERATION_PORT +echo "====================================================" +echo " start federation listening on port=$FEDERATION_PORT +echo "====================================================" pm2 start --name gradido-federation "yarn --cwd $PROJECT_ROOT/federation start" -l $GRADIDO_LOG_PATH/pm2.federation.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save diff --git a/federation/src/config/index.ts b/federation/src/config/index.ts index c8a841315..82011a6bc 100644 --- a/federation/src/config/index.ts +++ b/federation/src/config/index.ts @@ -73,7 +73,7 @@ if ( const federation = { // FEDERATION_DHT_TOPIC: process.env.FEDERATION_DHT_TOPIC || null, // FEDERATION_DHT_SEED: process.env.FEDERATION_DHT_SEED || null, - FEDERATION_PORT: process.env.FEDERATION_PORT || 5010, + FEDERATION_PORT: process.env.FEDERATION_PORT || 5000, FEDERATION_API: process.env.FEDERATION_API || '1_0', FEDERATION_COMMUNITY_URL: process.env.FEDERATION_COMMUNITY_URL || null, } From 8ab39765420a14a0487cba153d49e460e07dff3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 22 Feb 2023 22:57:10 +0100 Subject: [PATCH 022/106] pm2 delete handle case of error as optional --- deployment/bare_metal/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 8ec4cfc48..746701206 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -184,7 +184,7 @@ yarn install yarn build # TODO maybe handle this differently? export NODE_ENV=production -pm2 delete gradido-federation +pm2 delete gradido-federation || : # set FEDERATION_PORT from ARG_API port=${ARG_API//_/} FEDERATION_PORT=$(($FEDERATION_PORT + $port)) From 3d7d3ffdeef4b7e3af7f2e4e5f9bd41b4dd763f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 22 Feb 2023 23:03:29 +0100 Subject: [PATCH 023/106] next try for pm2 delete handling error --- deployment/bare_metal/start.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 746701206..a7ffbd036 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -184,7 +184,6 @@ yarn install yarn build # TODO maybe handle this differently? export NODE_ENV=production -pm2 delete gradido-federation || : # set FEDERATION_PORT from ARG_API port=${ARG_API//_/} FEDERATION_PORT=$(($FEDERATION_PORT + $port)) @@ -192,7 +191,7 @@ export FEDERATION_PORT echo "====================================================" echo " start federation listening on port=$FEDERATION_PORT echo "====================================================" -pm2 start --name gradido-federation "yarn --cwd $PROJECT_ROOT/federation start" -l $GRADIDO_LOG_PATH/pm2.federation.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' +pm2 delete gradido-federation || : && pm2 start --name gradido-federation "yarn --cwd $PROJECT_ROOT/federation start" -l $GRADIDO_LOG_PATH/pm2.federation.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save # let nginx showing gradido From 3425e5998a84aa35c8e2b0848bf2e6f99bba6359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 22 Feb 2023 23:16:07 +0100 Subject: [PATCH 024/106] change federation port settings --- deployment/bare_metal/.env.dist | 1 + deployment/bare_metal/start.sh | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/deployment/bare_metal/.env.dist b/deployment/bare_metal/.env.dist index 80c1b36a1..0e3f2d995 100644 --- a/deployment/bare_metal/.env.dist +++ b/deployment/bare_metal/.env.dist @@ -62,6 +62,7 @@ WEBHOOK_ELOPAGE_SECRET=secret # FEDERATION_DHT_TOPIC=GRADIDO_HUB # FEDERATION_DHT_SEED=64ebcb0e3ad547848fef4197c6e2332f FEDERATION_CONFIG_VERSION=v1.2023-01-09 +FEDERATION_PORT=5000 FEDERATION_API=1_0 # database diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index a7ffbd036..19d1d8852 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -184,14 +184,16 @@ yarn install yarn build # TODO maybe handle this differently? export NODE_ENV=production +pm2 delete gradido-federation # set FEDERATION_PORT from ARG_API port=${ARG_API//_/} +FEDERATION_PORT=${FEDERATION_PORT:-5000} FEDERATION_PORT=$(($FEDERATION_PORT + $port)) export FEDERATION_PORT echo "====================================================" -echo " start federation listening on port=$FEDERATION_PORT +echo " start federation listening on port=$FEDERATION_PORT" echo "====================================================" -pm2 delete gradido-federation || : && pm2 start --name gradido-federation "yarn --cwd $PROJECT_ROOT/federation start" -l $GRADIDO_LOG_PATH/pm2.federation.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' +pm2 start --name gradido-federation "yarn --cwd $PROJECT_ROOT/federation start" -l $GRADIDO_LOG_PATH/pm2.federation.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save # let nginx showing gradido From cc4acd4378fe539106ac0810cebd05a4928ae0b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 22 Feb 2023 23:52:18 +0100 Subject: [PATCH 025/106] change commandline arg handling --- deployment/bare_metal/start.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 19d1d8852..2a2f7b4ea 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -1,9 +1,16 @@ #!/bin/bash +#================================================== +# Commandline Arguments: +# -a value short arg: api-version (default=1_0) +# -b value short arg: branch (default=master) +# --api-version=value arg: api-version (default=1_0) +# --branch=value arg: branch (default=master) +#================================================== while [ "$#" -gt 0 ]; do case "$1" in - -a) ARG_API="${2:-1_0}"; shift 2;; - -b) ARG_BRANCH="${2:-master}"; shift 2;; + -a) ARG_API="$2"; shift 2;; + -b) ARG_BRANCH="$2"; shift 2;; --api-version=*) ARG_API="${1#*=}"; shift 1;; --branch=*) ARG_BRANCH="${1#*=}"; shift 1;; @@ -13,7 +20,13 @@ while [ "$#" -gt 0 ]; do *) handle_argument "$1"; shift 1;; esac done - +if [ -z $ARG_API ]; then + ARG_API="1_0" +fi +if [ -z $ARG_BRANCH ]; then + ARG_BRANCH="master" +fi + echo "==================================================" echo "Arguments:" echo " -api-version = $ARG_API" From 28c4abc7e9bc2838bda73f26464f02ba9b88ad87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Fri, 24 Feb 2023 00:54:57 +0100 Subject: [PATCH 026/106] start several federation moduls base on FEDERATION_COMMUNITY_APIS --- deployment/bare_metal/.env.dist | 7 ++-- deployment/bare_metal/start.sh | 69 +++++++++++---------------------- federation/src/config/index.ts | 4 +- federation/src/index.ts | 2 +- 4 files changed, 30 insertions(+), 52 deletions(-) diff --git a/deployment/bare_metal/.env.dist b/deployment/bare_metal/.env.dist index 7028966bf..0a4a2db4d 100644 --- a/deployment/bare_metal/.env.dist +++ b/deployment/bare_metal/.env.dist @@ -61,14 +61,13 @@ FEDERATION_DHT_CONFIG_VERSION=v2.2023-02-07 # if you set the value of FEDERATION_DHT_TOPIC, the DHT hyperswarm will start to announce and listen on an hash created from this topic # FEDERATION_DHT_TOPIC=GRADIDO_HUB # FEDERATION_DHT_SEED=64ebcb0e3ad547848fef4197c6e2332f - -FEDERATION_CONFIG_VERSION=v1.2023-01-09 -FEDERATION_PORT=5000 -FEDERATION_API=1_0 FEDERATION_COMMUNITY_URL=http://stage1.gradido.net # the api port is the baseport, which will be added with the api-version, e.g. 1_0 = 5010 FEDERATION_COMMUNITY_API_PORT=5000 +FEDERATION_CONFIG_VERSION=v1.2023-01-09 +FEDERATION_COMMUNITY_APIS=1_0,1_1,2_0 + # database DATABASE_CONFIG_VERSION=v1.2022-03-18 diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 39491d699..63c912b55 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -1,38 +1,5 @@ #!/bin/bash -#================================================== -# Commandline Arguments: -# -a value short arg: api-version (default=1_0) -# -b value short arg: branch (default=master) -# --api-version=value arg: api-version (default=1_0) -# --branch=value arg: branch (default=master) -#================================================== -while [ "$#" -gt 0 ]; do - case "$1" in - -a) ARG_API="$2"; shift 2;; - -b) ARG_BRANCH="$2"; shift 2;; - - --api-version=*) ARG_API="${1#*=}"; shift 1;; - --branch=*) ARG_BRANCH="${1#*=}"; shift 1;; - --api-version|--branch) echo "$1 requires an argument" >&2; exit 1;; - - -*) echo "unknown option: $1" >&2; exit 1;; - *) handle_argument "$1"; shift 1;; - esac -done -if [ -z $ARG_API ]; then - ARG_API="1_0" -fi -if [ -z $ARG_BRANCH ]; then - ARG_BRANCH="master" -fi - -echo "==================================================" -echo "Arguments:" -echo " -api-version = $ARG_API" -echo " -branch = $ARG_BRANCH" -echo "==================================================" - # Find current directory & configure paths set -o allexport SCRIPT_PATH=$(realpath $0) @@ -96,8 +63,7 @@ echo 'Stopping all Gradido services' >> $UPDATE_HTML pm2 stop all # git -# BRANCH=${1:-master} -BRANCH=$ARG_BRANCH +BRANCH=${1:-master} echo "Starting with git pull - branch:$BRANCH" >> $UPDATE_HTML cd $PROJECT_ROOT # TODO: this overfetches alot, but ensures we can use start.sh with tags @@ -219,17 +185,28 @@ yarn install yarn build # TODO maybe handle this differently? export NODE_ENV=production -pm2 delete gradido-federation -# set FEDERATION_PORT from ARG_API -port=${ARG_API//_/} -FEDERATION_PORT=${FEDERATION_PORT:-5000} -FEDERATION_PORT=$(($FEDERATION_PORT + $port)) -export FEDERATION_PORT -echo "====================================================" -echo " start federation listening on port=$FEDERATION_PORT" -echo "====================================================" -pm2 start --name gradido-federation "yarn --cwd $PROJECT_ROOT/federation start" -l $GRADIDO_LOG_PATH/pm2.federation.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' -pm2 save +# set FEDERATION_PORT from FEDERATION_COMMUNITY_APIS +IFS="," read -a API_ARRAY <<< $FEDERATION_COMMUNITY_APIS +for api in "${API_ARRAY[@]}" +do + FEDERATION_API=$api + export FEDERATION_API + modulname=gradido-federation-$api + # calculate port by remove '_' and add value of api to baseport + port=${api//_/} + FEDERATION_PORT=${FEDERATION_COMMUNITY_API_PORT:-5000} + FEDERATION_PORT=$(($FEDERATION_PORT + $port)) + export FEDERATION_PORT + echo "====================================================" + echo " start $modulename listening on port=$FEDERATION_PORT" + echo "====================================================" + pm2 delete $modulename + pm2 start --name $modulename "yarn --cwd $PROJECT_ROOT/federation start" -l $GRADIDO_LOG_PATH/pm2.$modulename.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' + pm2 save +done + + + # let nginx showing gradido echo 'Configuring nginx to serve gradido again' >> $UPDATE_HTML diff --git a/federation/src/config/index.ts b/federation/src/config/index.ts index 82011a6bc..de474f517 100644 --- a/federation/src/config/index.ts +++ b/federation/src/config/index.ts @@ -73,8 +73,10 @@ if ( const federation = { // FEDERATION_DHT_TOPIC: process.env.FEDERATION_DHT_TOPIC || null, // FEDERATION_DHT_SEED: process.env.FEDERATION_DHT_SEED || null, - FEDERATION_PORT: process.env.FEDERATION_PORT || 5000, + FEDERATION_COMMUNITY_API_PORT: + process.env.FEDERATION_COMMUNITY_API_PORT || 5000, FEDERATION_API: process.env.FEDERATION_API || '1_0', + FEDERATION_PORT: process.env.FEDERATION_PORT || 5010, FEDERATION_COMMUNITY_URL: process.env.FEDERATION_COMMUNITY_URL || null, } diff --git a/federation/src/index.ts b/federation/src/index.ts index 9096cb260..daf9bfa56 100644 --- a/federation/src/index.ts +++ b/federation/src/index.ts @@ -20,7 +20,7 @@ async function main() { if (CONFIG.GRAPHIQL) { // eslint-disable-next-line no-console console.log( - `GraphIQL available at http://localhost:${CONFIG.FEDERATION_PORT}` + `GraphIQL available at ${CONFIG.FEDERATION_COMMUNITY_URL}:${CONFIG.FEDERATION_PORT}/api` ) } }) From ed010a50f94102f985105c91c11bf220ba8aa9b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Fri, 24 Feb 2023 01:08:02 +0100 Subject: [PATCH 027/106] =?UTF-8?q?correct=20modul-name=C3=ADng=20in=20loo?= =?UTF-8?q?p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deployment/bare_metal/start.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 63c912b55..1db9daf4a 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -189,9 +189,9 @@ export NODE_ENV=production IFS="," read -a API_ARRAY <<< $FEDERATION_COMMUNITY_APIS for api in "${API_ARRAY[@]}" do - FEDERATION_API=$api + FEDERATION_API="$api" export FEDERATION_API - modulname=gradido-federation-$api + modulname="gradido-federation-$api" # calculate port by remove '_' and add value of api to baseport port=${api//_/} FEDERATION_PORT=${FEDERATION_COMMUNITY_API_PORT:-5000} From f570c8416857d47028ca85283d8827216d2043a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Fri, 24 Feb 2023 01:17:37 +0100 Subject: [PATCH 028/106] next try to correct modulname in loop --- deployment/bare_metal/start.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 1db9daf4a..a86e1be3e 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -189,19 +189,20 @@ export NODE_ENV=production IFS="," read -a API_ARRAY <<< $FEDERATION_COMMUNITY_APIS for api in "${API_ARRAY[@]}" do - FEDERATION_API="$api" - export FEDERATION_API - modulname="gradido-federation-$api" + export FEDERATION_API=$api + echo "FEDERATION_API=$FEDERATION_API" + export MODULENAME=gradido-federation-$api + echo "MODULENAME=$MODULENAME" # calculate port by remove '_' and add value of api to baseport port=${api//_/} FEDERATION_PORT=${FEDERATION_COMMUNITY_API_PORT:-5000} FEDERATION_PORT=$(($FEDERATION_PORT + $port)) export FEDERATION_PORT echo "====================================================" - echo " start $modulename listening on port=$FEDERATION_PORT" + echo " start $MODULENAME listening on port=$FEDERATION_PORT" echo "====================================================" - pm2 delete $modulename - pm2 start --name $modulename "yarn --cwd $PROJECT_ROOT/federation start" -l $GRADIDO_LOG_PATH/pm2.$modulename.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' + pm2 delete $MODULENAME + pm2 start --name $MODULENAME "yarn --cwd $PROJECT_ROOT/federation start" -l $GRADIDO_LOG_PATH/pm2.$MODULENAME.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save done From 1394578a5c5df185ea9e852f9643f86d9b797333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Fri, 24 Feb 2023 22:04:38 +0100 Subject: [PATCH 029/106] remove old/existing federation processes from pm2-list before start new ones --- deployment/bare_metal/.env.dist | 1 + deployment/bare_metal/start.sh | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/deployment/bare_metal/.env.dist b/deployment/bare_metal/.env.dist index 0a4a2db4d..12297e357 100644 --- a/deployment/bare_metal/.env.dist +++ b/deployment/bare_metal/.env.dist @@ -66,6 +66,7 @@ FEDERATION_COMMUNITY_URL=http://stage1.gradido.net FEDERATION_COMMUNITY_API_PORT=5000 FEDERATION_CONFIG_VERSION=v1.2023-01-09 +# comma separated list of api-versions, which cause starting several federation moduls FEDERATION_COMMUNITY_APIS=1_0,1_1,2_0 # database diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index a86e1be3e..d30bfeb8e 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -185,6 +185,15 @@ yarn install yarn build # TODO maybe handle this differently? export NODE_ENV=production +# first remove previous pm2 gradido-federation processes from list +IFS="+--- " read -a PROCESS_ARRAY <<< pm2 ls -m | grep "+--- gradido-federation" +for proc in "${PROCESS_ARRAY[@]}" +do + echo "delete process $proc" + pm2 delete $proc +done +pm2 save + # set FEDERATION_PORT from FEDERATION_COMMUNITY_APIS IFS="," read -a API_ARRAY <<< $FEDERATION_COMMUNITY_APIS for api in "${API_ARRAY[@]}" From 6309c1f8835da5271d60b02d19385f2b3f82dcea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Fri, 24 Feb 2023 22:43:58 +0100 Subject: [PATCH 030/106] next try to remove federation-processes from pm2 before start api-version ones --- deployment/bare_metal/start.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index d30bfeb8e..83115916e 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -186,10 +186,12 @@ yarn build # TODO maybe handle this differently? export NODE_ENV=production # first remove previous pm2 gradido-federation processes from list -IFS="+--- " read -a PROCESS_ARRAY <<< pm2 ls -m | grep "+--- gradido-federation" +pm2 ls -m | grep "+--- gradido-federation" | tr '\n' ',' > proc.list +sed -i 's/+--- //g' < proc.list +IFS="\n" read -a PROCESS_ARRAY < proc.list for proc in "${PROCESS_ARRAY[@]}" do - echo "delete process $proc" + echo "---> delete process $proc" pm2 delete $proc done pm2 save From ebc66a0a50b7d108039ea3200574be072246d55c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Fri, 24 Feb 2023 23:07:40 +0100 Subject: [PATCH 031/106] next try to remove processes --- deployment/bare_metal/start.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 83115916e..c1e095fe3 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -186,9 +186,8 @@ yarn build # TODO maybe handle this differently? export NODE_ENV=production # first remove previous pm2 gradido-federation processes from list -pm2 ls -m | grep "+--- gradido-federation" | tr '\n' ',' > proc.list -sed -i 's/+--- //g' < proc.list -IFS="\n" read -a PROCESS_ARRAY < proc.list +pm2 ls -m | grep "+--- gradido-federation" | tr '\n' ',' | sed -e 's/+---//g' > proc.list +IFS="," read -a PROCESS_ARRAY < proc.list for proc in "${PROCESS_ARRAY[@]}" do echo "---> delete process $proc" From fb8c3874c30e5d2f66707b40640360fdb762ec0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Fri, 24 Feb 2023 23:08:20 +0100 Subject: [PATCH 032/106] remove tmp file --- deployment/bare_metal/start.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index c1e095fe3..6ee7d4618 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -194,6 +194,7 @@ do pm2 delete $proc done pm2 save +rm proc.list # set FEDERATION_PORT from FEDERATION_COMMUNITY_APIS IFS="," read -a API_ARRAY <<< $FEDERATION_COMMUNITY_APIS From 17ef143ea8d29ff4b21861ea06fa962b76a83833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Fri, 24 Feb 2023 23:10:13 +0100 Subject: [PATCH 033/106] additional echo outs --- deployment/bare_metal/start.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 6ee7d4618..dd183dd5b 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -195,6 +195,8 @@ do done pm2 save rm proc.list +echo "finished removeing previous gradido-federation processes from pm2" +echo # set FEDERATION_PORT from FEDERATION_COMMUNITY_APIS IFS="," read -a API_ARRAY <<< $FEDERATION_COMMUNITY_APIS From 4510a8dc085f2b15029eb40eeff4ad151d49cf26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Mon, 27 Feb 2023 19:59:07 +0100 Subject: [PATCH 034/106] define nginx for federation --- .../sites-available/gradido.conf.template | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.template index b4c7b3463..2447a439a 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.template @@ -98,6 +98,52 @@ server { error_log $GRADIDO_LOG_PATH/nginx-error.admin.log warn; } + # Federation + location /graphql { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + + proxy_pass http://127.0.0.1:5010; + proxy_redirect off; + + access_log $GRADIDO_LOG_PATH/nginx-access.federation-5010.log gradido_log; + error_log $GRADIDO_LOG_PATH/nginx-error.federation-5010.log warn; + } + + location /graphql { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + + proxy_pass http://127.0.0.1:5011; + proxy_redirect off; + + access_log $GRADIDO_LOG_PATH/nginx-access.federation-5011.log gradido_log; + error_log $GRADIDO_LOG_PATH/nginx-error.federation-5011.log warn; + } + + location /graphql { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + + proxy_pass http://127.0.0.1:5020; + proxy_redirect off; + + access_log $GRADIDO_LOG_PATH/nginx-access.federation-5020.log gradido_log; + error_log $GRADIDO_LOG_PATH/nginx-error.federation-5020.log warn; + } + # TODO this could be a performance optimization #location /vue { # alias /var/www/html/gradido/frontend/dist; From 9c7b98fa700fdad386491c668cdfba6a5ff972fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Mon, 27 Feb 2023 20:01:28 +0100 Subject: [PATCH 035/106] log-output for mismatching received publicKey --- backend/src/federation/validateCommunities.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/backend/src/federation/validateCommunities.ts b/backend/src/federation/validateCommunities.ts index f5a0c50ac..903ceb68b 100644 --- a/backend/src/federation/validateCommunities.ts +++ b/backend/src/federation/validateCommunities.ts @@ -44,13 +44,12 @@ export async function validateCommunities(): Promise { 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) From 8104bd6b4a5c93ad5463ed2dc1f3a595f9197ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Mon, 27 Feb 2023 20:02:41 +0100 Subject: [PATCH 036/106] multi singleton instance handling depending on endpoint --- .../src/federation/client/GraphQLGetClient.ts | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/backend/src/federation/client/GraphQLGetClient.ts b/backend/src/federation/client/GraphQLGetClient.ts index 7e2d89b6c..8086a95fa 100644 --- a/backend/src/federation/client/GraphQLGetClient.ts +++ b/backend/src/federation/client/GraphQLGetClient.ts @@ -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 } } From d987fa9ab4958c10df6d6ddc73866b24af268102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Mon, 27 Feb 2023 20:03:22 +0100 Subject: [PATCH 037/106] solve request body password error --- backend/src/federation/client/1_0/FederationClient.ts | 6 +++++- backend/src/federation/client/1_1/FederationClient.ts | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/backend/src/federation/client/1_0/FederationClient.ts b/backend/src/federation/client/1_0/FederationClient.ts index 1c0ec4996..a8d7e1dff 100644 --- a/backend/src/federation/client/1_0/FederationClient.ts +++ b/backend/src/federation/client/1_0/FederationClient.ts @@ -18,9 +18,13 @@ export async function requestGetPublicKey(dbCom: DbCommunity): Promise Date: Mon, 27 Feb 2023 20:29:49 +0100 Subject: [PATCH 038/106] configure nginx for federation --- .../sites-available/gradido.conf.ssl.template | 46 +++++++++++++++++++ .../sites-available/gradido.conf.template | 6 +-- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template index aade0429b..e179109c8 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template @@ -112,6 +112,52 @@ server { error_log $GRADIDO_LOG_PATH/nginx-error.admin.log warn; } + # Federation + location /federation-5010 { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + + proxy_pass http://127.0.0.1:5010; + proxy_redirect off; + + access_log $GRADIDO_LOG_PATH/nginx-access.federation-5010.log gradido_log; + error_log $GRADIDO_LOG_PATH/nginx-error.federation-5010.log warn; + } + + location /federation-5011 { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + + proxy_pass http://127.0.0.1:5011; + proxy_redirect off; + + access_log $GRADIDO_LOG_PATH/nginx-access.federation-5011.log gradido_log; + error_log $GRADIDO_LOG_PATH/nginx-error.federation-5011.log warn; + } + + location /federation-5020 { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + + proxy_pass http://127.0.0.1:5020; + proxy_redirect off; + + access_log $GRADIDO_LOG_PATH/nginx-access.federation-5020.log gradido_log; + error_log $GRADIDO_LOG_PATH/nginx-error.federation-5020.log warn; + } + # TODO this could be a performance optimization #location /vue { # alias /var/www/html/gradido/frontend/dist; diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.template index 2447a439a..80fe963d5 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.template @@ -99,7 +99,7 @@ server { } # Federation - location /graphql { + location /federation-5010 { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; @@ -114,7 +114,7 @@ server { error_log $GRADIDO_LOG_PATH/nginx-error.federation-5010.log warn; } - location /graphql { + location /federation-5011 { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; @@ -129,7 +129,7 @@ server { error_log $GRADIDO_LOG_PATH/nginx-error.federation-5011.log warn; } - location /graphql { + location /federation-5020 { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; From 8297aa2c39821e0426a5bd11b0ba46e5b77992cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Mon, 27 Feb 2023 21:06:45 +0100 Subject: [PATCH 039/106] add federation modules to nginx --- .../sites-available/gradido.conf.ssl.template | 66 ++++++++++++++++--- .../sites-available/gradido.conf.template | 66 ++++++++++++++++--- 2 files changed, 112 insertions(+), 20 deletions(-) diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template index aade0429b..183d92153 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template @@ -42,19 +42,19 @@ server { # Frontend (default) location / { - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header Host $host; - - proxy_pass http://127.0.0.1:3000; - proxy_redirect off; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + + proxy_pass http://127.0.0.1:3000; + proxy_redirect off; access_log $GRADIDO_LOG_PATH/nginx-access.frontend.log gradido_log; error_log $GRADIDO_LOG_PATH/nginx-error.frontend.log warn; - } + } # Backend location /graphql { @@ -112,6 +112,52 @@ server { error_log $GRADIDO_LOG_PATH/nginx-error.admin.log warn; } + # Federation + location /federation-5010 { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + + proxy_pass http://127.0.0.1:5010; + proxy_redirect off; + + access_log $GRADIDO_LOG_PATH/nginx-access.federation-5010.log gradido_log; + error_log $GRADIDO_LOG_PATH/nginx-error.federation-5010.log warn; + } + + location /federation-5011 { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + + proxy_pass http://127.0.0.1:5011; + proxy_redirect off; + + access_log $GRADIDO_LOG_PATH/nginx-access.federation-5011.log gradido_log; + error_log $GRADIDO_LOG_PATH/nginx-error.federation-5011.log warn; + } + + location /federation-5020 { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + + proxy_pass http://127.0.0.1:5020; + proxy_redirect off; + + access_log $GRADIDO_LOG_PATH/nginx-access.federation-5020.log gradido_log; + error_log $GRADIDO_LOG_PATH/nginx-error.federation-5020.log warn; + } + # TODO this could be a performance optimization #location /vue { # alias /var/www/html/gradido/frontend/dist; diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.template index b4c7b3463..899809a39 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.template @@ -27,19 +27,19 @@ server { # Frontend (default) location / { - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header Host $host; - - proxy_pass http://127.0.0.1:3000; - proxy_redirect off; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + + proxy_pass http://127.0.0.1:3000; + proxy_redirect off; access_log $GRADIDO_LOG_PATH/nginx-access.frontend.log gradido_log; error_log $GRADIDO_LOG_PATH/nginx-error.frontend.log warn; - } + } # Backend location /graphql { @@ -98,6 +98,52 @@ server { error_log $GRADIDO_LOG_PATH/nginx-error.admin.log warn; } + # Federation + location /federation-5010 { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + + proxy_pass http://127.0.0.1:5010; + proxy_redirect off; + + access_log $GRADIDO_LOG_PATH/nginx-access.federation-5010.log gradido_log; + error_log $GRADIDO_LOG_PATH/nginx-error.federation-5010.log warn; + } + + location /federation-5011 { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + + proxy_pass http://127.0.0.1:5011; + proxy_redirect off; + + access_log $GRADIDO_LOG_PATH/nginx-access.federation-5011.log gradido_log; + error_log $GRADIDO_LOG_PATH/nginx-error.federation-5011.log warn; + } + + location /federation-5020 { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + + proxy_pass http://127.0.0.1:5020; + proxy_redirect off; + + access_log $GRADIDO_LOG_PATH/nginx-access.federation-5020.log gradido_log; + error_log $GRADIDO_LOG_PATH/nginx-error.federation-5020.log warn; + } + # TODO this could be a performance optimization #location /vue { # alias /var/www/html/gradido/frontend/dist; From 3bb0ff978bb97c46c4e725352c45f037de636a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 28 Feb 2023 15:52:59 +0100 Subject: [PATCH 040/106] correct nginx locations --- .../nginx/sites-available/gradido.conf.ssl.template | 6 +++--- .../bare_metal/nginx/sites-available/gradido.conf.template | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template index e179109c8..71885d29b 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template @@ -113,7 +113,7 @@ server { } # Federation - location /federation-5010 { + location /api/1_0 { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; @@ -128,7 +128,7 @@ server { error_log $GRADIDO_LOG_PATH/nginx-error.federation-5010.log warn; } - location /federation-5011 { + location /api/1_1 { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; @@ -143,7 +143,7 @@ server { error_log $GRADIDO_LOG_PATH/nginx-error.federation-5011.log warn; } - location /federation-5020 { + location /api/2_0 { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.template index 80fe963d5..b3c493c43 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.template @@ -99,7 +99,7 @@ server { } # Federation - location /federation-5010 { + location /api/1_0 { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; @@ -114,7 +114,7 @@ server { error_log $GRADIDO_LOG_PATH/nginx-error.federation-5010.log warn; } - location /federation-5011 { + location /api/1_1 { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; @@ -129,7 +129,7 @@ server { error_log $GRADIDO_LOG_PATH/nginx-error.federation-5011.log warn; } - location /federation-5020 { + location /api/2_0 { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; From 695dafbf5a362f01496e5a4dd339bd5135aa3cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 28 Feb 2023 15:56:23 +0100 Subject: [PATCH 041/106] correct nginx locations --- .../nginx/sites-available/gradido.conf.ssl.template | 6 +++--- .../bare_metal/nginx/sites-available/gradido.conf.template | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template index 183d92153..baad82135 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template @@ -113,7 +113,7 @@ server { } # Federation - location /federation-5010 { + location /api/1_0 { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; @@ -128,7 +128,7 @@ server { error_log $GRADIDO_LOG_PATH/nginx-error.federation-5010.log warn; } - location /federation-5011 { + location /api/1_1 { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; @@ -143,7 +143,7 @@ server { error_log $GRADIDO_LOG_PATH/nginx-error.federation-5011.log warn; } - location /federation-5020 { + location /api/2_0 { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.template index 899809a39..5dc41b01c 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.template @@ -99,7 +99,7 @@ server { } # Federation - location /federation-5010 { + location /api/1_0 { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; @@ -114,7 +114,7 @@ server { error_log $GRADIDO_LOG_PATH/nginx-error.federation-5010.log warn; } - location /federation-5011 { + location /api/1_1 { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; @@ -129,7 +129,7 @@ server { error_log $GRADIDO_LOG_PATH/nginx-error.federation-5011.log warn; } - location /federation-5020 { + location /api/2_0 { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; From b333bb0b0604a59b75aa80c6ef24d3199d32944e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 28 Feb 2023 22:59:07 +0100 Subject: [PATCH 042/106] modify nginx config for federation modules --- .../gradido-federation.conf.template | 14 ++++ .../sites-available/gradido.conf.template | 45 +------------ deployment/bare_metal/start.sh | 65 +++++++++++++------ 3 files changed, 61 insertions(+), 63 deletions(-) create mode 100644 deployment/bare_metal/nginx/sites-available/gradido-federation.conf.template diff --git a/deployment/bare_metal/nginx/sites-available/gradido-federation.conf.template b/deployment/bare_metal/nginx/sites-available/gradido-federation.conf.template new file mode 100644 index 000000000..2696a6b7d --- /dev/null +++ b/deployment/bare_metal/nginx/sites-available/gradido-federation.conf.template @@ -0,0 +1,14 @@ + location /api/$FEDERATION_APIVERSION { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + + proxy_pass http://127.0.0.1:$FEDERATION_PORT; + proxy_redirect off; + + access_log $GRADIDO_LOG_PATH/nginx-access.federation-$FEDERATION_PORT.log gradido_log; + error_log $GRADIDO_LOG_PATH/nginx-error.federation-$FEDERATION_PORT.log warn; + } diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.template index 5dc41b01c..f0cfb17b5 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.template @@ -99,50 +99,7 @@ server { } # Federation - location /api/1_0 { - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header Host $host; - - proxy_pass http://127.0.0.1:5010; - proxy_redirect off; - - access_log $GRADIDO_LOG_PATH/nginx-access.federation-5010.log gradido_log; - error_log $GRADIDO_LOG_PATH/nginx-error.federation-5010.log warn; - } - - location /api/1_1 { - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header Host $host; - - proxy_pass http://127.0.0.1:5011; - proxy_redirect off; - - access_log $GRADIDO_LOG_PATH/nginx-access.federation-5011.log gradido_log; - error_log $GRADIDO_LOG_PATH/nginx-error.federation-5011.log warn; - } - - location /api/2_0 { - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header Host $host; - - proxy_pass http://127.0.0.1:5020; - proxy_redirect off; - - access_log $GRADIDO_LOG_PATH/nginx-access.federation-5020.log gradido_log; - error_log $GRADIDO_LOG_PATH/nginx-error.federation-5020.log warn; - } + $FEDERATION_NGINX_CONF # TODO this could be a performance optimization #location /vue { diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index dd183dd5b..a4b990527 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -59,8 +59,8 @@ ln -s /etc/nginx/sites-available/update-page.conf /etc/nginx/sites-enabled/ sudo /etc/init.d/nginx restart # stop all services -echo 'Stopping all Gradido services' >> $UPDATE_HTML -pm2 stop all +echo 'Stopping and Delete all Gradido services' >> $UPDATE_HTML +pm2 delete all # git BRANCH=${1:-master} @@ -73,6 +73,29 @@ git pull export BUILD_COMMIT="$(git rev-parse HEAD)" # Generate gradido.conf from template +# *** 1st prepare for each apiversion the federation conf for nginx from federation-template +# *** set FEDERATION_PORT from FEDERATION_COMMUNITY_APIS and create gradido-federation.conf file +echo "================================================================================================" +IFS="," read -a API_ARRAY <<< $FEDERATION_COMMUNITY_APIS +for api in "${API_ARRAY[@]}" +do + export FEDERATION_APIVERSION=$api + # calculate port by remove '_' and add value of api to baseport + port=${api//_/} + FEDERATION_PORT=${FEDERATION_COMMUNITY_API_PORT:-5000} + FEDERATION_PORT=$(($FEDERATION_PORT + $port)) + export FEDERATION_PORT + echo " create ngingx config: location /api/$FEDERATION_APIVERSION to http://127.0.0.1:$FEDERATION_PORT" + envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido-federation.conf.template >> $NGINX_CONFIG_DIR/gradido-federation.conf +done +echo "================================================================================================" + +# *** 2nd read gradido-federation.conf file in env variable +FEDERATION_NGINX_CONF < $NGINX_CONFIG_DIR/gradido-federation.conf +export FEDERATION_NGINX_CONF +echo "FEDERATION_NGINX_CONF=$FEDERATION_NGINX_CONF" + +# *** 3rd generate gradido nginx config including federation modules per api-version echo 'Generate new gradido nginx config' >> $UPDATE_HTML case "$NGINX_SSL" in true) TEMPLATE_FILE="gradido.conf.ssl.template" ;; @@ -80,6 +103,10 @@ case "$NGINX_SSL" in esac envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf +# release lock +rm $LOCK_FILE +exit 1 + # Generate update-page.conf from template echo 'Generate new update-page nginx config' >> $UPDATE_HTML case "$NGINX_SSL" in @@ -126,7 +153,7 @@ if [ "$DEPLOY_SEED_DATA" = "true" ]; then fi # TODO maybe handle this differently? export NODE_ENV=production -pm2 delete gradido-backend +# pm2 delete gradido-backend pm2 start --name gradido-backend "yarn --cwd $PROJECT_ROOT/backend start" -l $GRADIDO_LOG_PATH/pm2.backend.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save @@ -139,7 +166,7 @@ yarn install yarn build # TODO maybe handle this differently? export NODE_ENV=production -pm2 delete gradido-frontend +# pm2 delete gradido-frontend pm2 start --name gradido-frontend "yarn --cwd $PROJECT_ROOT/frontend start" -l $GRADIDO_LOG_PATH/pm2.frontend.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save @@ -152,7 +179,7 @@ yarn install yarn build # TODO maybe handle this differently? export NODE_ENV=production -pm2 delete gradido-admin +# pm2 delete gradido-admin pm2 start --name gradido-admin "yarn --cwd $PROJECT_ROOT/admin start" -l $GRADIDO_LOG_PATH/pm2.admin.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save @@ -165,7 +192,7 @@ yarn install yarn build # TODO maybe handle this differently? export NODE_ENV=production -pm2 delete gradido-dht-node +# pm2 delete gradido-dht-node if [ ! -z $FEDERATION_DHT_TOPIC ]; then pm2 start --name gradido-dht-node "yarn --cwd $PROJECT_ROOT/dht-node start" -l $GRADIDO_LOG_PATH/pm2.dht-node.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save @@ -185,18 +212,18 @@ yarn install yarn build # TODO maybe handle this differently? export NODE_ENV=production -# first remove previous pm2 gradido-federation processes from list -pm2 ls -m | grep "+--- gradido-federation" | tr '\n' ',' | sed -e 's/+---//g' > proc.list -IFS="," read -a PROCESS_ARRAY < proc.list -for proc in "${PROCESS_ARRAY[@]}" -do - echo "---> delete process $proc" - pm2 delete $proc -done -pm2 save -rm proc.list -echo "finished removeing previous gradido-federation processes from pm2" -echo +# # first remove previous pm2 gradido-federation processes from list +# pm2 ls -m | grep "+--- gradido-federation" | tr '\n' ',' | sed -e 's/+---//g' > proc.list +# IFS="," read -a PROCESS_ARRAY < proc.list +# for proc in "${PROCESS_ARRAY[@]}" +# do +# echo "---> delete process $proc" +# pm2 delete $proc +# done +# pm2 save +# rm proc.list +# echo "finished removeing previous gradido-federation processes from pm2" +# echo # set FEDERATION_PORT from FEDERATION_COMMUNITY_APIS IFS="," read -a API_ARRAY <<< $FEDERATION_COMMUNITY_APIS @@ -214,7 +241,7 @@ do echo "====================================================" echo " start $MODULENAME listening on port=$FEDERATION_PORT" echo "====================================================" - pm2 delete $MODULENAME +# pm2 delete $MODULENAME pm2 start --name $MODULENAME "yarn --cwd $PROJECT_ROOT/federation start" -l $GRADIDO_LOG_PATH/pm2.$MODULENAME.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save done From 757053b7351cda90bec94082adb4117155b6da8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 28 Feb 2023 23:07:16 +0100 Subject: [PATCH 043/106] modify nginx config for federation modules --- .../nginx/sites-available/gradido-federation.conf.template | 1 + deployment/bare_metal/start.sh | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/deployment/bare_metal/nginx/sites-available/gradido-federation.conf.template b/deployment/bare_metal/nginx/sites-available/gradido-federation.conf.template index 2696a6b7d..2192b7dbb 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido-federation.conf.template +++ b/deployment/bare_metal/nginx/sites-available/gradido-federation.conf.template @@ -1,3 +1,4 @@ + location /api/$FEDERATION_APIVERSION { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index a4b990527..e2d3ce8cf 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -75,6 +75,7 @@ export BUILD_COMMIT="$(git rev-parse HEAD)" # Generate gradido.conf from template # *** 1st prepare for each apiversion the federation conf for nginx from federation-template # *** set FEDERATION_PORT from FEDERATION_COMMUNITY_APIS and create gradido-federation.conf file +rm $NGINX_CONFIG_DIR/gradido-federation.conf echo "================================================================================================" IFS="," read -a API_ARRAY <<< $FEDERATION_COMMUNITY_APIS for api in "${API_ARRAY[@]}" @@ -91,8 +92,7 @@ done echo "================================================================================================" # *** 2nd read gradido-federation.conf file in env variable -FEDERATION_NGINX_CONF < $NGINX_CONFIG_DIR/gradido-federation.conf -export FEDERATION_NGINX_CONF +export FEDERATION_NGINX_CONF < $NGINX_CONFIG_DIR/gradido-federation.conf echo "FEDERATION_NGINX_CONF=$FEDERATION_NGINX_CONF" # *** 3rd generate gradido nginx config including federation modules per api-version From c14eec061a300014e43e600ba4d71ee021f01fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 28 Feb 2023 23:19:20 +0100 Subject: [PATCH 044/106] modify nginx config for federation modules --- deployment/bare_metal/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index e2d3ce8cf..9592b219e 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -92,7 +92,7 @@ done echo "================================================================================================" # *** 2nd read gradido-federation.conf file in env variable -export FEDERATION_NGINX_CONF < $NGINX_CONFIG_DIR/gradido-federation.conf +export FEDERATION_NGINX_CONFr=$(< $NGINX_CONFIG_DIR/gradido-federation.conf) echo "FEDERATION_NGINX_CONF=$FEDERATION_NGINX_CONF" # *** 3rd generate gradido nginx config including federation modules per api-version From fc08dcd896bd25cbdb13aabc3aa1d6bc8ccfc14d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 28 Feb 2023 23:20:54 +0100 Subject: [PATCH 045/106] modify nginx config for federation modules --- deployment/bare_metal/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 9592b219e..0be61175e 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -92,7 +92,7 @@ done echo "================================================================================================" # *** 2nd read gradido-federation.conf file in env variable -export FEDERATION_NGINX_CONFr=$(< $NGINX_CONFIG_DIR/gradido-federation.conf) +export FEDERATION_NGINX_CONF=$(< $NGINX_CONFIG_DIR/gradido-federation.conf) echo "FEDERATION_NGINX_CONF=$FEDERATION_NGINX_CONF" # *** 3rd generate gradido nginx config including federation modules per api-version From b7ac341a0d8121ef28daa20963243e3d15033c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 28 Feb 2023 23:27:21 +0100 Subject: [PATCH 046/106] modify nginx config for federation modules --- .../sites-available/gradido.conf.ssl.template | 45 +------------------ deployment/bare_metal/start.sh | 14 +++--- 2 files changed, 6 insertions(+), 53 deletions(-) diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template index baad82135..18769e69e 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template @@ -113,50 +113,7 @@ server { } # Federation - location /api/1_0 { - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header Host $host; - - proxy_pass http://127.0.0.1:5010; - proxy_redirect off; - - access_log $GRADIDO_LOG_PATH/nginx-access.federation-5010.log gradido_log; - error_log $GRADIDO_LOG_PATH/nginx-error.federation-5010.log warn; - } - - location /api/1_1 { - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header Host $host; - - proxy_pass http://127.0.0.1:5011; - proxy_redirect off; - - access_log $GRADIDO_LOG_PATH/nginx-access.federation-5011.log gradido_log; - error_log $GRADIDO_LOG_PATH/nginx-error.federation-5011.log warn; - } - - location /api/2_0 { - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header Host $host; - - proxy_pass http://127.0.0.1:5020; - proxy_redirect off; - - access_log $GRADIDO_LOG_PATH/nginx-access.federation-5020.log gradido_log; - error_log $GRADIDO_LOG_PATH/nginx-error.federation-5020.log warn; - } + $FEDERATION_NGINX_CONF # TODO this could be a performance optimization #location /vue { diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 0be61175e..374cfeacc 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -76,7 +76,7 @@ export BUILD_COMMIT="$(git rev-parse HEAD)" # *** 1st prepare for each apiversion the federation conf for nginx from federation-template # *** set FEDERATION_PORT from FEDERATION_COMMUNITY_APIS and create gradido-federation.conf file rm $NGINX_CONFIG_DIR/gradido-federation.conf -echo "================================================================================================" +echo "====================================================================================================" IFS="," read -a API_ARRAY <<< $FEDERATION_COMMUNITY_APIS for api in "${API_ARRAY[@]}" do @@ -86,14 +86,13 @@ do FEDERATION_PORT=${FEDERATION_COMMUNITY_API_PORT:-5000} FEDERATION_PORT=$(($FEDERATION_PORT + $port)) export FEDERATION_PORT - echo " create ngingx config: location /api/$FEDERATION_APIVERSION to http://127.0.0.1:$FEDERATION_PORT" + echo " create ngingx config: location /api/$FEDERATION_APIVERSION to http://127.0.0.1:$FEDERATION_PORT" envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido-federation.conf.template >> $NGINX_CONFIG_DIR/gradido-federation.conf done -echo "================================================================================================" +echo "====================================================================================================" -# *** 2nd read gradido-federation.conf file in env variable +# *** 2nd read gradido-federation.conf file in env variable to be replaced in 3rd step export FEDERATION_NGINX_CONF=$(< $NGINX_CONFIG_DIR/gradido-federation.conf) -echo "FEDERATION_NGINX_CONF=$FEDERATION_NGINX_CONF" # *** 3rd generate gradido nginx config including federation modules per api-version echo 'Generate new gradido nginx config' >> $UPDATE_HTML @@ -102,10 +101,7 @@ case "$NGINX_SSL" in *) TEMPLATE_FILE="gradido.conf.template" ;; esac envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf - -# release lock -rm $LOCK_FILE -exit 1 +rm $NGINX_CONFIG_DIR/gradido-federation.conf # Generate update-page.conf from template echo 'Generate new update-page nginx config' >> $UPDATE_HTML From bf099845a1a74085da76f6dbc5e4d08970061bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 1 Mar 2023 00:33:10 +0100 Subject: [PATCH 047/106] beautify configs --- .../sites-available/gradido.conf.ssl.template | 18 +++++++++--------- .../sites-available/gradido.conf.template | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template index 18769e69e..ddb0724b0 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template @@ -42,15 +42,15 @@ server { # Frontend (default) location / { - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header Host $host; - - proxy_pass http://127.0.0.1:3000; - proxy_redirect off; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + + proxy_pass http://127.0.0.1:3000; + proxy_redirect off; access_log $GRADIDO_LOG_PATH/nginx-access.frontend.log gradido_log; error_log $GRADIDO_LOG_PATH/nginx-error.frontend.log warn; diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.template index f0cfb17b5..42a5a1851 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.template @@ -27,15 +27,15 @@ server { # Frontend (default) location / { - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header Host $host; - - proxy_pass http://127.0.0.1:3000; - proxy_redirect off; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + + proxy_pass http://127.0.0.1:3000; + proxy_redirect off; access_log $GRADIDO_LOG_PATH/nginx-access.frontend.log gradido_log; error_log $GRADIDO_LOG_PATH/nginx-error.frontend.log warn; From e80c170c32dc43aa24f955c3c6c6be95ac404a74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 1 Mar 2023 00:33:42 +0100 Subject: [PATCH 048/106] change logoutput --- federation/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/federation/src/index.ts b/federation/src/index.ts index daf9bfa56..71c7545aa 100644 --- a/federation/src/index.ts +++ b/federation/src/index.ts @@ -20,7 +20,7 @@ async function main() { if (CONFIG.GRAPHIQL) { // eslint-disable-next-line no-console console.log( - `GraphIQL available at ${CONFIG.FEDERATION_COMMUNITY_URL}:${CONFIG.FEDERATION_PORT}/api` + `GraphIQL available at ${CONFIG.FEDERATION_COMMUNITY_URL}/api/${CONFIG.FEDERATION_API}` ) } }) From 6ea9cc39a9bf1079756ae6ae4e71e2f44600f4de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 1 Mar 2023 00:34:44 +0100 Subject: [PATCH 049/106] small changes --- deployment/bare_metal/start.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 374cfeacc..0ede8cbff 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -61,6 +61,7 @@ sudo /etc/init.d/nginx restart # stop all services echo 'Stopping and Delete all Gradido services' >> $UPDATE_HTML pm2 delete all +pm2 save # git BRANCH=${1:-master} @@ -75,7 +76,7 @@ export BUILD_COMMIT="$(git rev-parse HEAD)" # Generate gradido.conf from template # *** 1st prepare for each apiversion the federation conf for nginx from federation-template # *** set FEDERATION_PORT from FEDERATION_COMMUNITY_APIS and create gradido-federation.conf file -rm $NGINX_CONFIG_DIR/gradido-federation.conf +rm -f $NGINX_CONFIG_DIR/gradido-federation.conf echo "====================================================================================================" IFS="," read -a API_ARRAY <<< $FEDERATION_COMMUNITY_APIS for api in "${API_ARRAY[@]}" From c7c4f52816824be2dfa89cbd3afa8b416cbd69d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 1 Mar 2023 00:42:49 +0100 Subject: [PATCH 050/106] correct migration downgrade by delete communities entries with last_announced_at is null --- database/migrations/0060-update_communities_table.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/database/migrations/0060-update_communities_table.ts b/database/migrations/0060-update_communities_table.ts index 79180e587..d7ab7c8b3 100644 --- a/database/migrations/0060-update_communities_table.ts +++ b/database/migrations/0060-update_communities_table.ts @@ -23,6 +23,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { // write downgrade logic as parameter of queryFn + await queryFn('DELETE * FROM TABLE `communities` WHERE `last_announced_at` IS NULL`;') await queryFn( 'ALTER TABLE `communities` MODIFY COLUMN `last_announced_at` datetime(3) NOT NULL AFTER `end_point`;', ) From 876bc91d9307cb1f8381530f29c77ef1f9a58589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 1 Mar 2023 00:46:58 +0100 Subject: [PATCH 051/106] correct migration downgrade by delete communities entries with last_announced_at is null --- database/migrations/0060-update_communities_table.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/0060-update_communities_table.ts b/database/migrations/0060-update_communities_table.ts index d7ab7c8b3..33c143262 100644 --- a/database/migrations/0060-update_communities_table.ts +++ b/database/migrations/0060-update_communities_table.ts @@ -23,7 +23,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { // write downgrade logic as parameter of queryFn - await queryFn('DELETE * FROM TABLE `communities` WHERE `last_announced_at` IS NULL`;') + await queryFn('DELETE FROM TABLE `communities` WHERE `last_announced_at` IS NULL`;') await queryFn( 'ALTER TABLE `communities` MODIFY COLUMN `last_announced_at` datetime(3) NOT NULL AFTER `end_point`;', ) From aaf4c9748c4bf25efa50ba10af402b33b9146498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 1 Mar 2023 00:57:52 +0100 Subject: [PATCH 052/106] correct migration downgrade by delete communities entries with last_announced_at is null --- database/migrations/0060-update_communities_table.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/0060-update_communities_table.ts b/database/migrations/0060-update_communities_table.ts index 33c143262..c1268850a 100644 --- a/database/migrations/0060-update_communities_table.ts +++ b/database/migrations/0060-update_communities_table.ts @@ -23,7 +23,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { // write downgrade logic as parameter of queryFn - await queryFn('DELETE FROM TABLE `communities` WHERE `last_announced_at` IS NULL`;') + await queryFn('DELETE FROM `communities` WHERE `last_announced_at` IS NULL;') await queryFn( 'ALTER TABLE `communities` MODIFY COLUMN `last_announced_at` datetime(3) NOT NULL AFTER `end_point`;', ) From b1a6fcdb42456a918aaa354a4cbe247c158d83da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 1 Mar 2023 01:23:28 +0100 Subject: [PATCH 053/106] adapt federation config files --- federation/.env.dist | 21 +++++++++++++++++++++ federation/.env.template | 16 ++++++++++++++++ federation/src/config/index.ts | 4 ++-- 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 federation/.env.dist create mode 100644 federation/.env.template diff --git a/federation/.env.dist b/federation/.env.dist new file mode 100644 index 000000000..a1330546c --- /dev/null +++ b/federation/.env.dist @@ -0,0 +1,21 @@ +LOG_LEVEL=debug +PORT=4000 +GRAPHIQL=true +// LOGIN_API_URL=http://login-server:1201/ +// COMMUNITY_API_URL=http://nginx/api/ +// GDT_API_URL=https://gdt.gradido.net/ + +# Database +# Database +DB_PORT=3306 +DB_DATABASE=gradido_community + + +COMMUNITY_NAME=Gradido Entwicklung +COMMUNITY_URL=http://localhost:4000/ +COMMUNITY_DESCRIPTION=lokale Entwicklungsumgebung + +# Federation +FEDERATION_API=1_0 +FEDERATION_PORT=5010 +FEDERATION_COMMUNITY_URL=http://localhost diff --git a/federation/.env.template b/federation/.env.template new file mode 100644 index 000000000..74f4cb75b --- /dev/null +++ b/federation/.env.template @@ -0,0 +1,16 @@ +LOG_LEVEL=$LOG_LEVEL +PORT=$PORT +GRAPHIQL=$GRAPHIQL + +# Database +DB_PORT=$DB_PORT +DB_DATABASE=$DB_DATABASE + +COMMUNITY_NAME=$COMMUNITY_NAME +COMMUNITY_URL=$COMMUNITY_URL +COMMUNITY_DESCRIPTION=$COMMUNITY_DESCRIPTION + +# Federation +FEDERATION_API=$FEDERATION_API +FEDERATION_PORT=$FEDERATION_PORT +FEDERATION_COMMUNITY_URL=$FEDERATION_COMMUNITY_URL diff --git a/federation/src/config/index.ts b/federation/src/config/index.ts index de474f517..dc2e77928 100644 --- a/federation/src/config/index.ts +++ b/federation/src/config/index.ts @@ -73,8 +73,8 @@ if ( const federation = { // FEDERATION_DHT_TOPIC: process.env.FEDERATION_DHT_TOPIC || null, // FEDERATION_DHT_SEED: process.env.FEDERATION_DHT_SEED || null, - FEDERATION_COMMUNITY_API_PORT: - process.env.FEDERATION_COMMUNITY_API_PORT || 5000, + // FEDERATION_COMMUNITY_API_PORT: + // process.env.FEDERATION_COMMUNITY_API_PORT || 5000, FEDERATION_API: process.env.FEDERATION_API || '1_0', FEDERATION_PORT: process.env.FEDERATION_PORT || 5010, FEDERATION_COMMUNITY_URL: process.env.FEDERATION_COMMUNITY_URL || null, From 7f12bf759d230d7e90b3f27bebb66cb1d1d1169c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 1 Mar 2023 01:52:44 +0100 Subject: [PATCH 054/106] change dir before nginx restart --- deployment/bare_metal/start.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 0ede8cbff..ca3de32e1 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -247,6 +247,7 @@ done # let nginx showing gradido +cd $SCRIPT_DIR echo 'Configuring nginx to serve gradido again' >> $UPDATE_HTML ln -s /etc/nginx/sites-available/gradido.conf /etc/nginx/sites-enabled/ rm /etc/nginx/sites-enabled/update-page.conf From 1e960cbd83c9b91d3196881ba8e731dc6ddd4a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 1 Mar 2023 02:13:26 +0100 Subject: [PATCH 055/106] correct gradido-federation.conf replacements --- deployment/bare_metal/start.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index ca3de32e1..e6b7c8689 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -88,11 +88,12 @@ do FEDERATION_PORT=$(($FEDERATION_PORT + $port)) export FEDERATION_PORT echo " create ngingx config: location /api/$FEDERATION_APIVERSION to http://127.0.0.1:$FEDERATION_PORT" - envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido-federation.conf.template >> $NGINX_CONFIG_DIR/gradido-federation.conf + envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido-federation.conf.template >> $NGINX_CONFIG_DIR/gradido-federation.conf.append done echo "====================================================================================================" # *** 2nd read gradido-federation.conf file in env variable to be replaced in 3rd step +envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido-federation.conf.append > $NGINX_CONFIG_DIR/gradido-federation.conf export FEDERATION_NGINX_CONF=$(< $NGINX_CONFIG_DIR/gradido-federation.conf) # *** 3rd generate gradido nginx config including federation modules per api-version @@ -102,6 +103,7 @@ case "$NGINX_SSL" in *) TEMPLATE_FILE="gradido.conf.template" ;; esac envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf +rm $NGINX_CONFIG_DIR/gradido-federation.conf.append rm $NGINX_CONFIG_DIR/gradido-federation.conf # Generate update-page.conf from template From 25634a9cfa80d3778fdc626d03c34e6bf8df6319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 1 Mar 2023 02:19:20 +0100 Subject: [PATCH 056/106] keep gradido-federation.conf files --- deployment/bare_metal/start.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index e6b7c8689..44db1815c 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -77,6 +77,7 @@ export BUILD_COMMIT="$(git rev-parse HEAD)" # *** 1st prepare for each apiversion the federation conf for nginx from federation-template # *** set FEDERATION_PORT from FEDERATION_COMMUNITY_APIS and create gradido-federation.conf file rm -f $NGINX_CONFIG_DIR/gradido-federation.conf +rm -f $NGINX_CONFIG_DIR/gradido-federation.conf.append echo "====================================================================================================" IFS="," read -a API_ARRAY <<< $FEDERATION_COMMUNITY_APIS for api in "${API_ARRAY[@]}" @@ -103,8 +104,8 @@ case "$NGINX_SSL" in *) TEMPLATE_FILE="gradido.conf.template" ;; esac envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf -rm $NGINX_CONFIG_DIR/gradido-federation.conf.append -rm $NGINX_CONFIG_DIR/gradido-federation.conf +# rm $NGINX_CONFIG_DIR/gradido-federation.conf.append +# rm $NGINX_CONFIG_DIR/gradido-federation.conf # Generate update-page.conf from template echo 'Generate new update-page nginx config' >> $UPDATE_HTML From 192d0520899a86a59964fe5e1e28117fdf5a43fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 1 Mar 2023 02:27:19 +0100 Subject: [PATCH 057/106] include gradido-federation.conf --- .../nginx/sites-available/gradido.conf.ssl.template | 2 +- .../bare_metal/nginx/sites-available/gradido.conf.template | 2 +- deployment/bare_metal/start.sh | 5 +---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template index ddb0724b0..2790c90cf 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template @@ -113,7 +113,7 @@ server { } # Federation - $FEDERATION_NGINX_CONF + include ./gradido-federation.conf # TODO this could be a performance optimization #location /vue { diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.template index 42a5a1851..378f9eee9 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.template @@ -99,7 +99,7 @@ server { } # Federation - $FEDERATION_NGINX_CONF + include ./gradido-federation.conf # TODO this could be a performance optimization #location /vue { diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 44db1815c..609fdce0b 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -77,7 +77,6 @@ export BUILD_COMMIT="$(git rev-parse HEAD)" # *** 1st prepare for each apiversion the federation conf for nginx from federation-template # *** set FEDERATION_PORT from FEDERATION_COMMUNITY_APIS and create gradido-federation.conf file rm -f $NGINX_CONFIG_DIR/gradido-federation.conf -rm -f $NGINX_CONFIG_DIR/gradido-federation.conf.append echo "====================================================================================================" IFS="," read -a API_ARRAY <<< $FEDERATION_COMMUNITY_APIS for api in "${API_ARRAY[@]}" @@ -89,12 +88,11 @@ do FEDERATION_PORT=$(($FEDERATION_PORT + $port)) export FEDERATION_PORT echo " create ngingx config: location /api/$FEDERATION_APIVERSION to http://127.0.0.1:$FEDERATION_PORT" - envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido-federation.conf.template >> $NGINX_CONFIG_DIR/gradido-federation.conf.append + envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido-federation.conf.template >> $NGINX_CONFIG_DIR/gradido-federation.conf done echo "====================================================================================================" # *** 2nd read gradido-federation.conf file in env variable to be replaced in 3rd step -envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido-federation.conf.append > $NGINX_CONFIG_DIR/gradido-federation.conf export FEDERATION_NGINX_CONF=$(< $NGINX_CONFIG_DIR/gradido-federation.conf) # *** 3rd generate gradido nginx config including federation modules per api-version @@ -104,7 +102,6 @@ case "$NGINX_SSL" in *) TEMPLATE_FILE="gradido.conf.template" ;; esac envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf -# rm $NGINX_CONFIG_DIR/gradido-federation.conf.append # rm $NGINX_CONFIG_DIR/gradido-federation.conf # Generate update-page.conf from template From 90887b1abe751bd8d3dc1ad1557da9d994a4b2d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 1 Mar 2023 02:33:11 +0100 Subject: [PATCH 058/106] define .env-files --- federation/{.env.template => .env.dist.template} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename federation/{.env.template => .env.dist.template} (100%) diff --git a/federation/.env.template b/federation/.env.dist.template similarity index 100% rename from federation/.env.template rename to federation/.env.dist.template From 780ece56c5155350d7226015d497a3ca97c8b7f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 1 Mar 2023 02:36:04 +0100 Subject: [PATCH 059/106] change include back to EnvVar-Replacement --- .../bare_metal/nginx/sites-available/gradido.conf.ssl.template | 2 +- .../bare_metal/nginx/sites-available/gradido.conf.template | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template index 2790c90cf..ddb0724b0 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template @@ -113,7 +113,7 @@ server { } # Federation - include ./gradido-federation.conf + $FEDERATION_NGINX_CONF # TODO this could be a performance optimization #location /vue { diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.template index 378f9eee9..42a5a1851 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.template @@ -99,7 +99,7 @@ server { } # Federation - include ./gradido-federation.conf + $FEDERATION_NGINX_CONF # TODO this could be a performance optimization #location /vue { From 0ee62ef6446e337ceb847547db048d5fd745a537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 1 Mar 2023 02:40:22 +0100 Subject: [PATCH 060/106] additional replacement step --- deployment/bare_metal/start.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 609fdce0b..25cbb59fd 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -101,7 +101,8 @@ case "$NGINX_SSL" in true) TEMPLATE_FILE="gradido.conf.ssl.template" ;; *) TEMPLATE_FILE="gradido.conf.template" ;; esac -envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf +envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf.tmp +envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido.conf.tmp > $NGINX_CONFIG_DIR/gradido.conf # rm $NGINX_CONFIG_DIR/gradido-federation.conf # Generate update-page.conf from template From 211c8f07c05a6ff379c74c5a3ba7bed90ccb4741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 1 Mar 2023 22:42:14 +0100 Subject: [PATCH 061/106] change replacement logic to insert federation locations --- .../bare_metal/nginx/sites-available/gradido.conf.ssl.template | 2 +- .../bare_metal/nginx/sites-available/gradido.conf.template | 2 +- deployment/bare_metal/start.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template index ddb0724b0..73b894faf 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template @@ -113,7 +113,7 @@ server { } # Federation - $FEDERATION_NGINX_CONF + FEDERATION_NGINX_CONF # TODO this could be a performance optimization #location /vue { diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.template index 42a5a1851..ae43dc94f 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.template @@ -99,7 +99,7 @@ server { } # Federation - $FEDERATION_NGINX_CONF + FEDERATION_NGINX_CONF # TODO this could be a performance optimization #location /vue { diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 25cbb59fd..d3d87b8d5 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -101,7 +101,7 @@ case "$NGINX_SSL" in true) TEMPLATE_FILE="gradido.conf.ssl.template" ;; *) TEMPLATE_FILE="gradido.conf.template" ;; esac -envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf.tmp +envsubst "$(env | sed -e 's/FEDERATION_NGINX_CONF/\$FEDERATION_NGINX_CONF/g')" < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf.tmp envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido.conf.tmp > $NGINX_CONFIG_DIR/gradido.conf # rm $NGINX_CONFIG_DIR/gradido-federation.conf From af5cf0f5856b050e7d1d68b5734aa5a50fa22e33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 1 Mar 2023 23:41:34 +0100 Subject: [PATCH 062/106] next try of replacement logic for federation locations --- .../nginx/sites-available/gradido.conf.ssl.template | 2 +- .../bare_metal/nginx/sites-available/gradido.conf.template | 2 +- deployment/bare_metal/start.sh | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template index 73b894faf..ddb0724b0 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.ssl.template @@ -113,7 +113,7 @@ server { } # Federation - FEDERATION_NGINX_CONF + $FEDERATION_NGINX_CONF # TODO this could be a performance optimization #location /vue { diff --git a/deployment/bare_metal/nginx/sites-available/gradido.conf.template b/deployment/bare_metal/nginx/sites-available/gradido.conf.template index ae43dc94f..42a5a1851 100644 --- a/deployment/bare_metal/nginx/sites-available/gradido.conf.template +++ b/deployment/bare_metal/nginx/sites-available/gradido.conf.template @@ -99,7 +99,7 @@ server { } # Federation - FEDERATION_NGINX_CONF + $FEDERATION_NGINX_CONF # TODO this could be a performance optimization #location /vue { diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index d3d87b8d5..8cccb856a 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -88,7 +88,7 @@ do FEDERATION_PORT=$(($FEDERATION_PORT + $port)) export FEDERATION_PORT echo " create ngingx config: location /api/$FEDERATION_APIVERSION to http://127.0.0.1:$FEDERATION_PORT" - envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido-federation.conf.template >> $NGINX_CONFIG_DIR/gradido-federation.conf + envsubst "$(env | sed -e 's/\$FEDERATION_APIVERSION\|\$FEDERATION_PORT//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido-federation.conf.template >> $NGINX_CONFIG_DIR/gradido-federation.conf done echo "====================================================================================================" @@ -101,7 +101,7 @@ case "$NGINX_SSL" in true) TEMPLATE_FILE="gradido.conf.ssl.template" ;; *) TEMPLATE_FILE="gradido.conf.template" ;; esac -envsubst "$(env | sed -e 's/FEDERATION_NGINX_CONF/\$FEDERATION_NGINX_CONF/g')" < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf.tmp +envsubst "$(env | sed -e 's/\$FEDERATION_NGINX_CONF//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf.tmp envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido.conf.tmp > $NGINX_CONFIG_DIR/gradido.conf # rm $NGINX_CONFIG_DIR/gradido-federation.conf From 1a2bfb487e0876670a2dc2e54df8bb026ffc6334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Thu, 2 Mar 2023 00:22:35 +0100 Subject: [PATCH 063/106] replace logic simply now with envsubst --- deployment/bare_metal/start.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 8cccb856a..afa13445b 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -88,7 +88,7 @@ do FEDERATION_PORT=$(($FEDERATION_PORT + $port)) export FEDERATION_PORT echo " create ngingx config: location /api/$FEDERATION_APIVERSION to http://127.0.0.1:$FEDERATION_PORT" - envsubst "$(env | sed -e 's/\$FEDERATION_APIVERSION\|\$FEDERATION_PORT//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido-federation.conf.template >> $NGINX_CONFIG_DIR/gradido-federation.conf + envsubst '$FEDERATION_APIVERSION, $FEDERATION_PORT' < $NGINX_CONFIG_DIR/gradido-federation.conf.template >> $NGINX_CONFIG_DIR/gradido-federation.conf done echo "====================================================================================================" @@ -101,8 +101,9 @@ case "$NGINX_SSL" in true) TEMPLATE_FILE="gradido.conf.ssl.template" ;; *) TEMPLATE_FILE="gradido.conf.template" ;; esac -envsubst "$(env | sed -e 's/\$FEDERATION_NGINX_CONF//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf.tmp +envsubst "$FEDERATION_NGINX_CONF" < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf.tmp envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido.conf.tmp > $NGINX_CONFIG_DIR/gradido.conf +# rm $NGINX_CONFIG_DIR/gradido.conf.tmp # rm $NGINX_CONFIG_DIR/gradido-federation.conf # Generate update-page.conf from template From e6b35e08849723652e6a085d99218f78dbac5e85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Thu, 2 Mar 2023 00:36:03 +0100 Subject: [PATCH 064/106] echo the current env before envsubst --- deployment/bare_metal/start.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index afa13445b..a2dca6608 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -88,7 +88,7 @@ do FEDERATION_PORT=$(($FEDERATION_PORT + $port)) export FEDERATION_PORT echo " create ngingx config: location /api/$FEDERATION_APIVERSION to http://127.0.0.1:$FEDERATION_PORT" - envsubst '$FEDERATION_APIVERSION, $FEDERATION_PORT' < $NGINX_CONFIG_DIR/gradido-federation.conf.template >> $NGINX_CONFIG_DIR/gradido-federation.conf + envsubst "$FEDERATION_APIVERSION, $FEDERATION_PORT" < $NGINX_CONFIG_DIR/gradido-federation.conf.template >> $NGINX_CONFIG_DIR/gradido-federation.conf done echo "====================================================================================================" @@ -102,6 +102,7 @@ case "$NGINX_SSL" in *) TEMPLATE_FILE="gradido.conf.template" ;; esac envsubst "$FEDERATION_NGINX_CONF" < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf.tmp +echo "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido.conf.tmp > $NGINX_CONFIG_DIR/gradido.conf # rm $NGINX_CONFIG_DIR/gradido.conf.tmp # rm $NGINX_CONFIG_DIR/gradido-federation.conf From a5177d54bd730447aa9ccc7800b82db1642af20e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Thu, 2 Mar 2023 00:47:15 +0100 Subject: [PATCH 065/106] next try --- deployment/bare_metal/start.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index a2dca6608..fc1860f0e 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -76,6 +76,7 @@ export BUILD_COMMIT="$(git rev-parse HEAD)" # Generate gradido.conf from template # *** 1st prepare for each apiversion the federation conf for nginx from federation-template # *** set FEDERATION_PORT from FEDERATION_COMMUNITY_APIS and create gradido-federation.conf file +rm -f $NGINX_CONFIG_DIR/gradido.conf.tmp rm -f $NGINX_CONFIG_DIR/gradido-federation.conf echo "====================================================================================================" IFS="," read -a API_ARRAY <<< $FEDERATION_COMMUNITY_APIS @@ -88,7 +89,7 @@ do FEDERATION_PORT=$(($FEDERATION_PORT + $port)) export FEDERATION_PORT echo " create ngingx config: location /api/$FEDERATION_APIVERSION to http://127.0.0.1:$FEDERATION_PORT" - envsubst "$FEDERATION_APIVERSION, $FEDERATION_PORT" < $NGINX_CONFIG_DIR/gradido-federation.conf.template >> $NGINX_CONFIG_DIR/gradido-federation.conf + envsubst '$FEDERATION_APIVERSION, $FEDERATION_PORT' < $NGINX_CONFIG_DIR/gradido-federation.conf.template >> $NGINX_CONFIG_DIR/gradido-federation.conf done echo "====================================================================================================" @@ -101,8 +102,9 @@ case "$NGINX_SSL" in true) TEMPLATE_FILE="gradido.conf.ssl.template" ;; *) TEMPLATE_FILE="gradido.conf.template" ;; esac -envsubst "$FEDERATION_NGINX_CONF" < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf.tmp -echo "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" +envsubst '$FEDERATION_NGINX_CONF' < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf.tmp +# echo "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" +echo "$(env)" envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido.conf.tmp > $NGINX_CONFIG_DIR/gradido.conf # rm $NGINX_CONFIG_DIR/gradido.conf.tmp # rm $NGINX_CONFIG_DIR/gradido-federation.conf From c2d9b75de297821359107eae8cbb70ffaae96bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Thu, 2 Mar 2023 00:58:04 +0100 Subject: [PATCH 066/106] delete exported env-vars after usage --- deployment/bare_metal/start.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index fc1860f0e..28f259d27 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -91,6 +91,8 @@ do echo " create ngingx config: location /api/$FEDERATION_APIVERSION to http://127.0.0.1:$FEDERATION_PORT" envsubst '$FEDERATION_APIVERSION, $FEDERATION_PORT' < $NGINX_CONFIG_DIR/gradido-federation.conf.template >> $NGINX_CONFIG_DIR/gradido-federation.conf done +export FEDERATION_APIVERSION= +export FEDERATION_PORT= echo "====================================================================================================" # *** 2nd read gradido-federation.conf file in env variable to be replaced in 3rd step @@ -103,6 +105,7 @@ case "$NGINX_SSL" in *) TEMPLATE_FILE="gradido.conf.template" ;; esac envsubst '$FEDERATION_NGINX_CONF' < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf.tmp +export FEDERATION_NGINX_CONF= # echo "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" echo "$(env)" envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido.conf.tmp > $NGINX_CONFIG_DIR/gradido.conf From 55dd5038c795e7484c55930402dc064d349fb681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Thu, 2 Mar 2023 01:47:34 +0100 Subject: [PATCH 067/106] remove echo outputs --- deployment/bare_metal/start.sh | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 28f259d27..d82bcbe9b 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -106,11 +106,9 @@ case "$NGINX_SSL" in esac envsubst '$FEDERATION_NGINX_CONF' < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf.tmp export FEDERATION_NGINX_CONF= -# echo "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" -echo "$(env)" envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido.conf.tmp > $NGINX_CONFIG_DIR/gradido.conf -# rm $NGINX_CONFIG_DIR/gradido.conf.tmp -# rm $NGINX_CONFIG_DIR/gradido-federation.conf +rm $NGINX_CONFIG_DIR/gradido.conf.tmp +rm $NGINX_CONFIG_DIR/gradido-federation.conf # Generate update-page.conf from template echo 'Generate new update-page nginx config' >> $UPDATE_HTML @@ -217,18 +215,6 @@ yarn install yarn build # TODO maybe handle this differently? export NODE_ENV=production -# # first remove previous pm2 gradido-federation processes from list -# pm2 ls -m | grep "+--- gradido-federation" | tr '\n' ',' | sed -e 's/+---//g' > proc.list -# IFS="," read -a PROCESS_ARRAY < proc.list -# for proc in "${PROCESS_ARRAY[@]}" -# do -# echo "---> delete process $proc" -# pm2 delete $proc -# done -# pm2 save -# rm proc.list -# echo "finished removeing previous gradido-federation processes from pm2" -# echo # set FEDERATION_PORT from FEDERATION_COMMUNITY_APIS IFS="," read -a API_ARRAY <<< $FEDERATION_COMMUNITY_APIS From 9907a4caf42e53b78ef5b42f151513bc012e001e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Thu, 2 Mar 2023 11:58:42 +0100 Subject: [PATCH 068/106] add .env.dist and .env.dist.template to federation module --- federation/.env.dist | 4 ---- federation/.env.dist.template | 1 + 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/federation/.env.dist b/federation/.env.dist index a1330546c..2bbf77fa8 100644 --- a/federation/.env.dist +++ b/federation/.env.dist @@ -1,11 +1,7 @@ LOG_LEVEL=debug PORT=4000 GRAPHIQL=true -// LOGIN_API_URL=http://login-server:1201/ -// COMMUNITY_API_URL=http://nginx/api/ -// GDT_API_URL=https://gdt.gradido.net/ -# Database # Database DB_PORT=3306 DB_DATABASE=gradido_community diff --git a/federation/.env.dist.template b/federation/.env.dist.template index 74f4cb75b..336da8f1a 100644 --- a/federation/.env.dist.template +++ b/federation/.env.dist.template @@ -14,3 +14,4 @@ COMMUNITY_DESCRIPTION=$COMMUNITY_DESCRIPTION FEDERATION_API=$FEDERATION_API FEDERATION_PORT=$FEDERATION_PORT FEDERATION_COMMUNITY_URL=$FEDERATION_COMMUNITY_URL + From 9419e9062c671b997f08a339edb39f7862c8e564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Thu, 2 Mar 2023 13:28:12 +0100 Subject: [PATCH 069/106] remove port from dht-url --- dht-node/src/dht_node/index.test.ts | 14 +++++++------- dht-node/src/dht_node/index.ts | 4 +--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/dht-node/src/dht_node/index.test.ts b/dht-node/src/dht_node/index.test.ts index b7e36c783..ac5b1b21a 100644 --- a/dht-node/src/dht_node/index.test.ts +++ b/dht-node/src/dht_node/index.test.ts @@ -719,11 +719,11 @@ describe('federation', () => { JSON.stringify([ { api: '1_0', - url: 'http://localhost:5001/api/', + url: 'http://localhost/api/', }, { api: '2_0', - url: 'http://localhost:5002/api/', + url: 'http://localhost/api/', }, ]), ), @@ -747,7 +747,7 @@ describe('federation', () => { foreign: true, publicKey: expect.any(Buffer), apiVersion: '1_0', - endPoint: 'http://localhost:5001/api/', + endPoint: 'http://localhost/api/', lastAnnouncedAt: expect.any(Date), createdAt: expect.any(Date), updatedAt: null, @@ -764,7 +764,7 @@ describe('federation', () => { foreign: true, publicKey: expect.any(Buffer), apiVersion: '2_0', - endPoint: 'http://localhost:5002/api/', + endPoint: 'http://localhost/api/', lastAnnouncedAt: expect.any(Date), createdAt: expect.any(Date), updatedAt: null, @@ -786,15 +786,15 @@ describe('federation', () => { JSON.stringify([ { api: '1_0', - url: 'http://localhost:5001/api/', + url: 'http://localhost/api/', }, { api: '1_1', - url: 'http://localhost:5002/api/', + url: 'http://localhost/api/', }, { api: '2_0', - url: 'http://localhost:5003/api/', + url: 'http://localhost/api/', }, ]), ), diff --git a/dht-node/src/dht_node/index.ts b/dht-node/src/dht_node/index.ts index 722a62af7..d101037ae 100644 --- a/dht-node/src/dht_node/index.ts +++ b/dht-node/src/dht_node/index.ts @@ -181,11 +181,9 @@ export const startDHT = async (topic: string): Promise => { async function writeHomeCommunityEnries(pubKey: any): Promise { const homeApiVersions: CommunityApi[] = Object.values(ApiVersionType).map(function (apiEnum) { - const port = - Number.parseInt(CONFIG.FEDERATION_COMMUNITY_API_PORT) + Number(apiEnum.replace('_', '')) const comApi: CommunityApi = { api: apiEnum, - url: CONFIG.FEDERATION_COMMUNITY_URL + ':' + port.toString() + '/api/', + url: CONFIG.FEDERATION_COMMUNITY_URL + '/api/', } return comApi }) From 3fbd2cbf0b2ff67e6c2fa942c28df094eb255328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Thu, 2 Mar 2023 13:38:23 +0100 Subject: [PATCH 070/106] complete graphql-client request with variables to avoid password expectation in header --- backend/src/federation/client/1_0/FederationClient.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/src/federation/client/1_0/FederationClient.ts b/backend/src/federation/client/1_0/FederationClient.ts index 1c0ec4996..a8d7e1dff 100644 --- a/backend/src/federation/client/1_0/FederationClient.ts +++ b/backend/src/federation/client/1_0/FederationClient.ts @@ -18,9 +18,13 @@ export async function requestGetPublicKey(dbCom: DbCommunity): Promise Date: Fri, 3 Mar 2023 23:59:25 +0100 Subject: [PATCH 071/106] remove todo as there is an issue now --- database/entity/0061-event_refactoring/Event.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/database/entity/0061-event_refactoring/Event.ts b/database/entity/0061-event_refactoring/Event.ts index 219861834..0f2afab43 100644 --- a/database/entity/0061-event_refactoring/Event.ts +++ b/database/entity/0061-event_refactoring/Event.ts @@ -37,7 +37,6 @@ export class Event extends BaseEntity { @JoinColumn({ name: 'affected_user_id', referencedColumnName: 'id' }) affectedUser: User - // TODO potentially save actingRole as well @Column({ name: 'acting_user_id', unsigned: true, nullable: false }) actingUserId: number From 76cbcc239393f61a2c9b26129b007cc7b59b07a5 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 4 Mar 2023 00:02:48 +0100 Subject: [PATCH 072/106] remove todo for foreign keys since there is an issue now --- database/entity/0061-event_refactoring/Event.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/database/entity/0061-event_refactoring/Event.ts b/database/entity/0061-event_refactoring/Event.ts index 0f2afab43..601852ccd 100644 --- a/database/entity/0061-event_refactoring/Event.ts +++ b/database/entity/0061-event_refactoring/Event.ts @@ -65,8 +65,6 @@ export class Event extends BaseEntity { @JoinColumn({ name: 'involved_contribution_id', referencedColumnName: 'id' }) involvedContribution: Contribution | null - // TEST do we need the Id field definition? - // TODO we need proper foreign keys to have things working without the explicit column @Column({ name: 'involved_contribution_message_id', type: 'int', unsigned: true, nullable: true }) involvedContributionMessageId: number | null From 08c379b46f83bdd5dd4e83ed925939b7ae485972 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 4 Mar 2023 00:30:56 +0100 Subject: [PATCH 073/106] transform event data --- backend/src/event/Event.ts | 13 -------- database/migrations/0061-event_refactoring.ts | 33 ++++++++++++++++++- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 5ba21fe19..7ed75fd45 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -76,8 +76,6 @@ export const EVENT_CONTRIBUTION_UPDATE = async ( amount, ).save() -// TODO what was user_id? affected or moderator user? -// await EVENT_ADMIN_CONTRIBUTION_CREATE(moderator.id, contribution.id, amount) export const EVENT_ADMIN_CONTRIBUTION_CREATE = async ( user: DbUser, moderator: DbUser, @@ -95,7 +93,6 @@ export const EVENT_ADMIN_CONTRIBUTION_CREATE = async ( amount, ).save() -// TODO await EVENT_ADMIN_CONTRIBUTION_UPDATE(emailContact.user.id, contributionToUpdate.id, amount) export const EVENT_ADMIN_CONTRIBUTION_UPDATE = async ( user: DbUser, moderator: DbUser, @@ -113,7 +110,6 @@ export const EVENT_ADMIN_CONTRIBUTION_UPDATE = async ( amount, ).save() -// TODO await EVENT_ADMIN_CONTRIBUTION_DELETE(contribution.userId, contribution.id, contribution.amount) export const EVENT_ADMIN_CONTRIBUTION_DELETE = async ( user: DbUser, moderator: DbUser, @@ -131,7 +127,6 @@ export const EVENT_ADMIN_CONTRIBUTION_DELETE = async ( amount, ).save() -// TODO await EVENT_CONTRIBUTION_CONFIRM(user.id, contribution.id, contribution.amount) export const EVENT_CONTRIBUTION_CONFIRM = async ( user: DbUser, moderator: DbUser, @@ -149,13 +144,6 @@ export const EVENT_CONTRIBUTION_CONFIRM = async ( amount, ).save() -// TODO await EVENT_ADMIN_CONTRIBUTION_DENY( -// contributionToUpdate.userId, -// moderator.id, -// contributionToUpdate.id, -// contributionToUpdate.amount, -// ) -// x User = moderator export const EVENT_ADMIN_CONTRIBUTION_DENY = async ( user: DbUser, moderator: DbUser, @@ -190,7 +178,6 @@ export const EVENT_TRANSACTION_SEND = async ( amount, ).save() -// TODO acting user = involved user export const EVENT_TRANSACTION_RECEIVE = async ( user: DbUser, involvedUser: DbUser, diff --git a/database/migrations/0061-event_refactoring.ts b/database/migrations/0061-event_refactoring.ts index 2fdc7dcef..54fc2f702 100644 --- a/database/migrations/0061-event_refactoring.ts +++ b/database/migrations/0061-event_refactoring.ts @@ -32,10 +32,41 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis 'ALTER TABLE `events` RENAME COLUMN `message_id` TO `involved_contribution_message_id`;', ) - // TODO insert data based on event type + // TODO this is untested + // TODO transform back? + await queryFn( + 'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET affected_user_id=contributions.user_id WHERE type = "ADMIN_CONTRIBUTION_CREATE";', + ) + + // inconsistent data on this type + await queryFn( + 'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET acting_user_id=0 WHERE type = "ADMIN_CONTRIBUTION_UPDATE";', + ) + + await queryFn( + 'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET acting_user_id=contributions.deleted_by WHERE type = "ADMIN_CONTRIBUTION_DELETE";', + ) + + await queryFn( + 'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET acting_user_id=contributions.confirmed_by WHERE type = "CONTRIBUTION_CONFIRM";', + ) + + await queryFn( + 'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET involved_user_id=NULL, acting_user_id=contributions.denied_by WHERE type = "ADMIN_CONTRIBUTION_DENY";', + ) + + await queryFn( + 'UPDATE `events` SET acting_user_id=involved_user_id WHERE type = "TRANSACTION_RECEIVE";', + ) } export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn( + 'UPDATE `events` involved_user_id=acting_user_id WHERE type = "ADMIN_CONTRIBUTION_DENY";', + ) + await queryFn( + 'UPDATE `events` affected_user_id=acting_user_id WHERE type = "ADMIN_CONTRIBUTION_CREATE";', + ) await queryFn( 'ALTER TABLE `events` RENAME COLUMN `involved_contribution_message_id` TO `message_id`;', ) From c0f40f9c73db7e6eb1784bf93bb9acadf1418a42 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 4 Mar 2023 00:31:33 +0100 Subject: [PATCH 074/106] added comment and removed todo --- database/migrations/0061-event_refactoring.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/0061-event_refactoring.ts b/database/migrations/0061-event_refactoring.ts index 54fc2f702..c72366322 100644 --- a/database/migrations/0061-event_refactoring.ts +++ b/database/migrations/0061-event_refactoring.ts @@ -33,7 +33,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis ) // TODO this is untested - // TODO transform back? + // Moderator id was saved in former user_id await queryFn( 'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET affected_user_id=contributions.user_id WHERE type = "ADMIN_CONTRIBUTION_CREATE";', ) From 38f563e29444dc32c33e263569b657e560be8034 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 4 Mar 2023 00:32:21 +0100 Subject: [PATCH 075/106] refine comment --- database/migrations/0061-event_refactoring.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/0061-event_refactoring.ts b/database/migrations/0061-event_refactoring.ts index c72366322..01d8d1574 100644 --- a/database/migrations/0061-event_refactoring.ts +++ b/database/migrations/0061-event_refactoring.ts @@ -38,7 +38,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis 'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET affected_user_id=contributions.user_id WHERE type = "ADMIN_CONTRIBUTION_CREATE";', ) - // inconsistent data on this type + // inconsistent data on this type, since not all data can be reconstructed await queryFn( 'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET acting_user_id=0 WHERE type = "ADMIN_CONTRIBUTION_UPDATE";', ) From 5515088929c0ccb4b3fa08dbd9164a8d8ed755d4 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 4 Mar 2023 00:38:08 +0100 Subject: [PATCH 076/106] removed obsolete todo --- backend/src/graphql/resolver/ContributionResolver.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 3a5c02d2e..1b8d24d2b 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -441,7 +441,6 @@ export class ContributionResolver { await contribution.save() const res = await contribution.softRemove() - // TODO allow to query the user with relation await EVENT_ADMIN_CONTRIBUTION_DELETE( { id: contribution.userId } as DbUser, moderator, From 10392960bfd880da6d68fb335863382507a85ea1 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 4 Mar 2023 00:43:55 +0100 Subject: [PATCH 077/106] fixed typo --- database/migrations/0061-event_refactoring.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/migrations/0061-event_refactoring.ts b/database/migrations/0061-event_refactoring.ts index 01d8d1574..43da6defa 100644 --- a/database/migrations/0061-event_refactoring.ts +++ b/database/migrations/0061-event_refactoring.ts @@ -62,10 +62,10 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { await queryFn( - 'UPDATE `events` involved_user_id=acting_user_id WHERE type = "ADMIN_CONTRIBUTION_DENY";', + 'UPDATE `events` SET involved_user_id=acting_user_id WHERE type = "ADMIN_CONTRIBUTION_DENY";', ) await queryFn( - 'UPDATE `events` affected_user_id=acting_user_id WHERE type = "ADMIN_CONTRIBUTION_CREATE";', + 'UPDATE `events` SET affected_user_id=acting_user_id WHERE type = "ADMIN_CONTRIBUTION_CREATE";', ) await queryFn( 'ALTER TABLE `events` RENAME COLUMN `involved_contribution_message_id` TO `message_id`;', From 63dc1b61833c8c3b6e5554b944b4bf854219457f Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 6 Mar 2023 13:47:45 +0100 Subject: [PATCH 078/106] escape type query --- database/migrations/0061-event_refactoring.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/database/migrations/0061-event_refactoring.ts b/database/migrations/0061-event_refactoring.ts index 43da6defa..3f424ef17 100644 --- a/database/migrations/0061-event_refactoring.ts +++ b/database/migrations/0061-event_refactoring.ts @@ -35,37 +35,37 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis // TODO this is untested // Moderator id was saved in former user_id await queryFn( - 'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET affected_user_id=contributions.user_id WHERE type = "ADMIN_CONTRIBUTION_CREATE";', + 'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET affected_user_id=contributions.user_id WHERE `type` = "ADMIN_CONTRIBUTION_CREATE";', ) // inconsistent data on this type, since not all data can be reconstructed await queryFn( - 'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET acting_user_id=0 WHERE type = "ADMIN_CONTRIBUTION_UPDATE";', + 'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET acting_user_id=0 WHERE `type` = "ADMIN_CONTRIBUTION_UPDATE";', ) await queryFn( - 'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET acting_user_id=contributions.deleted_by WHERE type = "ADMIN_CONTRIBUTION_DELETE";', + 'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET acting_user_id=contributions.deleted_by WHERE `type` = "ADMIN_CONTRIBUTION_DELETE";', ) await queryFn( - 'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET acting_user_id=contributions.confirmed_by WHERE type = "CONTRIBUTION_CONFIRM";', + 'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET acting_user_id=contributions.confirmed_by WHERE `type` = "CONTRIBUTION_CONFIRM";', ) await queryFn( - 'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET involved_user_id=NULL, acting_user_id=contributions.denied_by WHERE type = "ADMIN_CONTRIBUTION_DENY";', + 'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET involved_user_id=NULL, acting_user_id=contributions.denied_by WHERE `type` = "ADMIN_CONTRIBUTION_DENY";', ) await queryFn( - 'UPDATE `events` SET acting_user_id=involved_user_id WHERE type = "TRANSACTION_RECEIVE";', + 'UPDATE `events` SET acting_user_id=involved_user_id WHERE `type` = "TRANSACTION_RECEIVE";', ) } export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { await queryFn( - 'UPDATE `events` SET involved_user_id=acting_user_id WHERE type = "ADMIN_CONTRIBUTION_DENY";', + 'UPDATE `events` SET involved_user_id=acting_user_id WHERE `type` = "ADMIN_CONTRIBUTION_DENY";', ) await queryFn( - 'UPDATE `events` SET affected_user_id=acting_user_id WHERE type = "ADMIN_CONTRIBUTION_CREATE";', + 'UPDATE `events` SET affected_user_id=acting_user_id WHERE `type` = "ADMIN_CONTRIBUTION_CREATE";', ) await queryFn( 'ALTER TABLE `events` RENAME COLUMN `involved_contribution_message_id` TO `message_id`;', From 60d7ce451fb4fefac0a99e8ade2e44dfa15740bb Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 6 Mar 2023 13:54:37 +0100 Subject: [PATCH 079/106] removed todo since this is tested now --- database/migrations/0061-event_refactoring.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/database/migrations/0061-event_refactoring.ts b/database/migrations/0061-event_refactoring.ts index 3f424ef17..11e81f97f 100644 --- a/database/migrations/0061-event_refactoring.ts +++ b/database/migrations/0061-event_refactoring.ts @@ -32,7 +32,6 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis 'ALTER TABLE `events` RENAME COLUMN `message_id` TO `involved_contribution_message_id`;', ) - // TODO this is untested // Moderator id was saved in former user_id await queryFn( 'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET affected_user_id=contributions.user_id WHERE `type` = "ADMIN_CONTRIBUTION_CREATE";', From 1e4c84c42b6e0fcd07bec8b439874fc30d983c47 Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:27:56 +0100 Subject: [PATCH 080/106] Update deployment/bare_metal/.env.dist Co-authored-by: Ulf Gebhardt --- deployment/bare_metal/.env.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/bare_metal/.env.dist b/deployment/bare_metal/.env.dist index 12297e357..da745d705 100644 --- a/deployment/bare_metal/.env.dist +++ b/deployment/bare_metal/.env.dist @@ -66,7 +66,7 @@ FEDERATION_COMMUNITY_URL=http://stage1.gradido.net FEDERATION_COMMUNITY_API_PORT=5000 FEDERATION_CONFIG_VERSION=v1.2023-01-09 -# comma separated list of api-versions, which cause starting several federation moduls +# comma separated list of api-versions, which cause starting several federation modules FEDERATION_COMMUNITY_APIS=1_0,1_1,2_0 # database From 78d74d362c8bd144ec74883a9192f5bbd73376ab Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:35:00 +0100 Subject: [PATCH 081/106] Update deployment/bare_metal/start.sh Co-authored-by: Ulf Gebhardt --- deployment/bare_metal/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index d82bcbe9b..c1e8ab3a8 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -59,7 +59,7 @@ ln -s /etc/nginx/sites-available/update-page.conf /etc/nginx/sites-enabled/ sudo /etc/init.d/nginx restart # stop all services -echo 'Stopping and Delete all Gradido services' >> $UPDATE_HTML +echo 'Stop and delete all Gradido services' >> $UPDATE_HTML pm2 delete all pm2 save From 633e34eb8b04b44ee1d1a4b83f7b889c19a85ee4 Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:35:39 +0100 Subject: [PATCH 082/106] Update deployment/bare_metal/start.sh Co-authored-by: Ulf Gebhardt --- deployment/bare_metal/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index c1e8ab3a8..63f206c1b 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -78,7 +78,7 @@ export BUILD_COMMIT="$(git rev-parse HEAD)" # *** set FEDERATION_PORT from FEDERATION_COMMUNITY_APIS and create gradido-federation.conf file rm -f $NGINX_CONFIG_DIR/gradido.conf.tmp rm -f $NGINX_CONFIG_DIR/gradido-federation.conf -echo "====================================================================================================" +echo "====================================================================================================" >> $UPDATE_HTML IFS="," read -a API_ARRAY <<< $FEDERATION_COMMUNITY_APIS for api in "${API_ARRAY[@]}" do From 931cd400680a582787912b790a25387b6b33912c Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:36:07 +0100 Subject: [PATCH 083/106] Update deployment/bare_metal/start.sh Co-authored-by: Ulf Gebhardt --- deployment/bare_metal/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 63f206c1b..5375b6d2e 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -88,7 +88,7 @@ do FEDERATION_PORT=${FEDERATION_COMMUNITY_API_PORT:-5000} FEDERATION_PORT=$(($FEDERATION_PORT + $port)) export FEDERATION_PORT - echo " create ngingx config: location /api/$FEDERATION_APIVERSION to http://127.0.0.1:$FEDERATION_PORT" + echo "create ngingx config: location /api/$FEDERATION_APIVERSION to http://127.0.0.1:$FEDERATION_PORT" >> $UPDATE_HTML envsubst '$FEDERATION_APIVERSION, $FEDERATION_PORT' < $NGINX_CONFIG_DIR/gradido-federation.conf.template >> $NGINX_CONFIG_DIR/gradido-federation.conf done export FEDERATION_APIVERSION= From 36518a636a0dd2a488b22ff062de97a170382047 Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:37:09 +0100 Subject: [PATCH 084/106] Update deployment/bare_metal/start.sh Co-authored-by: Ulf Gebhardt --- deployment/bare_metal/start.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 5375b6d2e..641999a45 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -91,8 +91,8 @@ do echo "create ngingx config: location /api/$FEDERATION_APIVERSION to http://127.0.0.1:$FEDERATION_PORT" >> $UPDATE_HTML envsubst '$FEDERATION_APIVERSION, $FEDERATION_PORT' < $NGINX_CONFIG_DIR/gradido-federation.conf.template >> $NGINX_CONFIG_DIR/gradido-federation.conf done -export FEDERATION_APIVERSION= -export FEDERATION_PORT= +unset FEDERATION_APIVERSION +unset FEDERATION_PORT echo "====================================================================================================" # *** 2nd read gradido-federation.conf file in env variable to be replaced in 3rd step From 7dbf7ecc993ef3b4b82fe4427640bcf22ba48d86 Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:37:33 +0100 Subject: [PATCH 085/106] Update deployment/bare_metal/start.sh Co-authored-by: Ulf Gebhardt --- deployment/bare_metal/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 641999a45..96bc3fb3d 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -93,7 +93,7 @@ do done unset FEDERATION_APIVERSION unset FEDERATION_PORT -echo "====================================================================================================" +echo "====================================================================================================" >> $UPDATE_HTML # *** 2nd read gradido-federation.conf file in env variable to be replaced in 3rd step export FEDERATION_NGINX_CONF=$(< $NGINX_CONFIG_DIR/gradido-federation.conf) From f799c56afce642d173427a59843220f8db996440 Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:44:50 +0100 Subject: [PATCH 086/106] Update deployment/bare_metal/start.sh Co-authored-by: Ulf Gebhardt --- deployment/bare_metal/start.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 96bc3fb3d..92773f496 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -200,9 +200,9 @@ if [ ! -z $FEDERATION_DHT_TOPIC ]; then pm2 start --name gradido-dht-node "yarn --cwd $PROJECT_ROOT/dht-node start" -l $GRADIDO_LOG_PATH/pm2.dht-node.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save else - echo "=====================================================================" - echo "WARNING: FEDERATION_DHT_TOPIC not configured. DHT-Node not started..." - echo "=====================================================================" + echo "=====================================================================" >> $UPDATE_HTML + echo "WARNING: FEDERATION_DHT_TOPIC not configured. DHT-Node not started..." >> $UPDATE_HTML + echo "=====================================================================" >> $UPDATE_HTML fi From 9a2890351178d553266de4a152bcc5356dca847f Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:45:15 +0100 Subject: [PATCH 087/106] Update deployment/bare_metal/start.sh Co-authored-by: Ulf Gebhardt --- deployment/bare_metal/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 92773f496..46e814ee0 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -221,7 +221,7 @@ IFS="," read -a API_ARRAY <<< $FEDERATION_COMMUNITY_APIS for api in "${API_ARRAY[@]}" do export FEDERATION_API=$api - echo "FEDERATION_API=$FEDERATION_API" + echo "FEDERATION_API=$FEDERATION_API" >> $UPDATE_HTML export MODULENAME=gradido-federation-$api echo "MODULENAME=$MODULENAME" # calculate port by remove '_' and add value of api to baseport From 5fbf8613c540bccb21f7d3f131b3b55f0453da07 Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:45:47 +0100 Subject: [PATCH 088/106] Update deployment/bare_metal/start.sh Co-authored-by: Ulf Gebhardt --- deployment/bare_metal/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 46e814ee0..4408431c1 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -223,7 +223,7 @@ do export FEDERATION_API=$api echo "FEDERATION_API=$FEDERATION_API" >> $UPDATE_HTML export MODULENAME=gradido-federation-$api - echo "MODULENAME=$MODULENAME" + echo "MODULENAME=$MODULENAME" >> $UPDATE_HTML # calculate port by remove '_' and add value of api to baseport port=${api//_/} FEDERATION_PORT=${FEDERATION_COMMUNITY_API_PORT:-5000} From 53566cc8c5e69ca312a88db8ed0902aaee658829 Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:46:32 +0100 Subject: [PATCH 089/106] Update deployment/bare_metal/start.sh Co-authored-by: Ulf Gebhardt --- deployment/bare_metal/start.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 4408431c1..90b743417 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -229,9 +229,9 @@ do FEDERATION_PORT=${FEDERATION_COMMUNITY_API_PORT:-5000} FEDERATION_PORT=$(($FEDERATION_PORT + $port)) export FEDERATION_PORT - echo "====================================================" - echo " start $MODULENAME listening on port=$FEDERATION_PORT" - echo "====================================================" + echo "====================================================" >> $UPDATE_HTML + echo " start $MODULENAME listening on port=$FEDERATION_PORT" >> $UPDATE_HTML + echo "====================================================" >> $UPDATE_HTML # pm2 delete $MODULENAME pm2 start --name $MODULENAME "yarn --cwd $PROJECT_ROOT/federation start" -l $GRADIDO_LOG_PATH/pm2.$MODULENAME.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save From ee728ffd7901acfef9bf9fb4dbe21488327ee209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Mon, 6 Mar 2023 15:08:00 +0100 Subject: [PATCH 090/106] remove 'hex' at comparing the publicKey --- backend/src/federation/validateCommunities.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/federation/validateCommunities.ts b/backend/src/federation/validateCommunities.ts index 903ceb68b..c06b2fd72 100644 --- a/backend/src/federation/validateCommunities.ts +++ b/backend/src/federation/validateCommunities.ts @@ -40,7 +40,7 @@ export async function validateCommunities(): Promise { 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)}`) From 569b3e0d7d8b928249bc374290df3a43efd8af50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Mon, 6 Mar 2023 16:08:59 +0100 Subject: [PATCH 091/106] rework PR-comments --- deployment/bare_metal/start.sh | 12 ++++-------- federation/.env.dist | 14 +++----------- federation/.env.dist.template | 11 ++++++----- federation/src/config/index.ts | 20 -------------------- 4 files changed, 13 insertions(+), 44 deletions(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 90b743417..aee21fbee 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -77,7 +77,7 @@ export BUILD_COMMIT="$(git rev-parse HEAD)" # *** 1st prepare for each apiversion the federation conf for nginx from federation-template # *** set FEDERATION_PORT from FEDERATION_COMMUNITY_APIS and create gradido-federation.conf file rm -f $NGINX_CONFIG_DIR/gradido.conf.tmp -rm -f $NGINX_CONFIG_DIR/gradido-federation.conf +rm -f $NGINX_CONFIG_DIR/gradido-federation.conf.locations echo "====================================================================================================" >> $UPDATE_HTML IFS="," read -a API_ARRAY <<< $FEDERATION_COMMUNITY_APIS for api in "${API_ARRAY[@]}" @@ -89,14 +89,14 @@ do FEDERATION_PORT=$(($FEDERATION_PORT + $port)) export FEDERATION_PORT echo "create ngingx config: location /api/$FEDERATION_APIVERSION to http://127.0.0.1:$FEDERATION_PORT" >> $UPDATE_HTML - envsubst '$FEDERATION_APIVERSION, $FEDERATION_PORT' < $NGINX_CONFIG_DIR/gradido-federation.conf.template >> $NGINX_CONFIG_DIR/gradido-federation.conf + envsubst '$FEDERATION_APIVERSION, $FEDERATION_PORT' < $NGINX_CONFIG_DIR/gradido-federation.conf.template >> $NGINX_CONFIG_DIR/gradido-federation.conf.locations done unset FEDERATION_APIVERSION unset FEDERATION_PORT echo "====================================================================================================" >> $UPDATE_HTML # *** 2nd read gradido-federation.conf file in env variable to be replaced in 3rd step -export FEDERATION_NGINX_CONF=$(< $NGINX_CONFIG_DIR/gradido-federation.conf) +export FEDERATION_NGINX_CONF=$(< $NGINX_CONFIG_DIR/gradido-federation.conf.locations) # *** 3rd generate gradido nginx config including federation modules per api-version echo 'Generate new gradido nginx config' >> $UPDATE_HTML @@ -108,7 +108,7 @@ envsubst '$FEDERATION_NGINX_CONF' < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CO export FEDERATION_NGINX_CONF= envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido.conf.tmp > $NGINX_CONFIG_DIR/gradido.conf rm $NGINX_CONFIG_DIR/gradido.conf.tmp -rm $NGINX_CONFIG_DIR/gradido-federation.conf +rm $NGINX_CONFIG_DIR/gradido-federation.conf.locations # Generate update-page.conf from template echo 'Generate new update-page nginx config' >> $UPDATE_HTML @@ -156,7 +156,6 @@ if [ "$DEPLOY_SEED_DATA" = "true" ]; then fi # TODO maybe handle this differently? export NODE_ENV=production -# pm2 delete gradido-backend pm2 start --name gradido-backend "yarn --cwd $PROJECT_ROOT/backend start" -l $GRADIDO_LOG_PATH/pm2.backend.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save @@ -169,7 +168,6 @@ yarn install yarn build # TODO maybe handle this differently? export NODE_ENV=production -# pm2 delete gradido-frontend pm2 start --name gradido-frontend "yarn --cwd $PROJECT_ROOT/frontend start" -l $GRADIDO_LOG_PATH/pm2.frontend.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save @@ -182,7 +180,6 @@ yarn install yarn build # TODO maybe handle this differently? export NODE_ENV=production -# pm2 delete gradido-admin pm2 start --name gradido-admin "yarn --cwd $PROJECT_ROOT/admin start" -l $GRADIDO_LOG_PATH/pm2.admin.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save @@ -195,7 +192,6 @@ yarn install yarn build # TODO maybe handle this differently? export NODE_ENV=production -# pm2 delete gradido-dht-node if [ ! -z $FEDERATION_DHT_TOPIC ]; then pm2 start --name gradido-dht-node "yarn --cwd $PROJECT_ROOT/dht-node start" -l $GRADIDO_LOG_PATH/pm2.dht-node.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save diff --git a/federation/.env.dist b/federation/.env.dist index 2bbf77fa8..68cedd5bb 100644 --- a/federation/.env.dist +++ b/federation/.env.dist @@ -1,15 +1,7 @@ -LOG_LEVEL=debug -PORT=4000 -GRAPHIQL=true - # Database -DB_PORT=3306 -DB_DATABASE=gradido_community - - -COMMUNITY_NAME=Gradido Entwicklung -COMMUNITY_URL=http://localhost:4000/ -COMMUNITY_DESCRIPTION=lokale Entwicklungsumgebung +# DB_HOST=localhost +# DB_PORT=3306 +# DB_DATABASE=gradido_community # Federation FEDERATION_API=1_0 diff --git a/federation/.env.dist.template b/federation/.env.dist.template index 336da8f1a..63185117b 100644 --- a/federation/.env.dist.template +++ b/federation/.env.dist.template @@ -1,14 +1,15 @@ +CONFIG_VERSION=$FEDERATION_CONFIG_VERSION + LOG_LEVEL=$LOG_LEVEL -PORT=$PORT GRAPHIQL=$GRAPHIQL # Database +DB_HOST=$DB_HOST DB_PORT=$DB_PORT DB_DATABASE=$DB_DATABASE - -COMMUNITY_NAME=$COMMUNITY_NAME -COMMUNITY_URL=$COMMUNITY_URL -COMMUNITY_DESCRIPTION=$COMMUNITY_DESCRIPTION +DB_USER=$DB_USER +DB_PASSWORD=$DB_PASSWORD +DB_DATABASE=$DB_DATABASE # Federation FEDERATION_API=$FEDERATION_API diff --git a/federation/src/config/index.ts b/federation/src/config/index.ts index dc2e77928..e9036fc49 100644 --- a/federation/src/config/index.ts +++ b/federation/src/config/index.ts @@ -24,7 +24,6 @@ const constants = { } const server = { - PORT: process.env.PORT || 5010, // JWT_SECRET: process.env.JWT_SECRET || 'secret123', // JWT_EXPIRES_IN: process.env.JWT_EXPIRES_IN || '10m', GRAPHIQL: process.env.GRAPHIQL === 'true' || false, @@ -40,21 +39,6 @@ const database = { TYPEORM_LOGGING_RELATIVE_PATH: process.env.TYPEORM_LOGGING_RELATIVE_PATH || 'typeorm.backend.log', } -/* -const community = { - COMMUNITY_NAME: process.env.COMMUNITY_NAME || 'Gradido Entwicklung', - COMMUNITY_URL: process.env.COMMUNITY_URL || 'http://localhost/', - COMMUNITY_REGISTER_URL: process.env.COMMUNITY_REGISTER_URL || 'http://localhost/register', - COMMUNITY_REDEEM_URL: process.env.COMMUNITY_REDEEM_URL || 'http://localhost/redeem/{code}', - COMMUNITY_REDEEM_CONTRIBUTION_URL: - process.env.COMMUNITY_REDEEM_CONTRIBUTION_URL || 'http://localhost/redeem/CL-{code}', - COMMUNITY_DESCRIPTION: - process.env.COMMUNITY_DESCRIPTION || 'Die lokale Entwicklungsumgebung von Gradido.', -} -*/ - -// This is needed by graphql-directive-auth -// process.env.APP_SECRET = server.JWT_SECRET // Check config version constants.CONFIG_VERSION.CURRENT = @@ -71,10 +55,6 @@ if ( } const federation = { - // FEDERATION_DHT_TOPIC: process.env.FEDERATION_DHT_TOPIC || null, - // FEDERATION_DHT_SEED: process.env.FEDERATION_DHT_SEED || null, - // FEDERATION_COMMUNITY_API_PORT: - // process.env.FEDERATION_COMMUNITY_API_PORT || 5000, FEDERATION_API: process.env.FEDERATION_API || '1_0', FEDERATION_PORT: process.env.FEDERATION_PORT || 5010, FEDERATION_COMMUNITY_URL: process.env.FEDERATION_COMMUNITY_URL || null, From 8b64fb810ac5d2b9ac564ba3445d92e05d8e3df7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Mon, 6 Mar 2023 21:56:40 +0100 Subject: [PATCH 092/106] rework PR-comments --- federation/.env.dist.template | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/federation/.env.dist.template b/federation/.env.dist.template index 63185117b..780779722 100644 --- a/federation/.env.dist.template +++ b/federation/.env.dist.template @@ -1,7 +1,8 @@ CONFIG_VERSION=$FEDERATION_CONFIG_VERSION LOG_LEVEL=$LOG_LEVEL -GRAPHIQL=$GRAPHIQL +# this is set fix to false, because it is important for 'production' environments. only set to true if a graphql-playground should be in use +GRAPHIQL=false # Database DB_HOST=$DB_HOST From cbc7a0557d1449886ff371d95d72783af9432d31 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Mar 2023 12:16:17 +0100 Subject: [PATCH 093/106] modify column to datetime(3) --- database/entity/0061-event_refactoring/Event.ts | 2 +- database/migrations/0061-event_refactoring.ts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/database/entity/0061-event_refactoring/Event.ts b/database/entity/0061-event_refactoring/Event.ts index 601852ccd..ab75c2d94 100644 --- a/database/entity/0061-event_refactoring/Event.ts +++ b/database/entity/0061-event_refactoring/Event.ts @@ -25,7 +25,7 @@ export class Event extends BaseEntity { @CreateDateColumn({ name: 'created_at', type: 'datetime', - default: () => 'CURRENT_TIMESTAMP()', + default: () => 'CURRENT_TIMESTAMP(3)', nullable: false, }) createdAt: Date diff --git a/database/migrations/0061-event_refactoring.ts b/database/migrations/0061-event_refactoring.ts index 11e81f97f..f05f99929 100644 --- a/database/migrations/0061-event_refactoring.ts +++ b/database/migrations/0061-event_refactoring.ts @@ -57,9 +57,16 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis await queryFn( 'UPDATE `events` SET acting_user_id=involved_user_id WHERE `type` = "TRANSACTION_RECEIVE";', ) + + await queryFn( + 'ALTER TABLE `events` MODIFY COLUMN `created_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3);', + ) } export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn( + 'ALTER TABLE `events` MODIFY COLUMN `created_at` datetime() NOT NULL DEFAULT CURRENT_TIMESTAMP();', + ) await queryFn( 'UPDATE `events` SET involved_user_id=acting_user_id WHERE `type` = "ADMIN_CONTRIBUTION_DENY";', ) From ae792850c335113e1d1d4d36cbc473399935f39f Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Mar 2023 12:28:13 +0100 Subject: [PATCH 094/106] fix down script --- database/migrations/0061-event_refactoring.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/0061-event_refactoring.ts b/database/migrations/0061-event_refactoring.ts index f05f99929..eec403acc 100644 --- a/database/migrations/0061-event_refactoring.ts +++ b/database/migrations/0061-event_refactoring.ts @@ -65,7 +65,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { await queryFn( - 'ALTER TABLE `events` MODIFY COLUMN `created_at` datetime() NOT NULL DEFAULT CURRENT_TIMESTAMP();', + 'ALTER TABLE `events` MODIFY COLUMN `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP();', ) await queryFn( 'UPDATE `events` SET involved_user_id=acting_user_id WHERE `type` = "ADMIN_CONTRIBUTION_DENY";', From b5efaa47c18d9ef3b2c37978cd9f779d56055689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 7 Mar 2023 13:32:16 +0100 Subject: [PATCH 095/106] rework PR-comments --- federation/.env.dist | 8 +++++--- federation/.env.dist.template | 2 -- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/federation/.env.dist b/federation/.env.dist index 68cedd5bb..42b3d05bf 100644 --- a/federation/.env.dist +++ b/federation/.env.dist @@ -1,7 +1,9 @@ # Database -# DB_HOST=localhost -# DB_PORT=3306 -# DB_DATABASE=gradido_community +DB_HOST=localhost +DB_PORT=3306 +DB_DATABASE=gradido_community +DB_USER=root +DB_PASSWORD= # Federation FEDERATION_API=1_0 diff --git a/federation/.env.dist.template b/federation/.env.dist.template index 780779722..3bd795f41 100644 --- a/federation/.env.dist.template +++ b/federation/.env.dist.template @@ -13,7 +13,5 @@ DB_PASSWORD=$DB_PASSWORD DB_DATABASE=$DB_DATABASE # Federation -FEDERATION_API=$FEDERATION_API -FEDERATION_PORT=$FEDERATION_PORT FEDERATION_COMMUNITY_URL=$FEDERATION_COMMUNITY_URL From 369c2d88b90e7c14fee58eeaeaf59531b16ab3bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 7 Mar 2023 14:21:46 +0100 Subject: [PATCH 096/106] add federation- and dht-node modules to release.sh --- scripts/release.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/release.sh b/scripts/release.sh index 80a54d949..df6ece9b6 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -7,6 +7,8 @@ FRONTEND_DIR="${PROJECT_DIR}/frontend/" BACKEND_DIR="${PROJECT_DIR}/backend/" DATABASE_DIR="${PROJECT_DIR}/database/" ADMIN_DIR="${PROJECT_DIR}/admin/" +DHTNODE_DIR="${PROJECT_DIR}/dht-node/" +FEDERATION_DIR="${PROJECT_DIR}/federation/" # navigate to project directory cd ${PROJECT_DIR} @@ -26,6 +28,10 @@ cd ${DATABASE_DIR} yarn version --no-git-tag-version --no-commit-hooks --no-commit --new-version ${VERSION} cd ${ADMIN_DIR} yarn version --no-git-tag-version --no-commit-hooks --no-commit --new-version ${VERSION} +cd ${DHTNODE_DIR} +yarn version --no-git-tag-version --no-commit-hooks --no-commit --new-version ${VERSION} +cd ${FEDERATION_DIR} +yarn version --no-git-tag-version --no-commit-hooks --no-commit --new-version ${VERSION} # generate changelog cd ${PROJECT_DIR} From bf891670b4495f10b5ec1d47803f43f584eed65e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 7 Mar 2023 14:25:55 +0100 Subject: [PATCH 097/106] rename .env.template file --- federation/{.env.dist.template => .env.template} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename federation/{.env.dist.template => .env.template} (100%) diff --git a/federation/.env.dist.template b/federation/.env.template similarity index 100% rename from federation/.env.dist.template rename to federation/.env.template From 3e7247ba292cfb706f7a36c81afcc774e5b49580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 7 Mar 2023 14:39:21 +0100 Subject: [PATCH 098/106] linting --- federation/src/graphql/api/1_0/model/GetPublicKeyResult.ts | 2 ++ federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/federation/src/graphql/api/1_0/model/GetPublicKeyResult.ts b/federation/src/graphql/api/1_0/model/GetPublicKeyResult.ts index 1582ad892..696c96cfe 100644 --- a/federation/src/graphql/api/1_0/model/GetPublicKeyResult.ts +++ b/federation/src/graphql/api/1_0/model/GetPublicKeyResult.ts @@ -1,6 +1,8 @@ +// eslint-disable-next-line @typescript-eslint/no-unused-vars import { Field, ObjectType } from 'type-graphql' @ObjectType() +// eslint-disable-next-line @typescript-eslint/no-unused-vars export class GetPublicKeyResult { constructor(pubKey: string) { this.publicKey = pubKey diff --git a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts index 53f0d0bd4..2e21af945 100644 --- a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts +++ b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts @@ -1,9 +1,11 @@ -import { Field, ObjectType, Query, Resolver } from 'type-graphql' +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import { 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() +// eslint-disable-next-line @typescript-eslint/no-unused-vars export class PublicKeyResolver { @Query(() => GetPublicKeyResult) async getPublicKey(): Promise { From bfa8f33ea6787588b9bef41120304b3a91186914 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 14 Mar 2023 16:08:57 +0100 Subject: [PATCH 099/106] merge conflict --- backend/src/graphql/resolver/TransactionResolver.test.ts | 4 ++-- backend/src/graphql/resolver/UserResolver.test.ts | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/backend/src/graphql/resolver/TransactionResolver.test.ts b/backend/src/graphql/resolver/TransactionResolver.test.ts index 9c20dd47c..6c1b4be7f 100644 --- a/backend/src/graphql/resolver/TransactionResolver.test.ts +++ b/backend/src/graphql/resolver/TransactionResolver.test.ts @@ -341,7 +341,7 @@ describe('send coins', () => { memo: 'unrepeatable memo', }) - expect(DbEvent.find()).resolves.toContainEqual( + await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.TRANSACTION_SEND, affectedUserId: user[1].id, @@ -359,7 +359,7 @@ describe('send coins', () => { memo: 'unrepeatable memo', }) - expect(DbEvent.find()).resolves.toContainEqual( + await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.TRANSACTION_RECEIVE, affectedUserId: user[0].id, diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index d2ac15085..b91ed8709 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -216,7 +216,7 @@ describe('UserResolver', () => { }) }) - it('stores the SEND_CONFIRMATION_EMAIL event in the database', () => { + it('stores the SEND_CONFIRMATION_EMAIL event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.SEND_CONFIRMATION_EMAIL, @@ -363,7 +363,7 @@ describe('UserResolver', () => { ) }) - it('stores the ACTIVATE_ACCOUNT event in the database', () => { + it('stores the ACTIVATE_ACCOUNT event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ACTIVATE_ACCOUNT, @@ -373,7 +373,7 @@ describe('UserResolver', () => { ) }) - it('stores the REDEEM_REGISTER event in the database', () => { + it('stores the REDEEM_REGISTER event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.REDEEM_REGISTER, @@ -940,7 +940,7 @@ describe('UserResolver', () => { ) }) - it('stores the LOGIN event in the database', () => { + it('stores the LOGIN event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.LOGIN, @@ -1861,7 +1861,6 @@ describe('UserResolver', () => { { email: 'bibi@bloxberg.de' }, { relations: ['user'] }, ) - await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_SEND_CONFIRMATION_EMAIL, From e8114e40837aafa62266821ac8c39d5ecc4f7d70 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 14 Mar 2023 20:04:28 +0100 Subject: [PATCH 100/106] remove mul -1 for congruency --- backend/src/graphql/resolver/TransactionResolver.ts | 3 +-- database/migrations/0061-event_refactoring.ts | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/resolver/TransactionResolver.ts b/backend/src/graphql/resolver/TransactionResolver.ts index 3145a999e..c3f4b5d48 100644 --- a/backend/src/graphql/resolver/TransactionResolver.ts +++ b/backend/src/graphql/resolver/TransactionResolver.ts @@ -142,8 +142,7 @@ export const executeTransaction = async ( sender, recipient, transactionSend, - // TODO why mul -1? - transactionSend.amount.mul(-1), + transactionSend.amount, ) await EVENT_TRANSACTION_RECEIVE( diff --git a/database/migrations/0061-event_refactoring.ts b/database/migrations/0061-event_refactoring.ts index eec403acc..019d3272b 100644 --- a/database/migrations/0061-event_refactoring.ts +++ b/database/migrations/0061-event_refactoring.ts @@ -58,6 +58,8 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis 'UPDATE `events` SET acting_user_id=involved_user_id WHERE `type` = "TRANSACTION_RECEIVE";', ) + await queryFn('UPDATE `events` SET amount = amount * -1 WHERE `type` = "TRANSACTION_SEND";') + await queryFn( 'ALTER TABLE `events` MODIFY COLUMN `created_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3);', ) @@ -67,6 +69,9 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom await queryFn( 'ALTER TABLE `events` MODIFY COLUMN `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP();', ) + + await queryFn('UPDATE `events` SET amount = amount * -1 WHERE `type` = "TRANSACTION_SEND";') + await queryFn( 'UPDATE `events` SET involved_user_id=acting_user_id WHERE `type` = "ADMIN_CONTRIBUTION_DENY";', ) From d790e9cfcf1c58ff4d246d93d4b76313e687c66f Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 14 Mar 2023 20:08:11 +0100 Subject: [PATCH 101/106] lint fix --- backend/src/graphql/resolver/TransactionResolver.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/backend/src/graphql/resolver/TransactionResolver.ts b/backend/src/graphql/resolver/TransactionResolver.ts index c3f4b5d48..5b10c098f 100644 --- a/backend/src/graphql/resolver/TransactionResolver.ts +++ b/backend/src/graphql/resolver/TransactionResolver.ts @@ -138,12 +138,7 @@ export const executeTransaction = async ( await queryRunner.commitTransaction() logger.info(`commit Transaction successful...`) - await EVENT_TRANSACTION_SEND( - sender, - recipient, - transactionSend, - transactionSend.amount, - ) + await EVENT_TRANSACTION_SEND(sender, recipient, transactionSend, transactionSend.amount) await EVENT_TRANSACTION_RECEIVE( recipient, From 3af7239d5efa85b7779f29f63c23e636df2df054 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 14 Mar 2023 23:43:31 +0100 Subject: [PATCH 102/106] fix foreach singleton problem --- backend/src/federation/client/GraphQLGetClient.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/backend/src/federation/client/GraphQLGetClient.ts b/backend/src/federation/client/GraphQLGetClient.ts index 8086a95fa..2f5281532 100644 --- a/backend/src/federation/client/GraphQLGetClient.ts +++ b/backend/src/federation/client/GraphQLGetClient.ts @@ -26,11 +26,10 @@ export class GraphQLGetClient extends GraphQLClient { * just one instance of each subclass around. */ public static getInstance(url: string): GraphQLGetClient { - GraphQLGetClient.instanceArray.forEach(function (instance) { - if (instance.url === url) { - return instance.client - } - }) + const instance = GraphQLGetClient.instanceArray.find((instance) => instance.url === url) + if (instance) { + return instance.client + } const client = new GraphQLGetClient(url, { method: 'GET', jsonSerializer: { From 6fa55fd8cc51411b274e4ac5f4e9af06d432db88 Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Tue, 14 Mar 2023 23:43:47 +0100 Subject: [PATCH 103/106] Update federation/.env.template Co-authored-by: Ulf Gebhardt --- federation/.env.template | 1 - 1 file changed, 1 deletion(-) diff --git a/federation/.env.template b/federation/.env.template index 3bd795f41..af6e8f627 100644 --- a/federation/.env.template +++ b/federation/.env.template @@ -10,7 +10,6 @@ DB_PORT=$DB_PORT DB_DATABASE=$DB_DATABASE DB_USER=$DB_USER DB_PASSWORD=$DB_PASSWORD -DB_DATABASE=$DB_DATABASE # Federation FEDERATION_COMMUNITY_URL=$FEDERATION_COMMUNITY_URL From 14c499cd3b8f7518622dfb069b9755d4dbf2f256 Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Tue, 14 Mar 2023 23:44:31 +0100 Subject: [PATCH 104/106] Update deployment/bare_metal/start.sh Co-authored-by: Ulf Gebhardt --- deployment/bare_metal/start.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index aee21fbee..1d0f982c2 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -237,7 +237,6 @@ done # let nginx showing gradido -cd $SCRIPT_DIR echo 'Configuring nginx to serve gradido again' >> $UPDATE_HTML ln -s /etc/nginx/sites-available/gradido.conf /etc/nginx/sites-enabled/ rm /etc/nginx/sites-enabled/update-page.conf From e5732526e271a802a1413edd06bc96260a28e7a2 Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Tue, 14 Mar 2023 23:44:44 +0100 Subject: [PATCH 105/106] Update deployment/bare_metal/start.sh Co-authored-by: Ulf Gebhardt --- deployment/bare_metal/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 1d0f982c2..6c3c07766 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -105,7 +105,7 @@ case "$NGINX_SSL" in *) TEMPLATE_FILE="gradido.conf.template" ;; esac envsubst '$FEDERATION_NGINX_CONF' < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf.tmp -export FEDERATION_NGINX_CONF= +unset FEDERATION_NGINX_CONF envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/gradido.conf.tmp > $NGINX_CONFIG_DIR/gradido.conf rm $NGINX_CONFIG_DIR/gradido.conf.tmp rm $NGINX_CONFIG_DIR/gradido-federation.conf.locations From 89024dffbb1ae856789afca5cdfbab47351b2725 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 14 Mar 2023 23:50:25 +0100 Subject: [PATCH 106/106] fix linting --- backend/src/federation/validateCommunities.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/src/federation/validateCommunities.ts b/backend/src/federation/validateCommunities.ts index 0a2585af5..dfd46a3e9 100644 --- a/backend/src/federation/validateCommunities.ts +++ b/backend/src/federation/validateCommunities.ts @@ -48,7 +48,9 @@ export async function validateCommunities(): Promise { logger.debug(`Federation: updated dbCom: ${JSON.stringify(dbCom)}`) } else { logger.warn( - `Federation: received not matching publicKey -> received: ${pubKey}, expected: ${dbCom.publicKey} `, + `Federation: received not matching publicKey -> received: ${ + pubKey || 'null' + }, expected: ${dbCom.publicKey.toString()} `, ) // DbCommunity.delete({ id: dbCom.id }) }