Fix loading invalid metadata YAML #4

Open
opened 2021-11-19 08:52:25 +01:00 by PeterSurda · 0 comments
Owner
diff --git a/main.py b/main.py
index 929b0a1..3629e2b 100644
--- a/main.py
+++ b/main.py
@@ -147,7 +147,10 @@ class CloudInitApp:
         filepath = os.path.join(PATH, "data", data['local-hostname'], META_DATA_FILENAME)
         if os.path.exists(filepath):
             with open(filepath, "r") as metadata:
-                data.update(yaml.safe_load(metadata))
+                try:
+                    data.update(yaml.safe_load(metadata))
+                except ValueError:
+                    pass
 
         cherrypy.response.headers['Content-Type'] = \
             'text/yaml'
``` diff --git a/main.py b/main.py index 929b0a1..3629e2b 100644 --- a/main.py +++ b/main.py @@ -147,7 +147,10 @@ class CloudInitApp: filepath = os.path.join(PATH, "data", data['local-hostname'], META_DATA_FILENAME) if os.path.exists(filepath): with open(filepath, "r") as metadata: - data.update(yaml.safe_load(metadata)) + try: + data.update(yaml.safe_load(metadata)) + except ValueError: + pass cherrypy.response.headers['Content-Type'] = \ 'text/yaml' ```
PeterSurda self-assigned this 2023-01-28 03:57:38 +01:00
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Sysdeploy/cloud-init-cherrypy#4
No description provided.