-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for kong >=0.10.x, resolve #63
- Loading branch information
Showing
11 changed files
with
221 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const isValueSameOneArrayElement = (a, b) => { | ||
return typeof a === 'string' | ||
&& Array.isArray(b) | ||
&& b.length === 1 | ||
&& !isValueDifferent(a, b[0]); | ||
}; | ||
|
||
const isValueDifferent = (a, b) => { | ||
if (Array.isArray(a)) { | ||
return !Array.isArray(b) | ||
|| a.length != b.length | ||
|| a.filter(x => b.indexOf(x) === -1).length > 0; | ||
} | ||
|
||
return JSON.stringify(a) !== JSON.stringify(b); | ||
} | ||
|
||
export default (defined, server) => { | ||
const keys = Object.keys(defined); | ||
|
||
return keys.reduce((changed, key) => { | ||
if (key === 'redirect_uri') { | ||
// hack for >=0.8.2 that allows multiple redirect_uris, | ||
// but accepts a string as well | ||
if (isValueSameOneArrayElement(defined[key], server[key])) { | ||
return changed; | ||
} | ||
} | ||
|
||
if (isValueDifferent(defined[key], server[key])) { | ||
return [...changed, key]; | ||
} | ||
|
||
return changed; | ||
}, []); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import semVer from 'semver'; | ||
|
||
const DEFINITION_V1 = 'v1'; | ||
const DEFINITION_V2 = 'v2'; | ||
|
||
const _removeUndefined = x => JSON.parse(JSON.stringify(x)); | ||
|
||
const _guessDefinitionVersion = (api) => { | ||
if (['hosts', 'uris', 'methods'].filter(x => api.attributes.hasOwnProperty(x)).length > 0) { | ||
return DEFINITION_V2; | ||
} | ||
|
||
return DEFINITION_V1; | ||
}; | ||
|
||
const _migrateV1toV2 = (api) => { | ||
const { | ||
request_host, | ||
request_path, | ||
strip_request_path, | ||
...oldAttributes, | ||
} = api.attributes; | ||
|
||
const newAttributes = { | ||
hosts: api.attributes.request_host ? [api.attributes.request_host] : undefined, | ||
uris: api.attributes.request_path ? [api.attributes.request_path] : undefined, | ||
strip_uri: api.attributes.strip_request_path, | ||
}; | ||
|
||
return _removeUndefined({ ...api, attributes: { ...oldAttributes, ...newAttributes }}); | ||
}; | ||
|
||
const _migrateApiDefinitionToVersion = (api, kongVersion) => { | ||
switch (_guessDefinitionVersion(api)) { | ||
case DEFINITION_V1: | ||
if (semVer.gte(kongVersion, '0.10.0')) { | ||
return _migrateV1toV2(api); | ||
} | ||
|
||
return api; | ||
default: | ||
return api; | ||
} | ||
} | ||
|
||
export const migrateApiDefinition = (api, fn) => world => fn(_migrateApiDefinitionToVersion(api, world.getVersion()), world); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.