Skip to content

Commit

Permalink
Replace hardcoded Garden Linux dist_id mapping with dynamic data from…
Browse files Browse the repository at this point in the history
… dump (#2)
  • Loading branch information
fwilhe authored Jan 17, 2025
1 parent 564a3b6 commit 9f1e84a
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 4 deletions.
1 change: 1 addition & 0 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ENV PAT NOT_SET

RUN apt-get update && apt-get install -y postgresql-client curl python3-yaml git

COPY dist_cpe.json /dist_cpe.json
COPY cli.py /cli.py
COPY entrypoint.sh /entrypoint.sh

Expand Down
9 changes: 5 additions & 4 deletions cli.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import yaml
import json
import os
import os.path

dist_id_mapping = {
'today': 14,
'1592.4': 15
}
dist_id_mapping = {}


def main():
with open('dist_cpe.json') as dist:
dist_id_mapping = json.loads(dist.read())

file = f"/data/{os.environ['GLVD_TRIAGE_FILE']}"
if not os.path.isfile(file):
raise Exception(f"{file} is not a file")
Expand Down
17 changes: 17 additions & 0 deletions dist_cpe.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
id,cpe_vendor,cpe_product,cpe_version,deb_codename
1,debian,debian_linux,13,trixie
2,debian,debian_linux,12,bookworm
3,debian,debian_linux,,
4,debian,debian_linux,11,bullseye
5,debian,debian_linux,10,buster
6,debian,debian_linux,9,stretch
7,debian,debian_linux,8,jessie
8,debian,debian_linux,7,wheezy
9,debian,debian_linux,6.0,squeeze
10,debian,debian_linux,5.0,lenny
11,debian,debian_linux,4.0,etch
12,debian,debian_linux,3.1,sarge
13,debian,debian_linux,3.0,woody
14,sap,gardenlinux,today,today
15,sap,gardenlinux,1592.4,1592.4
16,sap,gardenlinux,1592.5,1592.5
1 change: 1 addition & 0 deletions dist_cpe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"today": "14", "1592.4": "15", "1592.5": "16"}
16 changes: 16 additions & 0 deletions dist_mapping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import csv
import json

mapping = {}

with open('dist_cpe.csv', newline='') as dist_mapping:
foo = csv.reader(dist_mapping, delimiter=',')
for row in foo:
dist_id = row[0]
dist_name = row[2]
dist_version = row[3]
if dist_name == 'gardenlinux':
mapping[dist_version] = dist_id

with open('dist_cpe.json', 'w+') as dist_mapping_json:
dist_mapping_json.write(json.dumps(mapping))
4 changes: 4 additions & 0 deletions download_dist_mapping.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

LATEST_RUN_ID=$(gh run list --repo gardenlinux/glvd-data-ingestion --branch main --workflow 02-ingest-dump-snapshot.yaml --json databaseId --limit 1 | jq -r '.[0].databaseId')
gh run download $LATEST_RUN_ID -n dist_cpe.csv --repo gardenlinux/glvd-data-ingestion

0 comments on commit 9f1e84a

Please sign in to comment.