Skip to content

Instantly share code, notes, and snippets.

@boris317
Created April 1, 2017 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boris317/56bd2c71afb521c010446e76a23ebf5a to your computer and use it in GitHub Desktop.
Save boris317/56bd2c71afb521c010446e76a23ebf5a to your computer and use it in GitHub Desktop.
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