Skip to content

Commit 78c08b4

Browse files
committed
Initial commit
0 parents  commit 78c08b4

File tree

9 files changed

+233
-0
lines changed

9 files changed

+233
-0
lines changed

LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2016 elastic.io GmbH <[email protected]> (https://elastic.io)
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# pubsub-component [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url]
2+
> Pub/Sub Component for async communication with queues and topics
3+
4+
# pubsub-component
5+
PubSub component for the [elastic.io platform](http://www.elastic.io &#34;elastic.io platform&#34;)
6+
7+
If you plan to **deploy it into [elastic.io platform](http://www.elastic.io &#34;elastic.io platform&#34;) you must follow sets of instructions to succseed**.
8+
9+
## Before you Begin
10+
11+
Before you can deploy any code into elastic.io **you must be a registered elastic.io platform user**. Please see our home page at [http://www.elastic.io](http://www.elastic.io) to learn how.
12+
13+
We&#39;ll use git and SSH public key authentication to upload your component code, therefore you must **[upload your SSH Key](http://docs.elastic.io/docs/ssh-key)**.
14+
15+
&gt; If you fail to upload you SSH Key you will get **permission denied** error during the deployment.
16+
17+
## Getting Started
18+
19+
After registration and uploading of your SSH Key you can proceed to deploy it into our system. At this stage we suggest you to:
20+
* [Create a team](http://docs.elastic.io/docs/teams) to work on your new component. This is not required but will be automatically created using random naming by our system so we suggest you name your team accordingly.
21+
* [Create a repository](http://docs.elastic.io/docs/component-repositories) where your new component is going to *reside* inside the team that you have just created.
22+
23+
Now as you have a team name and component repository name you can add a new git remote where code shall be pushed to. It is usually displayed on the empty repository page:
24+
25+
```bash
26+
$ git remote add elasticio [email protected]:your-repository.git
27+
```
28+
29+
Obviously the naming of your team and repository is entirely upto you and if you do not put any corresponding naming our system will auto generate it for you but the naming might not entirely correspond to your project requirements.
30+
Now we are ready to push it:
31+
32+
```bash
33+
$ git push elasticio master
34+
```
35+
36+
## Authentication
37+
38+
This component is using the internal RabbitMQ instance that is available as part of elastic.io
39+
infrastructure, it expects following environment variables to be present when started:
40+
* ``ELASTICIO_AMQP_URI`` something like ``amqp://foo:bar@server``
41+
* ``ELASTICIO_MESSAGE_CRYPTO_IV`` key for symmetric encryption
42+
* ``ELASTICIO_MESSAGE_CRYPTO_PASSWORD`` password for symmetric encryption
43+
* ``ELASTICIO_PUBLISH_MESSAGES_TO`` AMQP exchange name, like ``56a63248661ec20500000014_user``
44+
45+
46+
## Known issues
47+
48+
No known issues are there yet.
49+
50+
51+
## License
52+
53+
Apache-2.0 © [elastic.io GmbH](https://elastic.io)
54+
55+
56+
[npm-image]: https://badge.fury.io/js/pubsub-component.svg
57+
[npm-url]: https://npmjs.org/package/pubsub-component
58+
[travis-image]: https://travis-ci.org/elasticio/pubsub-component.svg?branch=master
59+
[travis-url]: https://travis-ci.org/elasticio/pubsub-component
60+
[daviddm-image]: https://david-dm.org/elasticio/pubsub-component.svg?theme=shields.io
61+
[daviddm-url]: https://david-dm.org/elasticio/pubsub-component

component.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"title": "PubSub",
3+
"description": "Pub/Sub Component for async communication with queues and topics",
4+
"credentials": {
5+
"fields": {
6+
"name": {
7+
"label": "My API Key",
8+
"required": true,
9+
"viewClass": "TextFieldView"
10+
}
11+
}
12+
},
13+
"actions": {
14+
"publish": {
15+
"title": "Publish",
16+
"main": "./lib/actions/publish.js",
17+
"metadata": {
18+
"in": "./lib/schemas/publish.in.json",
19+
"out": "./lib/schemas/publish.out.json"
20+
}
21+
}
22+
}
23+
}

lib/actions/publish.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
const eioUtils = require('elasticio-node').messages;
3+
const co = require('co');
4+
const rp = require('request-promise');
5+
6+
module.exports.process = processAction;
7+
8+
/**
9+
* This method will be called from elastic.io platform providing following data
10+
*
11+
* @param msg incoming message object that contains ``body`` with payload
12+
* @param cfg configuration that is account information and configuration field values
13+
* @param snapshot - current values from the snapshot
14+
*/
15+
function processAction(msg, cfg, snapshot) {
16+
console.log('Action started, snapshot=%j', snapshot);
17+
18+
co(function*() {
19+
console.log('Creating new request bin');
20+
21+
const bin = yield rp({
22+
method: 'POST',
23+
uri: 'http://requestb.in/api/v1/bins',
24+
json: true
25+
});
26+
27+
console.log('New request bin created bin=%j', bin);
28+
29+
this.emit('data', eioUtils.newMessageWithBody(bin));
30+
31+
console.log('Processing completed');
32+
33+
this.emit('end');
34+
}.bind(this)).catch(err => {
35+
console.log('Error occurred', err.stack || err);
36+
this.emit('error', err);
37+
this.emit('end');
38+
});
39+
}

lib/schemas/publish.in.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"inValue": {
5+
"type": "string",
6+
"required": true,
7+
"title": "Input Value"
8+
}
9+
}
10+
}

lib/schemas/publish.out.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"outValue": {
5+
"type": "string",
6+
"required": true,
7+
"title": "Output Value"
8+
}
9+
}
10+
}

logo.png

Lines changed: 7 additions & 0 deletions
Loading

package.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "pub-sub",
3+
"version": "0.0.0",
4+
"description": "Pub/Sub Component for async communication with queues and topics",
5+
"homepage": "http://www.elastic.io",
6+
"author": {
7+
"name": "elastic.io GmbH",
8+
"email": "[email protected]",
9+
"url": "https://elastic.io"
10+
},
11+
"files": [
12+
"lib"
13+
],
14+
"main": "lib/index.js",
15+
"keywords": [
16+
"elasticio",
17+
"component",
18+
"ipas",
19+
"amqp",
20+
"rabbitmq",
21+
"pubsub",
22+
"elasticio-component"
23+
],
24+
"dependencies": {
25+
"co": "^4.6.0",
26+
"bluebird": "^3.4.6",
27+
"request": "^2.75.0",
28+
"request-promise": "^4.1.1",
29+
"elasticio-sailor-nodejs": "1.3.0",
30+
"elasticio-node": "0.0.5"
31+
},
32+
"devDependencies": {
33+
"eslint": "^2.1.0",
34+
"eslint-config-xo-space": "^0.10.0"
35+
},
36+
"eslintConfig": {
37+
"extends": "xo-space",
38+
"env": {
39+
"mocha": true
40+
}
41+
},
42+
"repository": "elasticio/pub-sub",
43+
"license": "Apache-2.0"
44+
}

verifyCredentials.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
const co = require('co');
3+
const rp = require('request-promise');
4+
5+
// This function will be called by the platform to verify credentials
6+
module.exports = function verifyCredentials(credentials, cb) {
7+
console.log('Credentials passed for verification %j', credentials);
8+
9+
co(function*() {
10+
console.log('Fetching user information');
11+
12+
const test = yield rp({
13+
uri: 'https://cdn.elastic.io/test.json',
14+
json: true
15+
});
16+
17+
console.log('Fetched JSON value=%j', test);
18+
19+
console.log('Verification completed');
20+
21+
cb(null, {verified: true});
22+
}).catch(err => {
23+
console.log('Error occurred', err.stack || err);
24+
cb(err , {verified: false});
25+
});
26+
};

0 commit comments

Comments
 (0)