Update the repo for a helm KDU before install and upgrade
[osm/N2VC.git] / n2vc / utils.py
index f0146a0..5ac0e2c 100644 (file)
@@ -16,6 +16,8 @@ import base64
 import re
 import binascii
 import yaml
+import string
+import secrets
 from enum import Enum
 from juju.machine import Machine
 from juju.application import Application
@@ -33,7 +35,11 @@ def base64_to_cacert(b64string):
     try:
         cacert = base64.b64decode(b64string).decode("utf-8")
 
-        cacert = re.sub(r"\\n", r"\n", cacert,)
+        cacert = re.sub(
+            r"\\n",
+            r"\n",
+            cacert,
+        )
     except binascii.Error as e:
         raise N2VCInvalidCertificate(message="Invalid CA Certificate: {}".format(e))
 
@@ -143,3 +149,15 @@ def obj_to_dict(obj: object) -> dict:
     yaml_text = obj_to_yaml(obj)
     # parse to dict
     return yaml.load(yaml_text, Loader=yaml.Loader)
+
+
+def generate_random_alfanum_string(size: int) -> str:
+    """
+    Generate random alfa-numeric string with a size given by argument
+    :param size:
+    :return: random generated string
+    """
+
+    return "".join(
+        secrets.choice(string.ascii_letters + string.digits) for i in range(size)
+    )