From 7be37ef90fcb5a4d385b68b3632c9cba63e235f8 Mon Sep 17 00:00:00 2001
From: Randomizer3000 <95537953+randomizer3000@users.noreply.github.com>
Date: Sun, 5 Dec 2021 03:15:42 +1100
Subject: [PATCH 1/3] added polling_interval which tells certmonger how long to
 wait in seconds before retrying

---
 bin/cepces-submit              |  4 +++-
 cepces/certmonger/operation.py | 10 ++++++----
 cepces/config.py               | 13 ++++++++++---
 conf/cepces.conf.dist          |  3 +++
 4 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/bin/cepces-submit b/bin/cepces-submit
index ae3a563..b3d7b26 100755
--- a/bin/cepces-submit
+++ b/bin/cepces-submit
@@ -83,12 +83,14 @@ if __name__ == '__main__':
         choices=['Anonymous', 'Kerberos',
                  'UsernamePassword', 'Certificate'],
         default='Kerberos')
+    parser.add_argument('--poll_interval',
+        help='Time in seconds before re-checking if the certificate has been issued')
     parser.add_argument('--keytab', help='Use the specified keytab')
     parser.add_argument('--principals',
         help='A list of principals to try when requesting a ticket')
     args = parser.parse_args()
     if args.server is not None:
-        g_overrides = { 'server': args.server, 'auth': args.auth }
+        g_overrides = { 'server': args.server, 'auth': args.auth, 'poll_interval': args.poll_interval }
         endpoint = 'https://%s/ADPolicyProvider_CEP_%s/service.svc/CEP' % \
                         (args.server, args.auth)
         g_overrides['endpoint'] = endpoint
diff --git a/cepces/certmonger/operation.py b/cepces/certmonger/operation.py
index 0b9089a..b7a1e11 100644
--- a/cepces/certmonger/operation.py
+++ b/cepces/certmonger/operation.py
@@ -132,14 +132,15 @@ class Submit(Operation):
 
         # Output a "cookie" that can be used to later poll the status.
         print(
-            '{},{}'.format(
+            '{}\n{},{}'.format(
+                self._config.poll_interval,
                 result.request_id,
                 result.reference,
             ),
             file=self._out,
         )
 
-        return CertmongerResult.WAIT
+        return CertmongerResult.WAITMORE
 
 
 class Poll(Operation):
@@ -172,14 +173,15 @@ class Poll(Operation):
 
         # Output a "cookie" that can be used to later poll the status.
         print(
-            '{},{}'.format(
+            '{}\n{},{}'.format(
+                self._config.poll_interval,
                 result.request_id,
                 result.reference,
             ),
             file=self._out,
         )
 
-        return CertmongerResult.WAIT
+        return CertmongerResult.WAITMORE
 
 
 class Identify(Operation):
diff --git a/cepces/config.py b/cepces/config.py
index a8dcfed..15f5e4b 100644
--- a/cepces/config.py
+++ b/cepces/config.py
@@ -55,13 +55,14 @@ class Configuration(Base):
         'Certificate': SOAPAuth.MessageCertificateAuthentication,
     }
 
-    def __init__(self, endpoint, endpoint_type, cas, auth):
+    def __init__(self, endpoint, endpoint_type, cas, auth, poll_interval):
         super().__init__()
 
         self._endpoint = endpoint
         self._endpoint_type = endpoint_type
         self._cas = cas
         self._auth = auth
+        self.pollInterval = poll_interval
 
     @property
     def endpoint(self):
@@ -83,6 +84,11 @@ class Configuration(Base):
         """Return the authentication method."""
         return self._auth
 
+    @property
+    def poll_interval(self):
+        """Return the poll interval."""
+        return self._poll_interval
+
     @classmethod
     def load(cls, files=None, dirs=None, global_overrides=None,
              krb5_overrides=None):
@@ -149,7 +155,7 @@ class Configuration(Base):
         section = parser['global']
 
         # Ensure certain required variables are present.
-        for var in ['endpoint', 'auth', 'type']:
+        for var in ['endpoint', 'auth', 'type', 'poll_interval']:
             if var not in section:
                 raise RuntimeError(
                     'Missing "{}/{}" variable in configuration.'.format(
@@ -171,8 +177,9 @@ class Configuration(Base):
         endpoint_type = section.get('type')
         authn = Configuration.AUTH_HANDLER_MAP[section['auth']](parser)
         cas = section.get('cas', True)
+        poll_interval = section.get('poll_interval')
 
         if cas == '':
             cas = False
 
-        return Configuration(endpoint, endpoint_type, cas, authn.handle())
+        return Configuration(endpoint, endpoint_type, cas, authn.handle(), poll_interval)
diff --git a/conf/cepces.conf.dist b/conf/cepces.conf.dist
index c38a5f4..4c71105 100644
--- a/conf/cepces.conf.dist
+++ b/conf/cepces.conf.dist
@@ -45,6 +45,9 @@ endpoint=https://${server}/ADPolicyProvider_CEP_${auth}/service.svc/CEP
 # Default: <not defined>
 #cas=
 
+# Time in seconds before re-checking if the certificate has been issued
+poll_interval=3600
+
 [kerberos]
 # Use the specified keytab. If unspecified, the system default is used.
 #
-- 
2.42.1


From debeb0d152f148d2165e374564cf5f8ebdce0e2b Mon Sep 17 00:00:00 2001
From: David Mulder <dmulder@samba.org>
Date: Thu, 20 Oct 2022 05:31:49 -0600
Subject: [PATCH 2/3] Fix cepces-submit 'TypeError: option values must be
 strings'

cepces-submit failed with 'TypeError: option
values must be strings' in config.py because the
poll_interval command line parameter defaulted
to `None`.

Signed-off-by: David Mulder <dmulder@samba.org>
---
 bin/cepces-submit | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/bin/cepces-submit b/bin/cepces-submit
index b3d7b26..69a764d 100755
--- a/bin/cepces-submit
+++ b/bin/cepces-submit
@@ -89,13 +89,15 @@ if __name__ == '__main__':
     parser.add_argument('--principals',
         help='A list of principals to try when requesting a ticket')
     args = parser.parse_args()
+    g_overrides = {}
     if args.server is not None:
-        g_overrides = { 'server': args.server, 'auth': args.auth, 'poll_interval': args.poll_interval }
+        g_overrides['server'] = args.server
+        g_overrides['auth'] = args.auth
         endpoint = 'https://%s/ADPolicyProvider_CEP_%s/service.svc/CEP' % \
                         (args.server, args.auth)
         g_overrides['endpoint'] = endpoint
-    else:
-        g_overrides = {}
+    if args.poll_interval is not None:
+        g_overrides['poll_interval'] = args.poll_interval
     k_overrides = {}
     if args.keytab is not None:
         k_overrides['keytab'] = args.keytab
-- 
2.42.1


From 57a50e75a478609854d50789f10c936c623f54e0 Mon Sep 17 00:00:00 2001
From: g-t-u <g-t-u@users.noreply.github.com>
Date: Mon, 23 May 2022 18:59:56 +0700
Subject: [PATCH 3/3] Fix unavailable poll_interval config value in Submit and
 Poll operations.

---
 cepces/certmonger/operation.py | 4 ++--
 cepces/config.py               | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/cepces/certmonger/operation.py b/cepces/certmonger/operation.py
index b7a1e11..1fd6fbc 100644
--- a/cepces/certmonger/operation.py
+++ b/cepces/certmonger/operation.py
@@ -133,7 +133,7 @@ class Submit(Operation):
         # Output a "cookie" that can be used to later poll the status.
         print(
             '{}\n{},{}'.format(
-                self._config.poll_interval,
+                service._config.poll_interval,
                 result.request_id,
                 result.reference,
             ),
@@ -174,7 +174,7 @@ class Poll(Operation):
         # Output a "cookie" that can be used to later poll the status.
         print(
             '{}\n{},{}'.format(
-                self._config.poll_interval,
+                service._config.poll_interval,
                 result.request_id,
                 result.reference,
             ),
diff --git a/cepces/config.py b/cepces/config.py
index 15f5e4b..5f8e9b7 100644
--- a/cepces/config.py
+++ b/cepces/config.py
@@ -62,7 +62,7 @@ class Configuration(Base):
         self._endpoint_type = endpoint_type
         self._cas = cas
         self._auth = auth
-        self.pollInterval = poll_interval
+        self._poll_interval = poll_interval
 
     @property
     def endpoint(self):
-- 
2.42.1

