summaryrefslogtreecommitdiff
path: root/cloudinit/sources/helpers
diff options
context:
space:
mode:
authorChris Patterson <cpatterson@microsoft.com>2022-02-10 15:03:10 -0500
committerGitHub <noreply@github.com>2022-02-10 14:03:10 -0600
commit50de985bc4e47dff1a8fc52abb7679032bb40cae (patch)
treeeec039c570ff733a202c6c7ef341fda3873b1c4f /cloudinit/sources/helpers
parentc3482971f0f155475f367d6dec00bae25b79cfff (diff)
downloadvyos-cloud-init-50de985bc4e47dff1a8fc52abb7679032bb40cae.tar.gz
vyos-cloud-init-50de985bc4e47dff1a8fc52abb7679032bb40cae.zip
sources/azure: refactor ssh key handling (#1248)
Split _get_public_ssh_keys_and_source() into _get_public_keys_from_imds() and _get_public_keys_from_ovf(). Set _get_public_keys_from_imds() to take a parameter of the IMDS metadata rather than assuming it is already set in self.metadata. This will allow us to move negotation into local phase where self.metadata may not be set yet. Update this method to raise KeyError if IMDS metadata is missing/malformed, and ValueError if SSH key format is not supported. Update get_public_ssh_keys() to catch these errors and fall back to the OVF/Wireserver keys as needed. To improve clarity, update register_with_azure_and_fetch_data() to return the list of SSH keys, rather than bundling them into a dictionary for updating against the metadata dictionary. There should be no change in behavior with this refactor. Signed-off-by: Chris Patterson <cpatterson@microsoft.com>
Diffstat (limited to 'cloudinit/sources/helpers')
-rwxr-xr-xcloudinit/sources/helpers/azure.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/cloudinit/sources/helpers/azure.py b/cloudinit/sources/helpers/azure.py
index 8e8f5ce5..ec6ab80c 100755
--- a/cloudinit/sources/helpers/azure.py
+++ b/cloudinit/sources/helpers/azure.py
@@ -12,6 +12,7 @@ import zlib
from contextlib import contextmanager
from datetime import datetime
from errno import ENOENT
+from typing import List, Optional
from xml.etree import ElementTree
from xml.sax.saxutils import escape
@@ -1004,7 +1005,7 @@ class WALinuxAgentShim:
@azure_ds_telemetry_reporter
def register_with_azure_and_fetch_data(
self, pubkey_info=None, iso_dev=None
- ) -> dict:
+ ) -> Optional[List[str]]:
"""Gets the VM's GoalState from Azure, uses the GoalState information
to report ready/send the ready signal/provisioning complete signal to
Azure, and then uses pubkey_info to filter and obtain the user's
@@ -1037,7 +1038,7 @@ class WALinuxAgentShim:
self.eject_iso(iso_dev)
health_reporter.send_ready_signal()
- return {"public-keys": ssh_keys}
+ return ssh_keys
@azure_ds_telemetry_reporter
def register_with_azure_and_report_failure(self, description: str) -> None: