我搞砸了一个 Firebase 云函数,并意外地创建了 190 万张存储在gs://myapp.appspot.com//tmp/
. 那个双斜杠是准确的——服务器正在写入/tmp/
,我猜这会导致上面提到的路径。
我现在想删除那些文件(它们都是废话)。我尝试使用 Python 包装器,如下所示:
export GOOGLE_APPLICATION_CREDENTIALS="../secrets/service-account.json"
然后:
from google.cloud import storage
storage_client = storage.Client()
bucket = storage_client.get_bucket('tmp')
blobs = bucket.list_blobs(bucket='tmp', prefix='')
for blob in blobs:
print(' * deleting', blob)
blob.delete()
但这会抛出:
google.api_core.exceptions.Forbidden: 403 GET https://storage.googleapis.com/storage/v1/b/tmp?projection=noAcl: [email protected] does not have storage.buckets.get access to tmp.
有谁知道如何允许管理员凭据从中删除/tmp/
?任何指针都会非常有帮助!
我能够使用 gsutil 命令重现这个问题:
gsutil cp ~/<example-file> gs://<my-project-name>.appspot.com//tmp/
首先,在我的Firebase 控制台中,我可以通过一个勾号(整个文件夹)来完成,不确定您是否考虑过这一点。
无论如何,如果你想用 API 完成它,我找到了以下解决方案。
myapp.appspot.com
<Blob: <my-project-name>.appspot.com, /tmp/<example-file>, 1584700014023619
>第二个值是 blob 对象的名称属性。我注意到在这种情况下它的 blob 名称以/tmp/
在我这边工作的代码是:
from google.cloud import storage
storage_client = storage.Client()
bucket = storage_client.get_bucket('myapp.appspot.com')
blobs = bucket.list_blobs()
for blob in blobs:
if blob.name.startswith('/tmp/'):
print(' * deleting', blob)
blob.delete()
我不认为它是非常优雅的解决方案,但一次性修复可能已经足够了。
我希望它会有所帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句