Commit c61894cc authored by hinoka@chromium.org's avatar hinoka@chromium.org

Add no_auth flag to skip auth checking for buckets that don't require it. Also fix tests

BUG=321254

Review URL: https://codereview.chromium.org/76583002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@236039 0039d316-1c4b-4281-b951-d872f2087c98
parent aa74cf65
...@@ -45,8 +45,12 @@ class Gsutil(object): ...@@ -45,8 +45,12 @@ class Gsutil(object):
def get_sub_env(self): def get_sub_env(self):
env = os.environ.copy() 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['AWS_CREDENTIAL_FILE'] = self.boto_path
env['BOTO_CONFIG'] = self.boto_path
else: else:
custompath = env.get('AWS_CREDENTIAL_FILE', '~/.boto') + '.depot_tools' custompath = env.get('AWS_CREDENTIAL_FILE', '~/.boto') + '.depot_tools'
custompath = os.path.expanduser(custompath) custompath = os.path.expanduser(custompath)
...@@ -297,7 +301,10 @@ def main(args): ...@@ -297,7 +301,10 @@ def main(args):
help='Alias for "gsutil config". Run this if you want ' help='Alias for "gsutil config". Run this if you want '
'to initialize your saved Google Storage ' 'to initialize your saved Google Storage '
'credentials.') '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 ' help='A regular expression that is compared against '
'Python\'s sys.platform. If this option is specified, ' 'Python\'s sys.platform. If this option is specified, '
'the download will happen only if there is a match.') 'the download will happen only if there is a match.')
...@@ -311,6 +318,10 @@ def main(args): ...@@ -311,6 +318,10 @@ def main(args):
options.platform) options.platform)
return 0 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. # Make sure we can find a working instance of gsutil.
if os.path.exists(GSUTIL_DEFAULT_PATH): if os.path.exists(GSUTIL_DEFAULT_PATH):
gsutil = Gsutil(GSUTIL_DEFAULT_PATH, boto_path=options.boto) gsutil = Gsutil(GSUTIL_DEFAULT_PATH, boto_path=options.boto)
......
...@@ -82,7 +82,7 @@ class GstoolsUnitTests(unittest.TestCase): ...@@ -82,7 +82,7 @@ class GstoolsUnitTests(unittest.TestCase):
self.assertEqual(err_lines[0], 'gsutil version 3.25') self.assertEqual(err_lines[0], 'gsutil version 3.25')
self.assertEqual( self.assertEqual(
err_lines[1], err_lines[1],
'checksum 010822c61d38d70ac23600bc955fccf5 (OK)') 'checksum c9cffb512f467c0aa54880788b9ee6ca (OK)')
def test_get_sha1(self): def test_get_sha1(self):
lorem_ipsum = os.path.join(self.base_path, 'lorem_ipsum.txt') lorem_ipsum = os.path.join(self.base_path, 'lorem_ipsum.txt')
...@@ -179,6 +179,12 @@ class DownloadTests(unittest.TestCase): ...@@ -179,6 +179,12 @@ class DownloadTests(unittest.TestCase):
('ls', input_filename)), ('ls', input_filename)),
('check_call', ('check_call',
('cp', '-q', input_filename, output_filename))] ('cp', '-q', input_filename, output_filename))]
if sys.platform != 'win32':
expected_calls.append(
('check_call',
('ls',
'-L',
'gs://sometesturl/7871c8e24da15bad8b0be2c36edc9dc77e37727f')))
expected_output = [ expected_output = [
'0> Downloading %s...' % output_filename] '0> Downloading %s...' % output_filename]
expected_ret_codes = [] expected_ret_codes = []
...@@ -251,6 +257,12 @@ class DownloadTests(unittest.TestCase): ...@@ -251,6 +257,12 @@ class DownloadTests(unittest.TestCase):
('check_call', ('check_call',
('cp', '-q', input_filename, output_filename)) ('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(self.gsutil.history, expected_calls)
self.assertEqual(code, 101) self.assertEqual(code, 101)
...@@ -274,6 +286,12 @@ class DownloadTests(unittest.TestCase): ...@@ -274,6 +286,12 @@ class DownloadTests(unittest.TestCase):
('ls', input_filename)), ('ls', input_filename)),
('check_call', ('check_call',
('cp', '-q', input_filename, output_filename))] ('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(self.gsutil.history, expected_calls)
self.assertEqual(code, 0) self.assertEqual(code, 0)
......
...@@ -29,7 +29,7 @@ TEST_DIR = os.path.dirname(os.path.abspath(__file__)) ...@@ -29,7 +29,7 @@ TEST_DIR = os.path.dirname(os.path.abspath(__file__))
class UploadTests(unittest.TestCase): class UploadTests(unittest.TestCase):
def setUp(self): 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.temp_dir = tempfile.mkdtemp(prefix='gstools_test')
self.base_path = os.path.join(self.temp_dir, 'gstools') self.base_path = os.path.join(self.temp_dir, 'gstools')
shutil.copytree(os.path.join(TEST_DIR, 'gstools'), self.base_path) shutil.copytree(os.path.join(TEST_DIR, 'gstools'), self.base_path)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment