Skip to content

Commit

Permalink
Merge pull request #38 from lendingblock/master
Browse files Browse the repository at this point in the history
0.3.2
  • Loading branch information
lsbardel authored Sep 4, 2018
2 parents fd33259 + a4cf41c commit 3645189
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion kong/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Asynchronous Kong client"""

__version__ = '0.3.1'
__version__ = '0.3.2'
3 changes: 3 additions & 0 deletions kong/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ def __init__(self, root, data):
def __getitem__(self, item):
return self.data[item]

def __contains__(self, item):
return item in self.data

@property
def cli(self):
return self.root.cli
Expand Down
17 changes: 15 additions & 2 deletions kong/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ def get_list(self, **params):
url = '%s/%s' % (self.root.url, self.name)
return self.execute(url, params=params, wrap=self.wrap_list)

async def apply_json(self, data):
async def apply_json(self, data, **kwargs):
if not isinstance(data, list):
data = [data]
plugins = await self.get_list()
plugins = await self.get_list(**kwargs)
if not kwargs:
plugins = [p for p in plugins if self.root_plugin(p)]
plugins = dict(((p['name'], p) for p in plugins))
result = []
for entry in data:
Expand All @@ -36,6 +38,9 @@ async def apply_json(self, data):
await self.delete(entry['id'])
return result

def root_plugin(self, plugin):
return 'service_id' not in plugin and 'route_id' not in plugin

async def preprocess_parameters(self, params):
await anonymous(self.cli, params)
preprocessor = PLUGIN_PREPROCESSORS.get(params.get('name'))
Expand All @@ -62,6 +67,10 @@ async def create(self, skip_error=None, **params):
wrap=self.wrap, skip_error=skip_error
)

async def apply_json(self, data, **kwargs):
kwargs['service_id'] = self.root.id
return await super().apply_json(data, **kwargs)


class RoutePlugins(PluginMixin, CrudComponent):
"""Plugins associated with a Route
Expand All @@ -74,6 +83,10 @@ async def create(self, skip_error=None, **params):
wrap=self.wrap, skip_error=skip_error
)

async def apply_json(self, data, **kwargs):
kwargs['route_id'] = self.root.id
return await super().apply_json(data, **kwargs)


class Plugin(KongEntity):
pass
Expand Down

0 comments on commit 3645189

Please sign in to comment.