Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/log invalid kwarg #238

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions generator/batch_class_template.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import urllib


class ActionBatch{{ class_name }}(object):
def __init__(self):
def __init__(self, enable_kwargs_validation):
super(ActionBatch{{ class_name }}, self).__init__()

self.enable_kwargs_validation = enable_kwargs_validation
4 changes: 4 additions & 0 deletions generator/batch_function_template.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

{% if query_params|length > 0 %}
query_params = [{% for param in query_params %}'{{ param }}', {% endfor %}]
if self.enable_kwargs_validation:
validate_kwargs(query_params)
params = {k.strip(): v for k, v in kwargs.items() if k.strip() in query_params}

{% endif %}
Expand All @@ -44,6 +46,8 @@
{% endif %}
{% if body_params|length > 0 %}
body_params = [{% for param in body_params %}'{{ param }}', {% endfor %}]
if self.enable_kwargs_validation:
validate_kwargs(body_params)
{% if batch_operation != 'destroy'%}
payload = {k.strip(): v for k, v in kwargs.items() if k.strip() in body_params}
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions generator/class_template.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import urllib


class {{ class_name }}(object):
def __init__(self, session):
def __init__(self, session, enable_kwargs_validation):
super({{ class_name }}, self).__init__()
self._session = session

self.enable_kwargs_validation = enable_kwargs_validation
4 changes: 4 additions & 0 deletions generator/function_template.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

{% if query_params|length > 0 %}
query_params = [{% for param in query_params %}'{{ param }}', {% endfor %}]
if self.enable_kwargs_validation:
validate_kwargs(query_params)
params = {k.strip(): v for k, v in kwargs.items() if k.strip() in query_params}

{% endif %}
Expand All @@ -44,6 +46,8 @@
{% endif %}
{% if body_params|length > 0 %}
body_params = [{% for param in body_params %}'{{ param }}', {% endfor %}]
if self.enable_kwargs_validation:
validate_kwargs(body_params)
payload = {k.strip(): v for k, v in kwargs.items() if k.strip() in body_params}

{% endif %}
Expand Down
32 changes: 18 additions & 14 deletions meraki/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
BE_GEO_ID,
MERAKI_PYTHON_SDK_CALLER,
USE_ITERATOR_FOR_GET_PAGES,
ENABLE_KWARGS_VALIDATION,
)
from meraki.rest_session import *

Expand Down Expand Up @@ -72,6 +73,7 @@ class DashboardAPI(object):
- be_geo_id (string): optional partner identifier for API usage tracking; can also be set as an environment variable BE_GEO_ID
- caller (string): optional identifier for API usage tracking; can also be set as an environment variable MERAKI_PYTHON_SDK_CALLER
- use_iterator_for_get_pages (boolean): list* methods will return an iterator with each object instead of a complete list with all items
- enable_kwarg_validation (boolean): enable kwargs validation?
"""

def __init__(self,
Expand All @@ -97,6 +99,7 @@ def __init__(self,
caller=MERAKI_PYTHON_SDK_CALLER,
use_iterator_for_get_pages=USE_ITERATOR_FOR_GET_PAGES,
inherit_logging_config=INHERIT_LOGGING_CONFIG,
enable_kwarg_validation=ENABLE_KWARGS_VALIDATION,
):

# Check API key
Expand Down Expand Up @@ -167,20 +170,21 @@ def __init__(self,
use_iterator_for_get_pages=use_iterator_for_get_pages,
)

self._enable_kwargs_validation = enable_kwarg_validation
# API endpoints by section
self.administered = Administered(self._session)
self.organizations = Organizations(self._session)
self.networks = Networks(self._session)
self.devices = Devices(self._session)
self.appliance = Appliance(self._session)
self.camera = Camera(self._session)
self.cellularGateway = CellularGateway(self._session)
self.insight = Insight(self._session)
self.licensing = Licensing(self._session)
self.sensor = Sensor(self._session)
self.sm = Sm(self._session)
self.switch = Switch(self._session)
self.wireless = Wireless(self._session)
self.administered = Administered(self._session, self._enable_kwargs_validation )
self.organizations = Organizations(self._session, self._enable_kwargs_validation )
self.networks = Networks(self._session, self._enable_kwargs_validation )
self.devices = Devices(self._session, self._enable_kwargs_validation )
self.appliance = Appliance(self._session, self._enable_kwargs_validation )
self.camera = Camera(self._session, self._enable_kwargs_validation )
self.cellularGateway = CellularGateway(self._session, self._enable_kwargs_validation )
self.insight = Insight(self._session, self._enable_kwargs_validation )
self.licensing = Licensing(self._session, self._enable_kwargs_validation )
self.sensor = Sensor(self._session, self._enable_kwargs_validation )
self.sm = Sm(self._session, self._enable_kwargs_validation )
self.switch = Switch(self._session, self._enable_kwargs_validation )
self.wireless = Wireless(self._session, self._enable_kwargs_validation )

# Batch definitions
self.batch = Batch()
self.batch = Batch(self._enable_kwargs_validation )
24 changes: 12 additions & 12 deletions meraki/api/batch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@

# Batch class
class Batch:
def __init__(self):
def __init__(self, enable_kwarg_validation):
# Action Batch helper API endpoints by section
self.organizations = ActionBatchOrganizations()
self.networks = ActionBatchNetworks()
self.devices = ActionBatchDevices()
self.appliance = ActionBatchAppliance()
self.camera = ActionBatchCamera()
self.cellularGateway = ActionBatchCellularGateway()
self.insight = ActionBatchInsight()
self.sensor = ActionBatchSensor()
self.sm = ActionBatchSm()
self.switch = ActionBatchSwitch()
self.wireless = ActionBatchWireless()
self.organizations = ActionBatchOrganizations(enable_kwarg_validation)
self.networks = ActionBatchNetworks(enable_kwarg_validation)
self.devices = ActionBatchDevices(enable_kwarg_validation)
self.appliance = ActionBatchAppliance(enable_kwarg_validation)
self.camera = ActionBatchCamera(enable_kwarg_validation)
self.cellularGateway = ActionBatchCellularGateway(enable_kwarg_validation)
self.insight = ActionBatchInsight(enable_kwarg_validation)
self.sensor = ActionBatchSensor(enable_kwarg_validation)
self.sm = ActionBatchSm(enable_kwarg_validation)
self.switch = ActionBatchSwitch(enable_kwarg_validation)
self.wireless = ActionBatchWireless(enable_kwarg_validation)
3 changes: 3 additions & 0 deletions meraki/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,6 @@
# The choice is yours as long as you follow the format. You should **not** include other information in this string.
# If you are an official ecosystem partner, this is required.
MERAKI_PYTHON_SDK_CALLER = ""

# Enable or disable kwargs validation
ENABLE_KWARGS_VALIDATION = False
Loading