Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix storage encryption example, remove policy document example. #3221

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 3 additions & 34 deletions docs/storage_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def download_to_file(client, to_delete):
bucket = client.get_bucket('my-bucket')
encryption_key = 'c7f32af42e45e85b9848a6a14dd2a8f6'
blob = Blob('secure-data', bucket, encryption_key=encryption_key)
blob.upload_from_string('my secret message.')
with open('/tmp/my-secure-file', 'wb') as file_obj:
blob.download_to_file(file_obj)
# [END download_to_file]
Expand Down Expand Up @@ -138,7 +139,8 @@ def delete_blob(client, to_delete):
from google.cloud.exceptions import NotFound
client = storage.Client()
bucket = client.get_bucket('my-bucket')
assert isinstance(bucket.list_blobs(), list)
blobs = list(bucket.list_blobs())
assert len(blobs) > 0
# [<Blob: my-bucket, my-file.txt>]
bucket.delete_blob('my-file.txt')
try:
Expand Down Expand Up @@ -221,39 +223,6 @@ def list_buckets(client, to_delete):
to_delete.append(bucket)


@snippet
def policy_document(client, to_delete):
# pylint: disable=unused-argument
# [START policy_document]
bucket = client.bucket('my-bucket')
conditions = [
['starts-with', '$key', ''],
{'acl': 'public-read'}]

policy = bucket.generate_upload_policy(conditions)

# Generate an upload form using the form fields.
policy_fields = ''.join(
'<input type="hidden" name="{key}" value="{value}">'.format(
key=key, value=value)
for key, value in policy.items()
)

upload_form = (
'<form action="http://{bucket_name}.storage.googleapis.com"'
' method="post"enctype="multipart/form-data">'
'<input type="text" name="key" value="">'
'<input type="hidden" name="bucket" value="{bucket_name}">'
'<input type="hidden" name="acl" value="public-read">'
'<input name="file" type="file">'
'<input type="submit" value="Upload">'
'{policy_fields}'
'<form>').format(bucket_name=bucket.name, policy_fields=policy_fields)

print(upload_form)
# [END policy_document]


def _line_no(func):
code = getattr(func, '__code__', None) or getattr(func, 'func_code')
return code.co_firstlineno
Expand Down
6 changes: 0 additions & 6 deletions storage/google/cloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,12 +857,6 @@ def generate_upload_policy(
`policy documents`_ to allow visitors to a website to upload files to
Google Cloud Storage without giving them direct write access.

For example:

.. literalinclude:: storage_snippets.py
:start-after: [START policy_document]
:end-before: [END policy_document]

.. _policy documents:
https://cloud.google.com/storage/docs/xml-api\
/post-object#policydocument
Expand Down