From 03a9bf67395e5d0ca46682b27d8afbd401d3a7b2 Mon Sep 17 00:00:00 2001
From: Ken Dreyer <kdreyer@ibm.com>
Date: Jul 07 2023 03:15:17 +0000
Subject: [PATCH 1/2] write-repo-file: add --gpgcheck argument


Support "gpgcheck = 1"

---

diff --git a/compose_utils/repo_file.py b/compose_utils/repo_file.py
index 28d4fbe..3f6b48d 100644
--- a/compose_utils/repo_file.py
+++ b/compose_utils/repo_file.py
@@ -13,7 +13,7 @@ REPO = """\
 name = {name}
 baseurl = {baseurl}
 enabled = {enabled}
-gpgcheck = 0
+gpgcheck = {gpgcheck}
 """
 
 CONTENT_TYPES = {
@@ -86,7 +86,8 @@ def emit(compose, opts, variant, output, content_type="repository"):
         if not is_url(baseurl):
             baseurl = "file://" + baseurl
 
-    content = REPO.format(name=name, enabled=enabled, baseurl=baseurl)
+    content = REPO.format(name=name, enabled=enabled, baseurl=baseurl,
+                          gpgcheck=int(opts.gpgcheck))
     print(content, file=output)
 
 
@@ -160,6 +161,11 @@ def main(args=None):
         default="{release_short}-{release_version}-{variant}",
         help="Pattern for repository names.",
     )
+    parser.add_argument(
+        "--gpgcheck",
+        action="store_true",
+        help="Enable gpgcheck = 1. Default is gpgcheck = 0.",
+    )
     opts = parser.parse_args(args)
 
     try:
diff --git a/tests/fixtures/gpgcheck.repo b/tests/fixtures/gpgcheck.repo
new file mode 100644
index 0000000..34b9ed3
--- /dev/null
+++ b/tests/fixtures/gpgcheck.repo
@@ -0,0 +1,12 @@
+[DP-1.0-Client-rpms]
+name = DP-1.0-Client-rpms
+baseurl = file:///composes/DP-1.0-20160315.t.0/compose/Client/$basearch/os
+enabled = 1
+gpgcheck = 1
+
+[DP-1.0-Server-rpms]
+name = DP-1.0-Server-rpms
+baseurl = file:///composes/DP-1.0-20160315.t.0/compose/Server/$basearch/os
+enabled = 1
+gpgcheck = 1
+
diff --git a/tests/test_repo_file.py b/tests/test_repo_file.py
index 285d857..9e54779 100644
--- a/tests/test_repo_file.py
+++ b/tests/test_repo_file.py
@@ -101,6 +101,9 @@ class TestRepoFile(unittest.TestCase):
             "/Client/$basearch/os does not start with /foo/bar.\n", mock_err.getvalue()
         )
 
+    def test_gpgcheck(self):
+        self.success_run(["--gpgcheck"], "DP-1.0-20160315.t.0", "gpgcheck.repo")
+
     def test_is_url(self):
         self.assertTrue(repo_file.is_url('http://example.com/foobar'))
         self.assertTrue(repo_file.is_url('https://example.com/foobar'))

From 7bacb715f5a55842a2b7a480fabdac809f3c5ebe Mon Sep 17 00:00:00 2001
From: Ken Dreyer <kdreyer@ibm.com>
Date: Jul 07 2023 03:25:49 +0000
Subject: [PATCH 2/2] write-repo-file: add --gpgkey argument


Support "gpgkey = file://path/to/key"

---

diff --git a/compose_utils/repo_file.py b/compose_utils/repo_file.py
index 3f6b48d..d04d5e1 100644
--- a/compose_utils/repo_file.py
+++ b/compose_utils/repo_file.py
@@ -88,6 +88,8 @@ def emit(compose, opts, variant, output, content_type="repository"):
 
     content = REPO.format(name=name, enabled=enabled, baseurl=baseurl,
                           gpgcheck=int(opts.gpgcheck))
+    if opts.gpgkey:
+        content += "gpgkey = %s\n" % opts.gpgkey
     print(content, file=output)
 
 
@@ -166,6 +168,10 @@ def main(args=None):
         action="store_true",
         help="Enable gpgcheck = 1. Default is gpgcheck = 0.",
     )
+    parser.add_argument(
+        "--gpgkey",
+        help="gpgkey value (public key URL). Multiple key URLs should be comma-separated. Use --gpgcheck with this option.",
+    )
     opts = parser.parse_args(args)
 
     try:
diff --git a/tests/fixtures/gpgkey.repo b/tests/fixtures/gpgkey.repo
new file mode 100644
index 0000000..66bdb9a
--- /dev/null
+++ b/tests/fixtures/gpgkey.repo
@@ -0,0 +1,14 @@
+[DP-1.0-Client-rpms]
+name = DP-1.0-Client-rpms
+baseurl = file:///composes/DP-1.0-20160315.t.0/compose/Client/$basearch/os
+enabled = 1
+gpgcheck = 1
+gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-DummyProduct
+
+[DP-1.0-Server-rpms]
+name = DP-1.0-Server-rpms
+baseurl = file:///composes/DP-1.0-20160315.t.0/compose/Server/$basearch/os
+enabled = 1
+gpgcheck = 1
+gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-DummyProduct
+
diff --git a/tests/test_repo_file.py b/tests/test_repo_file.py
index 9e54779..703fe1a 100644
--- a/tests/test_repo_file.py
+++ b/tests/test_repo_file.py
@@ -104,6 +104,12 @@ class TestRepoFile(unittest.TestCase):
     def test_gpgcheck(self):
         self.success_run(["--gpgcheck"], "DP-1.0-20160315.t.0", "gpgcheck.repo")
 
+    def test_gpgkey(self):
+        self.success_run(
+            ["--gpgcheck",
+             "--gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-DummyProduct"],
+            "DP-1.0-20160315.t.0", "gpgkey.repo")
+
     def test_is_url(self):
         self.assertTrue(repo_file.is_url('http://example.com/foobar'))
         self.assertTrue(repo_file.is_url('https://example.com/foobar'))

