From de79a47f2183b337928d2a6667a1d20690279b2a Mon Sep 17 00:00:00 2001 From: Gerald Baulig Date: Fri, 12 Apr 2024 14:06:42 +0200 Subject: [PATCH] fix(config): fix configs, add missing acs, fix event handler binding --- cfg/config.json | 66 +++++++++++++++++++ cfg/config_production.json | 35 +++++++--- src/services/fulfillment_command_interface.ts | 5 +- src/services/fulfillment_product.ts | 2 +- src/worker.ts | 18 +++-- 5 files changed, 107 insertions(+), 19 deletions(-) diff --git a/cfg/config.json b/cfg/config.json index 9645d6d..369bc01 100644 --- a/cfg/config.json +++ b/cfg/config.json @@ -36,6 +36,12 @@ } }, "client": { + "acs-srv": { + "address": "localhost:50061" + }, + "user": { + "address": "localhost:50051" + }, "customer": { "address": "localhost:50063" }, @@ -183,6 +189,15 @@ "setApiKeyCommand": { "messageObject": "io.restorecommerce.commandinterface.CommandRequest" }, + "setApiKeyResponse": { + "messageObject": "io.restorecommerce.commandinterface.CommandResponse" + }, + "flushCacheCommand": { + "messageObject": "io.restorecommerce.commandinterface.CommandRequest" + }, + "flushCacheResponse": { + "messageObject": "io.restorecommerce.commandinterface.CommandResponse" + }, "topics": { "command": { "topic": "io.restorecommerce.command", @@ -244,6 +259,57 @@ "productName": "urn:restorecommerce:fulfillment:product:attribute:dhl:productName", "accountNumber": "urn:restorecommerce:fulfillment:product:attribute:dhl:accountNumber" }, + "authorization": { + "service": "acs-srv", + "enabled": true, + "enforce": true, + "database": "arangoDB", + "client": { + "acs-srv": { + "address": "localhost:50061" + }, + "user": { + "address": "localhost:50051" + } + }, + "urns": { + "entity": "urn:restorecommerce:acs:names:model:entity", + "user": "urn:restorecommerce:acs:model:user.User", + "model": "urn:restorecommerce:acs:model", + "role": "urn:restorecommerce:acs:names:role", + "roleScopingEntity": "urn:restorecommerce:acs:names:roleScopingEntity", + "roleScopingInstance": "urn:restorecommerce:acs:names:roleScopingInstance", + "unauthenticated_user": "urn:restorecommerce:acs:names:unauthenticated-user", + "property": "urn:restorecommerce:acs:names:model:property", + "ownerIndicatoryEntity": "urn:restorecommerce:acs:names:ownerIndicatoryEntity", + "ownerInstance": "urn:restorecommerce:acs:names:ownerInstance", + "orgScope": "urn:restorecommerce:acs:model:organization.Organization", + "subjectID": "urn:oasis:names:tc:xacml:1.0:subject:subject-id", + "resourceID": "urn:oasis:names:tc:xacml:1.0:resource:resource-id", + "actionID": "urn:oasis:names:tc:xacml:1.0:action:action-id", + "action": "urn:restorecommerce:acs:names:action", + "operation": "urn:restorecommerce:acs:names:operation", + "execute": "urn:restorecommerce:acs:names:action:execute", + "permitOverrides": "urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides", + "denyOverrides": "urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-overrides", + "create": "urn:restorecommerce:acs:names:action:create", + "read": "urn:restorecommerce:acs:names:action:read", + "modify": "urn:restorecommerce:acs:names:action:modify", + "delete": "urn:restorecommerce:acs:names:action:delete", + "organization": "urn:restorecommerce:acs:model:organization.Organization", + "aclIndicatoryEntity": "urn:restorecommerce:acs:names:aclIndicatoryEntity", + "aclInstance": "urn:restorecommerce:acs:names:aclInstance", + "skipACL": "urn:restorecommerce:acs:names:skipACL", + "maskedProperty": "urn:restorecommerce:acs:names:obligation:maskedProperty" + }, + "cache": { + "host": "localhost", + "port": 6379, + "db-index": 5, + "ttl": 3600, + "prefix": "acs:" + } + }, "server": { "transports": [ { diff --git a/cfg/config_production.json b/cfg/config_production.json index 253e6f5..da9944d 100644 --- a/cfg/config_production.json +++ b/cfg/config_production.json @@ -1,7 +1,7 @@ { "logger": { "elasticsearch": { - "level": "crit", + "level": "info", "clientOpts": { "node": "http://elasticsearch:9200" }, @@ -22,29 +22,35 @@ } }, "client": { + "acs-srv": { + "address": "access-control-srv:50051" + }, + "user": { + "address": "identity-srv:50051" + }, "customer": { - "address": "localhost:50051" + "address": "resource-srv:50051" }, "shop": { - "address": "localhost:50051" + "address": "resource-srv:50051" }, "organization": { - "address": "localhost:50051" + "address": "resource-srv:50051" }, "contact_point": { - "address": "localhost:50051" + "address": "resource-srv:50051" }, "address": { - "address": "localhost:50051" + "address": "resource-srv:50051" }, "country": { - "address": "localhost:50051" + "address": "resource-srv:50051" }, "tax": { - "address": "localhost:50051" + "address": "resource-srv:50051" }, "product": { - "address": "localhost:50051" + "address": "resource-srv:50051" } }, "events": { @@ -56,6 +62,17 @@ } } }, + "authorization": { + "acs-srv": { + "address": "access-control-srv:50051" + }, + "user": { + "address": "identity-srv:50051" + }, + "cache": { + "url": "redis://redis:6379" + } + }, "server": { "transports": [ { diff --git a/src/services/fulfillment_command_interface.ts b/src/services/fulfillment_command_interface.ts index 64287f1..177fa94 100644 --- a/src/services/fulfillment_command_interface.ts +++ b/src/services/fulfillment_command_interface.ts @@ -1,5 +1,6 @@ import { Logger } from 'winston'; import { RedisClientType as RedisClient } from 'redis'; +import { ServiceConfig } from '@restorecommerce/service-config'; import { Events } from '@restorecommerce/kafka-client'; import { Server, @@ -9,10 +10,10 @@ import { export class FulfillmentCommandInterface extends CommandInterface { constructor( server: Server, + cfg: ServiceConfig, + logger: Logger, events: Events, redisClient: RedisClient, - cfg: any, - logger: Logger, ) { super(server, cfg, logger, events, redisClient); this.logger = logger; diff --git a/src/services/fulfillment_product.ts b/src/services/fulfillment_product.ts index b1a9131..f7f4147 100644 --- a/src/services/fulfillment_product.ts +++ b/src/services/fulfillment_product.ts @@ -913,7 +913,7 @@ export class FulfillmentProductService action: AuthZAction.DELETE, operation: Operation.isAllowed, context: FulfillmentProductService.ACSContextFactory, - resource: DefaultResourceFactory('order'), + resource: DefaultResourceFactory('fulfillment_product'), database: 'arangoDB', useCache: true, }) diff --git a/src/worker.ts b/src/worker.ts index e70ae9f..6c5c88f 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -149,11 +149,14 @@ export class Worker { } } - bindHandler(serviceName: string, functionName: string) { - return (msg: any, context: any, config: any, eventName: string): Promise => { - return this[serviceName]?.[functionName]?.(msg, context).then( + protected bindHandler(serviceName: string, functionName: string) { + this.logger.debug(`Bind event to handler: ${serviceName}.${functionName}`); + return (msg: any, context: any, config: any, eventName: string): Promise => { + return (this as any)[serviceName]?.[functionName]?.(msg, context).then( () => this.logger.info(`Event ${eventName} handled.`), (err: any) => this.logger.error(`Error while handling event ${eventName}: ${err}`), + ) ?? this.logger.warn( + `Event ${eventName} was not bound to handler: ${serviceName}.${functionName} does not exist!.` ); }; } @@ -204,9 +207,10 @@ export class Worker { logger.verbose('Setting up command interface services'); this.fulfillmentCommandInterface = new FulfillmentCommandInterface( this.server, + cfg, + logger, this.events, this.redisClient, - cfg, logger, ); logger.verbose('Setting up fulfillment courier services'); this.fulfillmentCourierService = new FulfillmentCourierService( @@ -252,9 +256,9 @@ export class Worker { // Add reflection service const reflectionServiceName = serviceNamesCfg.reflection; const reflectionService = buildReflectionService([ - { descriptor: FulfillmentMeta.fileDescriptor }, - { descriptor: FulfillmentCourierMeta.fileDescriptor }, - { descriptor: FulfillmentProductMeta.fileDescriptor }, + { descriptor: FulfillmentMeta.fileDescriptor as any }, + { descriptor: FulfillmentCourierMeta.fileDescriptor as any }, + { descriptor: FulfillmentProductMeta.fileDescriptor as any }, ]); await this.server.bind(reflectionServiceName, {