Explorar o código

Set cache-control when uploading to google storage

R=gavinmak@google.com

Bug: 585752
Change-Id: I25ece89abd09ad509807a7db0403bac0f5ebdd4e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3171825
Auto-Submit: Josip Sokcevic <sokcevic@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Josip Sokcevic %!s(int64=3) %!d(string=hai) anos
pai
achega
c1fd44b01a
Modificáronse 3 ficheiros con 9 adicións e 10 borrados
  1. 2 1
      gsutil.py
  2. 6 8
      tests/upload_to_google_storage_unittest.py
  3. 1 1
      upload_to_google_storage.py

+ 2 - 1
gsutil.py

@@ -177,7 +177,8 @@ def run_gsutil(target, args, clean=False):
 def parse_args():
   bin_dir = os.environ.get('DEPOT_TOOLS_GSUTIL_BIN_DIR', DEFAULT_BIN_DIR)
 
-  parser = argparse.ArgumentParser()
+  # Help is disabled as it conflicts with gsutil -h, which controls headers.
+  parser = argparse.ArgumentParser(add_help=False)
 
   parser.add_argument('--clean', action='store_true',
       help='Clear any existing gsutil package, forcing a new download.')

+ 6 - 8
tests/upload_to_google_storage_unittest.py

@@ -68,8 +68,8 @@ class UploadTests(unittest.TestCase):
         [('check_call',
           ('ls', '%s/%s' % (self.base_url, self.lorem_ipsum_sha1))),
          ('check_call',
-          ('cp', '-z', 'txt', filenames[0],
-           '%s/%s' % (self.base_url, self.lorem_ipsum_sha1)))])
+          ('-h', 'Cache-Control:public, max-age=31536000', 'cp', '-z', 'txt',
+           filenames[0], '%s/%s' % (self.base_url, self.lorem_ipsum_sha1)))])
     self.assertTrue(os.path.exists(output_filename))
     self.assertEqual(
         open(output_filename, 'rb').read().decode(),
@@ -157,12 +157,10 @@ class UploadTests(unittest.TestCase):
         filenames, self.base_url, self.gsutil, False, False, 1, True, None)
     self.assertEqual(
         self.gsutil.history,
-        [('check_call',
-          ('ls', '%s/%s' % (self.base_url, fake_hash))),
-         ('check_call',
-          ('ls', '-L', '%s/%s' % (self.base_url, fake_hash))),
-         ('check_call',
-          ('cp', filenames[0], '%s/%s' % (self.base_url, fake_hash)))])
+        [('check_call', ('ls', '%s/%s' % (self.base_url, fake_hash))),
+         ('check_call', ('ls', '-L', '%s/%s' % (self.base_url, fake_hash))),
+         ('check_call', ('-h', 'Cache-Control:public, max-age=31536000', 'cp',
+                         filenames[0], '%s/%s' % (self.base_url, fake_hash)))])
     self.assertEqual(
         open(output_filename, 'rb').read().decode(), fake_hash)
     os.remove(output_filename)

+ 1 - 1
upload_to_google_storage.py

@@ -100,7 +100,7 @@ def _upload_worker(
           continue
     stdout_queue.put('%d> Uploading %s...' % (
         thread_num, filename))
-    gsutil_args = ['cp']
+    gsutil_args = ['-h', 'Cache-Control:public, max-age=31536000', 'cp']
     if gzip:
       gsutil_args.extend(['-z', gzip])
     gsutil_args.extend([filename, file_url])