@codefresh-io/service-base 4.0.5 → 4.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@
3
3
  const _ = require('lodash');
4
4
  const Promise = require('bluebird');
5
5
  const uuid = require('node-uuid');
6
- const cryptoAsync = require('@ronomon/crypto-async');
6
+ const crypto = require('crypto');
7
7
 
8
8
  const config = require('../config');
9
9
  const mongoClient = require('../mongo');
@@ -12,6 +12,19 @@ const ALGORITHM = 'AES-256-CTR';
12
12
  const CRYPTO_PREFIX = '$$$crypto$$$';
13
13
  const STRINGIFY_CRYPTO_PREFIX = '$$$crypto-obj$$$';
14
14
 
15
+ async function cipher(algorithm, encrypt, key, iv, data) {
16
+ if (encrypt) {
17
+ const cipherObject = crypto.createCipheriv(algorithm, key, iv);
18
+ let ciphertext = cipherObject.update(data, 'utf8', 'hex');
19
+ ciphertext += cipherObject.final('hex');
20
+ return ciphertext;
21
+ }
22
+ const decipher = crypto.createDecipheriv(algorithm, key, iv);
23
+ let plaintext = decipher.update(data, 'hex', 'utf8');
24
+ plaintext += decipher.final('utf8');
25
+ return plaintext;
26
+ }
27
+
15
28
  const Safe = function (safeModel) { // eslint-disable-line
16
29
  this.safeModel = safeModel;
17
30
  };
@@ -61,17 +74,14 @@ Safe.prototype.read_crypto = function (ciphertext) { // eslint-disable-line
61
74
  }
62
75
 
63
76
  const encrypt = 0; // 0 = Decrypt
64
- cryptoAsync.cipher(
65
- ALGORITHM, encrypt, key, iv, Buffer.from(ciphertext.slice(prefix.length), 'hex'),
66
- (error, plaintext) => {
67
- if (error) {
68
- deferred.reject(error);
69
- return;
70
- }
71
- const ret = plaintext.toString();
72
- deferred.resolve(shouldParse ? JSON.parse(ret) : ret);
73
- },
74
- );
77
+ cipher(ALGORITHM, encrypt, key, iv, Buffer.from(ciphertext.slice(prefix.length), 'hex')).then((plaintext) => {
78
+ const ret = plaintext.toString();
79
+ deferred.resolve(shouldParse ? JSON.parse(ret) : ret);
80
+ }).catch((error) => {
81
+ if (error) {
82
+ deferred.reject(error);
83
+ }
84
+ });
75
85
  return deferred.promise;
76
86
  };
77
87
 
@@ -93,16 +103,13 @@ Safe.prototype.write_crypto = function (plaintext) { // eslint-disable-line
93
103
  }
94
104
 
95
105
  const encrypt = 1; // 1 = Encrypt
96
- cryptoAsync.cipher(
97
- ALGORITHM, encrypt, key, iv, Buffer.from(textToEncrypt),
98
- (error, ciphertext) => {
99
- if (error) {
100
- deferred.reject(error);
101
- return;
102
- }
103
- deferred.resolve(`${prefix}${ciphertext.toString('hex')}`);
104
- },
105
- );
106
+ cipher(ALGORITHM, encrypt, key, iv, Buffer.from(textToEncrypt)).then((ciphertext) => {
107
+ deferred.resolve(`${prefix}${ciphertext.toString('hex')}`);
108
+ }).catch((error) => {
109
+ if (error) {
110
+ deferred.reject(error);
111
+ }
112
+ });
106
113
  return deferred.promise;
107
114
  };
108
115
 
package/infra/mongo.js CHANGED
@@ -22,10 +22,9 @@ class Mongo {
22
22
 
23
23
  const logger = require('cf-logs').Logger('codefresh:infra:mongo'); // eslint-disable-line
24
24
  this.logger = logger;
25
- logger.info(`Mongo got config ${JSON.stringify(config.mongo)}`);
25
+
26
26
  const { uri } = config.mongo;
27
27
  const dbName = config.mongo.dbName || getDbNameFromUri(uri);
28
- logger.info(`Use Uri ${uri} settings ${JSON.stringify(clientSettings)}, the dbName is ${dbName}`);
29
28
  return MongoClient.connect(uri, clientSettings)
30
29
  .then(async (client) => {
31
30
  this.client = client;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codefresh-io/service-base",
3
- "version": "4.0.5",
3
+ "version": "4.0.7",
4
4
  "main": "index.js",
5
5
  "description": "",
6
6
  "bin": {
@@ -30,12 +30,11 @@
30
30
  "homepage": "https://github.com/codefresh-io/service-base#readme",
31
31
  "dependencies": {
32
32
  "@codefresh-io/authenticated-entity": "^2.17.1",
33
- "@codefresh-io/cf-monitor": "^0.0.27",
33
+ "@codefresh-io/cf-monitor": "^0.0.29",
34
34
  "@codefresh-io/cf-openapi": "^0.7.20",
35
35
  "@codefresh-io/eventbus": "^2.0.0",
36
36
  "@codefresh-io/http-infra": "^1.8.15",
37
37
  "@codefresh-io/internal-service-config": "^1.0.3",
38
- "@ronomon/crypto-async": "^5.0.1",
39
38
  "@wegolook/joi-objectid": "^2.4.0",
40
39
  "ajv": "^6.10.0",
41
40
  "bluebird": "^3.5.3",