diff --git a/osf/external/cedar/client.py b/osf/external/cedar/client.py new file mode 100644 index 00000000000..f451ee9b4fa --- /dev/null +++ b/osf/external/cedar/client.py @@ -0,0 +1,22 @@ +import requests +from urllib.parse import quote_plus +from website import settings + +class CedarClient(object): + host = settings.CEDAR_API_HOST + api_key = settings.CEDAR_API_KEY + home_folder_id = quote_plus(settings.CEDAR_HOME_FOLDER_ID) + headers = { + 'Authorization': f'apikey {api_key}' + } + + def retrieve_all_template_ids(self): + url = f'{self.host}folders/{self.home_folder_id}/contents/?resource_types=template' + r = requests.get(url, headers=self.headers) + resources = r.json()['resources'] + return [item['@id'] for item in resources] + + def retreive_template_by_id(self, id): + url = f'{self.host}templates/{quote_plus(id)}' + r = requests.get(url, headers=self.headers) + return r.json() diff --git a/website/settings/defaults.py b/website/settings/defaults.py index 77ee38075e6..443a26e9397 100644 --- a/website/settings/defaults.py +++ b/website/settings/defaults.py @@ -1992,6 +1992,11 @@ class CeleryConfig: SPAM_THROTTLE_AUTOBAN = True SPAM_CREATION_THROTTLE_LIMIT = 5 +# CEDAR API configs +CEDAR_API_HOST = '' +CEDAR_API_KEY = '' +CEDAR_HOME_FOLDER_ID = '' + # refresh campaign every 5 minutes CAMPAIGN_REFRESH_THRESHOLD = 5 * 60 # 5 minutes in seconds diff --git a/website/settings/local-dist.py b/website/settings/local-dist.py index e44788a403d..85a9b420db5 100644 --- a/website/settings/local-dist.py +++ b/website/settings/local-dist.py @@ -75,6 +75,11 @@ OSF_SERVER_KEY = None OSF_SERVER_CERT = None +# CEDAR API configs +CEDAR_API_HOST = '' +CEDAR_API_KEY = '' +CEDAR_HOME_FOLDER_ID = '' + class CeleryConfig(defaults.CeleryConfig): """ Celery configuration