Created
April 1, 2017 17:17
-
-
Save boris317/56bd2c71afb521c010446e76a23ebf5a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
let plugins = getPlugins() | |
.flatMap(p => p) | |
// Group plugins by consumer_id or app_id | |
.reduce((obj, p) => { | |
let id = p.consumer_id || p.api_id; | |
if (id in obj) { | |
obj[id].push(p); | |
} else { | |
obj[id] = [p]; | |
} | |
return obj; | |
}, {}) | |
.shareReplay(1) | |
.repeat(); | |
expose.$consumers = getConsumers() | |
.flatMap(c => c) | |
.flatMap(insertAcls) | |
.zip(plugins, insertPlugins) | |
.reduce(keyByCustomId, {}); | |
function insertPlugins(obj, plugins) { | |
if (obj.id in plugins) { | |
obj.plugins = plugins[obj.id]; | |
} | |
return obj; | |
} | |
function insertAcls(consumer) { | |
var resource = kong | |
.consumers(consumer.id) | |
.acls(); | |
return getResource(resource) | |
.map(acls => { | |
consumer.acls = acls; | |
return consumer; | |
}); | |
} | |
function getResource(kongResource) { | |
return kongResource | |
.get({size: 100000}) | |
.retry(2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment