Small service that takes VRE API commands to create Virtual Research Workspace (VRW) through LDAP
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.9 KiB

from agent import WORKINGDIR, logger, VRWLDAP
from dotenv import dotenv_values
import json
from pathlib import Path
EXPORT_PATH = Path(f'{WORKINGDIR}/export/')
if __name__ == "__main__":
config_path = f'{WORKINGDIR}/.env'
if not Path(config_path).exists():
print('Missing .env file with credentials. Terminate!')
config = dotenv_values(config_path)
print('Logging into LDAP server')
# Load LDAP client
ldap_client = VRWLDAP(config['LDAP_HOST'], int(config['LDAP_PORT']), config['LDAP_USER'], config['LDAP_PASS'], config['LDAP_SSL'], not config['LDAP_MANUAL_GROUPS'])
if not ldap_client.check_connection():
logger.error(f'Could not login to the LDAP server. Check connection credentials.')
print('Start exporting researcher and study data')
# Get the data from the LDAP server
(researchers, studies) = ldap_client.export()
# convert study dict to list. Is less data and easier for the import later on.
studies_list = []
for study_data in studies.values():
contributor_list = []
for contributor in study_data['contributors'].values():
study_data['contributors'] = contributor_list
# Make sure the export folder does exists
if not EXPORT_PATH.exists():
# Clear old export
for file in EXPORT_PATH.iterdir():
data = {
'researchers': researchers,
'studies': studies_list,
for data_name, data_set in data.items():
json_data = json.dumps(data_set, indent=2)
# Write data to file
export_file = Path(f'{EXPORT_PATH}/{data_name}.json')
print(f'Exported {data_name} data to json file: {export_file}')
print('Done exporting VRW LDAP data')