aboutsummaryrefslogtreecommitdiffstats
path: root/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/migrations/0022_merge_20211102_2136.py14
-rw-r--r--src/api/models.py6
-rw-r--r--src/api/views.py17
3 files changed, 28 insertions, 9 deletions
diff --git a/src/api/migrations/0022_merge_20211102_2136.py b/src/api/migrations/0022_merge_20211102_2136.py
new file mode 100644
index 0000000..bb27ae4
--- /dev/null
+++ b/src/api/migrations/0022_merge_20211102_2136.py
@@ -0,0 +1,14 @@
+# Generated by Django 2.2 on 2021-11-02 21:36
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('api', '0019_auto_20210907_1448'),
+ ('api', '0021_auto_20210405_1943'),
+ ]
+
+ operations = [
+ ]
diff --git a/src/api/models.py b/src/api/models.py
index 5928ea9..93168f5 100644
--- a/src/api/models.py
+++ b/src/api/models.py
@@ -20,6 +20,7 @@ from django.utils import timezone
import json
import uuid
import yaml
+import re
from booking.models import Booking
from resource_inventory.models import (
@@ -362,7 +363,8 @@ class GeneratedCloudConfig(models.Model):
def _normalize_username(self, username: str) -> str:
# TODO: make usernames posix compliant
- return username
+ s = re.sub(r'\W+', '', username)
+ return s
def _get_ssh_string(self, username: str) -> str:
user = User.objects.get(username=username)
@@ -502,7 +504,7 @@ class GeneratedCloudConfig(models.Model):
return main_dict
def serialize(self) -> str:
- return yaml.dump(self._to_dict())
+ return yaml.dump(self._to_dict(), width=float("inf"))
class APILog(models.Model):
diff --git a/src/api/views.py b/src/api/views.py
index a10b3ec..1516374 100644
--- a/src/api/views.py
+++ b/src/api/views.py
@@ -295,7 +295,7 @@ def resource_ci_userdata(request, lab_name="", job_id="", resource_id="", file_i
"datasource_list": ["None"],
}
- return HttpResponse(yaml.dump(cloud_dict), status=200)
+ return HttpResponse(yaml.dump(cloud_dict, width=float("inf")), status=200)
@csrf_exempt
@@ -310,9 +310,9 @@ def resource_ci_userdata_directory(request, lab_name="", job_id="", resource_id=
files = resource.config.cloud_init_files
files = [{"id": file.id, "priority": file.priority} for file in files.order_by("priority").all()]
- d = {
- 'merge_failures': []
- }
+ d = {}
+
+ merge_failures = []
merger = Merger(
[
@@ -325,7 +325,7 @@ def resource_ci_userdata_directory(request, lab_name="", job_id="", resource_id=
for f in resource.config.cloud_init_files.order_by("priority").all():
try:
- other_dict = yaml.load(f.text)
+ other_dict = yaml.safe_load(f.text)
if not (type(d) is dict):
raise Exception("CI file was valid yaml but was not a dict")
@@ -335,9 +335,12 @@ def resource_ci_userdata_directory(request, lab_name="", job_id="", resource_id=
print("Failed to merge file in, as it had invalid content:", f.id)
print("File text was:")
print(f.text)
- d['merge_failures'].append({f.id: str(e)})
+ merge_failures.append({f.id: str(e)})
+
+ if len(merge_failures) > 0:
+ d['merge_failures'] = merge_failures
- file = CloudInitFile.create(text=yaml.dump(d), priority=0)
+ file = CloudInitFile.create(text=yaml.dump(d, width=float("inf")), priority=0)
return HttpResponse(json.dumps([{"id": file.id, "priority": file.priority}]), status=200)