Skip to content

Commit

Permalink
feat: move service factories/singletons to server-kit-package (#387)
Browse files Browse the repository at this point in the history
* feat: move vault singleton management to server-kit package

* feat: move authup singleton management to server-kit package

* feat: refactored usage of shared services in sever-storage package

* feat: refactored usage of shared services in sever-realtime package

* feat: refactored usage of shared services in sever-analyis-manager package

* feat: move amqp client singleton management to kit package

* feat: adjusted amqplib usage across packages
  • Loading branch information
tada5hi authored May 23, 2024
1 parent 3c15093 commit 669d352
Show file tree
Hide file tree
Showing 93 changed files with 299 additions and 487 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { ComponentContextWithCommand } from '@privateaim/server-kit';
import { useAmqpClient } from '../../../core';
import { useAmqpClient } from '@privateaim/server-kit';
import type { BuilderCommand } from '../constants';
import { BuilderEvent } from '../constants';
import type { BuilderBuildCommandContext, BuilderBuildPayload } from '../type';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { ComponentContextWithCommand } from '@privateaim/server-kit';
import { useAmqpClient } from '../../../core';
import { useAmqpClient } from '@privateaim/server-kit';
import type { BuilderCommand } from '../constants';
import { BuilderEvent } from '../constants';
import type { BuilderBuildCommandContext, BuilderBuildPayload } from '../type';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* view the LICENSE file that was distributed with this source code.
*/

import { useAmqpClient } from '../../../core';
import { useAmqpClient } from '@privateaim/server-kit';
import { BuilderEvent } from '../constants';
import type { BuilderCheckCommandContext, BuilderCheckPayload } from '../type';
import { buildBuilderAggregatorQueuePayload } from '../utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* view the LICENSE file that was distributed with this source code.
*/

import { useAmqpClient } from '../../../core';
import { useAmqpClient } from '@privateaim/server-kit';
import { BuilderEvent } from '../constants';
import type { BuilderCheckCommandContext, BuilderCheckPayload } from '../type';
import { buildBuilderAggregatorQueuePayload } from '../utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { ComponentContextWithCommand, ComponentContextWithError } from '@privateaim/server-kit';
import { useAmqpClient } from '../../../core';
import { useAmqpClient } from '@privateaim/server-kit';
import type { BuilderCommand } from '../constants';
import { BuilderEvent } from '../constants';
import type { BuilderCommandContext } from '../type';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* view the LICENSE file that was distributed with this source code.
*/

import { useAmqpClient } from '../../../core';
import { useAmqpClient } from '@privateaim/server-kit';
import { BuilderEvent } from '../constants';
import type { BuilderCheckCommandContext, BuilderCheckPayload } from '../type';
import { buildBuilderAggregatorQueuePayload } from '../utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { ComponentContextWithCommand } from '@privateaim/server-kit';
import { useAmqpClient } from '../../../core';
import { useAmqpClient } from '@privateaim/server-kit';
import type { BuilderCommand } from '../constants';
import { BuilderEvent } from '../constants';
import type { BuilderBuildCommandContext, BuilderBuildPayload } from '../type';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { ComponentContextWithCommand } from '@privateaim/server-kit';
import { useAmqpClient } from '../../../core';
import { useAmqpClient } from '@privateaim/server-kit';
import type { BuilderCommand } from '../constants';
import { BuilderEvent } from '../constants';
import type { BuilderBuildCommandContext, BuilderBuildPayload } from '../type';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type { Logger } from '@privateaim/server-kit';
import { createLogger } from '@privateaim/server-kit';
import { getWritableDirPath } from '../../../config';
import { WRITABLE_DIRECTORY_PATH } from '../../../config';
import { ComponentName } from '../../constants';

let instance : Logger | undefined;
Expand All @@ -24,7 +24,7 @@ export function useBuilderLogger() : Logger {
},
},
// todo: allow customizing specific path
directory: getWritableDirPath(),
directory: WRITABLE_DIRECTORY_PATH,
});

return instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* view the LICENSE file that was distributed with this source code.
*/

import { useAmqpClient } from '../../../core';
import { useAmqpClient } from '@privateaim/server-kit';
import { CoreEvent } from '../constants';
import type { CoreConfigureCommandContext } from '../type';
import { buildCoreAggregatorQueuePayload } from '../utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* view the LICENSE file that was distributed with this source code.
*/

import { useAmqpClient } from '../../../core';
import { useAmqpClient } from '@privateaim/server-kit';
import { CoreEvent } from '../constants';
import type { CoreConfigureCommandContext } from '../type';
import { buildCoreAggregatorQueuePayload } from '../utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* view the LICENSE file that was distributed with this source code.
*/

import { useAmqpClient } from '../../../core';
import { useAmqpClient } from '@privateaim/server-kit';
import { CoreEvent } from '../constants';
import type { CoreDestroyCommandContext } from '../type';
import { buildCoreAggregatorQueuePayload } from '../utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* view the LICENSE file that was distributed with this source code.
*/

import { useAmqpClient } from '../../../core';
import { useAmqpClient } from '@privateaim/server-kit';
import { CoreEvent } from '../constants';
import type { CoreDestroyCommandContext } from '../type';
import { buildCoreAggregatorQueuePayload } from '../utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { ComponentContextWithError } from '@privateaim/server-kit';
import { useAmqpClient } from '../../../core';
import { useAmqpClient } from '@privateaim/server-kit';
import { CoreEvent } from '../constants';
import type { CoreCommandContext } from '../type';
import { buildCoreAggregatorQueuePayload } from '../utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type { Logger } from '@privateaim/server-kit';
import { createLogger } from '@privateaim/server-kit';
import { getWritableDirPath } from '../../../config';
import { WRITABLE_DIRECTORY_PATH } from '../../../config';
import { ComponentName } from '../../constants';

let instance : Logger | undefined;
Expand All @@ -24,7 +24,7 @@ export function useCoreLogger() : Logger {
},
},
// todo: allow specifying custom path
directory: getWritableDirPath(),
directory: WRITABLE_DIRECTORY_PATH,
});

return instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
import type {
Component,
} from '@privateaim/server-kit';
import { isComponentCommandQueuePayload } from '@privateaim/server-kit';
import { isComponentCommandQueuePayload, useAmqpClient, useLogger } from '@privateaim/server-kit';
import { ComponentName } from '../../../constants';
import { executeCoreCommand } from '../../../core';
import {
executeBuilderCommand,
} from '../../../index';
import { useAmqpClient, useLogger } from '../../../../core';
import { ROUTER_QUEUE_ROUTING_KEY } from './constants';

export function buildComponentRouter() : Component {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
* view the LICENSE file that was distributed with this source code.
*/

import type { Client } from 'redis-extension';
import path from 'node:path';
import process from 'node:process';

export type Config = {
redisDatabase: Client
};
export const WRITABLE_DIRECTORY_PATH = path.join(process.cwd(), 'writable');
3 changes: 2 additions & 1 deletion packages/server-analysis-manager/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

export * from './env';
export * from './module';
export * from './paths';
export * from './constants';
export * from './types';
23 changes: 7 additions & 16 deletions packages/server-analysis-manager/src/config/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,22 @@
* view the LICENSE file that was distributed with this source code.
*/

import type { TokenCreatorOptions } from '@authup/core-http-kit';
import type { Aggregator, Component } from '@privateaim/server-kit';
import { guessAuthupTokenCreatorOptions } from '@privateaim/server-kit';
import { buildComponentRouter } from '../components';
import { useEnv } from './env';
import {
configureAMQP,
configureCoreService,
configureStorageService,
configureAMQP, configureCoreService, configureStorageService, setupLogger, setupVault,
} from './services';

export type Config = {
aggregators: {start: () => void}[]
components: {start: () => void}[]
};
import type { Config } from './types';

export function createConfig() : Config {
const tokenCreator : TokenCreatorOptions = {
type: 'robotInVault',
name: 'system',
vault: useEnv('vaultConnectionString'),
};
setupLogger();
setupVault();
configureAMQP();

const tokenCreator = guessAuthupTokenCreatorOptions();
configureStorageService({ tokenCreator });
configureCoreService({ tokenCreator });
configureAMQP();

const aggregators : Aggregator[] = [];

Expand Down
24 changes: 0 additions & 24 deletions packages/server-analysis-manager/src/config/paths.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/server-analysis-manager/src/config/services/amqp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
*/

import { Client } from 'amqp-extension';
import { setAmqpFactory } from '../../core/amqp';
import { setAmqpClientFactory } from '@privateaim/server-kit';
import { useEnv } from '../env';

export function configureAMQP() {
setAmqpFactory(() => new Client({
setAmqpClientFactory(() => new Client({
connection: useEnv('rabbitMqConnectionString'),
exchange: {
name: 'pht',
Expand Down
2 changes: 2 additions & 0 deletions packages/server-analysis-manager/src/config/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@

export * from './amqp';
export * from './core';
export * from './logger';
export * from './storage';
export * from './vault';
15 changes: 15 additions & 0 deletions packages/server-analysis-manager/src/config/services/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2024.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/

import { createLogger, setLoggerFactory } from '@privateaim/server-kit';
import { WRITABLE_DIRECTORY_PATH } from '../constants';

export function setupLogger(): void {
setLoggerFactory(() => createLogger({
directory: WRITABLE_DIRECTORY_PATH,
}));
}
18 changes: 18 additions & 0 deletions packages/server-analysis-manager/src/config/services/vault.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2024.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/

import { VaultClient, setVaultFactory } from '@privateaim/server-kit';
import { useEnv } from '../env';

export function setupVault() {
const connectionString = useEnv('vaultConnectionString');
if (typeof connectionString !== 'undefined') {
setVaultFactory(() => new VaultClient({
connectionString,
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/
import type { Aggregator, Component } from '@privateaim/server-kit';

export * from './module';
export type Config = {
aggregators: Aggregator[]
components: Component[]
};
2 changes: 0 additions & 2 deletions packages/server-analysis-manager/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
* view the LICENSE file that was distributed with this source code.
*/

export * from './amqp';
export * from './core';
export * from './crypto';
export * from './docker';
export * from './harbor';
export * from './logger';
export * from './storage';
export * from './utils';
8 changes: 0 additions & 8 deletions packages/server-analysis-manager/src/core/logger/index.ts

This file was deleted.

37 changes: 0 additions & 37 deletions packages/server-analysis-manager/src/core/logger/module.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/server-analysis-manager/src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* view the LICENSE file that was distributed with this source code.
*/

import { useLogger } from '@privateaim/server-kit';
import { createConfig, useEnv } from './config';
import { useLogger } from './core';
import { createHttpServer } from './http';

const config = createConfig();
Expand Down
Loading

0 comments on commit 669d352

Please sign in to comment.