Skip to content

Commit

Permalink
Support v2/ping which seems to be identical to v1/ping
Browse files Browse the repository at this point in the history
  • Loading branch information
Croydon committed May 18, 2024
1 parent dc1c464 commit b53e215
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions bincrafters_conan_remote/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def get_external_site(request: Request, url_path: str):
# logger.info(f"Remote Type: {remote_type}, Remote HTTP URL: {remote_http_url}, Remote Name: {remote_config}")
# logger.info(f"url_path: {url_path}, cache_url_path: {cache_url_path}")

if url_path == "v1/ping" and len(cached_headers) != 0:
if (url_path == "v1/ping" or url_path == "v2/ping") and len(cached_headers) != 0:
# logger.info(f"Cached headers: {cached_headers}")
return Response(headers=cached_headers)

Expand Down Expand Up @@ -92,15 +92,15 @@ async def get_external_site(request: Request, url_path: str):
# logger.info(f"cache_dir: {cache_dir}")
os.makedirs(cache_dir, exist_ok=True)

if url_path == "v1/ping":
if url_path == "v1/ping" or url_path == "v2/ping":
for header in r.headers:
if header.startswith("x-conan"):
cached_headers[header] = r.headers[header]
cache_path_parts = cache_path.split(os.sep)
with open(os.path.join(*cache_path_parts[:4], conf["filename_server_conan_headers"]), "w") as f:
f.write(json.dumps(cached_headers))

if not url_path in ["v1/ping",]:
if not url_path in ["v1/ping","v2/ping",]:
if filename.endswith(".tgz"):
if CREATE_FULL_LOCAL_BACKUP:
with open(os.path.join(cache_path), "wb") as f:
Expand Down
8 changes: 4 additions & 4 deletions bincrafters_conan_remote/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def read_root(request: Request):
return {"Hello": "World", "User-Agent": user_agent, "pwd": os.getcwd()}


def v1_ping(remote_http_url, user_agent):
def v2_ping(remote_http_url, user_agent):
if remote_http_url in cached_headers:
headers = cached_headers[remote_http_url]
else:
Expand Down Expand Up @@ -99,11 +99,11 @@ async def get_external_site(request: Request, url_path: str):

default_response_type = "application/json"

if url_path == "v1/ping":
return v1_ping(remote_http_url=remote_http_url, user_agent=user_agent)
if url_path == "v1/ping" or url_path == "v2/ping":
return v2_ping(remote_http_url=remote_http_url, user_agent=user_agent)

if not remote_http_url in cached_headers:
_ = v1_ping(remote_http_url=remote_http_url, user_agent=user_agent)
_ = v2_ping(remote_http_url=remote_http_url, user_agent=user_agent)

if url_path.endswith("latest"):
tmp_path = "/".join(url_path.split("/")[:-1])
Expand Down

0 comments on commit b53e215

Please sign in to comment.