Comparing version 1.2.25 to 1.3.0
@@ -1540,3 +1540,3 @@ { | ||
"client_id": "4u#6&Wn22R&2U^*zW^&sK4&BwhVJZv9u", | ||
"redirect_uri": "http://irrelevant-domain.com", | ||
"redirect_uri": ["http://irrelevant-domain.com", "http://irrelevant-domain.comddd"], | ||
"name": "Marketplace-Leads", | ||
@@ -1550,3 +1550,3 @@ "client_secret": "pjR6MVdE5F&KNaF!7FV5Z$JgUWw!2aQf" | ||
"client_id": "NWJTEr0iZZT2hCcbyEB52NRHbPaUx5LO", | ||
"redirect_uri": "http://www.mybuilder.com/irrelevant-url", | ||
"redirect_uri": "http://www.mybuilder.com/irrelevant-url232", | ||
"name": "Marketplace-Leads", | ||
@@ -1553,0 +1553,0 @@ "client_secret": "0Wh6PsLv9UAMFl9yXxpS3aS9Z3RnTLX0" |
@@ -18,2 +18,3 @@ 'use strict'; | ||
var pluginSchemasCache = undefined; | ||
var kongVersionCache = undefined; | ||
var resultsCache = {}; | ||
@@ -78,2 +79,13 @@ | ||
}, | ||
fetchKongVersion: function fetchKongVersion() { | ||
if (kongVersionCache) { | ||
return Promise.resolve(kongVersionCache); | ||
} | ||
return getPaginatedJson(router({ name: 'root' })).then(function (json) { | ||
return Promise.resolve(json.version); | ||
}).then(function (version) { | ||
return kongVersionCache = version; | ||
}); | ||
}, | ||
requestEndpoint: function requestEndpoint(endpoint, params) { | ||
@@ -80,0 +92,0 @@ resultsCache = {}; |
@@ -31,2 +31,8 @@ 'use strict'; | ||
var _migrate = require('./migrate'); | ||
var _diff = require('./diff'); | ||
var _diff2 = _interopRequireDefault(_diff); | ||
var _actions = require('./actions'); | ||
@@ -204,4 +210,9 @@ | ||
var plugins = _ref.plugins; | ||
var version = _ref.version; | ||
var world = { | ||
getVersion: function getVersion() { | ||
return version; | ||
}, | ||
hasApi: function hasApi(apiName) { | ||
@@ -371,9 +382,3 @@ return Array.isArray(apis) && apis.some(function (api) { | ||
isApiUpToDate: function isApiUpToDate(api) { | ||
var current = world.getApi(api.name); | ||
var different = Object.keys(api.attributes).filter(function (key) { | ||
return api.attributes[key] !== current[key]; | ||
}); | ||
return different.length == 0; | ||
return (0, _diff2.default)(api.attributes, world.getApi(api.name)).length == 0; | ||
}, | ||
@@ -387,8 +392,2 @@ | ||
var diff = function diff(a, b) { | ||
return Object.keys(a).filter(function (key) { | ||
return JSON.stringify(a[key]) !== JSON.stringify(b[key]); | ||
}); | ||
}; | ||
var current = world.getPlugin(apiName, plugin.name); | ||
@@ -402,3 +401,3 @@ | ||
return diff(config, current.config).length === 0 && diff(rest, current).length === 0; | ||
return (0, _diff2.default)(config, current.config).length === 0 && (0, _diff2.default)(rest, current).length === 0; | ||
}, | ||
@@ -412,8 +411,2 @@ | ||
var diff = function diff(a, b) { | ||
return Object.keys(a).filter(function (key) { | ||
return JSON.stringify(a[key]) !== JSON.stringify(b[key]); | ||
}); | ||
}; | ||
var current = world.getGlobalPlugin(plugin.name); | ||
@@ -427,3 +420,3 @@ | ||
return diff(config, current.config).length === 0 && diff(rest, current).length === 0; | ||
return (0, _diff2.default)(config, current.config).length === 0 && (0, _diff2.default)(rest, current).length === 0; | ||
}, | ||
@@ -434,7 +427,3 @@ | ||
var different = Object.keys(credential.attributes).filter(function (key) { | ||
return JSON.stringify(credential.attributes[key]) !== JSON.stringify(current[key]); | ||
}); | ||
return different.length === 0; | ||
return (0, _diff2.default)(credential.attributes, current).length === 0; | ||
} | ||
@@ -465,3 +454,3 @@ }; | ||
return function (world) { | ||
return (0, _migrate.migrateApiDefinition)(api, function (api, world) { | ||
if (api.ensure == 'removed') { | ||
@@ -482,3 +471,3 @@ return world.hasApi(api.name) ? (0, _actions.removeApi)(api.name) : (0, _actions.noop)(); | ||
return (0, _actions.createApi)(api.name, api.attributes); | ||
}; | ||
}); | ||
} | ||
@@ -485,0 +474,0 @@ |
@@ -25,3 +25,4 @@ 'use strict'; | ||
var fetchConsumerAcls = _ref.fetchConsumerAcls; | ||
var apis, apisWithPlugins, consumers, consumersWithCredentialsAndAcls, allPlugins, globalPlugins; | ||
var fetchKongVersion = _ref.fetchKongVersion; | ||
var version, apis, apisWithPlugins, consumers, consumersWithCredentialsAndAcls, allPlugins, globalPlugins; | ||
return regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
@@ -32,7 +33,12 @@ while (1) { | ||
_context3.next = 2; | ||
return fetchKongVersion(); | ||
case 2: | ||
version = _context3.sent; | ||
_context3.next = 5; | ||
return fetchApis(); | ||
case 2: | ||
case 5: | ||
apis = _context3.sent; | ||
_context3.next = 5; | ||
_context3.next = 8; | ||
return Promise.all(apis.map((function () { | ||
@@ -65,10 +71,10 @@ var ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(item) { | ||
case 5: | ||
case 8: | ||
apisWithPlugins = _context3.sent; | ||
_context3.next = 8; | ||
_context3.next = 11; | ||
return fetchConsumers(); | ||
case 8: | ||
case 11: | ||
consumers = _context3.sent; | ||
_context3.next = 11; | ||
_context3.next = 14; | ||
return Promise.all(consumers.map((function () { | ||
@@ -130,8 +136,8 @@ var ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee2(consumer) { | ||
case 11: | ||
case 14: | ||
consumersWithCredentialsAndAcls = _context3.sent; | ||
_context3.next = 14; | ||
_context3.next = 17; | ||
return fetchGlobalPlugins(); | ||
case 14: | ||
case 17: | ||
allPlugins = _context3.sent; | ||
@@ -144,6 +150,7 @@ globalPlugins = allPlugins.filter(function (plugin) { | ||
consumers: consumersWithCredentialsAndAcls, | ||
plugins: globalPlugins | ||
plugins: globalPlugins, | ||
version: version | ||
}); | ||
case 17: | ||
case 20: | ||
case 'end': | ||
@@ -150,0 +157,0 @@ return _context3.stop(); |
@@ -11,2 +11,6 @@ 'use strict'; | ||
var _semver = require('semver'); | ||
var _semver2 = _interopRequireDefault(_semver); | ||
var _kongState = require('./kongState'); | ||
@@ -28,7 +32,8 @@ | ||
case 0: | ||
return _context.abrupt('return', Promise.all([(0, _kongState2.default)(adminApi), adminApi.fetchPluginSchemas()]).then(function (_ref) { | ||
var _ref2 = _slicedToArray(_ref, 2); | ||
return _context.abrupt('return', Promise.all([(0, _kongState2.default)(adminApi), adminApi.fetchPluginSchemas(), adminApi.fetchKongVersion()]).then(function (_ref) { | ||
var _ref2 = _slicedToArray(_ref, 3); | ||
var state = _ref2[0]; | ||
var schemas = _ref2[1]; | ||
var version = _ref2[2]; | ||
@@ -46,3 +51,3 @@ var prepareConfig = function prepareConfig(plugin, config) { | ||
return { | ||
apis: parseApis(state.apis, parseApiPluginsForSchemes), | ||
apis: parseApis(state.apis, parseApiPluginsForSchemes, version), | ||
consumers: parseConsumers(state.consumers), | ||
@@ -124,3 +129,11 @@ plugins: parsePluginsForSchemes(state.plugins) | ||
function parseApis(apis, parseApiPlugins) { | ||
function parseApis(apis, parseApiPlugins, kongVersion) { | ||
if (_semver2.default.gte(kongVersion, '0.10.0')) { | ||
return parseApisV10(apis, parseApiPlugins); | ||
} | ||
return parseApisBeforeV10(apis, parseApiPlugins); | ||
} | ||
function parseApisBeforeV10(apis, parseApiPlugins) { | ||
return apis.map(function (_ref8) { | ||
@@ -155,26 +168,40 @@ var name = _ref8.name; | ||
function parseApiPlugins(plugins, prepareConfig) { | ||
if (!Array.isArray(plugins)) { | ||
return []; | ||
} | ||
return plugins.map(function (_ref9) { | ||
function parseApisV10(apis, parseApiPlugins) { | ||
return apis.map(function (_ref9) { | ||
var name = _ref9.name; | ||
var config = _ref9.config; | ||
var plugins = _ref9.plugins; | ||
var hosts = _ref9.hosts; | ||
var uris = _ref9.uris; | ||
var methods = _ref9.methods; | ||
var strip_uri = _ref9.strip_uri; | ||
var preserve_host = _ref9.preserve_host; | ||
var upstream_url = _ref9.upstream_url; | ||
var id = _ref9.id; | ||
var api_id = _ref9.api_id; | ||
var consumer_id = _ref9.consumer_id; | ||
var enabled = _ref9.enabled; | ||
var created_at = _ref9.created_at; | ||
var https_only = _ref9.https_only; | ||
var http_if_terminated = _ref9.http_if_terminated; | ||
var retries = _ref9.retries; | ||
var upstream_connect_timeout = _ref9.upstream_connect_timeout; | ||
var upstream_read_timeout = _ref9.upstream_read_timeout; | ||
var upstream_send_timeout = _ref9.upstream_send_timeout; | ||
return { | ||
name: name, | ||
plugins: parseApiPlugins(plugins), | ||
attributes: { | ||
enabled: enabled, | ||
config: prepareConfig(name, config) | ||
hosts: hosts, | ||
uris: uris, | ||
methods: methods, | ||
strip_uri: strip_uri, | ||
preserve_host: preserve_host, | ||
upstream_url: upstream_url, | ||
retries: retries, | ||
upstream_connect_timeout: upstream_connect_timeout, | ||
upstream_read_timeout: upstream_read_timeout, | ||
upstream_send_timeout: upstream_send_timeout, | ||
https_only: https_only, | ||
http_if_terminated: http_if_terminated | ||
}, | ||
_info: { | ||
id: id, | ||
//api_id, | ||
consumer_id: consumer_id, | ||
created_at: created_at | ||
@@ -186,3 +213,3 @@ } | ||
function parseGlobalPlugins(plugins, prepareConfig) { | ||
function parseApiPlugins(plugins, prepareConfig) { | ||
if (!Array.isArray(plugins)) { | ||
@@ -194,3 +221,2 @@ return []; | ||
var name = _ref10.name; | ||
var enabled = _ref10.enabled; | ||
var config = _ref10.config; | ||
@@ -200,2 +226,3 @@ var id = _ref10.id; | ||
var consumer_id = _ref10.consumer_id; | ||
var enabled = _ref10.enabled; | ||
var created_at = _ref10.created_at; | ||
@@ -211,2 +238,32 @@ | ||
id: id, | ||
//api_id, | ||
consumer_id: consumer_id, | ||
created_at: created_at | ||
} | ||
}; | ||
}); | ||
} | ||
function parseGlobalPlugins(plugins, prepareConfig) { | ||
if (!Array.isArray(plugins)) { | ||
return []; | ||
} | ||
return plugins.map(function (_ref11) { | ||
var name = _ref11.name; | ||
var enabled = _ref11.enabled; | ||
var config = _ref11.config; | ||
var id = _ref11.id; | ||
var api_id = _ref11.api_id; | ||
var consumer_id = _ref11.consumer_id; | ||
var created_at = _ref11.created_at; | ||
return { | ||
name: name, | ||
attributes: { | ||
enabled: enabled, | ||
config: prepareConfig(name, config) | ||
}, | ||
_info: { | ||
id: id, | ||
api_id: api_id, | ||
@@ -213,0 +270,0 @@ consumer_id: consumer_id, |
@@ -45,2 +45,5 @@ 'use strict'; | ||
case 'root': | ||
return '' + adminApiRoot; | ||
default: | ||
@@ -47,0 +50,0 @@ throw new Error('Unknown route "' + name + '"'); |
{ | ||
"name": "kongfig", | ||
"version": "1.2.25", | ||
"version": "1.3.0", | ||
"description": "A tool for Kong to allow declarative configuration.", | ||
@@ -28,3 +28,4 @@ "repository": "https://github.com/mybuilder/kongfig", | ||
"object-assign": "^4.0.1", | ||
"prettyjson": "^1.1.3" | ||
"prettyjson": "^1.1.3", | ||
"semver": "^5.3.0" | ||
}, | ||
@@ -31,0 +32,0 @@ "devDependencies": { |
@@ -81,7 +81,15 @@ <p align="center"> | ||
attributes: | ||
request_host: | ||
request_path: | ||
strip_request_path: | ||
preserve_host: | ||
upstream_url: # (required) | ||
upstream_url: string # (required) | ||
hosts: [string] | ||
uris: [string] | ||
methods: ["POST", "GET"] | ||
strip_uri: bool | ||
preserve_host: bool | ||
retries: int | ||
upstream_connect_timeout: int | ||
upstream_read_timeout: int | ||
upstream_send_timeout: int | ||
https_only: bool # (required) | ||
http_if_terminated: bool | ||
``` | ||
@@ -217,3 +225,3 @@ | ||
client_secret: | ||
redirect_uri: # required by kong | ||
redirect_uri: string | [string] # required by kong | ||
``` | ||
@@ -290,3 +298,3 @@ | ||
custom_jwt: | ||
id: "key" # credential id name | ||
id: "key" # credential id name | ||
``` | ||
@@ -320,2 +328,25 @@ | ||
## Migrating from Kong <=0.9 to >=0.10 | ||
kongfig translates pre `>=0.10` kong config files automatically when applying them. | ||
So you can export your config from `<=0.9` kong instance by running: | ||
```bash | ||
kongfig dump --host kong_9:8001 > config.v9.yml | ||
``` | ||
Then apply it to kong `0.10` instance | ||
```bash | ||
kongfig apply --path config.v9.yml --host kong_10:8001 | ||
``` | ||
`apis` endpoint changed between `<=0.9` and `>=0.10`: | ||
* `request_host: string` to `hosts: [string]` | ||
* `request_path: string` to `uris: [string]` | ||
* `strip_request_path: bool` -> `strip_uri: bool` | ||
* Adds `methods`, `retries`, `upstream_connect_timeout`, `upstream_read_timeout`, `upstream_send_timeout`, `https_only`, `http_if_terminated` | ||
--- | ||
@@ -322,0 +353,0 @@ Created by [MyBuilder](http://www.mybuilder.com/) - Check out our [blog](http://tech.mybuilder.com/) for more information and our other open-source projects. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
277230
36
3352
356
9
+ Addedsemver@^5.3.0
+ Addedsemver@5.7.2(transitive)