Skip to content

Commit

Permalink
Merge pull request #15 from devartis/v0.1.7
Browse files Browse the repository at this point in the history
V0.1.7
  • Loading branch information
SebastianHGonzalez authored Jun 12, 2018
2 parents dea4b83 + 75fc15f commit d391f23
Show file tree
Hide file tree
Showing 11 changed files with 384 additions and 228 deletions.
211 changes: 121 additions & 90 deletions kong/kong_clients.py

Large diffs are not rendered by default.

151 changes: 135 additions & 16 deletions kong/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,18 @@ def __init__(self, name, **kwargs):
self.__setattr__(k, val)

@abstractmethod
def validate_schema(self, **kwargs):
def validate_obligatory_parameters(self, **kwargs):
pass

@abstractmethod
def validate_semi_optional_parameters(self, **kwargs): # pylint:disable=invalid-name
pass

def validate_schema(self, **kwargs):
self.validate_obligatory_parameters(**kwargs)
self.validate_semi_optional_parameters(**kwargs)
return kwargs

@property
@abstractmethod
def allowed_parameters(self):
Expand All @@ -34,7 +43,7 @@ def validate_parameter(self, parameter, value):

if not isinstance(value, (str, int, bool, list, dict)):
raise ValueError('invalid value: %s value must be str, int, '
'bool, list or dict' % parameter)
'bool, _perform_list or dict' % parameter)

def as_dict(self):
return self.__dict__.copy()
Expand All @@ -57,21 +66,15 @@ def allowed_parameters(self):
'upstream_send_timeout', 'upstream_read_timeout',\
'created_at'

@staticmethod
def satisfy_semi_optional_parameters(**kwargs): # pylint: disable=invalid-name
return 'hosts' in kwargs\
or 'uris' in kwargs\
or 'methods' in kwargs

@staticmethod
def satisfy_obligatory_parameters(**kwargs):
return 'upstream_url' in kwargs
def validate_obligatory_parameters(self, **kwargs):
if 'upstream_url' not in kwargs:
raise SchemaViolation('name and upstream_url must be provided to _perform_create')

def validate_schema(self, **kwargs):
if not self.satisfy_obligatory_parameters(**kwargs):
raise SchemaViolation('name and upstream_url must be provided to create')
if not self.satisfy_semi_optional_parameters(**kwargs):
raise SchemaViolation('uris, methods or hosts must be provided to create')
def validate_semi_optional_parameters(self, **kwargs):
if not ('hosts' in kwargs
or 'uris' in kwargs
or 'methods' in kwargs):
raise SchemaViolation('uris, methods or hosts must be provided to _perform_create')

return kwargs

Expand All @@ -90,6 +93,12 @@ def __normalize_uri(uri):

class ServiceData(ObjectData):

def validate_semi_optional_parameters(self, **kwargs):
pass

def validate_obligatory_parameters(self, **kwargs):
pass

def validate_schema(self, **kwargs):

if 'url' not in kwargs:
Expand Down Expand Up @@ -127,3 +136,113 @@ def allowed_parameters(self):
@property
def url(self):
return Url(scheme=self.protocol, host=self.host, port=self.port, path=self.path).url


class PluginData(ObjectData):
def validate_semi_optional_parameters(self, **kwargs):
pass

def validate_obligatory_parameters(self, **kwargs):
if "name" not in kwargs:
raise SchemaViolation('name must be provided to _perform_create')

@property
def allowed_parameters(self):
return "id", "service_id", "consumer_id",\
"name", "config", "enabled",\
"created_at"


class ConsumerData(ObjectData):
def validate_obligatory_parameters(self, **kwargs):
pass

@property
def allowed_parameters(self):
return "id", "username", "custom_id"

def validate_semi_optional_parameters(self, **kwargs):
if ("username" not in kwargs) and ("custom_id" not in kwargs):
raise SchemaViolation('at least one of username or '
'custom_id must be provided '
'to _perform_create')


class RouteData(ObjectData):

def validate_semi_optional_parameters(self, **kwargs):
if not ('hosts' in kwargs
or 'paths' in kwargs
or 'methods' in kwargs):
raise SchemaViolation('uris, methods or hosts must be provided to _perform_create')

def validate_obligatory_parameters(self, **kwargs):
pass

@property
def allowed_parameters(self):
return "id", "created_at", "updated_at", \
"protocols", "methods", "hosts", \
"paths", "regex_priority", "strip_path", \
"preserve_host", "service"


class TargetData(ObjectData):
def validate_semi_optional_parameters(self, **kwargs):
pass

def validate_obligatory_parameters(self, **kwargs):
if "target" not in kwargs:
raise SchemaViolation("target must be provided to _perform_create")

@property
def allowed_parameters(self):
return "id", "target", "weight", \
"upstream_id", "created_at"


class UpstreamData(ObjectData):
@staticmethod
def allowed_update_params():
return [
'name', 'slots', 'hash_on', 'hash_fallback', 'hash_on_header',
'hash_fallback_header', 'healthchecks.active.timeout',
'healthchecks.active.concurrency',
'healthchecks.active.http_path',
'healthchecks.active.healthy.interval',
'healthchecks.active.healthy.http_statuses',
'healthchecks.active.healthy.successes',
'healthchecks.active.unhealthy.interval',
'healthchecks.active.unhealthy.http_statuses',
'healthchecks.active.unhealthy.tcp_failures',
'healthchecks.active.unhealthy.timeouts',
'healthchecks.active.unhealthy.http_failures',
'healthchecks.passive.healthy.http_statuses',
'healthchecks.passive.healthy.successes',
'healthchecks.passive.unhealthy.http_statuses',
'healthchecks.passive.unhealthy.tcp_failures',
'healthchecks.passive.unhealthy.timeouts',
'healthchecks.passive.unhealthy.http_failures',
]

def validate_semi_optional_parameters(self, **kwargs):
if ("hash_on" in kwargs) \
and (kwargs['hash_on'].lower() == "header") \
and ("hash_on_header" not in kwargs):
raise SchemaViolation("hash_on_header required when "
"hash_on is set to header")

if("hash_fallback" in kwargs) \
and (kwargs['hash_fallback'].lower() == 'header') \
and ('hash_fallback_header' not in kwargs):
raise SchemaViolation("hash_fallback_header required "
"when hash_fallback is set to "
"header")

def validate_obligatory_parameters(self, **kwargs):
if "name" not in kwargs:
raise SchemaViolation("name must be provided to _perform_create")

@property
def allowed_parameters(self):
return self.allowed_update_params()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "python-kong-client",
"version": "0.1.6",
"version": "0.1.7",
"description": "## Setup",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Description
This is a small library to provide [kong](http://getkong.org/) server administration functionality inside your python application

This library is currently in version 0.1.6 and it was built around [kong 0.13.x specifications](https://getkong.org/docs/0.13.x/admin-api/)
This library is currently in version 0.1.7 and it was built around [kong 0.13.x specifications](https://getkong.org/docs/0.13.x/admin-api/)

## Features
Supported Information Routes
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from setuptools import setup

__version__ = '0.1.6'
__version__ = '0.1.7'

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

Expand All @@ -27,7 +27,7 @@ def read(*names, **kwargs):
name='python-kong-client',
version=__version__,
license='BSD',
description='A Python client for the Kong API 0.12.x (http://getkong.org/)',
description='A Python client for the Kong API 0.13.x (http://getkong.org/)',
author='Sebastian Gonzalez',
author_email='[email protected]',
url='',
Expand Down
Loading

0 comments on commit d391f23

Please sign in to comment.