Skip to content

Commit de79a47

Browse files
author
Gerald Baulig
committed
fix(config): fix configs, add missing acs, fix event handler binding
1 parent 1e08edb commit de79a47

File tree

5 files changed

+107
-19
lines changed

5 files changed

+107
-19
lines changed

cfg/config.json

+66
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
}
3737
},
3838
"client": {
39+
"acs-srv": {
40+
"address": "localhost:50061"
41+
},
42+
"user": {
43+
"address": "localhost:50051"
44+
},
3945
"customer": {
4046
"address": "localhost:50063"
4147
},
@@ -183,6 +189,15 @@
183189
"setApiKeyCommand": {
184190
"messageObject": "io.restorecommerce.commandinterface.CommandRequest"
185191
},
192+
"setApiKeyResponse": {
193+
"messageObject": "io.restorecommerce.commandinterface.CommandResponse"
194+
},
195+
"flushCacheCommand": {
196+
"messageObject": "io.restorecommerce.commandinterface.CommandRequest"
197+
},
198+
"flushCacheResponse": {
199+
"messageObject": "io.restorecommerce.commandinterface.CommandResponse"
200+
},
186201
"topics": {
187202
"command": {
188203
"topic": "io.restorecommerce.command",
@@ -244,6 +259,57 @@
244259
"productName": "urn:restorecommerce:fulfillment:product:attribute:dhl:productName",
245260
"accountNumber": "urn:restorecommerce:fulfillment:product:attribute:dhl:accountNumber"
246261
},
262+
"authorization": {
263+
"service": "acs-srv",
264+
"enabled": true,
265+
"enforce": true,
266+
"database": "arangoDB",
267+
"client": {
268+
"acs-srv": {
269+
"address": "localhost:50061"
270+
},
271+
"user": {
272+
"address": "localhost:50051"
273+
}
274+
},
275+
"urns": {
276+
"entity": "urn:restorecommerce:acs:names:model:entity",
277+
"user": "urn:restorecommerce:acs:model:user.User",
278+
"model": "urn:restorecommerce:acs:model",
279+
"role": "urn:restorecommerce:acs:names:role",
280+
"roleScopingEntity": "urn:restorecommerce:acs:names:roleScopingEntity",
281+
"roleScopingInstance": "urn:restorecommerce:acs:names:roleScopingInstance",
282+
"unauthenticated_user": "urn:restorecommerce:acs:names:unauthenticated-user",
283+
"property": "urn:restorecommerce:acs:names:model:property",
284+
"ownerIndicatoryEntity": "urn:restorecommerce:acs:names:ownerIndicatoryEntity",
285+
"ownerInstance": "urn:restorecommerce:acs:names:ownerInstance",
286+
"orgScope": "urn:restorecommerce:acs:model:organization.Organization",
287+
"subjectID": "urn:oasis:names:tc:xacml:1.0:subject:subject-id",
288+
"resourceID": "urn:oasis:names:tc:xacml:1.0:resource:resource-id",
289+
"actionID": "urn:oasis:names:tc:xacml:1.0:action:action-id",
290+
"action": "urn:restorecommerce:acs:names:action",
291+
"operation": "urn:restorecommerce:acs:names:operation",
292+
"execute": "urn:restorecommerce:acs:names:action:execute",
293+
"permitOverrides": "urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides",
294+
"denyOverrides": "urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-overrides",
295+
"create": "urn:restorecommerce:acs:names:action:create",
296+
"read": "urn:restorecommerce:acs:names:action:read",
297+
"modify": "urn:restorecommerce:acs:names:action:modify",
298+
"delete": "urn:restorecommerce:acs:names:action:delete",
299+
"organization": "urn:restorecommerce:acs:model:organization.Organization",
300+
"aclIndicatoryEntity": "urn:restorecommerce:acs:names:aclIndicatoryEntity",
301+
"aclInstance": "urn:restorecommerce:acs:names:aclInstance",
302+
"skipACL": "urn:restorecommerce:acs:names:skipACL",
303+
"maskedProperty": "urn:restorecommerce:acs:names:obligation:maskedProperty"
304+
},
305+
"cache": {
306+
"host": "localhost",
307+
"port": 6379,
308+
"db-index": 5,
309+
"ttl": 3600,
310+
"prefix": "acs:"
311+
}
312+
},
247313
"server": {
248314
"transports": [
249315
{

cfg/config_production.json

+26-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"logger": {
33
"elasticsearch": {
4-
"level": "crit",
4+
"level": "info",
55
"clientOpts": {
66
"node": "http://elasticsearch:9200"
77
},
@@ -22,29 +22,35 @@
2222
}
2323
},
2424
"client": {
25+
"acs-srv": {
26+
"address": "access-control-srv:50051"
27+
},
28+
"user": {
29+
"address": "identity-srv:50051"
30+
},
2531
"customer": {
26-
"address": "localhost:50051"
32+
"address": "resource-srv:50051"
2733
},
2834
"shop": {
29-
"address": "localhost:50051"
35+
"address": "resource-srv:50051"
3036
},
3137
"organization": {
32-
"address": "localhost:50051"
38+
"address": "resource-srv:50051"
3339
},
3440
"contact_point": {
35-
"address": "localhost:50051"
41+
"address": "resource-srv:50051"
3642
},
3743
"address": {
38-
"address": "localhost:50051"
44+
"address": "resource-srv:50051"
3945
},
4046
"country": {
41-
"address": "localhost:50051"
47+
"address": "resource-srv:50051"
4248
},
4349
"tax": {
44-
"address": "localhost:50051"
50+
"address": "resource-srv:50051"
4551
},
4652
"product": {
47-
"address": "localhost:50051"
53+
"address": "resource-srv:50051"
4854
}
4955
},
5056
"events": {
@@ -56,6 +62,17 @@
5662
}
5763
}
5864
},
65+
"authorization": {
66+
"acs-srv": {
67+
"address": "access-control-srv:50051"
68+
},
69+
"user": {
70+
"address": "identity-srv:50051"
71+
},
72+
"cache": {
73+
"url": "redis://redis:6379"
74+
}
75+
},
5976
"server": {
6077
"transports": [
6178
{

src/services/fulfillment_command_interface.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Logger } from 'winston';
22
import { RedisClientType as RedisClient } from 'redis';
3+
import { ServiceConfig } from '@restorecommerce/service-config';
34
import { Events } from '@restorecommerce/kafka-client';
45
import {
56
Server,
@@ -9,10 +10,10 @@ import {
910
export class FulfillmentCommandInterface extends CommandInterface {
1011
constructor(
1112
server: Server,
13+
cfg: ServiceConfig,
14+
logger: Logger,
1215
events: Events,
1316
redisClient: RedisClient,
14-
cfg: any,
15-
logger: Logger,
1617
) {
1718
super(server, cfg, logger, events, redisClient);
1819
this.logger = logger;

src/services/fulfillment_product.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ export class FulfillmentProductService
913913
action: AuthZAction.DELETE,
914914
operation: Operation.isAllowed,
915915
context: FulfillmentProductService.ACSContextFactory,
916-
resource: DefaultResourceFactory('order'),
916+
resource: DefaultResourceFactory('fulfillment_product'),
917917
database: 'arangoDB',
918918
useCache: true,
919919
})

src/worker.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,14 @@ export class Worker {
149149
}
150150
}
151151

152-
bindHandler(serviceName: string, functionName: string) {
153-
return (msg: any, context: any, config: any, eventName: string): Promise<any> => {
154-
return this[serviceName]?.[functionName]?.(msg, context).then(
152+
protected bindHandler(serviceName: string, functionName: string) {
153+
this.logger.debug(`Bind event to handler: ${serviceName}.${functionName}`);
154+
return (msg: any, context: any, config: any, eventName: string): Promise<any> => {
155+
return (this as any)[serviceName]?.[functionName]?.(msg, context).then(
155156
() => this.logger.info(`Event ${eventName} handled.`),
156157
(err: any) => this.logger.error(`Error while handling event ${eventName}: ${err}`),
158+
) ?? this.logger.warn(
159+
`Event ${eventName} was not bound to handler: ${serviceName}.${functionName} does not exist!.`
157160
);
158161
};
159162
}
@@ -204,9 +207,10 @@ export class Worker {
204207
logger.verbose('Setting up command interface services');
205208
this.fulfillmentCommandInterface = new FulfillmentCommandInterface(
206209
this.server,
210+
cfg,
211+
logger,
207212
this.events,
208213
this.redisClient,
209-
cfg, logger,
210214
);
211215
logger.verbose('Setting up fulfillment courier services');
212216
this.fulfillmentCourierService = new FulfillmentCourierService(
@@ -252,9 +256,9 @@ export class Worker {
252256
// Add reflection service
253257
const reflectionServiceName = serviceNamesCfg.reflection;
254258
const reflectionService = buildReflectionService([
255-
{ descriptor: FulfillmentMeta.fileDescriptor },
256-
{ descriptor: FulfillmentCourierMeta.fileDescriptor },
257-
{ descriptor: FulfillmentProductMeta.fileDescriptor },
259+
{ descriptor: FulfillmentMeta.fileDescriptor as any },
260+
{ descriptor: FulfillmentCourierMeta.fileDescriptor as any },
261+
{ descriptor: FulfillmentProductMeta.fileDescriptor as any },
258262
]);
259263

260264
await this.server.bind(reflectionServiceName, {

0 commit comments

Comments
 (0)