Comparing version 1.4.0 to 1.4.1
174
lib/core.js
@@ -8,6 +8,6 @@ 'use strict'; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
exports.getAclSchema = getAclSchema; | ||
@@ -47,6 +47,2 @@ exports.apis = apis; | ||
var _stateSelector = require('./stateSelector'); | ||
var _stateSelector2 = _interopRequireDefault(_stateSelector); | ||
var _diff = require('./diff'); | ||
@@ -92,3 +88,3 @@ | ||
var selectWorldStateBind = function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(adminApi, internalLogger) { | ||
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee2(adminApi, internalLogger) { | ||
var state; | ||
@@ -117,3 +113,3 @@ return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
return _context2.abrupt('return', function (f) { | ||
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { | ||
return _asyncToGenerator(regeneratorRuntime.mark(function _callee() { | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
@@ -123,3 +119,3 @@ while (1) { | ||
case 0: | ||
return _context.abrupt('return', f(_createWorld((0, _stateSelector2.default)(state)))); | ||
return _context.abrupt('return', f(_createWorld(state))); | ||
@@ -151,18 +147,6 @@ case 1: | ||
// there is an issue with dependency by other definitions to consumers | ||
// so they need to be added first and removed last | ||
var splitConsumersByRemoved = function splitConsumersByRemoved(consumers) { | ||
return (consumers || []).reduce(function (results, consumer) { | ||
if (consumer.ensure === 'removed') { | ||
return _extends({}, results, { removed: [].concat(_toConsumableArray(results.removed), [consumer]) }); | ||
} | ||
return _extends({}, results, { added: [].concat(_toConsumableArray(results.added), [consumer]) }); | ||
}, { removed: [], added: [] }); | ||
}; | ||
exports.default = function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(config, adminApi) { | ||
var _ref3 = _asyncToGenerator(regeneratorRuntime.mark(function _callee3(config, adminApi) { | ||
var logger = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {}; | ||
var internalLogger, splitConsumersConfig, actions; | ||
var internalLogger, actions; | ||
return regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
@@ -173,4 +157,3 @@ while (1) { | ||
internalLogger = logFanout(); | ||
splitConsumersConfig = splitConsumersByRemoved(config.consumers); | ||
actions = [].concat(_toConsumableArray(consumers(splitConsumersConfig.added)), _toConsumableArray(upstreams(config.upstreams)), _toConsumableArray(apis(config.apis)), _toConsumableArray(globalPlugins(config.plugins)), _toConsumableArray(consumers(splitConsumersConfig.removed))); | ||
actions = [].concat(_toConsumableArray(consumers(config.consumers)), _toConsumableArray(apis(config.apis)), _toConsumableArray(globalPlugins(config.plugins)), _toConsumableArray(upstreams(config.upstreams))); | ||
@@ -181,6 +164,6 @@ | ||
_context3.t0 = internalLogger; | ||
_context3.next = 7; | ||
_context3.next = 6; | ||
return adminApi.fetchKongVersion(); | ||
case 7: | ||
case 6: | ||
_context3.t1 = _context3.sent; | ||
@@ -195,6 +178,6 @@ _context3.t2 = { | ||
_context3.t3 = actions; | ||
_context3.next = 13; | ||
_context3.next = 12; | ||
return selectWorldStateBind(adminApi, internalLogger); | ||
case 13: | ||
case 12: | ||
_context3.t4 = _context3.sent; | ||
@@ -209,3 +192,3 @@ | ||
case 17: | ||
case 16: | ||
case 'end': | ||
@@ -292,3 +275,3 @@ return _context3.stop(); | ||
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() { | ||
return _asyncToGenerator(regeneratorRuntime.mark(function _callee4() { | ||
var params; | ||
@@ -355,3 +338,3 @@ return regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
return function (f) { | ||
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() { | ||
return _asyncToGenerator(regeneratorRuntime.mark(function _callee5() { | ||
var state; | ||
@@ -412,14 +395,14 @@ return regeneratorRuntime.wrap(function _callee5$(_context5) { | ||
}, | ||
getGlobalPlugin: function getGlobalPlugin(pluginName, pluginConsumerID) { | ||
getGlobalPlugin: function getGlobalPlugin(pluginName) { | ||
var plugin = plugins.find(function (plugin) { | ||
return plugin.api_id === undefined && plugin.name === pluginName && plugin._info.consumer_id == pluginConsumerID; | ||
return plugin.api_id === undefined && plugin.name === pluginName; | ||
}); | ||
(0, _invariant2.default)(plugin, 'Unable to find global plugin ' + pluginName + ' for consumer ' + pluginConsumerID); | ||
(0, _invariant2.default)(plugin, 'Unable to find global plugin ' + pluginName); | ||
return plugin; | ||
}, | ||
getPlugin: function getPlugin(apiName, pluginName, pluginConsumerID) { | ||
getPlugin: function getPlugin(apiName, pluginName) { | ||
var plugin = world.getApi(apiName).plugins.find(function (plugin) { | ||
return plugin.name == pluginName && plugin._info.consumer_id == pluginConsumerID; | ||
return plugin.name == pluginName; | ||
}); | ||
@@ -431,4 +414,4 @@ | ||
}, | ||
getPluginId: function getPluginId(apiName, pluginName, pluginConsumerID) { | ||
var pluginId = world.getPlugin(apiName, pluginName, pluginConsumerID)._info.id; | ||
getPluginId: function getPluginId(apiName, pluginName) { | ||
var pluginId = world.getPlugin(apiName, pluginName)._info.id; | ||
@@ -439,4 +422,4 @@ (0, _invariant2.default)(pluginId, 'Unable to find plugin id for ' + apiName + ' and ' + pluginName); | ||
}, | ||
getGlobalPluginId: function getGlobalPluginId(pluginName, pluginConsumerID) { | ||
var globalPluginId = world.getGlobalPlugin(pluginName, pluginConsumerID)._info.id; | ||
getGlobalPluginId: function getGlobalPluginId(pluginName) { | ||
var globalPluginId = world.getGlobalPlugin(pluginName)._info.id; | ||
@@ -447,12 +430,12 @@ (0, _invariant2.default)(globalPluginId, 'Unable to find global plugin id ' + pluginName); | ||
}, | ||
hasPlugin: function hasPlugin(apiName, pluginName, pluginConsumerID) { | ||
hasPlugin: function hasPlugin(apiName, pluginName) { | ||
return Array.isArray(apis) && apis.some(function (api) { | ||
return api.name === apiName && Array.isArray(api.plugins) && api.plugins.some(function (plugin) { | ||
return plugin.name == pluginName && plugin._info.consumer_id == pluginConsumerID; | ||
return plugin.name == pluginName; | ||
}); | ||
}); | ||
}, | ||
hasGlobalPlugin: function hasGlobalPlugin(pluginName, pluginConsumerID) { | ||
hasGlobalPlugin: function hasGlobalPlugin(pluginName) { | ||
return Array.isArray(plugins) && plugins.some(function (plugin) { | ||
return plugin.api_id === undefined && plugin.name === pluginName && plugin._info.consumer_id === pluginConsumerID; | ||
return plugin.api_id === undefined && plugin.name === pluginName; | ||
}); | ||
@@ -481,4 +464,2 @@ }, | ||
getConsumer: function getConsumer(username) { | ||
(0, _invariant2.default)(username, 'Username is required'); | ||
var consumer = consumers.find(function (c) { | ||
@@ -494,7 +475,5 @@ return c.username === username; | ||
getConsumerId: function getConsumerId(username) { | ||
(0, _invariant2.default)(username, 'Username is required'); | ||
var consumerId = world.getConsumer(username)._info.id; | ||
(0, _invariant2.default)(consumerId, 'Unable to find consumer id ' + username + ' ' + consumerId); | ||
(0, _invariant2.default)(consumerId, 'Unable to find consumer id ' + username); | ||
@@ -550,3 +529,3 @@ return consumerId; | ||
isApiPluginUpToDate: function isApiPluginUpToDate(apiName, plugin, consumerID) { | ||
isApiPluginUpToDate: function isApiPluginUpToDate(apiName, plugin) { | ||
if (false == plugin.hasOwnProperty('attributes')) { | ||
@@ -557,3 +536,3 @@ // of a plugin has no attributes, and its been added then it is up to date | ||
var current = world.getPlugin(apiName, plugin.name, consumerID); | ||
var current = world.getPlugin(apiName, plugin.name); | ||
var attributes = (0, _utils.normalize)(plugin.attributes); | ||
@@ -564,3 +543,3 @@ | ||
isGlobalPluginUpToDate: function isGlobalPluginUpToDate(plugin, consumerID) { | ||
isGlobalPluginUpToDate: function isGlobalPluginUpToDate(plugin) { | ||
if (false == plugin.hasOwnProperty('attributes')) { | ||
@@ -571,3 +550,3 @@ // of a plugin has no attributes, and its been added then it is up to date | ||
var current = world.getGlobalPlugin(plugin.name, consumerID); | ||
var current = world.getGlobalPlugin(plugin.name); | ||
var attributes = (0, _utils.normalize)(plugin.attributes); | ||
@@ -609,3 +588,14 @@ | ||
hasUpstreamTarget: function hasUpstreamTarget(upstreamName, targetName) { | ||
return !!world.getActiveUpstreamTarget(upstreamName, targetName); | ||
var target = null; | ||
var upstream = upstreams.find(function (upstream) { | ||
return upstream.name === upstreamName; | ||
}); | ||
if (upstream) { | ||
target = upstream.targets.find(function (target) { | ||
return target.target === targetName; | ||
}); | ||
} | ||
return target !== null; | ||
}, | ||
@@ -621,3 +611,3 @@ getUpstreamTarget: function getUpstreamTarget(upstreamName, targetName) { | ||
if (!target.attributes) { | ||
return true; | ||
return false; | ||
} | ||
@@ -631,5 +621,6 @@ | ||
return !!existing && (0, _diff2.default)(target.attributes, existing.attributes).length === 0; | ||
return !!existing && (0, _diff2.default)(target.attributes, existing.attributes); | ||
}, | ||
getActiveUpstreamTarget: function getActiveUpstreamTarget(upstreamName, targetName) { | ||
var target = null; | ||
var upstream = upstreams.find(function (upstream) { | ||
@@ -651,4 +642,6 @@ return upstream.name === upstreamName && Array.isArray(upstream.targets) && upstream.targets.some(function (target) { | ||
return _targets[0]; | ||
target = _targets[0].weight > 0 ? _targets[0] : null; | ||
} | ||
return target; | ||
} | ||
@@ -741,35 +734,2 @@ }; | ||
var swapConsumerReference = function swapConsumerReference(world, plugin) { | ||
if (!plugin.hasOwnProperty('attributes')) { | ||
return plugin; | ||
} | ||
var newPluginDef = plugin; | ||
if (plugin.attributes.hasOwnProperty('config') && plugin.attributes.config.anonymous_username) { | ||
var _plugin$attributes = plugin.attributes, | ||
_plugin$attributes$co = _plugin$attributes.config, | ||
anonymous_username = _plugin$attributes$co.anonymous_username, | ||
config = _objectWithoutProperties(_plugin$attributes$co, ['anonymous_username']), | ||
attributes = _objectWithoutProperties(_plugin$attributes, ['config']); | ||
var anonymous = world.getConsumerId(anonymous_username); | ||
newPluginDef = _extends({}, plugin, { attributes: _extends({ config: _extends({ anonymous: anonymous }, config) }, attributes) }); | ||
} | ||
if (plugin.attributes.hasOwnProperty('username') && plugin.attributes.username) { | ||
var _plugin$attributes2 = plugin.attributes, | ||
username = _plugin$attributes2.username, | ||
_attributes = _objectWithoutProperties(_plugin$attributes2, ['username']); // remove username | ||
var consumer_id = world.getConsumerId(username); | ||
newPluginDef = _extends({}, plugin, { attributes: _extends({ consumer_id: consumer_id }, _attributes) }); | ||
} | ||
return newPluginDef; | ||
}; | ||
function _plugin(apiName, plugin) { | ||
@@ -779,8 +739,5 @@ validateEnsure(plugin.ensure); | ||
return function (world) { | ||
var finalPlugin = swapConsumerReference(world, plugin); | ||
var consumerID = finalPlugin.attributes && finalPlugin.attributes.consumer_id; | ||
if (plugin.ensure == 'removed') { | ||
if (world.hasPlugin(apiName, plugin.name, consumerID)) { | ||
return (0, _actions.removeApiPlugin)(world.getApiId(apiName), world.getPluginId(apiName, plugin.name, consumerID)); | ||
if (world.hasPlugin(apiName, plugin.name)) { | ||
return (0, _actions.removeApiPlugin)(world.getApiId(apiName), world.getPluginId(apiName, plugin.name)); | ||
} | ||
@@ -791,11 +748,11 @@ | ||
if (world.hasPlugin(apiName, plugin.name, consumerID)) { | ||
if (world.isApiPluginUpToDate(apiName, plugin, consumerID)) { | ||
if (world.hasPlugin(apiName, plugin.name)) { | ||
if (world.isApiPluginUpToDate(apiName, plugin)) { | ||
return (0, _actions.noop)({ type: 'noop-plugin', plugin: plugin }); | ||
} | ||
return (0, _actions.updateApiPlugin)(world.getApiId(apiName), world.getPluginId(apiName, plugin.name, consumerID), finalPlugin.attributes); | ||
return (0, _actions.updateApiPlugin)(world.getApiId(apiName), world.getPluginId(apiName, plugin.name), plugin.attributes); | ||
} | ||
return (0, _actions.addApiPlugin)(world.getApiId(apiName), plugin.name, finalPlugin.attributes); | ||
return (0, _actions.addApiPlugin)(world.getApiId(apiName), plugin.name, plugin.attributes); | ||
}; | ||
@@ -808,8 +765,5 @@ } | ||
return function (world) { | ||
var finalPlugin = swapConsumerReference(world, plugin); | ||
var consumerID = finalPlugin.attributes && finalPlugin.attributes.consumer_id; | ||
if (plugin.ensure == 'removed') { | ||
if (world.hasGlobalPlugin(plugin.name, consumerID)) { | ||
return (0, _actions.removeGlobalPlugin)(world.getGlobalPluginId(plugin.name, consumerID)); | ||
if (world.hasGlobalPlugin(plugin.name)) { | ||
return (0, _actions.removeGlobalPlugin)(world.getGlobalPluginId(plugin.name)); | ||
} | ||
@@ -820,11 +774,11 @@ | ||
if (world.hasGlobalPlugin(plugin.name, consumerID)) { | ||
if (world.isGlobalPluginUpToDate(plugin, consumerID)) { | ||
if (world.hasGlobalPlugin(plugin.name)) { | ||
if (world.isGlobalPluginUpToDate(plugin)) { | ||
return (0, _actions.noop)({ type: 'noop-global-plugin', plugin: plugin }); | ||
} | ||
return (0, _actions.updateGlobalPlugin)(world.getGlobalPluginId(plugin.name, consumerID), finalPlugin.attributes); | ||
return (0, _actions.updateGlobalPlugin)(world.getGlobalPluginId(plugin.name), plugin.attributes); | ||
} | ||
return (0, _actions.addGlobalPlugin)(plugin.name, finalPlugin.attributes); | ||
return (0, _actions.addGlobalPlugin)(plugin.name, plugin.attributes); | ||
}; | ||
@@ -1000,3 +954,3 @@ } | ||
return function (world) { | ||
if (target.ensure == 'removed' || target.attributes && target.attributes.weight === 0) { | ||
if (target.ensure == 'removed') { | ||
if (world.hasUpstreamTarget(upstreamName, target.target)) { | ||
@@ -1003,0 +957,0 @@ return (0, _upstreams.removeUpstreamTarget)(world.getUpstreamId(upstreamName), target.target); |
@@ -18,3 +18,3 @@ 'use strict'; | ||
exports.default = function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(_ref2) { | ||
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee4(_ref2) { | ||
var fetchApis = _ref2.fetchApis, | ||
@@ -46,3 +46,3 @@ fetchPlugins = _ref2.fetchPlugins, | ||
return Promise.all(apis.map(function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(item) { | ||
var _ref3 = _asyncToGenerator(regeneratorRuntime.mark(function _callee(item) { | ||
var plugins; | ||
@@ -82,3 +82,3 @@ return regeneratorRuntime.wrap(function _callee$(_context) { | ||
return Promise.all(consumers.map(function () { | ||
var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(consumer) { | ||
var _ref4 = _asyncToGenerator(regeneratorRuntime.mark(function _callee2(consumer) { | ||
var allCredentials, aclsFetched, consumerWithCredentials; | ||
@@ -145,3 +145,3 @@ return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
globalPlugins = allPlugins.filter(function (plugin) { | ||
return plugin.api_id === undefined; | ||
return plugin.api_id === undefined && plugin.consumer_id === undefined; | ||
}); | ||
@@ -155,3 +155,3 @@ _context4.next = 21; | ||
return Promise.all(upstreams.map(function () { | ||
var _ref7 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(item) { | ||
var _ref7 = _asyncToGenerator(regeneratorRuntime.mark(function _callee3(item) { | ||
var targets; | ||
@@ -158,0 +158,0 @@ return regeneratorRuntime.wrap(function _callee3$(_context3) { |
@@ -22,6 +22,2 @@ 'use strict'; | ||
var _stateSelector = require('./stateSelector'); | ||
var _stateSelector2 = _interopRequireDefault(_stateSelector); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -34,3 +30,3 @@ | ||
exports.default = function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(adminApi) { | ||
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(adminApi) { | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
@@ -46,3 +42,3 @@ while (1) { | ||
return (0, _stateSelector2.default)({ | ||
return { | ||
_info: { version: version }, | ||
@@ -53,3 +49,3 @@ apis: parseApis(state.apis, version), | ||
upstreams: (0, _upstreams.parseUpstreams)(state.upstreams) | ||
}); | ||
}; | ||
})); | ||
@@ -246,3 +242,2 @@ | ||
enabled: enabled, | ||
consumer_id: consumer_id, | ||
config: stripConfig(config) | ||
@@ -280,3 +275,2 @@ }, | ||
enabled: enabled, | ||
consumer_id: consumer_id, | ||
config: stripConfig(config) | ||
@@ -283,0 +277,0 @@ }, |
@@ -24,5 +24,3 @@ 'use strict'; | ||
case 'add-upstream-target': | ||
return [].concat(_toConsumableArray(state.filter(function (target) { | ||
return target.target !== params.targetName; | ||
})), [(0, _upstreams.parseTarget)(content)]); | ||
return [].concat(_toConsumableArray(state), [(0, _upstreams.parseTarget)(content)]); | ||
case 'update-upstream-target': | ||
@@ -29,0 +27,0 @@ return state.map(function (state) { |
{ | ||
"name": "kongfig", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "A tool for Kong to allow declarative configuration.", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/mybuilder/kongfig", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
619804
5067
1
73