diff --git a/cloudkitty/api/v2/rating/modules.py b/cloudkitty/api/v2/rating/modules.py index e9c4c2cd..c8b46d26 100644 --- a/cloudkitty/api/v2/rating/modules.py +++ b/cloudkitty/api/v2/rating/modules.py @@ -23,7 +23,6 @@ from cloudkitty.api.v2 import base from cloudkitty.api.v2 import utils as api_utils from cloudkitty.common import policy from cloudkitty import utils as ck_utils -from cloudkitty.utils import validation as vutils PROCESSORS_NAMESPACE = 'cloudkitty.rating.processors' @@ -32,11 +31,11 @@ MODULE_SCHEMA = { voluptuous.Required( 'description', default=None, - ): vutils.get_string_type(), + ): str, voluptuous.Required( 'module_id', default=None, - ): vutils.get_string_type(), + ): str, voluptuous.Required( 'enabled', default=None, diff --git a/cloudkitty/api/v2/scope/state.py b/cloudkitty/api/v2/scope/state.py index 38d89b85..15f2b386 100644 --- a/cloudkitty/api/v2/scope/state.py +++ b/cloudkitty/api/v2/scope/state.py @@ -22,7 +22,6 @@ from cloudkitty.common import policy from cloudkitty import messaging from cloudkitty import storage_state from cloudkitty.utils import tz as tzutils -from cloudkitty.utils import validation as vutils from oslo_log import log @@ -51,15 +50,13 @@ class ScopeState(base.BaseResource): api_utils.MultiQueryParam(int), }) @api_utils.add_output_schema({'results': [{ - voluptuous.Required('scope_id'): vutils.get_string_type(), - voluptuous.Required('scope_key'): vutils.get_string_type(), - voluptuous.Required('fetcher'): vutils.get_string_type(), - voluptuous.Required('collector'): vutils.get_string_type(), - voluptuous.Optional( - 'last_processed_timestamp'): vutils.get_string_type(), + voluptuous.Required('scope_id'): str, + voluptuous.Required('scope_key'): str, + voluptuous.Required('fetcher'): str, + voluptuous.Required('collector'): str, + voluptuous.Optional('last_processed_timestamp'): str, voluptuous.Required('active'): bool, - voluptuous.Optional('scope_activation_toggle_date'): - vutils.get_string_type(), + voluptuous.Optional('scope_activation_toggle_date'): str, }]}) def get(self, offset=0, limit=100, scope_id=None, scope_key=None, fetcher=None, collector=None, active=None): @@ -165,15 +162,14 @@ class ScopeState(base.BaseResource): api_utils.SingleQueryParam(bool), }) @api_utils.add_output_schema({ - voluptuous.Required('scope_id'): vutils.get_string_type(), - voluptuous.Required('scope_key'): vutils.get_string_type(), - voluptuous.Required('fetcher'): vutils.get_string_type(), - voluptuous.Required('collector'): vutils.get_string_type(), + voluptuous.Required('scope_id'): str, + voluptuous.Required('scope_key'): str, + voluptuous.Required('fetcher'): str, + voluptuous.Required('collector'): str, voluptuous.Optional('last_processed_timestamp'): voluptuous.Coerce(tzutils.dt_from_iso), voluptuous.Required('active'): bool, - voluptuous.Required('scope_activation_toggle_date'): - vutils.get_string_type() + voluptuous.Required('scope_activation_toggle_date'): str, }) def patch(self, scope_id, scope_key=None, fetcher=None, collector=None, active=None): @@ -234,15 +230,13 @@ class ScopeState(base.BaseResource): voluptuous.Coerce(tzutils.dt_from_iso), }) @api_utils.add_output_schema({ - voluptuous.Required('scope_id'): vutils.get_string_type(), - voluptuous.Required('scope_key'): vutils.get_string_type(), - voluptuous.Required('fetcher'): vutils.get_string_type(), - voluptuous.Required('collector'): vutils.get_string_type(), - voluptuous.Required('last_processed_timestamp'): - vutils.get_string_type(), + voluptuous.Required('scope_id'): str, + voluptuous.Required('scope_key'): str, + voluptuous.Required('fetcher'): str, + voluptuous.Required('collector'): str, + voluptuous.Required('last_processed_timestamp'): str, voluptuous.Required('active'): bool, - voluptuous.Required('scope_activation_toggle_date'): - vutils.get_string_type() + voluptuous.Required('scope_activation_toggle_date'): str, }) def post(self, scope_id, scope_key=None, fetcher=None, collector=None, active=None, last_processed_timestamp=None): diff --git a/cloudkitty/api/v2/task/reprocess.py b/cloudkitty/api/v2/task/reprocess.py index 3b6e8200..d3775f05 100644 --- a/cloudkitty/api/v2/task/reprocess.py +++ b/cloudkitty/api/v2/task/reprocess.py @@ -24,7 +24,6 @@ from cloudkitty.common import policy from cloudkitty import storage_state from cloudkitty.storage_state.models import ReprocessingScheduler from cloudkitty.utils import tz as tzutils -from cloudkitty.utils import validation as validation_utils from oslo_config import cfg @@ -257,14 +256,11 @@ class ReprocessSchedulerGetApi(base.BaseResource): api_utils.SingleQueryParam(str) }) @api_utils.add_output_schema({'results': [{ - voluptuous.Required('reason'): validation_utils.get_string_type(), - voluptuous.Required('scope_id'): validation_utils.get_string_type(), - voluptuous.Required('start_reprocess_time'): - validation_utils.get_string_type(), - voluptuous.Required('end_reprocess_time'): - validation_utils.get_string_type(), - voluptuous.Required('current_reprocess_time'): - validation_utils.get_string_type(), + voluptuous.Required('reason'): str, + voluptuous.Required('scope_id'): str, + voluptuous.Required('start_reprocess_time'): str, + voluptuous.Required('end_reprocess_time'): str, + voluptuous.Required('current_reprocess_time'): str, }]}) def get(self, scope_ids=[], path_scope_id=None, offset=0, limit=100, order="desc"): diff --git a/cloudkitty/api/v2/utils.py b/cloudkitty/api/v2/utils.py index e640cb93..81c06a5c 100644 --- a/cloudkitty/api/v2/utils.py +++ b/cloudkitty/api/v2/utils.py @@ -31,10 +31,6 @@ class SingleQueryParam(object): verifies its type and returns it directly, instead of returning a list containing a single element. - Note that this validator uses ``voluptuous.Coerce`` internally and thus - should not be used together with - ``cloudkitty.utils.validation.get_string_type`` in python2. - :param param_type: Type of the query parameter """ def __init__(self, param_type): @@ -56,10 +52,6 @@ class MultiQueryParam(object): verifies their type and returns it directly, instead of returning a list containing a single element. - Note that this validator uses ``voluptuous.Coerce`` internally and thus - should not be used together with - ``cloudkitty.utils.validation.get_string_type`` in python2. - :param param_type: Type of the query parameter """ def __init__(self, param_type): @@ -225,7 +217,7 @@ def paginated(func): voluptuous.Required( 'message', default='This is an example endpoint', - ): validation_utils.get_string_type(), + ): str, }) def get(self, offset=0, limit=100): # [...] @@ -249,7 +241,7 @@ def add_output_schema(schema): voluptuous.Required( 'message', default='This is an example endpoint', - ): validation_utils.get_string_type(), + ): str, }) def get(self): return {} diff --git a/cloudkitty/dataframe.py b/cloudkitty/dataframe.py index db84a53b..0d44754e 100644 --- a/cloudkitty/dataframe.py +++ b/cloudkitty/dataframe.py @@ -30,7 +30,7 @@ from cloudkitty.utils import validation as vutils # Decimal(str(0.121)) == Decimal('0.121') DATAPOINT_SCHEMA = voluptuous.Schema({ voluptuous.Required('vol'): { - voluptuous.Required('unit'): vutils.get_string_type(), + voluptuous.Required('unit'): str, voluptuous.Required('qty'): voluptuous.Coerce(str), }, voluptuous.Required('rating', default={}): { diff --git a/cloudkitty/utils/validation.py b/cloudkitty/utils/validation.py index 1c77b106..3e731149 100644 --- a/cloudkitty/utils/validation.py +++ b/cloudkitty/utils/validation.py @@ -85,8 +85,3 @@ class IterableValuesDict(DictTypeValidator): except (TypeError, ValueError) as e: raise voluptuous.Invalid( "{} can't be converted to a dict: {}".format(item, e)) - - -def get_string_type(): - """Returns ``basestring`` in python2 and ``str`` in python3.""" - return str diff --git a/doc/source/developer/api/tutorial.rst b/doc/source/developer/api/tutorial.rst index 576e0157..1233115f 100644 --- a/doc/source/developer/api/tutorial.rst +++ b/doc/source/developer/api/tutorial.rst @@ -90,15 +90,12 @@ Let's update our ``get`` method in order to use this decorator: voluptuous.Required( 'message', default='This is an example endpoint', - ): validation_utils.get_string_type(), + ): str, }) def get(self): return {} -.. note:: In this snippet, ``get_string_type`` returns ``basestring`` in - python2 and ``str`` in python3. - .. code-block:: console $ curl 'http://cloudkitty-api:8889/v2/example' @@ -118,7 +115,7 @@ exceptions for HTTP return codes. .. code-block:: python @api_utils.add_input_schema('body', { - voluptuous.Required('fruit'): validation_utils.get_string_type(), + voluptuous.Required('fruit'): str, }) def post(self, fruit=None): policy.authorize(flask.request.context, 'example:submit_fruit', {}) @@ -161,10 +158,6 @@ parameter is provided only once, and returns it. .. autoclass:: cloudkitty.api.v2.utils.SingleQueryParam :noindex: -.. warning:: ``SingleQueryParam`` uses ``voluptuous.Coerce`` internally for - type checking. Thus, ``validation_utils.get_string_type`` cannot - be used as ``basestring`` can't be instantiated. - Authorising methods -------------------