From b84444b1490f39bf38c275bf093cd55a16bcda8f Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Thu, 7 Nov 2019 14:50:28 +0100
Subject: [PATCH] canonicalize input address for peer-info route

---
 inventory_provider/routes/classifier.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/inventory_provider/routes/classifier.py b/inventory_provider/routes/classifier.py
index c62c50ee..f27cf07b 100644
--- a/inventory_provider/routes/classifier.py
+++ b/inventory_provider/routes/classifier.py
@@ -247,6 +247,14 @@ def find_interfaces_and_services(address_str):
 @common.require_accepts_json
 def peer_info(address):
 
+    # canonicalize the input address first ...
+    try:
+        obj = ipaddress.ip_address(address)
+        address = obj.exploded
+    except ValueError:
+        raise ClassifierProcessingError(
+            'unable to parse %r as an ip address' % address)
+
     r = common.get_current_redis()
 
     cache_key = 'classifier-cache:peer:%s' % address
-- 
GitLab