From 29d0f956fca43e1939700fa9b5cfb650b1810223 Mon Sep 17 00:00:00 2001 From: Aaron Blair Date: Thu, 16 Aug 2018 21:16:32 +1000 Subject: [PATCH] fix __hasorgaccess to check a specific orgid instead of testing against `/api/v0/organizations` related to https://github.com/meraki/dashboard-api-python/issues/28, but does not necessarily fix it. --- meraki.py | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/meraki.py b/meraki.py index 9ad26fd1..4b1e2d07 100644 --- a/meraki.py +++ b/meraki.py @@ -793,26 +793,28 @@ def __hasorgaccess(apikey, targetorg): Returns: None, raises OrgPermissionError if API Key does not have access to the specified Meraki Organization """ - geturl = '{0}/organizations'.format(str(base_url)) + geturl = '{0}/organizations/{1}'.format(str(base_url), str(targetorg)) headers = { 'x-cisco-meraki-api-key': format(str(apikey)), 'Content-Type': 'application/json' } dashboard = requests.get(geturl, headers=headers) - currentorgs = json.loads(dashboard.text) - orgs = [] + validjson = __isjson(dashboard.text) + if validjson is True: - for org in currentorgs: - if int(org['id']) == int(targetorg): - orgs.append(org['id']) - return None - else: - pass + currentorg = json.loads(dashboard.text) + + if int(currentorg['id']) == int(targetorg): + return None + else: + raise OrgPermissionError + + else: raise OrgPermissionError - return None + return None def __validemail(emailaddress): @@ -1298,23 +1300,6 @@ def getclients(apikey, serialnum, timestamp=86400, suppressprint=False): return result -# Return the client associated with the given identifier. This endpoint will lookup by client ID or either the MAC or IP depending on whether the network uses Track-by-IP. -# https://api.meraki.com/api_doc#return-the-client-associated-with-the-given-identifier -def getclient(apikey, networkid, identifier, suppressprint=False): - calltype = 'Device Clients' - geturl = '{0}/networks/{1}/clients/{2}'.format(str(base_url), str(networkid), str(identifier)) - headers = { - 'x-cisco-meraki-api-key': format(str(apikey)), - 'Content-Type': 'application/json' - } - dashboard = requests.get(geturl, headers=headers) - # - # Call return handler function to parse Dashboard response - # - result = __returnhandler(dashboard.status_code, dashboard.text, calltype, suppressprint) - return result - - # Return the policy assigned to a client on the network. # https://api.meraki.com/api_docs#return-the-policy-assigned-to-a-client-on-the-network def getclientpolicy(apikey, networkid, clientmac, timestamp=86400, suppressprint=False):