+
+# Helper: Callout kafka dispatcher server to notify it for policy operations
+def callout_kafka_dispatcher(policy_type_id, policy_id, payload, retcode):
+
+ target_url = KAFKA_DISPATCHER_URL + "/policytypes/" + policy_type_id + "/kafkadispatcher/" + policy_id
+ try:
+ # create operation, publish with payload
+ if (retcode == 201):
+ resp=requests.put(target_url, json=payload, timeout=30, verify=False)
+ return resp.status_code
+ # update operation, publish with payload
+ elif (retcode == 200):
+ # add headers an update-flag
+ headers = {'updateoper' : 'yes'}
+ resp=requests.put(target_url, json=payload, headers=headers, timeout=30, verify=False)
+ return resp.status_code
+ # delete operation, publish without payload
+ elif (retcode == 204):
+ resp=requests.delete(target_url, timeout=30, verify=False)
+ return resp.status_code
+ # get policy status operation, publish without payload
+ elif (retcode == 202):
+ # update endpoint
+ target_url = target_url + "/status"
+ resp=requests.get(target_url, timeout=30, verify=False)
+ return resp.status_code
+ except Exception:
+ return 419
+
+
+# Helper: Callout external server to notify it for policy operations
+# Returns 200, 201 and 204 for the success callout hooks, for the others returns 419
+def callout_external_server(policy_id, payload, operation):
+
+ target_url=EXT_SRV_URL + policy_id
+ try:
+ if (operation == 'PUT'):
+ #Suppress error when self-signed certificate is being used with verify flag
+ resp=requests.put(target_url, json=payload, timeout=10, verify=False)
+ return resp.status_code
+ elif (operation == 'DELETE'):
+ resp=requests.delete(target_url, timeout=10, verify=False)
+ return resp.status_code
+ except Exception:
+ #Return a generic unassigned HTTP status code as per iana, for all exceptions (419:Callout failed)
+ #https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
+ return 419
+