From a51b499cb344b05b2e0a9e8a755148ae0c92aefa Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Thu, 2 Dec 2021 15:43:43 +0800 Subject: [PATCH] Add UUID syntax validation --- main.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 9e65697..f9e7663 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,7 @@ import configparser import os import socket import sys +import uuid as uuid_module from ipaddress import AddressValueError, IPv4Address, IPv6Address from os import access, R_OK @@ -33,10 +34,17 @@ class CloudInitRequest: self.remoteip = None self.hostinfo = ('localhost', ) self.request = request - self.uuid = uuid self.meta_data = None self.meta_data_loaded = False self.user_data = None + + try: + self.uuid = str(uuid_module.UUID('{' + uuid + '}')) + # ValueError is wrong UUID syntax + # TypeError is None + except (ValueError, TypeError): + self.uuid = None + self._init_ip() self._generate_default_meta_data()