From 4a1ec9a3b91883f9b708166ead9f46f0af7090aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= <33655937+jkoenig134@users.noreply.github.com> Date: Thu, 6 Jun 2024 08:05:20 +0200 Subject: [PATCH] Remove deprecated elements (#174) * chore: remove deprecated modules * chore: remove backwards compatibility for creating attributes * chore: remove ACCOUNT env key mapping * chore: remove config rewrite from webhooksV2 to webhooks --- config/default.json | 13 ------- src/index.ts | 12 ------ .../amqpPublisher/AMQPPublisherModule.ts | 38 ------------------- .../controllers/AttributesController.ts | 14 ------- .../pubSubPublisher/PubSubPublisherModule.ts | 38 ------------------- 5 files changed, 115 deletions(-) delete mode 100644 src/modules/amqpPublisher/AMQPPublisherModule.ts delete mode 100644 src/modules/pubSubPublisher/PubSubPublisherModule.ts diff --git a/config/default.json b/config/default.json index d7fc1e31..b6dd2920 100644 --- a/config/default.json +++ b/config/default.json @@ -103,19 +103,6 @@ "targets": {}, "webhooks": [] }, - "amqpPublisher": { - "enabled": false, - "displayName": "AMQP Publisher", - "location": "amqpPublisher/AMQPPublisherModule" - }, - "PubSubPublisher": { - "enabled": false, - "displayName": "PubSub Publisher", - "location": "pubSubPublisher/PubSubPublisherModule", - "projectId": "", - "topic": "", - "keyFile": "" - }, "messageBrokerPublisher": { "enabled": false, "displayName": "Message Broker Publisher", diff --git a/src/index.ts b/src/index.ts index afdd8a6a..2a6ddc8c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,4 @@ import { RuntimeConfig } from "@nmshd/runtime"; -import _ from "lodash"; import nconf from "nconf"; import { ConnectorRuntime } from "./ConnectorRuntime"; import { ConnectorRuntimeConfig } from "./ConnectorRuntimeConfig"; @@ -30,21 +29,10 @@ export function createConnectorConfig(overrides?: RuntimeConfig): ConnectorRunti const connectorConfig = nconf.get(); - if (typeof connectorConfig.modules.webhooksV2 !== "undefined") { - // eslint-disable-next-line no-console - console.warn("The 'webhooksV2' configuration is deprecated. Please use 'webhooks' instead."); - - connectorConfig.modules.webhooks = _.defaultsDeep(connectorConfig.modules.webhooksV2, connectorConfig.modules.webhooks); - delete connectorConfig.modules.webhooksV2; - } - return connectorConfig; } const envKeyMapping: Record = { - // The DATABASE__DB_NAME env variable was called ACCOUNT in the past - we need to keep an alias for backwards compatibility. - ACCOUNT: "database:dbName", // eslint-disable-line @typescript-eslint/naming-convention - DATABASE_NAME: "database:dbName", // eslint-disable-line @typescript-eslint/naming-convention API_KEY: "infrastructure:httpServer:apiKey", // eslint-disable-line @typescript-eslint/naming-convention DATABASE_CONNECTION_STRING: "database:connectionString", // eslint-disable-line @typescript-eslint/naming-convention diff --git a/src/modules/amqpPublisher/AMQPPublisherModule.ts b/src/modules/amqpPublisher/AMQPPublisherModule.ts deleted file mode 100644 index ff38c013..00000000 --- a/src/modules/amqpPublisher/AMQPPublisherModule.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { Event } from "@js-soft/ts-utils"; -import { DataEvent } from "@nmshd/runtime"; -import { ConnectorRuntimeModule, ConnectorRuntimeModuleConfiguration } from "../../ConnectorRuntimeModule"; -import { AMQPConnector } from "../messageBrokerPublisher/connectors/AMQPConnector"; - -export interface AMQPPublisherModuleConfiguration extends ConnectorRuntimeModuleConfiguration { - url: string; - exchange?: string; - timeout?: number; -} - -export default class AMQPPublisherModule extends ConnectorRuntimeModule { - private amqpConnector: AMQPConnector; - - public async init(): Promise { - this.logger.warn("AMQPPublisherModule is deprecated and will be removed in the future. Please use MessageBrokerPublisherModule instead."); - - this.amqpConnector = new AMQPConnector(this.configuration, this.logger); - await this.amqpConnector.init(); - } - - public start(): void { - this.subscribeToEvent("**", this.handleEvent.bind(this)); - } - - private handleEvent(event: Event) { - const data = event instanceof DataEvent ? event.data : {}; - const buffer = Buffer.from(JSON.stringify(data)); - - this.amqpConnector.publish(event.namespace, buffer); - } - - public async stop(): Promise { - this.unsubscribeFromAllEvents(); - - await this.amqpConnector.close(); - } -} diff --git a/src/modules/coreHttpApi/controllers/AttributesController.ts b/src/modules/coreHttpApi/controllers/AttributesController.ts index f51e50c5..89e4e324 100644 --- a/src/modules/coreHttpApi/controllers/AttributesController.ts +++ b/src/modules/coreHttpApi/controllers/AttributesController.ts @@ -1,4 +1,3 @@ -import { ApplicationError } from "@js-soft/ts-utils"; import { ConsumptionServices, RuntimeErrors, TransportServices } from "@nmshd/runtime"; import { Inject } from "typescript-ioc"; import { Accept, Context, DELETE, GET, POST, Path, PathParam, QueryParam, Return, ServiceContext } from "typescript-rest"; @@ -17,19 +16,6 @@ export class AttributesController extends BaseController { @POST @Accept("application/json") public async createRepositoryAttribute(request: any): Promise> { - const selfAddress = (await this.transportServices.account.getIdentityInfo()).value.address; - if (request?.content?.owner && request?.content?.owner !== selfAddress) { - throw new ApplicationError( - "error.connector.attributes.cannotCreateNotSelfOwnedRepositoryAttribute", - "You are not allowed to create an attribute that is not owned by yourself" - ); - } - /* We left 'owner' and '@type' optional in the openapi spec for - * backwards compatibility. If set, they have to be removed here or the runtime - * use case will throw an error. */ - if (typeof request?.content?.owner !== "undefined") delete request.content.owner; - if (request?.content?.["@type"] === "IdentityAttribute") delete request.content["@type"]; - const result = await this.consumptionServices.attributes.createRepositoryAttribute(request); return this.created(result); } diff --git a/src/modules/pubSubPublisher/PubSubPublisherModule.ts b/src/modules/pubSubPublisher/PubSubPublisherModule.ts deleted file mode 100644 index 15b7c62f..00000000 --- a/src/modules/pubSubPublisher/PubSubPublisherModule.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { DataEvent, Event } from "@js-soft/ts-utils"; -import { DataEvent as RuntimeDataEvent } from "@nmshd/runtime"; -import { ConnectorRuntimeModule, ConnectorRuntimeModuleConfiguration } from "../../ConnectorRuntimeModule"; -import { PubSubConnector } from "../messageBrokerPublisher/connectors/PubSubConnector"; - -export interface PubSubPublisherModuleConfiguration extends ConnectorRuntimeModuleConfiguration { - projectId: string; - topicName: string; - keyFile: string; -} - -export default class PubSubPublisherModule extends ConnectorRuntimeModule { - private pubSubConnector: PubSubConnector; - - public async init(): Promise { - this.logger.warn("PubSubPublisherModule is deprecated and will be removed in the future. Please use MessageBrokerPublisherModule instead."); - - this.pubSubConnector = new PubSubConnector(this.configuration, this.logger); - await this.pubSubConnector.init(); - } - - public start(): void { - this.subscribeToEvent("**", this.handleEvent.bind(this)); - } - - private async handleEvent(event: Event) { - const data = event instanceof DataEvent || event instanceof RuntimeDataEvent ? event.data : {}; - const buffer = Buffer.from(JSON.stringify(data)); - - await this.pubSubConnector.publish(event.namespace, buffer); - } - - public async stop(): Promise { - this.unsubscribeFromAllEvents(); - - await this.pubSubConnector.close(); - } -}