Skip to content

Commit f70dbbf

Browse files
committed
unsandboxed service host
1 parent ff6e692 commit f70dbbf

20 files changed

Lines changed: 381 additions & 26 deletions

examples/test-service-host.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async function main(){
4848

4949
const host = new Dataparty.ServiceHost({
5050
runner,
51-
trust_proxy: false,
51+
trust_proxy: true,
5252
wsEnabled: true
5353
})
5454

examples/test-service-node-host.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const Path = require('path')
2+
const debug = require('debug')('test.server-db')
3+
const Dataparty = require('../src')
4+
5+
const BouncerServerModels = require('@dataparty/bouncer-model')
6+
const BouncerClientModels = require('@dataparty/bouncer-model/dist/bouncer-model.json')
7+
8+
class ExampleService extends Dataparty.IService {
9+
constructor(opts){
10+
super(opts)
11+
12+
this.addMiddleware(Dataparty.middleware_paths.pre.decrypt)
13+
this.addMiddleware(Dataparty.middleware_paths.pre.validate)
14+
15+
this.addMiddleware(Dataparty.middleware_paths.post.validate)
16+
this.addMiddleware(Dataparty.middleware_paths.post.encrypt)
17+
18+
this.addEndpoint(Dataparty.endpoint_paths.echo)
19+
this.addEndpoint(Dataparty.endpoint_paths.secureecho)
20+
this.addEndpoint(Dataparty.endpoint_paths.identity)
21+
this.addEndpoint(Dataparty.endpoint_paths.version)
22+
}
23+
24+
}
25+
26+
async function main(){
27+
28+
const uri = 'mongodb://localhost:27017/server-party-test'
29+
debug('db location', uri)
30+
31+
let party = new Dataparty.MongoParty({
32+
uri,
33+
model: BouncerClientModels,
34+
serverModels: BouncerServerModels,
35+
config: new Dataparty.Config.MemoryConfig()
36+
})
37+
38+
const service = new ExampleService({ name: '@dataparty/example', version: '0.0.1' })
39+
40+
const build = await service.compile(Path.join(__dirname,'/dataparty'), true)
41+
42+
debug('built', Object.keys(build))
43+
44+
const runner = new Dataparty.ServiceRunnerNode({
45+
party, service,
46+
sendFullErrors: true
47+
})
48+
49+
const host = new Dataparty.ServiceHost({
50+
runner,
51+
trust_proxy: true,
52+
wsEnabled: true
53+
})
54+
55+
await party.start()
56+
await runner.start()
57+
await host.start()
58+
59+
console.log('started')
60+
61+
//process.exit()
62+
}
63+
64+
65+
66+
main().catch(err=>{
67+
console.error(err)
68+
})

src/party/peer/peer-party.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
const debug = require('debug')('dataparty.peer-party')
44

5-
//const WRTC = require('wrtc')
65
const Qb = require('../qb')
76
const IParty = require('../iparty')
8-
//const RTCSocketComms = require('../../comms/rtc-socket-comms')
97

108
/**
119
* @class
@@ -34,10 +32,6 @@ class PeerParty extends IParty {
3432
}
3533
}
3634

37-
static get WRTC(){
38-
return WRTC
39-
}
40-
4135
async start(){
4236
await super.start()
4337
if(this.comms.host){

src/sandbox/sandbox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Sandbox {
4040
})
4141

4242
let fn = vm.run(this.script)
43-
const retVal = await fn(context)
43+
const retVal = await fn(context, sandbox)
4444
return retVal
4545

4646
} catch(err) {

src/service/endpoints/echo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = class EchoEndpoint extends IEndpoint {
2929
}
3030
}
3131

32-
static async run(ctx){
32+
static async run(ctx, {Package}){
3333

3434
ctx.debug('hello')
3535
debug('echo')

src/service/endpoints/secure-echo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = class SecureEchoEndpoint extends IEndpoint {
2929
}
3030
}
3131

32-
static async run(ctx){
32+
static async run(ctx, {Package}){
3333

3434
ctx.debug('hello')
3535
debug('echo')

src/service/endpoints/service-identity.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module.exports = class ServiceIdentity extends IEndpoint {
3838
}
3939
}
4040

41-
static async run(ctx, static_ctx){
41+
static async run(ctx, {Package}){
4242

4343

4444
const identity = ctx.party.identity

src/service/endpoints/service-version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = class ServiceVersion extends IEndpoint {
3333
}
3434
}
3535

36-
static async run(ctx, static_ctx){
36+
static async run(ctx, {Package}){
3737

3838
return {
3939
...Package

src/service/iendpoint.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@ module.exports = class IEndpoint {
1919

2020
}
2121

22-
static async run(context){
22+
static async run(context, {Package}){
2323
throw new Error('not implemented')
2424
}
25+
26+
static get info(){
27+
return {
28+
Name: this.Name,
29+
Description: this.Description,
30+
MiddlewareConfig: this.MiddlewareConfig
31+
}
32+
}
2533
}

src/service/imiddleware.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ module.exports = class IMiddleware {
2323

2424
}
2525

26-
static async run(context){
26+
static async run(context, {Config}){
2727
throw new Error('not implemented')
2828
}
29+
30+
static get info(){
31+
return {
32+
Name: this.Name,
33+
Type: this.Type,
34+
Description: this.Description,
35+
ConfigSchema: this.ConfigSchema
36+
}
37+
}
2938
}

0 commit comments

Comments
 (0)