From 656e0dc3da030fc2c9d65a002a152b29bb710608 Mon Sep 17 00:00:00 2001
From: Claudio Pisa <claudio.pisa@garr.it>
Date: Fri, 25 Jan 2019 10:45:44 +0000
Subject: [PATCH] use new function for the initial value of the namespace field

---
 .../overrides.py                                         | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/modules/garr_horizon_dashboard_customization_module/overrides.py b/modules/garr_horizon_dashboard_customization_module/overrides.py
index bddba60..7283150 100644
--- a/modules/garr_horizon_dashboard_customization_module/overrides.py
+++ b/modules/garr_horizon_dashboard_customization_module/overrides.py
@@ -121,7 +121,14 @@ forms.GARR_CreateApplicationCredentialForm = GARR_CreateApplicationCredentialFor
 def computeNamespaceName(os_name):
     # kubernetes allows only namespaces which are validated by the regular expression '[a-z0-9]([-a-z0-9]*[a-z0-9])?'
     # i.e. made by lowercase letters, numbers and '-' and starting with a lowercase letter
-    return hashlib.sha1(str(os_name) + "\n").hexdigest()
+    # and not longer than 63 characters
+    name = str(os_name)
+    name = name.lower()
+    name = "".join([ c for c in name if (ord(c) >= ord('a') and ord(c) <= ord('z')) or (ord(c) >= ord('0') and ord(c) <= ord('9')) or c == '@'])
+    name = name.replace('@', '-')
+    name = "g-" + name  # fix usernames beginning with numbers
+    name = name[:60]
+    return name
 
 # Create a new view class which uses both
 # GARR_CreateApplicationCredentialForm and GARR_CreateSuccessfulView
-- 
GitLab