Skip to content

Commit

Permalink
Merge pull request #17 from GermanoGuerrini/terms_and_conditions
Browse files Browse the repository at this point in the history
Added implicit acceptance of terms and conditions
  • Loading branch information
ricardo-correa authored Nov 7, 2022
2 parents 54e6691 + 4eb1bec commit 3eb0198
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions hda/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ def get_token(self):
session.auth = None
return result["access_token"]

def accept_tac(self):
url = "termsaccepted/Copernicus_General_License"
result = self.get(url)
if not result["accepted"]:
self.debug("TAC not yet accepted")
result = self.put({"accepted": True}, url)
self.debug("<=== %s", result)

@property
def session(self):
if self._session is None:
Expand Down Expand Up @@ -426,6 +434,7 @@ def wrapped(*args, **kwargs):
return wrapped

def search(self, query):
self.accept_tac()
return SearchResults(self, *DataRequestRunner(self).run(query))

def _datasets(self):
Expand All @@ -452,10 +461,6 @@ def metadata(self, datasetId):
return response

def get(self, *args):

if self.debug:
self.session # Force login

full = self.full_url(*args)
self.debug("===> GET %s", full)

Expand All @@ -466,10 +471,6 @@ def get(self, *args):
return result

def post(self, message, *args):

if self.debug:
self.session # Force login

full = self.full_url(*args)
self.debug("===> POST %s", full)
self.debug("===> POST %s", shorten(message))
Expand All @@ -480,6 +481,15 @@ def post(self, message, *args):
self.debug("<=== %s", shorten(result))
return result

def put(self, message, *args):
full = self.full_url(*args)
self.debug("===> PUT %s", full)
self.debug("===> PUT %s", shorten(message))

r = self.robust(self.session.put)(full, json=message, timeout=self.timeout)
r.raise_for_status()
return r

def stream(self, target, size, download_dir, *args):
full = self.full_url(*args)

Expand Down

0 comments on commit 3eb0198

Please sign in to comment.