diff --git a/.gitignore b/.gitignore index 27ace47..886279f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ venv logs results *.pyc -__pycache__ \ No newline at end of file +__pycache__ +.vscode \ No newline at end of file diff --git a/albs-oval-errata-diff.py b/albs-oval-errata-diff.py deleted file mode 100644 index 8c59f90..0000000 --- a/albs-oval-errata-diff.py +++ /dev/null @@ -1,4 +0,0 @@ -from albs_oval_erratta_diff.start import start - - -start() diff --git a/albs_oval_errata_diff.py b/albs_oval_errata_diff.py new file mode 100644 index 0000000..d878108 --- /dev/null +++ b/albs_oval_errata_diff.py @@ -0,0 +1,7 @@ +""" +albs_oval_errata_diff.py is a service startup script +""" +from albs_oval_errata_diff.start import start + + +start() diff --git a/albs_oval_erratta_diff/__init__.py b/albs_oval_errata_diff/__init__.py similarity index 100% rename from albs_oval_erratta_diff/__init__.py rename to albs_oval_errata_diff/__init__.py diff --git a/albs_oval_erratta_diff/comparer.py b/albs_oval_errata_diff/comparer.py similarity index 100% rename from albs_oval_erratta_diff/comparer.py rename to albs_oval_errata_diff/comparer.py diff --git a/albs_oval_errata_diff/config.py b/albs_oval_errata_diff/config.py new file mode 100644 index 0000000..ab69d67 --- /dev/null +++ b/albs_oval_errata_diff/config.py @@ -0,0 +1,105 @@ +''' +config.py used for generation service configuration based on input json file +''' + +from datetime import datetime, date +from pathlib import Path +from typing import Dict, List +from ipaddress import IPv4Address + +from pydantic import BaseModel, validator, Field # pylint: disable=import-error +import yaml + + +# DEFAULTS +DIFF_FILE = Path('/tmp/albs-oval-errata-diff.json') +DOWNLOAD_DIR = Path('/tmp') +LOG_FILE = Path('logs/albs-oval-errata-diff.log') +PACKAGES_EXCLUDE = [] +SA_EXCLUDE = [] +SERVER_PORT = 3001 +SERVER_IP = IPv4Address('127.0.0.1') +# not checking anything before RHEL-9.0 release +NOT_BEFORE = datetime(2022, 5, 18) +UPDATE_INTERVAL_MINUTES = 30 + + +class ReleaseUrls(BaseModel): + """ + ReleaseUrls represents list of RHEL/Alma Oval and Errata URLS for specific OS release + """ + rhel_oval_url: str = Field(description='URL for RHEL OVAL file') + alma_oval_url: str = Field(description='URL for Alma OVAL file') + alma_errata_url: str = Field(description='URL for Alma Errata file') + + +class Config(BaseModel): + """ + Config represents service configuration + """ + diff_file: Path = Field(description="file to store diff JSON in", + default=DIFF_FILE) + download_dir: Path = Field( + description='directory to download Oval/Errata files to', + default=DOWNLOAD_DIR) + log_file: Path = Field( + description='file to write logs to', + default=LOG_FILE) + packages_exclude: List[str] = Field( + description='list of RPM package names to exclude from checking', + default=PACKAGES_EXCLUDE) + releases: Dict[int, ReleaseUrls] = Field( + description='list of OS releases with Oval/Errata URLs to check') + sa_exclude: List[str] = Field( + description='list of Security Advisory IDs (ALSA-2022:5219) to exclude from checking', + default=SA_EXCLUDE) + server_port: int = Field( + description="port that will be used by websever", + default=SERVER_PORT) + server_ip: IPv4Address = Field( + description="IP that will be used by webserver", + default=SERVER_IP) + not_before: date = Field( + description='date to start checking from (YYYY-mm-dd)', + default=NOT_BEFORE) + update_interval_minutes: int = Field( + description='how often service will be running difference checks (in minutes)', + default=UPDATE_INTERVAL_MINUTES) + + @validator("releases", pre=True) + @classmethod + def parse_releases(cls, value) -> Dict[int, ReleaseUrls]: + """ + parse_release converts releases attribute + Dict[int, Dict[str, str]] -> Dict[str, ReleaseUrls] + """ + result: Dict[int, ReleaseUrls] = {} + for release, urls in value.items(): + result[release] = ReleaseUrls(rhel_oval_url=urls['rhel_oval_url'], + alma_oval_url=urls['alma_oval_url'], + alma_errata_url=urls['alma_errata_url']) + return result + + @validator("not_before", pre=True) + @classmethod + def str_to_datetime(cls, value) -> datetime: + """ + str_to_datetime converts string attr str -> datetime + """ + return datetime.strptime( + value, + "%Y-%m-%d" + ).date() + + +def get_config(yml_path: str) -> Config: + """ + get_config loads yml file and generates Config instance + """ + with open(yml_path, 'r', encoding='utf-8') as flr: + data = yaml.safe_load(flr) + return Config(**data) + + +if __name__ == "__main__": + print(get_config('./config.default.yml')) diff --git a/albs_oval_erratta_diff/package.py b/albs_oval_errata_diff/package.py similarity index 100% rename from albs_oval_erratta_diff/package.py rename to albs_oval_errata_diff/package.py diff --git a/albs_oval_erratta_diff/sa.py b/albs_oval_errata_diff/sa.py similarity index 100% rename from albs_oval_erratta_diff/sa.py rename to albs_oval_errata_diff/sa.py diff --git a/albs_oval_erratta_diff/start.py b/albs_oval_errata_diff/start.py similarity index 100% rename from albs_oval_erratta_diff/start.py rename to albs_oval_errata_diff/start.py diff --git a/albs_oval_erratta_diff/config.py b/albs_oval_erratta_diff/config.py deleted file mode 100644 index 73bedcd..0000000 --- a/albs_oval_erratta_diff/config.py +++ /dev/null @@ -1,21 +0,0 @@ -from pathlib import Path -import datetime - -RELEASES = { - 8: {'rhel_oval_url': 'https://www.redhat.com/security/data/oval/v2/RHEL8/rhel-8.oval.xml.bz2', - 'alma_oval_url': 'https://repo.almalinux.org/security/oval/org.almalinux.alsa-8.xml.bz2', - 'alma_errata_url': "https://errata.almalinux.org/8/errata.full.json", }, - 9: {'rhel_oval_url': 'https://www.redhat.com/security/data/oval/v2/RHEL9/rhel-9.oval.xml.bz2', - 'alma_oval_url': 'https://repo.almalinux.org/security/oval/org.almalinux.alsa-9.xml.bz2', - 'alma_errata_url': "https://errata.almalinux.org/9/errata.full.json", } -} -LOG_FILE = Path('logs/albs-oval-errata-diff.log') -DIFF_FILE = Path('results/diff.json') -DOWNLOAD_DIR = Path('/tmp') -# not checking anything before RHEL-9.0 release -NOT_BEFORE = datetime.datetime(2022, 5, 18) -UPDATE_INTERVAL_MINUTES = 30 -SERVER_PORT = 3001 -SERVER_IP = "127.0.0.1" -SA_EXCLUDE = [] -PACKAGES_EXCLUDE = ["dotnet-sdk-3.1-source-built-artifacts"] diff --git a/config.default.yml b/config.default.yml new file mode 100644 index 0000000..93c757a --- /dev/null +++ b/config.default.yml @@ -0,0 +1,68 @@ +--- +# diff_file +# file to store diff JSON in +# requred: no +# default: /tmp/albs-oval-errata-diff.json +diff_file: /tmp/albs-oval-errata-diff.json + +# download_dir +# directory to download Oval/Errata files to +# required: no +# default: /tmp +download_dir: /tmp + +# log_file +# file to write logs to +# requred: no +# default: logs/albs-oval-errata-diff.log +log_file: logs/albs-oval-errata-diff.log + +# packages_exclude +# list of RPM package names to exclude from checking +# requred: no +# default: [] +packages_exclude: [] + +# releases +# list of OS releases with Oval/Errata URLs to check +# required: yes +# default: N/A +releases: + 8: + rhel_oval_url: https://www.redhat.com/security/data/oval/v2/RHEL8/rhel-8.oval.xml.bz2 + alma_oval_url: https://repo.almalinux.org/security/oval/org.almalinux.alsa-8.xml.bz2 + alma_errata_url: https://errata.almalinux.org/8/errata.full.json + 9: + rhel_oval_url: https://www.redhat.com/security/data/oval/v2/RHEL9/rhel-9.oval.xml.bz2' + alma_oval_url: https://repo.almalinux.org/security/oval/org.almalinux.alsa-9.xml.bz2' + alma_errata_url: https://errata.almalinux.org/9/errata.full.json + +# sa_exclude +# list of Security Advisory IDs (ALSA-2022:5219) to exclude from checking +# requred: no +# default: [] +sa_exclude: [] + +# server_port +# port that will be used by websever +# required: no +# default: 3001 +server_port: 3001 + +# server_ip +# IP that will be used by webserver +# required: no +# default: 127.0.0.1 +server_ip: 127.0.0.1 + +# not_before +# date to start checking from (YYYY-mm-dd) +# required: no +# default: 2022-5-18 (Release of RHEL 9.0) +not_before: 2022-5-18 + +# update_interval_minutes +# how often service will be running difference checks (in minutes) +# required: no +# default: 30 +update_interval_minutes: 30 \ No newline at end of file