Skip to content

Commit

Permalink
Cedar client
Browse files Browse the repository at this point in the history
  • Loading branch information
adlius committed Nov 20, 2023
1 parent 316339d commit c862df6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
22 changes: 22 additions & 0 deletions osf/external/cedar/client.py
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 5 additions & 0 deletions website/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions website/settings/local-dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c862df6

Please sign in to comment.