From 30f9664b48921a44f5382160abff359158801785 Mon Sep 17 00:00:00 2001 From: George Engelbrecht Date: Wed, 14 Aug 2019 20:31:23 +0000 Subject: [PATCH] Add 'stat' to gsutil module. In support of the signing rework we're going to want to have the signers keep track of the calculated hash to ensure that we don't have a TOCTOU type issue. This commit adds the stat command to the gsutil module so that we can ask gs a files hash. Change-Id: Ib35d1541292a18fbfc26fab50f594c682ba4109d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1754262 Reviewed-by: Robbie Iannucci Commit-Queue: George Engelbrecht --- recipes/README.recipes.md | 10 ++++++---- recipes/recipe_modules/gsutil/api.py | 7 +++++++ .../gsutil/examples/full.expected/basic.json | 14 ++++++++++++++ recipes/recipe_modules/gsutil/examples/full.py | 1 + 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/recipes/README.recipes.md b/recipes/README.recipes.md index 5e74cc47a..876ee6c34 100644 --- a/recipes/README.recipes.md +++ b/recipes/README.recipes.md @@ -651,7 +651,7 @@ Arguments: — **def [cat](/recipes/recipe_modules/gsutil/api.py#108)(self, url, args=None, \*\*kwargs):** -— **def [copy](/recipes/recipe_modules/gsutil/api.py#115)(self, source_bucket, source, dest_bucket, dest, args=None, link_name='gsutil.copy', metadata=None, unauthenticated_url=False, \*\*kwargs):** +— **def [copy](/recipes/recipe_modules/gsutil/api.py#122)(self, source_bucket, source, dest_bucket, dest, args=None, link_name='gsutil.copy', metadata=None, unauthenticated_url=False, \*\*kwargs):** — **def [download](/recipes/recipe_modules/gsutil/api.py#94)(self, bucket, source, dest, args=None, \*\*kwargs):** @@ -659,11 +659,13 @@ Arguments:   **@property**
— **def [gsutil\_py\_path](/recipes/recipe_modules/gsutil/api.py#10)(self):** -— **def [list](/recipes/recipe_modules/gsutil/api.py#132)(self, url, args=None, \*\*kwargs):** +— **def [list](/recipes/recipe_modules/gsutil/api.py#139)(self, url, args=None, \*\*kwargs):** -— **def [remove\_url](/recipes/recipe_modules/gsutil/api.py#146)(self, url, args=None, \*\*kwargs):** +— **def [remove\_url](/recipes/recipe_modules/gsutil/api.py#153)(self, url, args=None, \*\*kwargs):** -— **def [signurl](/recipes/recipe_modules/gsutil/api.py#139)(self, private_key_file, bucket, dest, args=None, \*\*kwargs):** +— **def [signurl](/recipes/recipe_modules/gsutil/api.py#146)(self, private_key_file, bucket, dest, args=None, \*\*kwargs):** + +— **def [stat](/recipes/recipe_modules/gsutil/api.py#115)(self, url, args=None, \*\*kwargs):** — **def [upload](/recipes/recipe_modules/gsutil/api.py#78)(self, source, bucket, dest, args=None, link_name='gsutil.upload', metadata=None, unauthenticated_url=False, \*\*kwargs):** ### *recipe_modules* / [infra\_paths](/recipes/recipe_modules/infra_paths) diff --git a/recipes/recipe_modules/gsutil/api.py b/recipes/recipe_modules/gsutil/api.py index dc7c78a0e..bcae5deb2 100644 --- a/recipes/recipe_modules/gsutil/api.py +++ b/recipes/recipe_modules/gsutil/api.py @@ -112,6 +112,13 @@ class GSUtilApi(recipe_api.RecipeApi): name = kwargs.pop('name', 'cat') return self(cmd, name, **kwargs) + def stat(self, url, args=None, **kwargs): + args = args or [] + url = self._normalize_url(url) + cmd = ['stat'] + args + [url] + name = kwargs.pop('name', 'stat') + return self(cmd, name, **kwargs) + def copy(self, source_bucket, source, dest_bucket, dest, args=None, link_name='gsutil.copy', metadata=None, unauthenticated_url=False, **kwargs): diff --git a/recipes/recipe_modules/gsutil/examples/full.expected/basic.json b/recipes/recipe_modules/gsutil/examples/full.expected/basic.json index a0d1a23f2..0511da745 100644 --- a/recipes/recipe_modules/gsutil/examples/full.expected/basic.json +++ b/recipes/recipe_modules/gsutil/examples/full.expected/basic.json @@ -189,6 +189,20 @@ "infra_step": true, "name": "gsutil cat" }, + { + "cmd": [ + "python", + "-u", + "RECIPE_MODULE[depot_tools::gsutil]/resources/gsutil_smart_retry.py", + "--", + "RECIPE_REPO[depot_tools]/gsutil.py", + "----", + "stat", + "gs://example/foo" + ], + "infra_step": true, + "name": "gsutil stat" + }, { "name": "$result" } diff --git a/recipes/recipe_modules/gsutil/examples/full.py b/recipes/recipe_modules/gsutil/examples/full.py index 8b3e408a9..2e2279d2d 100644 --- a/recipes/recipe_modules/gsutil/examples/full.py +++ b/recipes/recipe_modules/gsutil/examples/full.py @@ -72,6 +72,7 @@ def RunSteps(api): api.gsutil.cat('gs://%s/foo' % bucket) + api.gsutil.stat('gs://%s/foo' % bucket) def GenTests(api): yield api.test('basic')