diff --git a/download_from_google_storage.py b/download_from_google_storage.py index bbb9e64f3..e00ac6262 100755 --- a/download_from_google_storage.py +++ b/download_from_google_storage.py @@ -45,8 +45,12 @@ class Gsutil(object): def get_sub_env(self): env = os.environ.copy() - if self.boto_path: + if self.boto_path == os.devnull: + env['AWS_CREDENTIAL_FILE'] = '' + env['BOTO_CONFIG'] = '' + elif self.boto_path: env['AWS_CREDENTIAL_FILE'] = self.boto_path + env['BOTO_CONFIG'] = self.boto_path else: custompath = env.get('AWS_CREDENTIAL_FILE', '~/.boto') + '.depot_tools' custompath = os.path.expanduser(custompath) @@ -297,7 +301,10 @@ def main(args): help='Alias for "gsutil config". Run this if you want ' 'to initialize your saved Google Storage ' 'credentials.') - parser.add_option('-p', '--platform', + parser.add_option('-n', '--no_auth', action='store_true', + help='Skip auth checking. Use if it\'s known that the ' + 'target bucket is a public bucket.') + parser.add_option('-p', '--platform', help='A regular expression that is compared against ' 'Python\'s sys.platform. If this option is specified, ' 'the download will happen only if there is a match.') @@ -311,6 +318,10 @@ def main(args): options.platform) return 0 + # Set the boto file to /dev/null if we don't need auth. + if options.no_auth: + options.boto = os.devnull + # Make sure we can find a working instance of gsutil. if os.path.exists(GSUTIL_DEFAULT_PATH): gsutil = Gsutil(GSUTIL_DEFAULT_PATH, boto_path=options.boto) diff --git a/tests/download_from_google_storage_unittests.py b/tests/download_from_google_storage_unittests.py index 24cc7997d..77dd40a67 100755 --- a/tests/download_from_google_storage_unittests.py +++ b/tests/download_from_google_storage_unittests.py @@ -82,7 +82,7 @@ class GstoolsUnitTests(unittest.TestCase): self.assertEqual(err_lines[0], 'gsutil version 3.25') self.assertEqual( err_lines[1], - 'checksum 010822c61d38d70ac23600bc955fccf5 (OK)') + 'checksum c9cffb512f467c0aa54880788b9ee6ca (OK)') def test_get_sha1(self): lorem_ipsum = os.path.join(self.base_path, 'lorem_ipsum.txt') @@ -179,6 +179,12 @@ class DownloadTests(unittest.TestCase): ('ls', input_filename)), ('check_call', ('cp', '-q', input_filename, output_filename))] + if sys.platform != 'win32': + expected_calls.append( + ('check_call', + ('ls', + '-L', + 'gs://sometesturl/7871c8e24da15bad8b0be2c36edc9dc77e37727f'))) expected_output = [ '0> Downloading %s...' % output_filename] expected_ret_codes = [] @@ -251,6 +257,12 @@ class DownloadTests(unittest.TestCase): ('check_call', ('cp', '-q', input_filename, output_filename)) ] + if sys.platform != 'win32': + expected_calls.append( + ('check_call', + ('ls', + '-L', + 'gs://sometesturl/7871c8e24da15bad8b0be2c36edc9dc77e37727f'))) self.assertEqual(self.gsutil.history, expected_calls) self.assertEqual(code, 101) @@ -274,6 +286,12 @@ class DownloadTests(unittest.TestCase): ('ls', input_filename)), ('check_call', ('cp', '-q', input_filename, output_filename))] + if sys.platform != 'win32': + expected_calls.append( + ('check_call', + ('ls', + '-L', + 'gs://sometesturl/7871c8e24da15bad8b0be2c36edc9dc77e37727f'))) self.assertEqual(self.gsutil.history, expected_calls) self.assertEqual(code, 0) diff --git a/tests/upload_to_google_storage_unittests.py b/tests/upload_to_google_storage_unittests.py index 8879f5cf8..24ac6b89c 100755 --- a/tests/upload_to_google_storage_unittests.py +++ b/tests/upload_to_google_storage_unittests.py @@ -29,7 +29,7 @@ TEST_DIR = os.path.dirname(os.path.abspath(__file__)) class UploadTests(unittest.TestCase): def setUp(self): - self.gsutil = GsutilMock(GSUTIL_DEFAULT_PATH) + self.gsutil = GsutilMock(GSUTIL_DEFAULT_PATH, None) self.temp_dir = tempfile.mkdtemp(prefix='gstools_test') self.base_path = os.path.join(self.temp_dir, 'gstools') shutil.copytree(os.path.join(TEST_DIR, 'gstools'), self.base_path)