From e564a96e50b3b0d498bb2eb52c0cb7478dd044b9 Mon Sep 17 00:00:00 2001 From: Radek Vykydal Date: Mon, 9 Dec 2024 11:24:46 +0100 Subject: [PATCH] edns: name the options --filename and --dir It describes their purpose better than --name and --path. --- dracut/parse-kickstart | 20 ++++---- .../modules/common/structures/security.py | 28 +++++------ .../security/certificates/certificates.py | 8 ++-- .../security/certificates/installation.py | 8 ++-- .../security/test_module_certificates.py | 48 +++++++++---------- .../modules/security/test_module_security.py | 8 ++-- 6 files changed, 60 insertions(+), 60 deletions(-) diff --git a/dracut/parse-kickstart b/dracut/parse-kickstart index 3ae417436d3..d823818476e 100755 --- a/dracut/parse-kickstart +++ b/dracut/parse-kickstart @@ -406,20 +406,20 @@ def ksnet_to_dracut(args, lineno, net, bootdev=False): return " ".join(line) -def _dump_certificate(cert, root="/", path=None): +def _dump_certificate(cert, root="/", dump_dir=None): """Dump the certificate into specified file.""" - path = path or cert.path - if not path: - log.error("Certificate destination is missing for %s", cert.name) + dump_dir = dump_dir or cert.dir + if not dump_dir: + log.error("Certificate destination is missing for %s", cert.filename) return - dst_dir = os.path.join(root+path.lstrip('/')) - log.debug("Dumping certificate %s into %s.", cert.name, dst_dir) + dst_dir = os.path.join(root+dump_dir.lstrip('/')) + log.debug("Dumping certificate %s into %s.", cert.filename, dst_dir) if not os.path.exists(dst_dir): log.debug("Path %s for certificate does not exist, creating.", dst_dir) os.makedirs(dst_dir) - dst = os.path.join(dst_dir, cert.name) + dst = os.path.join(dst_dir, cert.filename) if os.path.exists(dst): log.warning("Certificate file %s already exists, replacing.", dst) @@ -433,10 +433,10 @@ def process_certificates(handler): """Import certificates defined in %certificate sections.""" for cert in handler.certificates: - log.info("Processing kickstart certificate %s", cert.name) + log.info("Processing kickstart certificate %s", cert.filename) - if not cert.name: - log.error("Missing certificate name, skipping.") + if not cert.filename: + log.error("Missing certificate file name, skipping.") continue _dump_certificate(cert) diff --git a/pyanaconda/modules/common/structures/security.py b/pyanaconda/modules/common/structures/security.py index c7366a1e4f3..c0c93629ba1 100644 --- a/pyanaconda/modules/common/structures/security.py +++ b/pyanaconda/modules/common/structures/security.py @@ -26,18 +26,18 @@ class CertificateData(DBusData): """Structure for the certificate data.""" def __init__(self): - self._name = "" + self._filename = "" self._cert = "" - self._path = "" + self._dir = "" @property - def name(self) -> Str: - """The certificate name.""" - return self._name + def filename(self) -> Str: + """The certificate file name.""" + return self._filename - @name.setter - def name(self, value: Str) -> None: - self._name = value + @filename.setter + def filename(self, value: Str) -> None: + self._filename = value @property def cert(self) -> Str: @@ -49,10 +49,10 @@ def cert(self, value: Str) -> None: self._cert = value @property - def path(self) -> Str: - """The certificate path.""" - return self._path + def dir(self) -> Str: + """The certificate directory.""" + return self._dir - @path.setter - def path(self, value: Str) -> None: - self._path = value + @dir.setter + def dir(self, value: Str) -> None: + self._dir = value diff --git a/pyanaconda/modules/security/certificates/certificates.py b/pyanaconda/modules/security/certificates/certificates.py index 48b25176c70..0ca989b00fa 100644 --- a/pyanaconda/modules/security/certificates/certificates.py +++ b/pyanaconda/modules/security/certificates/certificates.py @@ -50,17 +50,17 @@ def process_kickstart(self, data): certificates = [] for cert in data.certificates: cert_data = CertificateData() - cert_data.name = cert.name + cert_data.filename = cert.filename cert_data.cert = cert.cert - if cert.path: - cert_data.path = cert.path + if cert.dir: + cert_data.dir = cert.dir certificates.append(cert_data) self.set_certificates(certificates) def setup_kickstart(self, data): """Setup the kickstart data.""" for cert in self._certificates: - cert_ksdata = Certificate(cert=cert.cert, name=cert.name, path=cert.path) + cert_ksdata = Certificate(cert=cert.cert, filename=cert.filename, dir=cert.dir) data.certificates.append(cert_ksdata) @property diff --git a/pyanaconda/modules/security/certificates/installation.py b/pyanaconda/modules/security/certificates/installation.py index 02f34ec0033..f71576f4dfe 100644 --- a/pyanaconda/modules/security/certificates/installation.py +++ b/pyanaconda/modules/security/certificates/installation.py @@ -53,17 +53,17 @@ def name(self): def _dump_certificate(self, cert, root): """Dump the certificate into specified file and directory.""" - if not cert.path: + if not cert.dir: raise SecurityInstallationError( - "Certificate destination is missing for {}".format(cert.name) + "Certificate destination is missing for {}".format(cert.filename) ) - dst_dir = join_paths(root, cert.path) + dst_dir = join_paths(root, cert.dir) if not os.path.exists(dst_dir): log.debug("Path %s for certificate does not exist, creating.", dst_dir) make_directories(dst_dir) - dst = join_paths(dst_dir, cert.name) + dst = join_paths(dst_dir, cert.filename) if os.path.exists(dst): log.warning("Certificate file %s already exists, replacing.", dst) diff --git a/tests/unit_tests/pyanaconda_tests/modules/security/test_module_certificates.py b/tests/unit_tests/pyanaconda_tests/modules/security/test_module_certificates.py index 8744cfd6d26..41bf9959a58 100644 --- a/tests/unit_tests/pyanaconda_tests/modules/security/test_module_certificates.py +++ b/tests/unit_tests/pyanaconda_tests/modules/security/test_module_certificates.py @@ -82,13 +82,13 @@ def test_certificates_property(self): certs_value = [ { 'cert': get_variant(Str, CERT1_CERT), - 'name': get_variant(Str, 'rvtest.pem'), - 'path': get_variant(Str, '/etc/pki/ca-trust/extracted/pem') + 'filename': get_variant(Str, 'rvtest.pem'), + 'dir': get_variant(Str, '/etc/pki/ca-trust/extracted/pem'), }, { 'cert': get_variant(Str, CERT2_CERT), - 'name': get_variant(Str, 'rvtest2.pem'), - 'path': get_variant(Str, '') + 'filename': get_variant(Str, 'rvtest2.pem'), + 'dir': get_variant(Str, ''), } ] self._check_dbus_property( @@ -106,13 +106,13 @@ def test_import_with_task_default(self, publisher): def _get_2_test_certs(self): cert1 = CertificateData() - cert1.name = "cert1.pem" + cert1.filename = "cert1.pem" cert1.cert = CERT1_CERT - cert1.path = "/cert/drop/directory1" + cert1.dir = "/cert/drop/directory1" cert2 = CertificateData() - cert2.name = "cert2.pem" + cert2.filename = "cert2.pem" cert2.cert = CERT2_CERT - cert2.path = "/cert/drop/directory2" + cert2.dir = "/cert/drop/directory2" return(cert1, cert2) @patch_dbus_publish_object @@ -127,9 +127,9 @@ def test_import_with_task_configured(self, publisher): obj = check_task_creation(task_path, publisher, ImportCertificatesTask) assert obj.implementation._sysroot == "/" assert len(obj.implementation._certificates) == 2 - t_cert1, t_cert2 = obj.implementation._certificates - assert (t_cert1.name, t_cert1.path, t_cert1.cert) == (cert1.name, cert1.path, cert1.cert) - assert (t_cert2.name, t_cert2.path, t_cert2.cert) == (cert2.name, cert2.path, cert2.cert) + c1, c2 = obj.implementation._certificates + assert (c1.filename, c1.dir, c1.cert) == (cert1.filename, cert1.dir, cert1.cert) + assert (c2.filename, c2.dir, c2.cert) == (cert2.filename, cert2.dir, cert2.cert) @patch_dbus_publish_object def test_install_with_task_default(self, publisher): @@ -151,9 +151,9 @@ def test_install_with_task_configured(self, publisher): obj = check_task_creation(task_path, publisher, ImportCertificatesTask) assert obj.implementation._sysroot == "/mnt/sysroot" assert len(obj.implementation._certificates) == 2 - t_cert1, t_cert2 = obj.implementation._certificates - assert (t_cert1.name, t_cert1.path, t_cert1.cert) == (cert1.name, cert1.path, cert1.cert) - assert (t_cert2.name, t_cert2.path, t_cert2.cert) == (cert2.name, cert2.path, cert2.cert) + c1, c2 = obj.implementation._certificates + assert (c1.filename, c1.dir, c1.cert) == (cert1.filename, cert1.dir, cert1.cert) + assert (c2.filename, c2.dir, c2.cert) == (cert2.filename, cert2.dir, cert2.cert) @patch_dbus_publish_object def test_pre_install_with_task_default(self, publisher): @@ -175,18 +175,18 @@ def test_pre_install_with_task_configured(self, publisher): obj = check_task_creation(task_path, publisher, ImportCertificatesTask) assert obj.implementation._sysroot == "/mnt/sysroot" assert len(obj.implementation._certificates) == 2 - t_cert1, t_cert2 = obj.implementation._certificates - assert (t_cert1.name, t_cert1.path, t_cert1.cert) == (cert1.name, cert1.path, cert1.cert) - assert (t_cert2.name, t_cert2.path, t_cert2.cert) == (cert2.name, cert2.path, cert2.cert) + c1, c2 = obj.implementation._certificates + assert (c1.filename, c1.dir, c1.cert) == (cert1.filename, cert1.dir, cert1.cert) + assert (c2.filename, c2.dir, c2.cert) == (cert2.filename, cert2.dir, cert2.cert) def test_import_certificates_task_files(self): """Test the ImportCertificatesTask task""" cert1, cert2 = self._get_2_test_certs() with tempfile.TemporaryDirectory() as sysroot: - # cert1 has existing path - os.makedirs(sysroot+cert1.path) - # cert2 has non-existing path + # cert1 has existing dir + os.makedirs(sysroot+cert1.dir) + # cert2 has non-existing dir ImportCertificatesTask( sysroot=sysroot, @@ -197,7 +197,7 @@ def test_import_certificates_task_files(self): self._check_cert_file(cert2, sysroot) def _check_cert_file(self, cert, sysroot, missing=False): - cert_file = sysroot + cert.path + "/" + cert.name + cert_file = sysroot + cert.dir + "/" + cert.filename if missing: assert os.path.exists(cert_file) is False else: @@ -211,8 +211,8 @@ def test_import_certificates_task_existing_file(self): with tempfile.TemporaryDirectory() as sysroot: # certificate file to be dumped already exists - os.makedirs(sysroot+cert1.path) - cert1_file = sysroot + cert1.path + "/" + cert1.name + os.makedirs(sysroot+cert1.dir) + cert1_file = sysroot + cert1.dir + "/" + cert1.filename open(cert1_file, 'w') ImportCertificatesTask( @@ -225,7 +225,7 @@ def test_import_certificates_task_existing_file(self): def test_import_certificates_missing_destination(self): """Test the ImportCertificatesTask task with missing destination""" cert1, _ = self._get_2_test_certs() - cert1.path = '' + cert1.dir = '' with tempfile.TemporaryDirectory() as sysroot: with self.assertRaises(SecurityInstallationError): diff --git a/tests/unit_tests/pyanaconda_tests/modules/security/test_module_security.py b/tests/unit_tests/pyanaconda_tests/modules/security/test_module_security.py index e9e867bed2b..e37edb636c4 100644 --- a/tests/unit_tests/pyanaconda_tests/modules/security/test_module_security.py +++ b/tests/unit_tests/pyanaconda_tests/modules/security/test_module_security.py @@ -159,7 +159,7 @@ def test_realm_kickstart(self): def test_certificates_kickstart(self): """Test the %certificates section.""" ks_in = """ - %certificate --name=rvtest.pem --path=/cert_path + %certificate --filename=rvtest.pem --dir=/cert_dir -----BEGIN CERTIFICATE----- MIIBjTCCATOgAwIBAgIUWR5HO3v/0I80Ne0jQWVZFODuWLEwCgYIKoZIzj0EAwIw FDESMBAGA1UEAwwJUlZURVNUIENBMB4XDTI0MTEyMDEzNTk1N1oXDTM0MTExODEz @@ -173,7 +173,7 @@ def test_certificates_kickstart(self): -----END CERTIFICATE----- %end - %certificate --name=rvtest2.pem --path=/cert_path2 + %certificate --filename=rvtest2.pem --dir=/cert_dir2 -----BEGIN CERTIFICATE----- MIIBkTCCATegAwIBAgIUN6r4TjFJqP/TS6U25iOGL2Wt/6kwCgYIKoZIzj0EAwIw FjEUMBIGA1UEAwwLUlZURVNUIDIgQ0EwHhcNMjQxMTIwMTQwMzIxWhcNMzQxMTE4 @@ -188,7 +188,7 @@ def test_certificates_kickstart(self): %end """ ks_out = """ - %certificate --name=rvtest.pem --path=/cert_path + %certificate --filename=rvtest.pem --dir=/cert_dir -----BEGIN CERTIFICATE----- MIIBjTCCATOgAwIBAgIUWR5HO3v/0I80Ne0jQWVZFODuWLEwCgYIKoZIzj0EAwIw FDESMBAGA1UEAwwJUlZURVNUIENBMB4XDTI0MTEyMDEzNTk1N1oXDTM0MTExODEz @@ -202,7 +202,7 @@ def test_certificates_kickstart(self): -----END CERTIFICATE----- %end - %certificate --name=rvtest2.pem --path=/cert_path2 + %certificate --filename=rvtest2.pem --dir=/cert_dir2 -----BEGIN CERTIFICATE----- MIIBkTCCATegAwIBAgIUN6r4TjFJqP/TS6U25iOGL2Wt/6kwCgYIKoZIzj0EAwIw FjEUMBIGA1UEAwwLUlZURVNUIDIgQ0EwHhcNMjQxMTIwMTQwMzIxWhcNMzQxMTE4