Skip to content

Make sailor to use object-storage-client #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: elasticio-1543-object-storage-for-error
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/amqp.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const log = require('./logging.js');
const amqplib = require('amqplib');
const encryptor = require('./encryptor.js');
const ObjectStorage = require('./objectStorage.js');
const { ObjectStorage } = require('@elastic.io/object-storage-client');
const co = require('co');
const _ = require('lodash');
const eventToPromise = require('event-to-promise');
Expand All @@ -12,7 +12,13 @@ const HEADER_ERROR_RESPONSE = 'x-eio-error-response';
class Amqp {
constructor(settings) {
this.settings = settings;
this.objectStorage = new ObjectStorage(settings);
this.objectStorage = new ObjectStorage({
uri: settings.OBJECT_STORAGE_URI,
cipher: {
key: process.env.ELASTICIO_MESSAGE_CRYPTO_PASSWORD,
iv: process.env.ELASTICIO_MESSAGE_CRYPTO_IV
}
});
}

connect(uri) {
Expand Down Expand Up @@ -61,7 +67,7 @@ class Amqp {
return encryptor.decryptMessageContent(message.content);
}

return await this.objectStorage.getObject(objectId);
return await this.objectStorage.getAsJSON(objectId, this.settings.OBJECT_STORAGE_TOKEN);
}

async encryptMessage(data, properties) {
Expand All @@ -71,7 +77,7 @@ class Amqp {

let message = '';
try {
properties.headers.objectId = await this.objectStorage.addObject(data);
properties.headers.objectId = await this.objectStorage.addAsJSON(data, this.settings.OBJECT_STORAGE_TOKEN);
} catch (e) {
log.error('Failed to add message to object storage: %s', e);
message = encryptor.encryptMessageContent(data);
Expand Down
81 changes: 0 additions & 81 deletions lib/objectStorage.js

This file was deleted.

18 changes: 15 additions & 3 deletions mocha_spec/integration_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const { EventEmitter } = require('events');
const PREFIX = 'sailor_nodejs_integration_test';
const nock = require('nock');
const getStream = require('get-stream');
const encryptor = require('../lib/encryptor.js');
const { Readable } = require('stream');
const { Message } = require('@elastic.io/object-storage-client');
const encryptor = require('../lib/encryptor');

const env = process.env;

Expand Down Expand Up @@ -134,7 +136,7 @@ class AmqpHelper extends EventEmitter {
this.publishChannel.ack(message);

const content = message.content.toString();
const emittedMessage = content ? JSON.parse(content) : content;
const emittedMessage = content ? encryptor.decryptMessageContent(message.content) : content;

const data = {
properties: message.properties,
Expand Down Expand Up @@ -184,6 +186,9 @@ function prepareEnv() {
env.ELASTICIO_OBJECT_STORAGE_URI = 'http://ma.es.ter';
env.ELASTICIO_OBJECT_STORAGE_ENABLED = '';
env.ELASTICIO_OBJECT_STORAGE_TOKEN = 'jwt';

env.ELASTICIO_MESSAGE_CRYPTO_PASSWORD = 'testCryptoPassword';
env.ELASTICIO_MESSAGE_CRYPTO_IV = 'iv=any16_symbols';
}

function mockApiTaskStepResponse(response) {
Expand All @@ -203,7 +208,14 @@ function mockApiTaskStepResponse(response) {
}

async function encryptForObjectStorage(input) {
const stream = encryptor.encryptMessageContentStream(input);
const dataStream = new Readable();
dataStream.push(JSON.stringify(input));
dataStream.push(null);
const message = new Message({
key: env.ELASTICIO_MESSAGE_CRYPTO_PASSWORD,
iv: env.ELASTICIO_MESSAGE_CRYPTO_IV
});
const stream = message.packStream(dataStream);
return await getStream.buffer(stream);
}

Expand Down
136 changes: 0 additions & 136 deletions mocha_spec/objectStorage.spec.js

This file was deleted.

2 changes: 0 additions & 2 deletions mocha_spec/run.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ describe('Integration Test', () => {
.get('/customers')
.reply(200, customers);

const log = sinon.stub(logging, 'warn');
const objectStorageGet = nock(process.env.ELASTICIO_OBJECT_STORAGE_URI)
.get(`/objects/${objectId}`)
.matchHeader('authorization', /Bearer/)
Expand Down Expand Up @@ -282,7 +281,6 @@ describe('Integration Test', () => {
expect(body).to.be.null;
expect(objectStorageGet.isDone()).to.be.true;
expect(objectStoragePut.isDone()).to.be.true;
expect(log.getCall(1).args[1].toString()).to.include('400');
done();
});

Expand Down
Loading