Commit 5b2337b4 authored by Tamim Ziai's avatar Tamim Ziai

Merge branch 'develop' into 'master'

Develop

See merge request crust/customer!16
parents f6bfdf42 0347c676
......@@ -6,6 +6,8 @@ CRUST_TASK_URL_2 = '' # Deactivating URL by emtpy string ''
CRUST_TASK_URL_3 = '' # Deactivating URL by emtpy string ''
TASK_PRIVATE_ATTRIBUTES = ['mail', 'telephoneNumber']
TASK_RETRY_THRESHOLD = 5
TASK_FAILURE_EXECUTION_PERIOD = 1 # In minutes
\ No newline at end of file
......@@ -6,6 +6,8 @@ CRUST_TASK_URL_2 = @CRUST_TASK_URL_2@ # Deactivating URL by emtpy string ''
CRUST_TASK_URL_3 = @CRUST_TASK_URL_3@ # Deactivating URL by emtpy string ''
TASK_PRIVATE_ATTRIBUTES = @TASK_PRIVATE_ATTRIBUTES@
TASK_RETRY_THRESHOLD = 5
TASK_FAILURE_EXECUTION_PERIOD = 1
......@@ -3,24 +3,23 @@ import base64
import tasks.settings as settings
from general.class_provider import get_class, get_function
import json
import ldap
class granted:
def execute(self, user_ldap_entry):
def execute(self, user_ldap_entry, user_dn):
delete_private_data(user_dn)
if not getattr(settings, 'CRUST_TASK_URL_1') == '':
json_body = provide_request_body(user_ldap_entry)
#headers = {'X-TENANT-ID': 'lui2backend', 'Authorization': 'Basic ' + base64.b64encode('crust:Unity-Grease-Cow-Sensitive-Despair-5'.encode()).decode()}
response = requests.delete(getattr(settings, 'CRUST_TASK_URL_1'), data=json_body, timeout=1)
response = requests.post(getattr(settings, 'CRUST_TASK_URL_1'), data=json_body, timeout=1)
if response.status_code is not 200:
return response.status_code
if not getattr(settings, 'CRUST_TASK_URL_2') == '':
json_body = provide_request_body(user_ldap_entry)
#headers = {'X-TENANT-ID': 'lui2backend', 'Authorization': 'Basic ' + base64.b64encode('crust:Unity-Grease-Cow-Sensitive-Despair-5'.encode()).decode()}
response = requests.post(getattr(settings, 'CRUST_TASK_URL_2'), data=json_body, timeout=1)
if response.status_code is not 200:
return response.status_code
if not getattr(settings, 'CRUST_TASK_URL_3') == '':
json_body = provide_request_body(user_ldap_entry)
#headers = {'X-TENANT-ID': 'lui2backend', 'Authorization': 'Basic ' + base64.b64encode('crust:Unity-Grease-Cow-Sensitive-Despair-5'.encode()).decode()}
response = requests.post(getattr(settings, 'CRUST_TASK_URL_3'), timeout=1, data=json_body)
if response.status_code is not 200:
return response.status_code
......@@ -28,7 +27,7 @@ class granted:
return response.status_code
class denied:
def execute(self,user_ldap_entry):
def execute(self,user_ldap_entry, user_dn):
pass
......@@ -39,4 +38,16 @@ def provide_request_body(ldap_entry):
if attribute in ldap_entry:
json_body[attribute] = ldap_entry[attribute]
return json.dumps(json_body)
def delete_private_data(dn):
private_attributes = getattr(settings, 'TASK_PRIVATE_ATTRIBUTES', ['mail'])
mod_list = build_modlist_for_patch(private_attributes)
patch_class = get_class('PatchRequest', 'ldap_app.processors.dispatcher.Request')(None, dn)
patch_class.mod_attr_list = mod_list
patch_class.write_in_ldap()
def build_modlist_for_patch(attributes):
mod_list = list()
for attribute in attributes:
mod_list.append((ldap.MOD_DELETE, attribute, None))
return mod_list
......@@ -5,30 +5,28 @@ from general.class_provider import get_class, get_function
import json
class granted:
def execute(self, user_ldap_entry):
def execute(self, user_ldap_entry, user_dn):
if not getattr(settings, 'CRUST_TASK_URL_1') == '':
json_body = provide_request_body(user_ldap_entry)
#headers = {'X-TENANT-ID': 'lui2backend', 'Authorization': 'Basic ' + base64.b64encode('crust:Unity-Grease-Cow-Sensitive-Despair-5'.encode()).decode()}
response = requests.delete(getattr(settings, 'CRUST_TASK_URL_1'), data=json_body, timeout=1)
response = requests.post(getattr(settings, 'CRUST_TASK_URL_1'), data=json_body, timeout=1)
if response.status_code is not 200:
return response.status_code
if not getattr(settings, 'CRUST_TASK_URL_2') == '':
json_body = provide_request_body(user_ldap_entry)
#headers = {'X-TENANT-ID': 'lui2backend', 'Authorization': 'Basic ' + base64.b64encode('crust:Unity-Grease-Cow-Sensitive-Despair-5'.encode()).decode()}
response = requests.post(getattr(settings, 'CRUST_TASK_URL_2'), data=json_body, timeout=1)
if response.status_code is not 200:
return response.status_code
if not getattr(settings, 'CRUST_TASK_URL_3') == '':
json_body = provide_request_body(user_ldap_entry)
#headers = {'X-TENANT-ID': 'lui2backend', 'Authorization': 'Basic ' + base64.b64encode('crust:Unity-Grease-Cow-Sensitive-Despair-5'.encode()).decode()}
response = requests.post(getattr(settings, 'CRUST_TASK_URL_3'), timeout=1, data=json_body)
if response.status_code is not 200:
return response.status_code
delete_all_private_data(user_dn)
return response.status_code
class denied:
def execute(self,user_ldap_entry):
def execute(self,user_ldap_entry, user_dn):
pass
......@@ -39,4 +37,8 @@ def provide_request_body(ldap_entry):
if attribute in ldap_entry:
json_body[attribute] = ldap_entry[attribute]
return json.dumps(json_body)
def delete_all_private_data(dn):
delete_class = get_class('DeleteRequest', 'ldap_app.processors.dispatcher.Request')(dn)
delete_class.run()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment