-
Notifications
You must be signed in to change notification settings - Fork 4
Added object storage support #96
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
PaulAnnekov
wants to merge
37
commits into
master
Choose a base branch
from
elasticio-1456-add-maester-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 35 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
79a7151
elasticio#1456 removed unused argument
PaulAnnekov ddad1d5
elasticio#1456 1st draft
PaulAnnekov e374344
elasticio#1456 generate uuid for maester, we can't use messageId beca…
PaulAnnekov b590030
elasticio#1456 fixed missing this
PaulAnnekov 7c020ab
elasticio#1456 writing integration test
PaulAnnekov cd2542b
elasticio#1456 small code fixes, made test to work
PaulAnnekov 4277bdc
elasticio#1456 added test to respond directly, updated tests
PaulAnnekov d9d82cc
elasticio#1456 isolate enc/dec code together with maester in a separa…
PaulAnnekov adb2012
elasticio#1456 work with ecnrypted data as base64, not binary
PaulAnnekov e120aa0
elasticio#1456 handle maester errors and conflicts
PaulAnnekov d458603
elasticio#1456 group common headers
PaulAnnekov 3a5c964
elasticio#1456 MAESTER_IS_STORE -> MAESTER_OUT
PaulAnnekov ce86502
elasticio#1456 ignore eslint, we can't fix this
PaulAnnekov 5c5141d
elasticio#1456 fixed unit-tests
PaulAnnekov fc8dc24
elasticio#1456 maester -> object storage
PaulAnnekov 228def6
elasticio#1456 OBJECT_STORAGE_BASEPATH-> OBJECT_STORAGE_URI
PaulAnnekov d142975
elasticio#1456 2.4.0-dev.24
PaulAnnekov 6d12ac8
elasticio#1456 pass correct content-type
PaulAnnekov dcd065f
elasticio#1456 2.4.0-dev.26
PaulAnnekov e32b0e4
elasticio#1456 no need to handle encryptMessage errors, it's ok
PaulAnnekov 07da777
elasticio#1456 object storage stream + gzip
PaulAnnekov 9bb8fac
elasticio#1456 fixed working with requests streams by using axios, is…
PaulAnnekov 74e0da8
elasticio#1456 2.4.0-dev.27
PaulAnnekov c2657eb
elasticio#1456 checked whether maester can return empty object, it's …
PaulAnnekov e06cd34
elasticio#1456 removed unused dependency
PaulAnnekov b91d229
elasticio#1456 fixed tests
PaulAnnekov 6ee68d5
elasticio#1456 unit tests for objectStorage, fixed object storage bug
PaulAnnekov 45c56e1
elasticio#1456 2.4.0-dev.28
PaulAnnekov 54ea830
elasticio#1456 2.4.0-dev.29
PaulAnnekov d6125a0
elasticio#1456 updated package-lock
PaulAnnekov 6949dfd
elasticio#1456 added parentheses and rule
PaulAnnekov d9e0ed4
elasticio#1456 added more parentheses
PaulAnnekov af9bb1c
elasticio#1456 decryptMessage -> onMessage
PaulAnnekov 0602665
elasticio#1456 OBJECT_STORAGE_OUT -> OBJECT_STORAGE_ENABLED
PaulAnnekov c832151
elasticio#1456 createReq -> request, onRes -> onResponse
PaulAnnekov 5b9341c
elasticio#1456 added fallback to message send via rabbitmq on object …
PaulAnnekov 2f23324
elasticio#1456 2.4.2-dev.0
PaulAnnekov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,41 @@ | ||
var cipher = require('./cipher.js'); | ||
var Readable = require('stream').Readable; | ||
var zlib = require('zlib'); | ||
var getStream = require('get-stream'); | ||
|
||
exports.encryptMessageContent = encryptMessageContent; | ||
exports.decryptMessageContent = decryptMessageContent; | ||
exports.encryptMessageContentStream = encryptMessageContentStream; | ||
exports.decryptMessageContentStream = decryptMessageContentStream; | ||
|
||
function encryptMessageContent(messagePayload) { | ||
return cipher.encrypt(JSON.stringify(messagePayload)); | ||
} | ||
|
||
function decryptMessageContent(messagePayload, messageHeaders) { | ||
function decryptMessageContent(messagePayload) { | ||
if (!messagePayload || messagePayload.toString().length === 0) { | ||
return null; | ||
} | ||
try { | ||
return JSON.parse(cipher.decrypt(messagePayload.toString(), messageHeaders)); | ||
return JSON.parse(cipher.decrypt(messagePayload.toString())); | ||
} catch (err) { | ||
console.error(err.stack); | ||
throw Error('Failed to decrypt message: ' + err.message); | ||
} | ||
} | ||
|
||
function encryptMessageContentStream(data) { | ||
const dataStream = new Readable(); | ||
dataStream.push(JSON.stringify(data)); | ||
dataStream.push(null); | ||
return dataStream | ||
.pipe(zlib.createGzip()) | ||
.pipe(cipher.encryptStream()); | ||
} | ||
|
||
async function decryptMessageContentStream(stream) { | ||
const s = stream.pipe(cipher.decryptStream()).pipe(zlib.createGunzip()); | ||
const content = await getStream(s); | ||
|
||
return JSON.parse(content); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
const encryptor = require('./encryptor.js'); | ||
const uuid = require('uuid'); | ||
const axios = require('axios'); | ||
const http = require('http'); | ||
const https = require('https'); | ||
|
||
class ObjectStorage { | ||
constructor(settings) { | ||
this.api = axios.create({ | ||
baseURL: `${settings.OBJECT_STORAGE_URI}/`, | ||
httpAgent: new http.Agent({ keepAlive: true }), | ||
httpsAgent: new https.Agent({ keepAlive: true }), | ||
headers: { Authorization: `Bearer ${settings.OBJECT_STORAGE_TOKEN}` }, | ||
validateStatus: null | ||
}); | ||
} | ||
|
||
async requestRetry({ maxAttempts, delay, request, onResponse }) { | ||
let attempts = 0; | ||
let res; | ||
let err; | ||
while (attempts < maxAttempts) { | ||
err = null; | ||
res = null; | ||
attempts++; | ||
try { | ||
res = await request(); | ||
} catch (e) { | ||
err = e; | ||
} | ||
if (onResponse && onResponse(err, res)) { | ||
continue; | ||
} | ||
if (err || res.status >= 400) { | ||
await new Promise((resolve) => setTimeout(resolve, delay)); | ||
continue; | ||
} | ||
break; | ||
} | ||
if (err || res.status >= 400) { | ||
throw err || new Error(`HTTP error during object get: ${res.status} (${res.statusText})`); | ||
} | ||
return res; | ||
} | ||
|
||
async getObject(objectId) { | ||
const res = await this.requestRetry({ | ||
maxAttempts: 3, | ||
delay: 100, | ||
request: () => this.api.get(`/objects/${objectId}`, { responseType: 'stream' }) | ||
}); | ||
|
||
return await encryptor.decryptMessageContentStream(res.data); | ||
} | ||
|
||
async addObject(data) { | ||
let objectId = uuid.v4(); | ||
await this.requestRetry({ | ||
maxAttempts: 3, | ||
delay: 100, | ||
request: () => this.api.put( | ||
`/objects/${objectId}`, | ||
encryptor.encryptMessageContentStream(data), | ||
{ headers: { 'content-type': 'application/octet-stream' } } | ||
), | ||
onResponse: (err, res) => { | ||
if (!err && res.status === 409) { | ||
objectId = uuid.v4(); | ||
return true; | ||
} | ||
} | ||
}); | ||
|
||
return objectId; | ||
} | ||
} | ||
|
||
module.exports = ObjectStorage; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.