summaryrefslogtreecommitdiff
path: root/plugins/release-status.lua
blob: 19d27080e298d6b3ab2a54852395660538c3ad96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
selector = config["selector"]
path = config["file"]
text = config["text"]

if not selector then
   Log.warning("`selector' must be configured.")
elseif path and text then
   Log.warning("Only one of `path' and `text' can be specified.")
elseif text then
   toml_string = text
elseif path then
   toml_string = Sys.read_file(path)
else
   Log.warning("Either `path' or `text' must be specified.")
end

function generate_table(vyos_version, version_table)
   local target_elem = HTML.select_one(page, selector)
   
   local codename_header = HTML.create_element("h3", vyos_version)
   HTML.set_attribute(codename_header, "id", vyos_version)
   HTML.add_class(codename_header, "version")
   local codename_anchor = HTML.create_element("a")
   HTML.set_attribute(codename_anchor, "href", "#" .. vyos_version)
   HTML.append_child(codename_anchor, codename_header)
   HTML.append_child(target_elem, codename_anchor)

   local version_string = version_table["latest"]
   local version_header = HTML.create_element("h4", version_string)
   HTML.set_attribute(version_header, "id", version_string)
   local version_anchor = HTML.create_element("a")
   HTML.set_attribute(version_anchor, "href", "#" .. version_string)
   HTML.append_child(version_anchor, version_header)
   HTML.append_child(target_elem, version_anchor)

   local notes_string = version_table["notes"]
   if notes_string then
      local notes = HTML.create_element("p", notes_string)
      HTML.append_child(target_elem, notes)
   end

   if not Table.is_empty(version_table["security_advisory"]) then
     Log.debug(JSON.pretty_print(version_table["security_advisory"]))
     local status_table = HTML.create_element("table")
     HTML.append_child(status_table, HTML.parse("<tr><th>CVE</th><th>Name</th><th>Description</th><th>Status</th></tr>"))
      
     local i = 1
     while version_table["security_advisory"][i] do
        local row = version_table["security_advisory"][i]
        local advisory = HTML.create_element("tr")
        HTML.append_child(advisory, HTML.create_element("td", row["cve"]))
        HTML.append_child(advisory, HTML.create_element("td", row["title"]))
        HTML.append_child(advisory, HTML.create_element("td", row["description"]))
        HTML.append_child(advisory, HTML.create_element("td", row["status"]))
        HTML.append_child(status_table, advisory)
        i = i + 1
     end
     HTML.append_child(HTML.select_one(page, selector), status_table)
   end
end

if toml_string then
   local toml_table = TOML.from_string(toml_string)
   Table.iter_ordered(generate_table, toml_table["release"])
end