From c008906bedf7b0dea31aae5bc5b7ec4bea1ab851 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Fri, 16 Oct 2009 16:30:44 +0200
Subject: [PATCH] bootstrap: Factorize HMAC key generation

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/bootstrap.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/lib/bootstrap.py b/lib/bootstrap.py
index ae0fae773..190cc261d 100644
--- a/lib/bootstrap.py
+++ b/lib/bootstrap.py
@@ -100,6 +100,16 @@ def GenerateSelfSignedSslCert(file_name, validity=(365 * 5)):
     os.close(fd)
 
 
+def GenerateHmacKey(file_name):
+  """Writes a new HMAC key.
+
+  @type file_name: str
+  @param file_name: Path to output file
+
+  """
+  utils.WriteFile(file_name, data=utils.GenerateSecret(), mode=0400)
+
+
 def _InitGanetiServerSetup():
   """Setup the necessary configuration for the initial node daemon.
 
@@ -114,9 +124,7 @@ def _InitGanetiServerSetup():
     GenerateSelfSignedSslCert(constants.RAPI_CERT_FILE)
 
   if not os.path.exists(constants.HMAC_CLUSTER_KEY):
-    utils.WriteFile(constants.HMAC_CLUSTER_KEY,
-                    data=utils.GenerateSecret(),
-                    mode=0400)
+    GenerateHmacKey(constants.HMAC_CLUSTER_KEY)
 
   result = utils.RunCmd([constants.NODE_INITD_SCRIPT, "restart"])
 
-- 
GitLab