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):
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,6 +301,9 @@ def main(args):
help='Alias for "gsutil config". Run this if you want '
'to initialize your saved Google Storage '
'credentials.')
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, '
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
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