summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-11-05 11:43:30 +0200
committerLars Wirzenius <liw@liw.fi>2022-11-05 11:44:47 +0200
commit0915a60346d3bb9d75d9f95958279c0f46337431 (patch)
tree6cac2b348b1a1621c367dd47fa3ca1d6e133e793
parent12391ce9978cc689c0eda67cb26232ce30ae8865 (diff)
downloadvmadm-0915a60346d3bb9d75d9f95958279c0f46337431.tar.gz
refactor: make more named constants
Sponsored-by: author
-rw-r--r--cloud-init.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/cloud-init.py b/cloud-init.py
index 377b770..3618ad8 100644
--- a/cloud-init.py
+++ b/cloud-init.py
@@ -4,7 +4,14 @@ import yaml
USER_CA_KEYS = "user-ca-keys"
+ETC = "/etc/ssh"
+CONFIG = "ssh_config"
LGGFILE = "/tmp/vmadm.script"
+USER_DATA = "/var/lib/cloud/instance/user-data.txt"
+
+
+def etc_join(*paths):
+ return os.path.join(etc, *paths)
def log(msg):
@@ -20,8 +27,8 @@ if os.environ.get("VMADM_TESTING"):
filename = "smoke/user-data"
etc = "x"
else:
- filename = "/var/lib/cloud/instance/user-data.txt"
- etc = "/etc/ssh"
+ filename = USER_DATA
+ etc = ETC
key_types = ("rsa", "dsa", "ecdsa", "ed25519")
@@ -36,7 +43,7 @@ keys = []
certs = []
for key_type in key_types:
- filename = os.path.join(etc, f"ssh_host_{key_type}_key.pub")
+ filename = etc_join(f"ssh_host_{key_type}_key.pub")
if os.path.exists(filename):
log(f"removing {filename}")
os.remove(filename)
@@ -50,25 +57,25 @@ for key_type in key_types:
log(f"cert {key_type} {cert }")
if key:
- filename = os.path.join(etc, f"ssh_host_{key_type}_key")
+ filename = etc_join(f"ssh_host_{key_type}_key")
log(f"writing key {filename}")
keys.append(filename)
with open(filename, "w") as f:
f.write(key)
if cert:
- filename = os.path.join(etc, f"ssh_host_{key_type}_key-cert.pub")
+ filename = etc_join(f"ssh_host_{key_type}_key-cert.pub")
log(f"writing cert {filename}")
certs.append(filename)
with open(filename, "w") as f:
f.write(cert)
-user_ca_filename = os.path.join(etc, USER_CA_KEYS)
+user_ca_filename = etc_join(USER_CA_KEYS)
if user_ca_pubkey:
with open(user_ca_filename, "w") as f:
f.write(user_ca_pubkey)
-config = os.path.join(etc, "sshd_config")
+config = etc_join(CONFIG)
data = ""
if os.path.exists(config):
data = open(config).read()