Skip to content

Commit

Permalink
refactoring of url in the minibased s3
Browse files Browse the repository at this point in the history
  • Loading branch information
sametd committed Sep 20, 2024
1 parent 4884676 commit 25a0e3e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions polytope_server/common/staging/s3_staging.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(self, config):
secure = config.get("secure", False)
self.url = config.get("url", None)
internal_url = "{}:{}".format(self.host, self.port)
secure = config.get("use_ssl", False)
use_ssl = config.get("use_ssl", False)

if access_key == "" or secret_key == "":
self.client = Minio(
Expand All @@ -97,7 +97,8 @@ def __init__(self, config):
secure=secure,
)

self.internal_url = ("https://" if secure else "http://") + internal_url
self.prefix = ("https://" if use_ssl else "http://") + internal_url
self.internal_url = f"http://{self.host}:{self.port}"

try:
self.client.make_bucket(self.bucket)
Expand Down Expand Up @@ -213,10 +214,13 @@ def collect_metric_info(self):
return self.storage_metric_collector.collect().serialize()

def get_url(self, name):
if self.url is None:
return None
url = "{}/{}/{}".format(self.url, self.bucket, name)
return url
if self.url:
if self.url.startswith("http"):
# This covers both http and https
return f"{self.url}/{self.bucket}/{name}"
else:
return f"{self.prefix}://{self.url}/{self.bucket}/{name}"
return None

def get_internal_url(self, name):
url = "{}/{}/{}".format(self.internal_url, self.bucket, name)
Expand Down

0 comments on commit 25a0e3e

Please sign in to comment.