Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
785acfaba4 | |||
5a4dceb75d | |||
a17834a8f0 | |||
01765fa50f |
@ -10,15 +10,18 @@ stages:
|
|||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- trigger
|
- metadata
|
||||||
- pages
|
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# security stage
|
||||||
|
# ====================
|
||||||
mirror:
|
mirror:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
snyk:
|
||||||
stage: security
|
stage: security
|
||||||
@ -28,7 +31,11 @@ snyk:
|
|||||||
- npmci command snyk test
|
- npmci command snyk test
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# test stage
|
||||||
|
# ====================
|
||||||
testLEGACY:
|
testLEGACY:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
@ -38,6 +45,7 @@ testLEGACY:
|
|||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
|
||||||
testLTS:
|
testLTS:
|
||||||
@ -49,6 +57,7 @@ testLTS:
|
|||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
testSTABLE:
|
testSTABLE:
|
||||||
stage: test
|
stage: test
|
||||||
@ -59,34 +68,60 @@ testSTABLE:
|
|||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# metadata stage
|
||||||
|
# ====================
|
||||||
|
codequality:
|
||||||
|
stage: metadata
|
||||||
|
image: docker:stable
|
||||||
|
allow_failure: true
|
||||||
|
services:
|
||||||
|
- docker:stable-dind
|
||||||
|
script:
|
||||||
|
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||||
|
- docker run
|
||||||
|
--env SOURCE_CODE="$PWD"
|
||||||
|
--volume "$PWD":/code
|
||||||
|
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||||
|
artifacts:
|
||||||
|
paths: [codeclimate.json]
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: trigger
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: hosttoday/ht-docker-node:npmci
|
||||||
stage: pages
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command yarn global add npmpage
|
- npmci command yarn global add npmpage
|
||||||
- npmci command npmpage
|
- npmci command npmpage
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
artifacts:
|
artifacts:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartuniverse",
|
"name": "@pushrocks/smartuniverse",
|
||||||
"version": "1.0.14",
|
"version": "1.0.16",
|
||||||
"description": "messaging service for your micro services",
|
"description": "messaging service for your micro services",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
@ -17,8 +17,10 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lik": "^2.0.5",
|
"lik": "^2.0.5",
|
||||||
|
"nodehash": "^1.0.4",
|
||||||
"rxjs": "^5.5.8",
|
"rxjs": "^5.5.8",
|
||||||
"smartcli": "^2.0.12",
|
"smartcli": "^2.0.12",
|
||||||
|
"smartdelay": "^1.0.4",
|
||||||
"smartexpress": "^1.0.21",
|
"smartexpress": "^1.0.21",
|
||||||
"smartfile": "^4.2.28",
|
"smartfile": "^4.2.28",
|
||||||
"smartq": "^1.1.8",
|
"smartq": "^1.1.8",
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
import * as plugins from './smartuniverse.plugins';
|
|
||||||
|
|
||||||
import { Objectmap } from 'lik';
|
|
||||||
import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
|
||||||
|
|
||||||
export class UniverseManager {
|
|
||||||
public channelStore = new Objectmap<UniverseChannel>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* register a new member
|
|
||||||
*/
|
|
||||||
public async registerMember() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* register a new channel within the universe
|
|
||||||
* @param channelName the name of the channel
|
|
||||||
* @param authSecret the secret against which to verify members of the channel
|
|
||||||
*/
|
|
||||||
public async registerChannel(channelName: string, authSecret: string) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +1,6 @@
|
|||||||
import * as plugins from './smartuniverse.plugins';
|
import * as plugins from './smartuniverse.plugins';
|
||||||
|
|
||||||
import { Handler, Route, Server } from 'smartexpress';
|
import { Handler, Route, Server } from 'smartexpress';
|
||||||
|
|
||||||
import { UniverseManager } from './smartuniverse.classes.manager';
|
|
||||||
import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
||||||
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
||||||
import { UniverseStore } from './smartuniverse.classes.universestore';
|
import { UniverseStore } from './smartuniverse.classes.universestore';
|
||||||
@ -20,6 +18,8 @@ export interface IServerGetMessagesRequestBody {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IServerPutMessageRequestBody {
|
export interface IServerPutMessageRequestBody {
|
||||||
|
channel: string;
|
||||||
|
passphrase: string;
|
||||||
message: string;
|
message: string;
|
||||||
payload: any;
|
payload: any;
|
||||||
}
|
}
|
||||||
@ -27,7 +27,6 @@ export interface IServerPutMessageRequestBody {
|
|||||||
export class Universe {
|
export class Universe {
|
||||||
// subinstances
|
// subinstances
|
||||||
public universeStore: UniverseStore;
|
public universeStore: UniverseStore;
|
||||||
public universeManager: UniverseManager;
|
|
||||||
|
|
||||||
// options
|
// options
|
||||||
private options: ISmartUniverseConstructorOptions;
|
private options: ISmartUniverseConstructorOptions;
|
||||||
@ -50,7 +49,6 @@ export class Universe {
|
|||||||
constructor(optionsArg: ISmartUniverseConstructorOptions) {
|
constructor(optionsArg: ISmartUniverseConstructorOptions) {
|
||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
this.universeStore = new UniverseStore(this.options.messageExpiryInMilliseconds);
|
this.universeStore = new UniverseStore(this.options.messageExpiryInMilliseconds);
|
||||||
this.universeManager = new UniverseManager();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,8 +65,13 @@ export class Universe {
|
|||||||
// message handling
|
// message handling
|
||||||
// adds messages
|
// adds messages
|
||||||
const addMessageHandler = new Handler('PUT', request => {
|
const addMessageHandler = new Handler('PUT', request => {
|
||||||
const requestBody = request.body;
|
const requestBody: IServerPutMessageRequestBody = request.body;
|
||||||
this.universeStore.addMessage(requestBody.message, requestBody.payload);
|
const message = new UniverseMessage(
|
||||||
|
requestBody.message,
|
||||||
|
requestBody.payload,
|
||||||
|
|
||||||
|
)
|
||||||
|
this.universeStore.addMessage(message);
|
||||||
console.log(requestBody);
|
console.log(requestBody);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
@ -10,23 +10,37 @@ export class UniverseChannel {
|
|||||||
* stores the channels that are available within the universe
|
* stores the channels that are available within the universe
|
||||||
*/
|
*/
|
||||||
public static channelStore = new Objectmap();
|
public static channelStore = new Objectmap();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates new channels
|
* creates new channels
|
||||||
* @param channelArg the name of the topic
|
* @param channelArg the name of the topic
|
||||||
* @param secretArg the secret thats used for a certain topic.
|
* @param passphraseArg the secret thats used for a certain topic.
|
||||||
*/
|
*/
|
||||||
public static createChannel = (channelArg: string, secretArg: string) => {
|
public static createChannel = (channelNameArg: string, passphraseArg: string) => {
|
||||||
|
const newChannel = new UniverseChannel(channelNameArg, passphraseArg);
|
||||||
|
return newChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the name of the channel
|
||||||
|
*/
|
||||||
|
public name: string;
|
||||||
|
|
||||||
credentials: {
|
/**
|
||||||
user: string;
|
* the passphrase for the channel
|
||||||
password: string;
|
*/
|
||||||
};
|
public passphrase: string;
|
||||||
|
|
||||||
|
constructor(channelNameArg: string, passphraseArg: string) {
|
||||||
|
this.name = channelNameArg;
|
||||||
|
this.passphrase = passphraseArg;
|
||||||
|
UniverseChannel.channelStore.add(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* authenticates a client on the server side
|
* authenticates a client on the server side
|
||||||
*/
|
*/
|
||||||
async authenticateClient() {}
|
public async authenticateClient(passphraseArg: string): boolean {
|
||||||
|
return passphraseArg === this.passphrase;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,36 +14,74 @@ export class UniverseMessage {
|
|||||||
* avoids duplications though
|
* avoids duplications though
|
||||||
*/
|
*/
|
||||||
public id: number;
|
public id: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the universe store the message is attached to
|
||||||
|
*/
|
||||||
public universeStore: UniverseStore;
|
public universeStore: UniverseStore;
|
||||||
public timestamp: TimeStamp; // when has this message been created
|
/**
|
||||||
public topic: string; // enables unprotected grouping of messages for efficiency purposes.
|
* enables unprotected grouping of messages for efficiency purposes.
|
||||||
public message: string; // the actual message
|
*/
|
||||||
public attachedPayload: any; // any attached payloads. Can be of binary format.
|
public universeChannel: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* time of creation
|
||||||
|
*/
|
||||||
|
public timestamp: TimeStamp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the actual message
|
||||||
|
*/
|
||||||
|
public message: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* any attached payloads. Can be of binary format.
|
||||||
|
*/
|
||||||
|
public attachedPayload: any;
|
||||||
public destructionTimer: Timer; // a timer to take care of message destruction
|
public destructionTimer: Timer; // a timer to take care of message destruction
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the constructor to create a universe message
|
* the constructor to create a universe message
|
||||||
* @param parentUniverseStore
|
* @param messageArg
|
||||||
* @param messageArg
|
* @param attachedPayloadArg
|
||||||
* @param attachedPayloadArg
|
|
||||||
* @param selfdestructAfterArg
|
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
parentUniverseStore: UniverseStore,
|
|
||||||
messageArg: string,
|
messageArg: string,
|
||||||
attachedPayloadArg: any,
|
attachedPayloadArg: any
|
||||||
selfdestructAfterArg: number
|
|
||||||
) {
|
) {
|
||||||
this.universeStore = parentUniverseStore;
|
|
||||||
this.timestamp = new TimeStamp();
|
this.timestamp = new TimeStamp();
|
||||||
this.message = messageArg;
|
this.message = messageArg;
|
||||||
this.attachedPayload = attachedPayloadArg;
|
this.attachedPayload = attachedPayloadArg;
|
||||||
this.destructionTimer = new Timer(selfdestructAfterArg);
|
this.fallBackDestruction();
|
||||||
this.destructionTimer.start();
|
}
|
||||||
|
|
||||||
// set up self destruction by removing this from the parent messageStore
|
public setUniverseStore (universeStoreArg: UniverseStore) {
|
||||||
this.destructionTimer.completed.then(async () => {
|
this.universeStore = universeStoreArg;
|
||||||
this.universeStore.messageStore.remove(this);
|
}
|
||||||
|
|
||||||
|
public setDestructionTimer (selfdestructAfterArg: number) {
|
||||||
|
if (selfdestructAfterArg) {
|
||||||
|
this.destructionTimer = new Timer(selfdestructAfterArg);
|
||||||
|
this.destructionTimer.start();
|
||||||
|
|
||||||
|
// set up self destruction by removing this from the parent messageStore
|
||||||
|
this.destructionTimer.completed.then(async () => {
|
||||||
|
this.universeStore.messageStore.remove(this);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.fallBackDestruction();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* prevents memory leaks if channels have no default
|
||||||
|
*/
|
||||||
|
private fallBackDestruction () {
|
||||||
|
plugins.smartdelay.delayFor(1000).then(() => {
|
||||||
|
if (!this.destructionTimer) {
|
||||||
|
this.setDestructionTimer(6000);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,8 @@ export class UniverseStore {
|
|||||||
* @param messageArg
|
* @param messageArg
|
||||||
* @param attachedPayloadArg
|
* @param attachedPayloadArg
|
||||||
*/
|
*/
|
||||||
public addMessage(messageArg, attachedPayloadArg) {
|
public addMessage(messageArg: UniverseMessage) {
|
||||||
this.messageStore.add(
|
this.messageStore.add(messageArg);
|
||||||
new UniverseMessage(this, messageArg, attachedPayloadArg, this.destructionTime)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import * as lik from 'lik';
|
import * as lik from 'lik';
|
||||||
|
import * as nodehash from 'nodehash';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as smartcli from 'smartcli';
|
import * as smartcli from 'smartcli';
|
||||||
|
import * as smartdelay from 'smartdelay';
|
||||||
import * as smartexpress from 'smartexpress';
|
import * as smartexpress from 'smartexpress';
|
||||||
import * as smartfile from 'smartfile';
|
import * as smartfile from 'smartfile';
|
||||||
import * as smartq from 'smartq';
|
import * as smartq from 'smartq';
|
||||||
@ -11,8 +13,10 @@ import * as smarttime from 'smarttime';
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
lik,
|
lik,
|
||||||
|
nodehash,
|
||||||
path,
|
path,
|
||||||
smartcli,
|
smartcli,
|
||||||
|
smartdelay,
|
||||||
smartexpress,
|
smartexpress,
|
||||||
smartfile,
|
smartfile,
|
||||||
smartq,
|
smartq,
|
||||||
|
Reference in New Issue
Block a user