RabbitInjector in node-module + sequences inject

This commit is contained in:
STEINNI
2025-09-22 19:51:25 +00:00
parent 5d223c776c
commit 6381bfe44a
26 changed files with 2138 additions and 1 deletions
@@ -0,0 +1,18 @@
{
"name": "Create user roles 1",
"channel":"dataSync:userRoles",
"packet":{
"sender":"backend-marklogic",
"reqid":"18dd9317-a08c-4f0a-9f4c-5a30860e02e4",
"eventType": "created",
"payload": {
"eventType": "created",
"data": {
"PROJECT_Coordinator": {"description": "Project Coordinator role on a project in the ICMP application"},
"SOE_ReadOnly": {"description": "SoE User with read-only access to the SoE Monitoring application"},
"PROJECT_PO_Backup": {"description": "Backup Project Officer (PO) role in the ICMP application"},
"BP_SPOC": {"description": "Domain Administrator (SPOC) role in the ByPass application"}
}
}
}
}
@@ -0,0 +1,17 @@
{
"channel":"dataSync:userRoles",
"packet":{
"sender":"backend-marklogic",
"reqid":"18dd9317-a08c-4f0a-9f4c-5a30860e02e4",
"eventType": "created",
"payload": {
"eventType": "created",
"data": {
"ML_Role1": { "description": "Hello world 2", "tintin":"toto2", "types": {"description":"string"} },
"PROJECT_Coordinator": {"description": "Project Coordinator role on a project in the ICMP application"},
"SOE_ReadOnly": {"description": "SoE User with read-only access to the SoE Monitoring application"},
"PROJECT_PO_Backup": {"description": "Backup Project Officer (PO) role in the ICMP application"}
}
}
}
}
+1
View File
@@ -0,0 +1 @@
{"channel":"infraNotifs:midas","packet":{"action":"TIME","sender":"steinic","reqid":"9d3bcb2e-ef1d-4620-86ff-5c0b0f4063f7"}}
+62
View File
@@ -0,0 +1,62 @@
{
"sequenceDelay": 500,
"sequenceLoop":10,
"sequence":[
{
"channel":"gps:agents",
"packet":{
"eventType": "moving",
"payload": {
"aid": "agent42",
"attrs": {
"x": "10",
"y": "10"
}
},
"sender": "steinic"
}
},
{
"channel":"gps:agents",
"packet":{
"eventType": "moving",
"payload": {
"aid": "agent42",
"attrs": {
"x": "800",
"y": "30"
}
},
"sender": "steinic"
}
},
{
"channel":"gps:agents",
"packet":{
"eventType": "moving",
"payload": {
"aid": "agent42",
"attrs": {
"x": "800",
"y": "500"
}
},
"sender": "steinic"
}
},
{
"channel":"gps:agents",
"packet":{
"eventType": "moving",
"payload": {
"aid": "agent42",
"attrs": {
"x": "10",
"y": "500"
}
},
"sender": "steinic"
}
}
]
}
+14
View File
@@ -0,0 +1,14 @@
{
"channel":"gps:agents",
"packet":{
"eventType": "moving",
"payload": {
"aid": "agent42",
"attrs": {
"x": "950",
"y": "650"
}
},
"sender": "steinic"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"channel":"services:notifications",
"packet":{
"sender":"backend-marklogic",
"reqid":"18dd9317-a08c-4f0a-9f4c-5a30860e02e4",
"payload":"{\"action\" : \"notify\",\"data\":{\"date\": \"2024-09-24T09:07:01.5528092+02:00\",\"uuid\": \"notification-K2FG--jvRWykweigEW01pQ\",\"templateId\": \"eff1e2eb-2e53-4ffe-b6d8-673906cb630b\",\"templateName\": \"TechDD - Expert access V1\",\"recipients\": [{\"email\": \"cadence.avila@mail.com\",\"recipientType\": \"TO\",\"euLoginId\": \"n003hxwb\",\"requestType\": \"testAvirer\",\"requestUuid\": \"12346578-242a-4d23-a418-9df966c7ea0b\",\"notificationType\": [ \"email\" ],\"tokens\": {\"expertLastName\": \"Avila\",\"proposalAcronym\": \"Nexdiag\",\"expertFirstName\": \"Cadence\",\"proposalId\": \"190186747\",\"expertFullName\": \"Cadence Avila\",\"reportURL\": \"/projects/190186747/techdd/dQEUCXptVQmidRV2zSerialNumber3UzvsQ\",\"proposalType\": \"Blended\"}},{\"email\": \"nico.labicoque@mail.com\",\"euLoginId\": \"steinic\",\"recipientType\": \"TO\",\"notificationType\": [ \"email\",\"sparcNotif\" ],\"tokens\": {\"expertFirstName\": \"Nico\",\"expertLastName\": \"Labicoque\",\"proposalAcronym\": \"JWST2\",\"proposalId\": \"190186748\",\"expertFullName\": \"Nico Labicoque\",\"reportURL\": \"/projects/190186748/techdd/dQEUCXptVQmxxxV2z3UzvsQ\",\"proposalType\": \"Blended\"}}]}}"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"channel":"services:notifications",
"packet":{
"sender":"steinic",
"reqid":"18dd9317-a08c-4f0a-9f4c-5a30860e02e4",
"payload":"{\"action\": \"notify\",\"data\": {\"date\": \"2024-09-24T09:07:01.5528092+02:00\",\"uuid\": \"notification-K2FG--jvRWykweigEW01pQ\",\"templateId\": \"1c5c78a3-40c4-468c-acc9-46e92f6a881a\",\"templateName\": \"test template 1\",\"recipients\": [{\"email\": \"franck.leple@amexiogroup.com\",\"recipientType\": \"TO\",\"euLoginId\": \"leplef\",\"notificationType\": [\"email\"],\"tokens\": {\"userName\": \"Franck\"}},{\"email\": \"nicolas.stein@internike.com\",\"euLoginId\": \"steinic\",\"recipientType\": \"TO\",\"notificationType\": [\"email\",\"sparcNotif\"],\"tokens\": {\"userName\": \"Nico\"}},{\"email\": \"niketufjo@gmail.com\",\"euLoginId\": \"steinic\",\"recipientType\": \"TO\",\"notificationType\": [\"email\",\"sparcNotif\"],\"tokens\": {\"userName\": \"Nike\"}}]}}"
}
}
+9
View File
@@ -0,0 +1,9 @@
{
"channel":"services:notifications",
"packet":{
"sender":"steinic",
"reqid":"18dd9317-a08c-4f0a-9f4c-5a30860e02e4",
"payload":
{"action": "notify","data": {"date": "2024-09-24T09:07:01.5528092+02:00","uuid": "notification-K2FG--jvRWykweigEW01pQ","templateId": "1cf69669-4d23-4382-a2ac-f843e75500c6","templateName": "TechDD - report consultation V1","recipients": [{"email": "franck.leple@amexiogroup.com","recipientType": "TO","euLoginId": "leplef","notificationType": ["email"],"tokens": {"proposalAcronym": "Nexdiag1","proposalId": "190181111","FIOFullName": "Franck LEPLE","FIOLastName": "Leple","FIOFirstName": "Franck","reportURL": "/projects/190181111/techdd/dQEUCXptVQmidRV2z3UzvsQ","proposalType": "Blended"}},{"email": "nicolas.stein@internike.com","euLoginId": "steinic","recipientType": "TO","notificationType": ["email","sparcNotif"],"tokens": {"proposalAcronym": "Nexdiag2","proposalId": "190182222","FIOFullName": "Nicolas STEIN","FIOLastName": "STEIN","FIOFirstName": "Nicolas","reportURL": "/projects/190182222/techdd/dQEUCXptVQmidRV2z3UzvsQ","proposalType": "Blended"}},{"email": "niketufjo@gmail.com","euLoginId": "steinic","recipientType": "TO","notificationType": ["email","sparcNotif"],"tokens": {"proposalAcronym": "Nexdiag3","proposalId": "190183333","FIOFullName": "Nike TUFJO","FIOLastName": "TUFJO","FIOFirstName": "Nike","reportURL": "/projects/190183333/techdd/dQEUCXptVQmidRV2z3UzvsQ","proposalType": "Blended"}}]}}
}
}
+9
View File
@@ -0,0 +1,9 @@
{
"channel":"services:notifications",
"packet":{
"sender":"backend-marklogic",
"reqid":"18dd9317-a08c-4f0a-9f4c-5a30860e02e4",
"payload":
{"action": "notify","data": {"date": "2024-09-24T09:07:01.5528092+02:00","uuid": "notification-K2FG--jvRWykweigEW01pQ","templateId": "1cf69669-4d23-4382-a2ac-f843e75500c6","templateName": "TechDD - report consultation V1","recipients": [{"requestType":"testAvirer","requestUuid": "12346578-242a-4d23-a418-9df966c7ea0b","email": "franck.leple@amexiogroup.com","recipientType": "TO","euLoginId": "leplef","notificationType": ["email"],"tokens": {"proposalAcronym": "Nexdiag1","proposalId": "190181111","FIOFullName": "Franck LEPLE","FIOLastName": "Leple","FIOFirstName": "Franck","reportURL": "/projects/190181111/techdd/dQEUCXptVQmidRV2z3UzvsQ","proposalType": "Blended"}},{"requestType": "testAvirer","requestUuid": "87654321-242a-4d23-a418-9df966c7ea0b", "email": "nicolas.stein@internike.com","euLoginId": "steinic","recipientType": "TO","notificationType": ["email","sparcNotif"],"tokens": {"proposalAcronym": "Nexdiag2","proposalId": "190182222","FIOFullName": "Nicolas STEIN","FIOLastName": "STEIN","FIOFirstName": "Nicolas","reportURL": "/projects/190182222/techdd/dQEUCXptVQmidRV2z3UzvsQ","proposalType": "Blended"}},{"email": "niketufjo@gmail.com","euLoginId": "steinic","recipientType": "TO","notificationType": ["email","sparcNotif"],"tokens": {"proposalAcronym": "Nexdiag3","proposalId": "190183333","FIOFullName": "Nike TUFJO","FIOLastName": "TUFJO","FIOFirstName": "Nike","reportURL": "/projects/190183333/techdd/dQEUCXptVQmidRV2z3UzvsQ","proposalType": "Blended"}}]}}
}
}
+202
View File
@@ -0,0 +1,202 @@
[
{
"channel":"services:pdfs",
"packet":{
"sender":"backend-smed",
"reqid":"048e081f-935f-4089-adf0-6fac6f652fd6",
"payload":{
"action": "makepdf",
"data": {
"uuid":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"templateId":"e0652993-a837-4749-9a58-40aaa22c9d3f",
"tokens": {
"expertFullName":"NIKE PIPERZEEL",
"proposalType": "wonderful",
"proposalAcronym": "MIDAS en folie",
"proposalId":"642"
}
}
}
}
},
{
"channel":"services:pdfs",
"packet":{
"sender":"backend-smed",
"reqid":"048e081f-935f-4089-adf0-6fac6f652fd6",
"payload":{
"action": "makepdf",
"data": {
"uuid":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"templateId":"e0652993-a837-4749-9a58-40aaa22c9d3f",
"tokens": {
"expertFullName":"NIKE PIPERZEEL",
"proposalType": "wonderful",
"proposalAcronym": "MIDAS en folie",
"proposalId":"642"
}
}
}
}
},
{
"channel":"services:pdfs",
"packet":{
"sender":"backend-smed",
"reqid":"048e081f-935f-4089-adf0-6fac6f652fd6",
"payload":{
"action": "makepdf",
"data": {
"uuid":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"templateId":"e0652993-a837-4749-9a58-40aaa22c9d3f",
"tokens": {
"expertFullName":"NIKE PIPERZEEL",
"proposalType": "wonderful",
"proposalAcronym": "MIDAS en folie",
"proposalId":"642"
}
}
}
}
},
{
"channel":"services:pdfs",
"packet":{
"sender":"backend-smed",
"reqid":"048e081f-935f-4089-adf0-6fac6f652fd6",
"payload":{
"action": "makepdf",
"data": {
"uuid":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"templateId":"e0652993-a837-4749-9a58-40aaa22c9d3f",
"tokens": {
"expertFullName":"NIKE PIPERZEEL",
"proposalType": "wonderful",
"proposalAcronym": "MIDAS en folie",
"proposalId":"642"
}
}
}
}
},
{
"channel":"services:pdfs",
"packet":{
"sender":"backend-smed",
"reqid":"048e081f-935f-4089-adf0-6fac6f652fd6",
"payload":{
"action": "makepdf",
"data": {
"uuid":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"templateId":"e0652993-a837-4749-9a58-40aaa22c9d3f",
"tokens": {
"expertFullName":"NIKE PIPERZEEL",
"proposalType": "wonderful",
"proposalAcronym": "MIDAS en folie",
"proposalId":"642"
}
}
}
}
},
{
"channel":"services:pdfs",
"packet":{
"sender":"backend-smed",
"reqid":"048e081f-935f-4089-adf0-6fac6f652fd6",
"payload":{
"action": "makepdf",
"data": {
"uuid":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"templateId":"e0652993-a837-4749-9a58-40aaa22c9d3f",
"tokens": {
"expertFullName":"NIKE PIPERZEEL",
"proposalType": "wonderful",
"proposalAcronym": "MIDAS en folie",
"proposalId":"642"
}
}
}
}
},
{
"channel":"services:pdfs",
"packet":{
"sender":"backend-smed",
"reqid":"048e081f-935f-4089-adf0-6fac6f652fd6",
"payload":{
"action": "makepdf",
"data": {
"uuid":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"templateId":"e0652993-a837-4749-9a58-40aaa22c9d3f",
"tokens": {
"expertFullName":"NIKE PIPERZEEL",
"proposalType": "wonderful",
"proposalAcronym": "MIDAS en folie",
"proposalId":"642"
}
}
}
}
},
{
"channel":"services:pdfs",
"packet":{
"sender":"backend-smed",
"reqid":"048e081f-935f-4089-adf0-6fac6f652fd6",
"payload":{
"action": "makepdf",
"data": {
"uuid":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"templateId":"e0652993-a837-4749-9a58-40aaa22c9d3f",
"tokens": {
"expertFullName":"NIKE PIPERZEEL",
"proposalType": "wonderful",
"proposalAcronym": "MIDAS en folie",
"proposalId":"642"
}
}
}
}
},
{
"channel":"services:pdfs",
"packet":{
"sender":"backend-smed",
"reqid":"048e081f-935f-4089-adf0-6fac6f652fd6",
"payload":{
"action": "makepdf",
"data": {
"uuid":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"templateId":"e0652993-a837-4749-9a58-40aaa22c9d3f",
"tokens": {
"expertFullName":"NIKE PIPERZEEL",
"proposalType": "wonderful",
"proposalAcronym": "MIDAS en folie",
"proposalId":"642"
}
}
}
}
},
{
"channel":"services:pdfs",
"packet":{
"sender":"backend-smed",
"reqid":"048e081f-935f-4089-adf0-6fac6f652fd6",
"payload":{
"action": "makepdf",
"data": {
"uuid":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"templateId":"e0652993-a837-4749-9a58-40aaa22c9d3f",
"tokens": {
"expertFullName":"NIKE PIPERZEEL",
"proposalType": "wonderful",
"proposalAcronym": "MIDAS en folie",
"proposalId":"642"
}
}
}
}
}
]
+20
View File
@@ -0,0 +1,20 @@
{
"channel":"services:pdfs",
"packet":{
"sender":"backend-smed",
"reqid":"048e081f-935f-4089-adf0-6fac6f652fd6",
"payload":{
"action": "makepdf",
"data": {
"uuid":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"templateId":"e0652993-a837-4749-9a58-40aaa22c9d3f",
"tokens": {
"expertFullName":"NIKE PIPERZEEL",
"proposalType": "wonderful",
"proposalAcronym": "MIDAS en folie",
"proposalId":"642"
}
}
}
}
}
+22
View File
@@ -0,0 +1,22 @@
{
"channel":"services:pdfs",
"packet":{
"sender":"backend-smed",
"reqid":"048e081f-935f-4089-adf0-6fac6f652fd6",
"payload":{
"action": "makepdf",
"data": {
"uuid":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"templateId":"e0652993-a837-4749-9a58-40aaa22c9d3f",
"tokens": {
"expertFullName":"NIKE PIPERZEEL",
"proposalType": "wonderful",
"proposalId":"642"
} ,
"base64Tokens": {
"proposalAcronym": "PHNwYW4gc3R5bGU9ImNvbG9yOiMwMEY7Zm9udC1zaXplOjJlbTsiIGF0dHJpYj0idmFsdWUiPk1JREFTIDxiPmVuIGZvbGllPC9iPjwvc3Bhbj4="
}
}
}
}
}
+224
View File
@@ -0,0 +1,224 @@
const redis = require('redis')
const sha256 = require('sha256')
const midasActions = require('../actions')
const AccesRights = require('../accesRights')
const crypto = require('crypto')
module.exports = class RedisConnexion {
constructor(options) {
Object.assign(this,midasActions.methods)
this.config = options.config
this.debug = options.debug
this.cfgh = options.cfgh
this.midasSubscriptions = []
this.accessRights = new AccesRights(this.config, options.debug)
this.AWScodeCommitRole = 'arn:aws:iam::959160311435:role/EIC-CodeCommitReader'
// Plugins related
this.plugins = {}
this.gitRepoName = 'myeic-midas-service'
this.gitRepoPath = `/tmp/${this.gitRepoName}`
this.repoPluginsPath = `${this.gitRepoPath}/plugins`
this.newPluginsPath = __dirname+'/newPlugins'
this.currentPluginsPath = __dirname+'/plugins'
this.pluginsReloadLock = false
this.redisClient = redis.createClient({
socket: {
tls: this.config.redis.tls,
host: this.config.redis.host,
port: this.config.redis.port
},
scripts:{
// Atomically deletes key only if correct value provided.
// Used by mutex as per https://redis.io/commands/set/#patterns
delKeyVal: redis.defineScript({
NUMBER_OF_KEYS: 1,
SCRIPT:`
if redis.call("get",KEYS[1]) == ARGV[1]
then
return redis.call("del",KEYS[1])
else
return 0
end
`,
transformArguments(key, toAdd) {
return [key, toAdd.toString()];
},
transformReply(reply) {
return reply;
}
})
}
});
this.redisSubscriber = null;
this.redisClient.on('error', (err) => {
console.error('Redis error: ', err);
});
if(this.debug) console.log('Redis started...')
}
async redisLogin(){
if(this.debug) console.log(`Connecting to Redis (${this.config.redis.host}:${this.config.redis.port}, tls:${this.config.redis.tls?'yes':'no'})...`);
await this.redisClient.connect();
if(this.debug) console.log('Connected to Redis !');
if(this.config.redis.user) {
await this.redisClient.sendCommand(['AUTH', this.config.redis.user, this.config.redis.pass]);
if(this.debug) console.log('Logged into Redis !');
} else {
if(this.debug) console.log('Connected (anon) to Redis...');
}
if(this.debug) {
var redisTime = await this.redisClient.time()
console.log('Redis time:', redisTime)
}
}
async redisChansStart(){ // Second subscriber connexion
this.redisSubscriber = this.redisClient.duplicate();
await this.redisSubscriber.connect();
if(this.config.redis.user) {
await this.redisSubscriber.sendCommand(['AUTH', this.config.redis.user, this.config.redis.pass]);
}
// Gather my chans of interest
this.refreshPluginsChans()
if(this.debug) console.log('PSubscription OK ', this.config.redis.basePrefix + '*');
}
async redisSubscribe(chanName, callBack){
if(!chanName.startsWith(this.config.redis.basePrefix)) chanName = this.config.redis.basePrefix + chanName
await this.redisSubscriber.subscribe(chanName, callBack);
}
async redisPublish(chanName, msg){
if(typeof (msg) != 'string') msg = JSON.stringify(msg);
if(!chanName.startsWith(this.config.redis.basePrefix)) chanName = this.config.redis.basePrefix + chanName
await this.redisClient.publish(chanName, msg);
}
async redisSet(k, v, exp = 0, customPrefix=null){
if(typeof(v) != 'string') v = JSON.stringify(v);
if(customPrefix!==null) k = customPrefix + k
else if(!k.startsWith(this.config.redis.basePrefix)) k = this.config.redis.basePrefix + k
if(this.debug) console.log('Redis SET ', k)
try { await this.redisClient.set(k, v) }
catch(err) { console.error('Redis crash doing Redis set: ', k, v) }
if(exp > 0) {
try { await this.redisClient.expire(k, exp) }
catch(err) { console.error('Redis crash doing Redis expire: ', k, exp) }
}
}
async redisGet(k, customPrefix=null){
if(customPrefix!==null) k = customPrefix + k
else if(!k.startsWith(this.config.redis.basePrefix)) k = this.config.redis.basePrefix + k
if(this.debug) console.log('Redis GET ', k)
let v=null
try { v = await this.redisClient.get(k) }
catch(err) { console.error('Redis crash doing Redis get: ', k) }
return(v);
}
async redisDel(k, customPrefix=null){
if(customPrefix!==null) k = customPrefix + k
else if(!k.startsWith(this.config.redis.basePrefix)) k = this.config.redis.basePrefix + k
if(this.debug) console.log('Deleting ', k);
await this.redisClient.del(k);
}
async redisGetTtl(k, customPrefix=null){
if(customPrefix!==null) k = customPrefix + k
else if(!k.startsWith(this.config.redis.basePrefix)) k = this.config.redis.basePrefix + k
if(this.debug) console.log('Redis Get TTL ', k)
let v=null
try { v = await this.redisClient.ttl(k) }
catch(err) { console.error('Redis crash doing Redis ttl: ', k) }
return(v);
}
async redisSetTtl(k, ttl, customPrefix=null){
if(customPrefix!==null) k = customPrefix + k
else if(!k.startsWith(this.config.redis.basePrefix)) k = this.config.redis.basePrefix + k
if(this.debug) console.log('Redis Set TTL ', k);
try { await this.redisClient.expire(k, ttl) }
catch(err) { console.error('Redis crash doing Redis expire: ', k, ttl) }
}
async redisXadd(streamName, kvObj, max = ''){
if(!streamName.startsWith(this.config.redis.basePrefix)) streamName = this.config.redis.basePrefix + streamName
if(this.debug) console.log('Redis XADD ', streamName, kvObj);
let arr = ['XADD', streamName]
if(max != '') arr = [...arr, ...['MAXLEN', '~', (1*max).toString()]]
arr.push('*')
let payload = '""'
try{ payload = JSON.stringify(kvObj) }
catch(e) { console.warn('cannot historize bad json: ',kvObj) }
arr.push('streamData')
arr.push(payload)
let sid = null
try { sid = await this.redisClient.sendCommand(arr); }
catch(err) { console.error('Redis crash doing Redis command: ', arr, err) }
return(sid);
}
async redisXrange(streamName, start = '-', end = '+'){
if(!streamName.startsWith(this.config.redis.basePrefix)) streamName = this.config.redis.basePrefix + streamName
if(this.debug) console.log('Redis XRANGE ', streamName);
if(typeof(start)!='string') start = start.toString()
if(typeof(end)!='string') end = end.toString()
let arr = ['XRANGE', streamName, start, end];
let res = []
try { res = await this.redisClient.sendCommand(arr) }
catch(err) { console.error('Redis crash doing Redis command: ', arr, err.msg) }
let o = {};
for (let row of res) { // We'll take only the first content of the stream (the value of the key 'streamdata')
let payload = ''
try{ payload = JSON.parse(row[1][1]) }
catch(e) { console.warn('cannot unhistorize bad json: ',row[1][1]) }
o[row[0]] = payload
}
return(o);
}
isHistorizedChan(chan){
if(!chan.startsWith(this.config.redis.basePrefix)) chan = this.config.redis.basePrefix + chan
var matches = this.config.historize.historizeChannels.filter((e) => {
if(!e.startsWith(this.config.redis.basePrefix)) e = this.config.redis.basePrefix + e
if(e.indexOf('*') > -1) {
let r = new RegExp('^'+e.replace(/\*/g,'(.+)')+'$','g')
return(chan.match(r) != null);
} else return(chan == e);
});
return(matches.length > 0);
}
async getUserRoles(uid){
let roles = []
//TODO : Maybe do better...? (check in DB ?)
if(uid.startsWith('backend-')){
roles = [uid.substr(8)]
} else {
let rawPayload = await this.redisGet(uid, this.config.redis.authTokenPrefix)
let payload = JSON.parse(rawPayload)
if(payload && payload.roles) roles = payload.roles
}
if(this.debug) console.log(`Got roles for ${uid} => ${roles}`)
return(roles)
}
}
/**
* TODOs:
* - Subscribe only to chans of interest (action chan + each plugin chan), not all-then-filter, we're not a gaeway !
*
*/
+255
View File
@@ -0,0 +1,255 @@
import yargs from 'yargs/yargs'
import { hideBin } from 'yargs/helpers'
import fs from 'fs'
import {RedisConnexion} from '../redisConnexion.js'
import riConfig from './riConfig.json' with { type: 'json' }
import pkg from 'enquirer';
const { prompt } = pkg;
const dialogData = {
'step1' : {
'question': {
'type': 'input',
'name': 'uid',
'message': 'Sender uid ? (Back-ends: backend-marklogic / backend-smed )'
},
'nextStep': 'step2'
},
'step2' : {
'question': {
'type': 'autocomplete',
'name': 'channel',
'message': 'Channel ?',
'limit': 10,
'initial': 2,
'choices': [
'[NEW]',
'dataSync:userRoles',
'system:notifs',
'infraNotifs:httpGateway',
'infraNotifs:midas',
'services:notifications',
'services:pdfs',
]
},
'nextStep': 'step3'
},
'step3': {
'question': {
'type': 'select',
'name': 'type',
'message': 'Type of message ?',
'choices': [
{ 'message': 'Event', 'value': 'event' },
{ 'message': 'Action', 'value': 'action' },
{ 'message': 'Other', 'value': 'other' },
]
},
'nextStep': 'step4-{{type}}'
},
'step4-event': {
'question': {
'type': 'select',
'name': 'eventType',
'message': 'Type of event ?',
'choices': null,
},
'nextStep': 'step5'
},
'step4-action': {
'question': {
'type': 'select',
'name': 'action',
'message': 'Type of action ?',
'choices': null
},
'nextStep': 'step5'
},
'step4-other': {
'question': {
'type': 'input',
'name': 'payload',
'message': 'Payload (json)'
},
'nextStep': 'step6'
},
'step5': {
'question': {
'type': 'input',
'name': 'payload',
'message': 'Payload (json), [enter for none]'
},
'nextStep': 'step6'
},
'step6': {
'question': {
'type': 'select',
'name': 'confirm',
'message': 'Confirm what you want:',
'initial': 'send',
'choices': [
{ 'message': 'Send on the bus', 'value': 'send' },
{ 'message': 'Save to file', 'value': 'save' },
{ 'message': 'Cancel', 'value': 'cancel' },
]
},
'nextStep': null
},
}
const selectors = {
'chan2eventTypes': {
'dataSync:userRoles': ['updated'],
'system:notifs': ['growl'],
},
'chan2actions': {
'infraNotifs:httpGateway': ['TIME', 'RELOADACCESSRIGHTS', 'GETACCESSRIGHTS'],
'infraNotifs:midas': ['TIME', 'LISTPLUGINS', 'RELOADPLUGINS'],
'services:notifications': [ 'notify' ],
}
}
class Dialog {
constructor(dialogData, selectors){
this.dialogData = dialogData
this.selectors = selectors
this.curStep = null
this.answers = {}
}
async start(step){
this.curStep = step
while(this.curStep && this.dialogData[this.curStep]){
let latestAnswer = await(this.askStep(this.curStep))
if(latestAnswer[this.dialogData[this.curStep].question.name]=='[NEW]'){
latestAnswer = await prompt({
'type': 'input',
'name': this.dialogData[this.curStep].question.name,
'message': `(enter your new/custom value) ${this.dialogData[this.curStep].question.message}`,
})
}
this.curStep = this.dialogData[this.curStep].nextStep
Object.assign(this.answers, latestAnswer)
if(this.curStep){
this.curStep = this.curStep.replace(/{{(\w+)}}/, (_, token) => (this.answers[token] || '' ) )
}
}
if(this.curStep) console.warn(`Stopped because cannot find step "${this.curStep}" !`)
return(this.answers)
}
async askStep(step){
// Fills empty selectors
let question = this.dialogData[step].question
if((question.type=='select') && (question.choices===null)){
switch(question.name){
case 'eventType':
question.choices = this.selectors.chan2eventTypes.hasOwnProperty(this.answers.channel)
? ['[NEW]', ...this.selectors.chan2eventTypes[this.answers.channel]]
: question.choices = ['[NEW]']
break
case 'action':
question.choices = this.selectors.chan2actions.hasOwnProperty(this.answers.channel)
? ['[NEW]', ...this.selectors.chan2actions[this.answers.channel]]
: question.choices = ['[NEW]']
break
default: question.choices = ['[NEW]']
}
}
return(await prompt(this.dialogData[step].question))
}
}
async function startRedis(midasConfig) {
let REDIScnx = new RedisConnexion({
debug: true,
config: midasConfig,
});
console.log('Starting REDIS...');
await REDIScnx.redisLogin();
console.log('REDIS Login OK');
return (REDIScnx);
}
async function inject(rediscnx, chan, packet){
await rediscnx.redisPublish(chan, packet)
}
async function batchInject(rediscnx, batch, delay=0){
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms))
for(let msg of batch){
if(msg.channel && msg.packet){
await rediscnx.redisPublish(msg.channel, msg.packet)
} else console.error('Bad message format, skipped !?', msg)
await sleep(delay)
}
}
const argv = yargs(hideBin(process.argv)).command('Rabbit-Injector', 'Injects messages on bus', {})
.options({
'file': {
description: 'Instead of asking question, directly inject from a .dmsg file',
alias: 'f',
type: 'string'
},
}).help().version('1.0').argv
if(argv.file){
let fileName = argv.file
if(!fileName.endsWith('.bmsg')) fileName+='.bmsg'
if(fs.existsSync(fileName)){
let fileData
try{
fileData = JSON.parse(fs.readFileSync(fileName))
} catch(err){
console.error('Bad json in file !?')
process.exit(1)
}
let rediscnx = await startRedis(riConfig)
if(Array.isArray(fileData)){
await batchInject(rediscnx, fileData)
} else {
if(Array.isArray(fileData.sequence)){
let batchIter = (parseInt(fileData.sequenceLoop)>1) ? parseInt(fileData.sequenceLoop) : 1
for(let i=0; i<batchIter; i++){
if(parseInt(fileData.sequenceDelay)>0) await batchInject(rediscnx, fileData.sequence, parseInt(fileData.sequenceDelay))
else await batchInject(rediscnx, fileData)
}
} else if(fileData.channel && fileData.packet){
await inject(rediscnx, fileData.channel, fileData.packet)
} else console.error('Bad file format !?', fileData)
}
await rediscnx.redisClient.disconnect()
}
} else {
let dialog = new Dialog(dialogData, selectors)
dialog.start('step1').then(answers => {
let packet = {}
if(answers.type != 'other') packet[answers.type] = answers[answers.type]
packet.sender = answers.uid
packet.reqid = crypto.randomUUID()
if(answers.payload) packet.payload = answers.payload
if(answers.confirm=="send"){
inject(answers.channel, packet)
} else if(answers.confirm=="save"){
prompt({'type': 'input', 'name': 'filename', 'message': 'Filename ?'}).then(answer =>{
let fileName = answer.filename
if(!fileName.endsWith('.bmsg')) fileName+='.bmsg'
fs.writeFileSync(fileName, JSON.stringify({ channel: answers.channel, packet: packet}))
})
}
})
}
+13
View File
@@ -0,0 +1,13 @@
{
"redis":{
"host": "127.0.0.1",
"tls": false,
"port": 6379,
"Xuser": "msgbus",
"Xpass": "yj465sqfCTA0bKDw3zEYg8OqYl9Tv",
"user": "",
"pass": "",
"basePrefix": "messageBus:",
"authTokenPrefix": "authorizer:message_bus_user_"
}
}
+14
View File
@@ -0,0 +1,14 @@
{
"channel":"services:evalText",
"packet":{
"sender":"backend-marklogic",
"reqid":"18dd9317-a08c-4f0a-9f4c-5a30860e02e4",
"payload":
{"action": "coverage",
"data": {
"question": "Describe how this project benefits the team.",
"answer": "This project helps streamline communication and reduce redundancy between the members.\nIt will be particularly be helpfull in nowadays tele-working context.\nTo reach that goal, we intend to blend AI directly whithin the current team's chat."
}
}
}
}
+9
View File
@@ -0,0 +1,9 @@
{
"channel":"services:evalText",
"packet":{
"sender":"backend-marklogic",
"reqid":"18dd9317-a08c-4f0a-9f4c-5a30860e02e4",
"payload":
{"action": "moderate","data": {"text": "This fucker should tell you it is bad content for pussies !"}}
}
}
+23
View File
@@ -0,0 +1,23 @@
const { prompt } = require('enquirer');
const questions = [
{
'type': 'input',
'name': 'uid',
'message': 'Sender uid ? (Back-ends: backend-marklogic / backend-smed )'
},
{
'type': 'select',
'name': 'type',
'message': 'Type of message ?',
'choices': [
{ 'message': 'Event', 'value': 'event' },
{ 'message': 'Action', 'value': 'action' },
{ 'message': 'Other', 'value': 'other' },
],
}
]
prompt(questions).then(answers => {
console.log(answers)
})
@@ -0,0 +1,22 @@
{
"packet": {
"payload": {
"eventType": "updated",
"data": {
"roles": [
"BP_PO",
"SP_Admin",
"Org_Admin",
"Org_Member",
"Org_Pending",
"SOE_Admin",
"COACH_Coach_Pending",
"PROJECT_FIO"
],
"euLoginId": "steinic"
}
},
"sender": "backend-marklogic"
},
"channel": "dataSync:userRoles"
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,29 @@
{
"channel":"dataSync:userRoles",
"packet":{
"sender":"backend-marklogic",
"reqid":"18dd9317-a08c-4f0a-9f4c-5a30860e02e4",
"eventType": "updated",
"payload":{
"euLoginId": "steinic",
"roles": [
"BP_PO",
"COACH_Coach",
"Org_Member",
"Org_Pending",
"PROJECT_PO",
"SOE_Admin",
"SP_Admin",
"EIC_Admin",
"EIC_Dev",
"MAIL_Editor",
"MAIL_Reviewer",
"MAIL_Sender",
"TEMPLATE_Editor"
]
}
}
}
+28
View File
@@ -0,0 +1,28 @@
{
"channel":"dataSync:userRoles",
"packet":{
"sender":"backend-marklogic",
"reqid":"18dd9317-a08c-4f0a-9f4c-5a30860e02e4",
"payload":
{"eventType": "updated",
"payload": {
"euLoginId": "steinic",
"roles": [
"BP_PO",
"COACH_Coach",
"Org_Member",
"Org_Pending",
"PROJECT_PO",
"SOE_Admin",
"SP_Admin",
"EIC_Admin",
"EIC_Dev",
"MAIL_Editor",
"MAIL_Reviewer",
"MAIL_Sender",
"TEMPLATE_Editor"
]
}
}
}
}
+21
View File
@@ -0,0 +1,21 @@
{
"channel":"dataSync:userRoles",
"packet":{
"sender":"backend-marklogic",
"reqid":"18dd9317-a08c-4f0a-9f4c-5a30860e02e4",
"payload":
{"eventType": "updated",
"payload": {
"euLoginId": "steinic",
"roles": [
"EIC_Admin",
"EIC_Dev",
"MAIL_Editor",
"MAIL_Reviewer",
"MAIL_Sender",
"TEMPLATE_Editor"
]
}
}
}
}
+19
View File
@@ -0,0 +1,19 @@
{
"channel":"dataSync:userRoles",
"packet":{
"sender":"backend-marklogic",
"reqid":"18dd9317-a08c-4f0a-9f4c-5a30860e02e4",
"payload":
{"eventType": "updated",
"payload": {
"euLoginId": "steinic",
"roles": [
"BP_PO",
"COACH_Coach",
"Org_Member",
"Org_Pending"
]
}
}
}
}
+17
View File
@@ -0,0 +1,17 @@
{
"channel":"dataSync:userRoles",
"packet":{
"sender":"backend-smed",
"reqid":"18dd9317-a08c-4f0a-9f4c-5a30860e02e4",
"payload":
{"eventType": "updated",
"payload": {
"euLoginId": "steinic",
"roles": [
"SMED_role1",
"EIC_Dev"
]
}
}
}
}