Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejpurves committed Feb 20, 2024
1 parent 3bdb281 commit a2ef487
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions binderhub/repoproviders.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,20 +264,11 @@ def get_build_slug(self):
return f"zenodo-{self.record_id}"


def get_hashed_slug(url, changes_with_content):
"""Return a unique slug that is invariant to query parameters in the url"""
parsed_url = urlparse(url)
stripped_url = urlunparse(
(parsed_url.scheme, parsed_url.netloc, parsed_url.path, "", "", "")
)

return "meca-" + md5(f"{stripped_url}-{changes_with_content}".encode()).hexdigest()

class MecaRepoProvider(RepoProvider):
"""BinderHub Provider that can handle the contents of a MECA bundle
Users must provide a spec consisting of a public URL to the bundle
The URL origin must conform to the origin trait when that is set
The URL origin must be included in the list of allowed_origins when that trait is set
"""

name = Unicode("MECA Bundle")
Expand Down Expand Up @@ -328,6 +319,14 @@ def __init__(self, *args, **kwargs):
self.log.info(f"MECA Bundle URL: {self.url}")
self.log.info(f"MECA Bundle raw spec: {self.spec}")

def get_hashed_slug(self, url, changes_with_content):
"""Return a unique slug that is invariant to query parameters in the url"""
parsed_url = urlparse(url)
stripped_url = urlunparse(
(parsed_url.scheme, parsed_url.netloc, parsed_url.path, "", "", "")
)
return "meca-" + md5(f"{stripped_url}-{changes_with_content}".encode()).hexdigest()

async def get_resolved_ref(self):
# Check the URL is reachable
client = AsyncHTTPClient()
Expand All @@ -336,11 +335,11 @@ async def get_resolved_ref(self):
try:
r = await client.fetch(req)
self.log.info(f"URL is reachable: {self.url}")
self.hashed_slug = get_hashed_slug(
self.hashed_slug = self.get_hashed_slug(
self.url, r.headers.get("ETag") or r.headers.get("Content-Length")
)
except Exception as e:
raise ValueError(f"URL is unreachable ({e})")
raise RuntimeError(f"URL is unreachable ({e})")

self.log.info(f"hashed_slug: {self.hashed_slug}")
return self.hashed_slug
Expand Down

0 comments on commit a2ef487

Please sign in to comment.