77
88try :
99 import boto3
10- from botocore import UNSIGNED
11- from botocore .config import Config
1210
1311 S3_ENABLED = True
1412except ImportError :
@@ -31,8 +29,7 @@ def write(self, s):
3129 pass
3230
3331 def close (self ):
34- """Finish logging. Implementations may save or copy the log.
35- May return a path to the saved log"""
32+ """Finish logging. Implementations may save or copy the log."""
3633 pass
3734
3835
@@ -89,7 +86,9 @@ def close(self):
8986 # Empty log means image already exists so nothing was built
9087 return
9188 dest = f"{ self .keyprefix } { self .logname } "
92- self .log .debug (f"Uploading log to { self .endpoint } key:{ self .bucket } /{ dest } " )
89+ self .log .info (
90+ f"Uploading log to { self .endpoint } bucket:{ self .bucket } key:{ dest } "
91+ )
9392 s3 = boto3 .resource (
9493 "s3" ,
9594 config = boto3 .session .Config (signature_version = "s3v4" ),
@@ -101,22 +100,3 @@ def close(self):
101100 ExtraArgs = {"ContentType" : "text/plain" , "ACL" : self .acl },
102101 )
103102 os .remove (self ._logfile .name )
104- return self ._get_url ()
105-
106- def _get_url (self ):
107- # For simple S3 servers you can easily build the canonical URL.
108- # For AWS S3 this can be more complicated as it depends on your region.
109- # boto3 doesn't have a way to just get the public URL, so instead we create a pre-signed
110- # URL but discard the parameters since the object is public.
111- s3unsigned = boto3 .client (
112- "s3" , config = Config (UNSIGNED ), ** self ._s3_credentials ()
113- )
114- link = s3unsigned .generate_presigned_url (
115- "get_object" ,
116- ExpiresIn = 0 ,
117- Params = {
118- "Bucket" : self .bucket ,
119- "Key" : f"{ self .keyprefix } { self .logname } " ,
120- },
121- )
122- return link .split ("?" , 1 )[0 ]
0 commit comments