Skip to content

Commit 0733cd1

Browse files
committed
Merge pull request #425 from CodeNow/only-cache-inspect-state
mongo doesn't like dotted keys
2 parents fafa9b7 + 31452b7 commit 0733cd1

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

lib/models/mongo/instance.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var Boom = require('dat-middleware').Boom;
1919
var keypather = require('keypather')();
2020
var isFunction = require('101/is-function');
2121
var createCount = require('callback-count');
22+
var removeDottedKeys = require('remove-dotted-keys');
2223

2324
var InstanceSchema = require('models/mongo/schemas/instance');
2425

@@ -159,7 +160,6 @@ InstanceSchema.methods.populateModels = function (cb) {
159160
}
160161
};
161162

162-
163163
/**
164164
* findAndModify container with containerInpect data (and dockerHost)
165165
* @param {Object} containerInspect docker
@@ -172,7 +172,7 @@ InstanceSchema.methods.modifySetContainer = function (containerInspect, dockerHo
172172
var updateFields = { // set it on the model, mongoose can cast things
173173
'container.dockerHost' : dockerHost,
174174
'container.dockerContainer': info.Id,
175-
'container.inspect': info
175+
'container.inspect' : removeDottedKeys(info)
176176
};
177177
// don't override ports if they are undefined so that hosts can be cleaned up
178178
var ports = info.NetworkSettings && info.NetworkSettings.Ports;

lib/remove-dotted-keys.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
var isObject = require('101/is-object');
3+
4+
// modifies original object
5+
module.exports = function removeDottedKeys (obj) {
6+
if (isObject(obj)) {
7+
try {
8+
Object.keys(obj).forEach(function (key) {
9+
if (~key.indexOf('.')) {
10+
delete obj[key];
11+
}
12+
removeDottedKeys(obj[key]);
13+
});
14+
}
15+
catch (err) {
16+
// object.keys on non-object
17+
// just skip it.
18+
}
19+
}
20+
return obj;
21+
};

0 commit comments

Comments
 (0)