Skip to content

Commit

Permalink
Remove S3LogStore.close return URL
Browse files Browse the repository at this point in the history
This adds unnecessary complexity since it depends on the S3 server, so rely on the user to know how to get the URL
  • Loading branch information
manics committed Oct 10, 2020
1 parent 83d0f28 commit 52c732b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 26 deletions.
2 changes: 0 additions & 2 deletions repo2docker/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,6 @@ def start(self):
finally:
try:
r = self._logstore.close()
if r:
self.log.info(f"Log path: {r}")
except Exception as e:
self.log.error("Failed to save log: {}".format(e))

Expand Down
28 changes: 4 additions & 24 deletions repo2docker/logstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

try:
import boto3
from botocore import UNSIGNED
from botocore.config import Config

S3_ENABLED = True
except ImportError:
Expand All @@ -31,8 +29,7 @@ def write(self, s):
pass

def close(self):
"""Finish logging. Implementations may save or copy the log.
May return a path to the saved log"""
"""Finish logging. Implementations may save or copy the log."""
pass


Expand Down Expand Up @@ -89,7 +86,9 @@ def close(self):
# Empty log means image already exists so nothing was built
return
dest = f"{self.keyprefix}{self.logname}"
self.log.debug(f"Uploading log to {self.endpoint} key:{self.bucket}/{dest}")
self.log.info(
f"Uploading log to {self.endpoint} bucket:{self.bucket} key:{dest}"
)
s3 = boto3.resource(
"s3",
config=boto3.session.Config(signature_version="s3v4"),
Expand All @@ -101,22 +100,3 @@ def close(self):
ExtraArgs={"ContentType": "text/plain", "ACL": self.acl},
)
os.remove(self._logfile.name)
return self._get_url()

def _get_url(self):
# For simple S3 servers you can easily build the canonical URL.
# For AWS S3 this can be more complicated as it depends on your region.
# boto3 doesn't have a way to just get the public URL, so instead we create a pre-signed
# URL but discard the parameters since the object is public.
s3unsigned = boto3.client(
"s3", config=Config(UNSIGNED), **self._s3_credentials()
)
link = s3unsigned.generate_presigned_url(
"get_object",
ExpiresIn=0,
Params={
"Bucket": self.bucket,
"Key": f"{self.keyprefix}{self.logname}",
},
)
return link.split("?", 1)[0]

0 comments on commit 52c732b

Please sign in to comment.