2
votes

I have researched a lot and unable to come up with a solution for this. Here is the code i am using to make all the files public in GCP:

def make_blob_public(bucket_name, blob_name):
    """Makes a blob publicly accessible."""
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(blob_name)

blob.make_public()

The above method works but when i write blob.make_private() to make all files private i get the error: AttributeError: 'Blob' object has no attribute 'make_private'

At this link:

https://googlecloudplatform.github.io/google-cloud-python/latest/storage/blobs.html

i can find both make_public() and make_private() but only make_public() works.

1

1 Answers

3
votes

make_private was added in the 1.10 version of the Storage client library. Check which version are you using with pip list, as you must be using a different version, and upgrade if possible.

Nonetheless, if you can't upgrade (let's say that your development environment is 'tied' to this version of the library), I tested this with a different version that I have in one development environment (version 1.8.0) , and if you follow the source code for make_private and do those two lines in the code, it works. So, like this:

#blob.make_private() is basically:

blob.acl.all().revoke_read()
blob.acl.save(client=blob.client)