Skip to content

Commit e770b0d

Browse files
committed
Merge pull request #501 from CodeNow/hotfix.fixhash
Hotfix.fixhash
2 parents d488e02 + ffd9021 commit e770b0d

File tree

3 files changed

+19
-30
lines changed

3 files changed

+19
-30
lines changed

lib/models/mongo/infra-code-version.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var last = require('101/last');
77
var isFunction = require('101/is-function');
88
var debug = require('debug')('runnable-api:infra-code-version:model');
99
var regexpQuote = require('regexp-quote');
10-
var bcrypt = require('bcrypt');
10+
var crypto = require('crypto');
1111
var jsonHash = require('json-stable-stringify');
1212
var dogstatsd = require('models/datadog');
1313
var uuid = require('uuid');
@@ -607,19 +607,16 @@ InfraCodeVersionSchema.methods.getHash = function (cb) {
607607

608608

609609
function hashString(data, cb) {
610-
// salt from require('bcrypt'.enSaltSync(1);
611-
var salt = '$2a$04$fLg/VU5eeDAUARmPVfyUo.';
612610
var start = new Date();
613-
bcrypt.hash(data
614-
.replace(/[\s\uFEFF\xA0]+\n/g, '\n') // trim whitespace after line
615-
.replace(/\n[\s\uFEFF\xA0]*\n/g, '\n') // remove blank lines
616-
.replace(/^[\s\uFEFF\xA0]*\n/g, '') // remove start of file blank lines
617-
.replace(/[\s\uFEFF\xA0]+$/g, '\n'), salt, function(err, hash) {
618-
if (err) { return cb(err); }
619-
dogstatsd.timing('api.infraCodeVersion.hashTime', new Date()-start, 1,
620-
['length:'+data.length]);
621-
cb(null, hash);
622-
});
611+
var md5 = crypto.createHash('md5');
612+
data = data
613+
.replace(/[\s\uFEFF\xA0]+\n/g, '\n') // trim whitespace after line
614+
.replace(/\n[\s\uFEFF\xA0]*\n/g, '\n') // remove blank lines
615+
.replace(/^[\s\uFEFF\xA0]*\n/g, '') // remove start of file blank lines
616+
.replace(/[\s\uFEFF\xA0]+$/g, '\n');
617+
var hash = md5.update(data, 'utf8').digest('hex');
618+
dogstatsd.timing('api.infraCodeVersion.hashTime', new Date()-start, 1, ['length:'+data.length]);
619+
cb(null, hash);
623620
}
624621

625622
var InfraCodeVersion = module.exports = mongoose.model('InfraCodeVersion', InfraCodeVersionSchema);

package.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"async": "^0.9.0",
1313
"aws-sdk": "^2.0.14",
1414
"batch": "^0.5.1",
15-
"bcrypt": "~0.7.5",
1615
"body-parser": "^1.4.3",
1716
"busboy": "^0.2.8",
1817
"callback-count": "~0.1.0",
@@ -30,8 +29,6 @@
3029
"dogerode": "0.0.3",
3130
"dogstatsyware": "0.0.1",
3231
"dotenv": "^0.4.0",
33-
"engine.io": "^1.3.1",
34-
"engine.io-client": "^1.3.1",
3532
"eson": "^0.5.0",
3633
"exec-sync": "^0.1.6",
3734
"express": "^4.8.3",
@@ -49,18 +46,13 @@
4946
"json-stable-stringify": "^1.0.0",
5047
"keypather": "^1.8.1",
5148
"middleware-flow": "^0.6.1",
52-
"mkdirp": "^0.5.0",
5349
"mongoose": "^3.8.13",
54-
"mongoose-text-search": "0.0.2",
5550
"mongoose-validator": "^1.0.0",
5651
"morgan": "^1.1.1",
5752
"multiparty": "^3.3.2",
5853
"newrelic": "^1.12.2",
5954
"node-dogstatsd": "0.0.5",
6055
"node-forge": "^0.6.12",
61-
"node-uuid": "~1.4.0",
62-
"nodemailer": "^0.7.0",
63-
"nodetime": "^0.8.15",
6456
"passport": "~0.2.0",
6557
"passport-github": "~0.1.5",
6658
"passport-strategy": "^1.0.0",
@@ -70,7 +62,6 @@
7062
"redis-types": "^0.2.3",
7163
"regexp-quote": "0.0.0",
7264
"request": "2.42.0",
73-
"rimraf": "^2.2.8",
7465
"rollbar": "^0.3.13",
7566
"runnable": "git+ssh://[email protected]:CodeNow/runnable-api-client#v0.38.16",
7667
"s3-stream-upload": "0.0.6",
@@ -98,6 +89,7 @@
9889
"nock": "^0.51.0",
9990
"nodemon": "^1.2.1",
10091
"require-inject": "^1.1.0",
92+
"rimraf": "^2.2.8",
10193
"sauron": "git+ssh://[email protected]:codenow/sauron#v0.0.8",
10294
"server-destroy": "^1.0.0"
10395
},

scripts/add-hash-to-files.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
require('loadenv')();
3-
var bcrypt = require('bcrypt');
3+
var crypto = require('crypto');
44
var InfraCodeVersion = require('models/mongo/infra-code-version.js');
55
var debug = require('debug')('script');
66
var mongoose = require('mongoose');
@@ -24,21 +24,21 @@ function getAllInfra (cb) {
2424
'files': {
2525
$elemMatch: {
2626
isDir: false,
27-
hash: { $exists: false }
27+
hash: { $regex: /^\$/ } // find only bcrypt files
2828
}
2929
}
3030
}, cb);
3131
}
3232

3333
function hashString(data, cb) {
34-
debug('hashString');
35-
// salt from require('bcrypt'.enSaltSync(1);
36-
var salt = '$2a$04$fLg/VU5eeDAUARmPVfyUo.';
37-
bcrypt.hash(data
34+
var md5 = crypto.createHash('md5');
35+
data = data
3836
.replace(/[\s\uFEFF\xA0]+\n/g, '\n') // trim whitespace after line
3937
.replace(/\n[\s\uFEFF\xA0]*\n/g, '\n') // remove blank lines
4038
.replace(/^[\s\uFEFF\xA0]*\n/g, '') // remove start of file blank lines
41-
.replace(/[\s\uFEFF\xA0]+$/g, '\n'), salt, cb);
39+
.replace(/[\s\uFEFF\xA0]+$/g, '\n');
40+
var hash = md5.update(data, 'utf8').digest('hex');
41+
cb(null, hash);
4242
}
4343

4444
function eachInfra (infras, cb) {
@@ -52,7 +52,7 @@ function eachInfra (infras, cb) {
5252
// for each file
5353

5454
async.each(infra.files, function(file, cb) {
55-
if(file.isDir || file.hash) { return cb(); }
55+
if(file.isDir) { return cb(); }
5656

5757
debug('eachInfra:infra:file', infra._id, file._id);
5858
var filePath = file.Key.substr(file.Key.indexOf('/source')+7);

0 commit comments

Comments
 (0)