Skip to content
This repository has been archived by the owner on Feb 4, 2020. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Frey <[email protected]>
  • Loading branch information
austinfrey committed Sep 23, 2017
0 parents commit d52861b
Show file tree
Hide file tree
Showing 10 changed files with 3,216 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
32 changes: 32 additions & 0 deletions faas/compose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

const path = require('path');
const BbPromise = require('bluebird');
const got = require('got');

const compose = baseUrl => {
return (initial, funcs) => {
const functions = funcs.map(func => {
return data => {
const options = {
method: 'POST',
body: data
};

const funcUrl = baseUrl + path.join('/function', func);
return got(funcUrl, options)
.then(res => BbPromise.resolve(res))
.catch(err => BbPromise.reject(err));
};
});

return functions.reduce(
(current, f) => {
return current.then(x => f(x.body));
},
new BbPromise(resolve => resolve(initial))
);
};
};

module.exports = compose;
24 changes: 24 additions & 0 deletions faas/deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

const got = require('got');

const deploy = gateway => {
const url = gateway;

return (name, network, image) => {
const deployPath = '/system/functions';
const options = {
method: 'POST',
json: true,
body: {
service: name,
network,
image
}
};

return got(url + deployPath, options);
};
};

module.exports = deploy;
16 changes: 16 additions & 0 deletions faas/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

const deploy = require('./deploy');
const remove = require('./remove');
const invoke = require('./invoke');
const compose = require('./compose');

const faas = url => ({
deploy: deploy(url),
remove: remove(url),
invoke: invoke(url),
compose: compose(url)
});

module.exports = faas;

24 changes: 24 additions & 0 deletions faas/invoke.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

const path = require('path');
const got = require('got');

const invoke = gateway => {
const url = gateway;

return (name, data) => {
const funcPath = path.join('/function', name);
const options = {
method: 'POST',
json: true
};

if (data) {
options.body = data;
}

return got(url + funcPath, options);
};
};

module.exports = invoke;
21 changes: 21 additions & 0 deletions faas/remove.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const got = require('got');

const remove = gateway => {
const url = gateway;

return name => {
const options = {
method: 'DELETE',
json: true,
body: {
functionName: name
}
};

return got(url + '/system/functions', options);
};
};

module.exports = remove;
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const Faas = require('./faas');

const faas = Faas('http://localhost:8080');

faas.deploy(
'yolo',
'func_functions',
'hello-serverless'
)
.then(x => console.log(x))
.catch(err => console.log(err));

Loading

0 comments on commit d52861b

Please sign in to comment.