-
Notifications
You must be signed in to change notification settings - Fork 6.5k
docs(storage): add samples #3687
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
Merged
busunkim96
merged 13 commits into
GoogleCloudPlatform:master
from
MaxxleLLC:storage_sample_docs_3
May 15, 2020
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
31f93b6
docs(storage): add samples
HemangChothani 5dd88f6
docs(storage): resolve conflict
HemangChothani 9b569af
docs(storage): address the comments
HemangChothani 8916235
Merge branch 'master' of https://github.com/GoogleCloudPlatform/pytho…
HemangChothani d894f53
Merge branch 'master' of https://github.com/GoogleCloudPlatform/pytho…
HemangChothani 6a9f73b
Merge branch 'master' into storage_sample_docs_3
frankyn 636e446
docs(storage): resolve conflict and arrange lib imports in order
HemangChothani 2f36e23
Merge branch 'master' into storage_sample_docs_3
busunkim96 ecb5829
fix lint
busunkim96 1b9ac70
Merge branch 'master' into storage_sample_docs_3
busunkim96 916c01b
docs(storage): fix csek test
HemangChothani 78755a3
Merge branch 'master' of https://github.com/GoogleCloudPlatform/pytho…
HemangChothani 89ae221
Merge branch 'master' into storage_sample_docs_3
busunkim96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,9 @@ | |
import storage_add_bucket_iam_member | ||
import storage_remove_bucket_conditional_iam_binding | ||
import storage_remove_bucket_iam_member | ||
import storage_set_bucket_public_iam | ||
import storage_view_bucket_iam_members | ||
|
||
|
||
MEMBER = "group:[email protected]" | ||
ROLE = "roles/storage.legacyBucketReader" | ||
|
||
|
@@ -112,3 +112,16 @@ def test_remove_bucket_conditional_iam_binding(bucket): | |
(binding["role"] == ROLE and binding.get("condition") == condition) | ||
for binding in policy.bindings | ||
) | ||
|
||
|
||
def test_set_bucket_public_iam(bucket): | ||
role = "roles/storage.objectViewer" | ||
member = "allUsers" | ||
storage_set_bucket_public_iam.set_bucket_public_iam( | ||
bucket.name, role, member | ||
) | ||
policy = bucket.get_iam_policy(requested_policy_version=3) | ||
assert any( | ||
binding["role"] == role and member in binding["members"] | ||
for binding in policy.bindings | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
storage/cloud-client/storage_bucket_delete_default_kms_key.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 2020 Google LLC. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the 'License'); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import sys | ||
|
||
# [START storage_bucket_delete_default_kms_key] | ||
from google.cloud import storage | ||
|
||
|
||
def bucket_delete_default_kms_key(bucket_name): | ||
"""Delete a default KMS key of bucket""" | ||
# bucket_name = "your-bucket-name" | ||
|
||
storage_client = storage.Client() | ||
|
||
bucket = storage_client.get_bucket(bucket_name) | ||
bucket.default_kms_key_name = None | ||
bucket.patch() | ||
|
||
print("Default KMS key was removed from {}".format(bucket.name)) | ||
return bucket | ||
|
||
|
||
# [END storage_bucket_delete_default_kms_key] | ||
|
||
if __name__ == "__main__": | ||
bucket_delete_default_kms_key(bucket_name=sys.argv[1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 2020 Google LLC. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the 'License'); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import sys | ||
|
||
# [START storage_compose_file] | ||
from google.cloud import storage | ||
|
||
|
||
def compose_file(bucket_name, sources, destination_blob_name): | ||
"""Concatenate source blobs into destination blob.""" | ||
# bucket_name = "your-bucket-name" | ||
# sources = [blob_1, blob_2] | ||
# destination_blob_name = "destination-object-name" | ||
|
||
storage_client = storage.Client() | ||
bucket = storage_client.bucket(bucket_name) | ||
destination = bucket.blob(destination_blob_name) | ||
destination.content_type = "text/plain" | ||
destination.compose(sources) | ||
|
||
print( | ||
"Composed new object {} in the bucket {}".format( | ||
destination_blob_name, bucket.name | ||
) | ||
) | ||
return destination | ||
|
||
|
||
# [END storage_compose_file] | ||
|
||
if __name__ == "__main__": | ||
compose_file( | ||
bucket_name=sys.argv[1], sources=sys.argv[2], destination_blob_name=sys.argv[3], | ||
) |
44 changes: 44 additions & 0 deletions
44
storage/cloud-client/storage_create_bucket_class_location.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 2020 Google LLC. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the 'License'); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import sys | ||
|
||
# [START storage_create_bucket_class_location] | ||
from google.cloud import storage | ||
|
||
|
||
def create_bucket_class_location(bucket_name): | ||
"""Create a new bucket in specific location with storage class""" | ||
# bucket_name = "your-new-bucket-name" | ||
|
||
storage_client = storage.Client() | ||
|
||
bucket = storage_client.bucket(bucket_name) | ||
bucket.storage_class = "COLDLINE" | ||
new_bucket = storage_client.create_bucket(bucket, location="us") | ||
|
||
print( | ||
"Created bucket {} in {} with storage class {}".format( | ||
new_bucket.name, new_bucket.location, new_bucket.storage_class | ||
) | ||
) | ||
return new_bucket | ||
|
||
|
||
# [END storage_create_bucket_class_location] | ||
|
||
if __name__ == "__main__": | ||
create_bucket_class_location(bucket_name=sys.argv[1]) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.