Skip to content

Commit

Permalink
fix(config): fix configs, add missing acs, fix event handler binding
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerald Baulig committed Apr 12, 2024
1 parent 1e08edb commit de79a47
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 19 deletions.
66 changes: 66 additions & 0 deletions cfg/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
}
},
"client": {
"acs-srv": {
"address": "localhost:50061"
},
"user": {
"address": "localhost:50051"
},
"customer": {
"address": "localhost:50063"
},
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": [
{
Expand Down
35 changes: 26 additions & 9 deletions cfg/config_production.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"logger": {
"elasticsearch": {
"level": "crit",
"level": "info",
"clientOpts": {
"node": "http://elasticsearch:9200"
},
Expand All @@ -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": {
Expand All @@ -56,6 +62,17 @@
}
}
},
"authorization": {
"acs-srv": {
"address": "access-control-srv:50051"
},
"user": {
"address": "identity-srv:50051"
},
"cache": {
"url": "redis://redis:6379"
}
},
"server": {
"transports": [
{
Expand Down
5 changes: 3 additions & 2 deletions src/services/fulfillment_command_interface.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/services/fulfillment_product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
18 changes: 11 additions & 7 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,14 @@ export class Worker {
}
}

bindHandler(serviceName: string, functionName: string) {
return (msg: any, context: any, config: any, eventName: string): Promise<any> => {
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<any> => {
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!.`
);
};
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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, {
Expand Down

0 comments on commit de79a47

Please sign in to comment.