Skip to content

Commit d19de76

Browse files
committed
service host endpoints working now
1 parent 145aad8 commit d19de76

13 files changed

Lines changed: 136 additions & 104 deletions

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"nconf": "^0.10.0",
4141
"node-persist": "^3.0.1",
4242
"nodemon-webpack-plugin": "^3.0.1",
43+
"origin-router": "^1.6.4",
4344
"parse-url": "^5.0.1",
4445
"prompt": "^1.0.0",
4546
"roslib": "^0.20.0",

src/sandbox/endpoint-info-sandbox.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//const debug = require('debug')('dataparty.EndpointInfoSandbox')
1+
const debug = require('debug')('dataparty.EndpointInfoSandbox')
22
const Sandbox = require('./sandbox')
33

44
class EndpointInfoSandbox extends Sandbox {
@@ -20,7 +20,6 @@ module.exports = async ()=>{
2020
2121
return {
2222
Name: Lib.Name,
23-
Type: Lib.Type,
2423
Description: Lib.Description,
2524
MiddlewareConfig: Lib.MiddlewareConfig
2625
}
@@ -42,6 +41,7 @@ module.exports = async ()=>{
4241

4342
async run(){
4443

44+
debug('running')
4545

4646
this.info = await super.run()
4747

src/sandbox/middleware-exec-sandbox.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//const debug = require('debug')('dataparty.MiddlewareExecSandbox')
1+
const debug = require('debug')('dataparty.MiddlewareExecSandbox')
22
const Sandbox = require('./sandbox')
33

44
class MiddlewareExecSandbox extends Sandbox {
@@ -35,8 +35,9 @@ module.exports = async (ctx, static_ctx)=>{
3535
this.result = null
3636
}
3737

38-
async run({ctx, static_ctx, party}){
38+
async run(ctx, static_ctx){
3939

40+
debug('running', ctx)
4041

4142
this.result = await super.run(ctx, static_ctx)
4243

src/sandbox/middleware-info-sandbox.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//const debug = require('debug')('dataparty.MiddlewareInfoSandbox')
1+
const debug = require('debug')('dataparty.MiddlewareInfoSandbox')
22
const Sandbox = require('./sandbox')
33

44
class MiddlewareInfoSandbox extends Sandbox {
@@ -42,7 +42,7 @@ module.exports = async ()=>{
4242

4343
async run(){
4444

45-
45+
debug('running', this.code)
4646
this.info = await super.run()
4747

4848
return this.info

src/sandbox/sandbox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const SandboxError = require('./sandbox-error')
55

66
class Sandbox {
77
constructor(code){
8-
debug('compiling code')
8+
debug('compiling code', typeof code)
99
this.code = code
1010
this.script = new VMScript(code)
1111
debug('compiled')

src/service/endpoint-context.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ class EndpointContext {
88

99
this.req = req
1010
this.res = res
11-
this.actor = actor
11+
this.actor = null
1212
this.stats = {
1313
start: Date.now(),
1414
bytes_in: !req ? null : JSON.stringify(req.body).length
1515
}
16-
this.oauth_cloud = oauth_cloud
17-
this.session = session
18-
this.identity = identity
19-
this.input = input
20-
this.input_session_id = input_session_id
16+
this.oauth_cloud = null
17+
this.session = null
18+
this.identity = null
19+
this.input = null
20+
this.input_session_id = null
2121
this._debug = Debug('dataparty.context.undefined')
2222
this._debugContent = []
2323
}
@@ -40,7 +40,9 @@ class EndpointContext {
4040
setActor(actor){ this.actor = actor }
4141
setInputSession(input_session_id){ this.input_session_id = input_session_id }
4242

43-
applyMiddleware
43+
/*async applyMiddleware(){
44+
45+
}*/
4446

4547
debug(msg, ...args){
4648
let line = ((new Error().stack).split('at ')[2]).trim()
Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,36 @@
11
const Joi = require('@hapi/joi')
22
const Hoek = require('@hapi/hoek')
33
const {Message, Routines} = require('@dataparty/crypto')
4-
const debug = require('debug')('roshub.middleware.pre.decrypt')
4+
const debug = require('debug')('roshub.endpoint.identity')
55

6-
const IMiddleware = require('../../imiddleware')
6+
const IEndpoint = require('../iendpoint')
77

8-
module.exports = class Decrypt extends IMiddleware {
8+
module.exports = class ServiceIdentity extends IEndpoint {
99

1010
static get Name(){
11-
return 'decrypt'
11+
return 'identity'
1212
}
1313

14-
static get Type(){
15-
return 'pre'
16-
}
1714

1815
static get Description(){
19-
return 'Decrypt inbound data'
16+
return 'Get host identity'
2017
}
2118

22-
static get ConfigSchema(){
23-
return Joi.boolean()
19+
static get MiddlewareConfig(){
20+
return {
21+
pre: {
22+
decrpyt: false
23+
}
24+
}
2425
}
2526

2627
static async run(ctx, static_ctx){
2728

28-
if (!Hoek.reach(ctx, 'endpoint.MiddlewareConfig.pre.decrypt', false)){
29-
return
30-
}
3129

32-
33-
const msg = new Message(ctx.input)
34-
const jsonContent = await msg.decrpyt(this.serviceParty.privateIdentity)
35-
const publicKeys = Routines.extractPublicKeys(msg.enc)
36-
37-
ctx.setInputSession(jsonContent.session)
30+
const identity = ctx.party.identity
3831

3932
return {
40-
input: Hoek.reach(content, 'data'),
41-
sender: {
42-
type: 'ecdsa',
43-
public: publicKeys
44-
}
33+
...identity
4534
}
4635
}
4736
}

src/service/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ module.exports = {
77
IEndpoint: require('./iendpoint'),
88
IMiddleware: require('./imiddleware'),
99
ServiceHost: require('./service-host'),
10+
ServiceRunner: require('./service-runner'),
11+
EndpointRunner: require('./endpoint-runner'),
12+
EndpointContext: require('./endpoint-context'),
13+
MiddlewareRunner: require('./middleware-runner'),
1014
middleware: {
1115
pre: {
1216
decrypt: require('./middleware/pre/decrypt')
@@ -16,5 +20,11 @@ module.exports = {
1620
pre: {
1721
decrypt: Path.join(__dirname, './middleware/pre/decrypt.js')
1822
}
23+
},
24+
endpoint: {
25+
identity: require('./endpoints/service-identity')
26+
},
27+
endpoint_paths: {
28+
identity: Path.join(__dirname, './endpoints/service-identity.js')
1929
}
2030
}

src/service/iservice.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ module.exports = class IService {
8080
}
8181

8282
addEndpoint(endpoint_path){
83+
debug('andEndpoint', endpoint_path)
8384
const endpoint = require(endpoint_path)
8485
const name = endpoint.Name
8586

src/service/middleware/pre/decrypt.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ module.exports = class Decrypt extends IMiddleware {
1111
return 'decrypt'
1212
}
1313

14+
static get Type(){
15+
return 'pre'
16+
}
17+
1418
static get Description(){
1519
return 'Decrypt inbound data'
1620
}
1721

18-
static get MiddlewareConfig(){
19-
throw new Error('not implemented')
22+
static get ConfigSchema(){
23+
return Joi.boolean()
2024
}
2125

2226
static async start(party){

0 commit comments

Comments
 (0)