diff --git a/appengine/standard/storage/.gitignore b/appengine/standard/storage/.gitignore deleted file mode 100644 index a65b41774ad..00000000000 --- a/appengine/standard/storage/.gitignore +++ /dev/null @@ -1 +0,0 @@ -lib diff --git a/appengine/standard/storage/api-client/README.md b/appengine/standard/storage/api-client/README.md deleted file mode 100644 index ea5e9ed6ea3..00000000000 --- a/appengine/standard/storage/api-client/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Cloud Storage & Google App Engine - -[![Open in Cloud Shell][shell_img]][shell_link] - -[shell_img]: http://gstatic.com/cloudssh/images/open-btn.png -[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=appengine/standard/storage/api-client/README.md - -This sample demonstrates how to use the [Google Cloud Storage API](https://cloud.google.com/storage/docs/json_api/) from Google App Engine. - -Refer to the [App Engine Samples README](../README.md) for information on how to run and deploy this sample. - -## Setup - -Before running the sample: - -1. You need a Cloud Storage Bucket. You create one with [`gsutil`](https://cloud.google.com/storage/docs/gsutil): - - gsutil mb gs://your-bucket-name - -2. Update `main.py` and replace `` with your Cloud Storage bucket. diff --git a/appengine/standard/storage/api-client/app.yaml b/appengine/standard/storage/api-client/app.yaml deleted file mode 100644 index 98ee086386e..00000000000 --- a/appengine/standard/storage/api-client/app.yaml +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2021 Google LLC -# -# 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. - -runtime: python27 -threadsafe: yes -api_version: 1 - -handlers: -- url: .* - script: main.app diff --git a/appengine/standard/storage/api-client/appengine_config.py b/appengine/standard/storage/api-client/appengine_config.py deleted file mode 100644 index f5bc3a79871..00000000000 --- a/appengine/standard/storage/api-client/appengine_config.py +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright 2021 Google LLC -# -# 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. - -from google.appengine.ext import vendor - -# Add any libraries installed in the "lib" folder. -vendor.add("lib") diff --git a/appengine/standard/storage/api-client/main.py b/appengine/standard/storage/api-client/main.py deleted file mode 100644 index 63cf52787ff..00000000000 --- a/appengine/standard/storage/api-client/main.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2015 Google Inc. -# -# 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. - -""" -Sample Google App Engine application that lists the objects in a Google Cloud -Storage bucket. - -For more information about Cloud Storage, see README.md in /storage. -For more information about Google App Engine, see README.md in /appengine. -""" - -import json -import StringIO - -import googleapiclient.discovery -import googleapiclient.http -import webapp2 - - -# The bucket that will be used to list objects. -BUCKET_NAME = "" - -storage = googleapiclient.discovery.build("storage", "v1") - - -class MainPage(webapp2.RequestHandler): - def upload_object(self, bucket, file_object): - body = { - "name": "storage-api-client-sample-file.txt", - } - req = storage.objects().insert( - bucket=bucket, - body=body, - media_body=googleapiclient.http.MediaIoBaseUpload( - file_object, "application/octet-stream" - ), - ) - resp = req.execute() - return resp - - def delete_object(self, bucket, filename): - req = storage.objects().delete(bucket=bucket, object=filename) - resp = req.execute() - return resp - - def get(self): - string_io_file = StringIO.StringIO("Hello World!") - self.upload_object(BUCKET_NAME, string_io_file) - - response = storage.objects().list(bucket=BUCKET_NAME).execute() - self.response.write( - "

Objects.list raw response:

" - "
{}
".format(json.dumps(response, sort_keys=True, indent=2)) - ) - - self.delete_object(BUCKET_NAME, "storage-api-client-sample-file.txt") - - -app = webapp2.WSGIApplication([("/", MainPage)], debug=True) diff --git a/appengine/standard/storage/api-client/main_test.py b/appengine/standard/storage/api-client/main_test.py deleted file mode 100644 index c02ca09370d..00000000000 --- a/appengine/standard/storage/api-client/main_test.py +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2015 Google Inc. -# -# 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 os -import re - -import webtest - -import main - -PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] - - -def test_get(): - main.BUCKET_NAME = PROJECT - app = webtest.TestApp(main.app) - - response = app.get("/") - - assert response.status_int == 200 - assert re.search(re.compile(r".*.*items.*etag.*", re.DOTALL), response.body) diff --git a/appengine/standard/storage/api-client/requirements-test.txt b/appengine/standard/storage/api-client/requirements-test.txt deleted file mode 100644 index c607ba3b2ab..00000000000 --- a/appengine/standard/storage/api-client/requirements-test.txt +++ /dev/null @@ -1,3 +0,0 @@ -# pin pytest to 4.6.11 for Python2. -pytest==4.6.11; python_version < '3.0' -WebTest==2.0.35; python_version < '3.0' diff --git a/appengine/standard/storage/api-client/requirements.txt b/appengine/standard/storage/api-client/requirements.txt deleted file mode 100644 index 782ceb3709b..00000000000 --- a/appengine/standard/storage/api-client/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -google-api-python-client==1.12.11; python_version < '3.0' -google-auth==2.17.3 -google-auth-httplib2==0.1.0 diff --git a/appengine/standard/storage/appengine-client/__init__.py b/appengine/standard/storage/appengine-client/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/appengine/standard/storage/appengine-client/app.yaml b/appengine/standard/storage/appengine-client/app.yaml deleted file mode 100644 index 91ed7d60e40..00000000000 --- a/appengine/standard/storage/appengine-client/app.yaml +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright 2021 Google LLC -# -# 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. - -runtime: python27 -api_version: 1 -threadsafe: yes - -env_variables: - -handlers: -- url: /blobstore.* - script: blobstore.app - -- url: /.* - script: main.app diff --git a/appengine/standard/storage/appengine-client/appengine_config.py b/appengine/standard/storage/appengine-client/appengine_config.py deleted file mode 100644 index f5bc3a79871..00000000000 --- a/appengine/standard/storage/appengine-client/appengine_config.py +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright 2021 Google LLC -# -# 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. - -from google.appengine.ext import vendor - -# Add any libraries installed in the "lib" folder. -vendor.add("lib") diff --git a/appengine/standard/storage/appengine-client/main.py b/appengine/standard/storage/appengine-client/main.py deleted file mode 100644 index 4681a2e6ce1..00000000000 --- a/appengine/standard/storage/appengine-client/main.py +++ /dev/null @@ -1,170 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2017 Google Inc. -# -# 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. - -# [START gae_storage_sample] -"""A sample app that uses GCS client to operate on bucket and file.""" - -# [START gae_storage_imports] -import os - -import cloudstorage -from google.appengine.api import app_identity - -import webapp2 -# [END gae_storage_imports] - -cloudstorage.set_default_retry_params( - cloudstorage.RetryParams( - initial_delay=0.2, max_delay=5.0, backoff_factor=2, max_retry_period=15 - ) -) - - -class MainPage(webapp2.RequestHandler): - """Main page for GCS demo application.""" - - # [START gae_storage_get_default_bucket] - def get(self): - bucket_name = os.environ.get( - "BUCKET_NAME", app_identity.get_default_gcs_bucket_name() - ) - - self.response.headers["Content-Type"] = "text/plain" - self.response.write( - "Demo GCS Application running from Version: {}\n".format( - os.environ["CURRENT_VERSION_ID"] - ) - ) - self.response.write("Using bucket name: {}\n\n".format(bucket_name)) - # [END gae_storage_get_default_bucket] - - bucket = "/" + bucket_name - filename = bucket + "/demo-testfile" - self.tmp_filenames_to_clean_up = [] - - self.create_file(filename) - self.response.write("\n\n") - - self.read_file(filename) - self.response.write("\n\n") - - self.stat_file(filename) - self.response.write("\n\n") - - self.create_files_for_list_bucket(bucket) - self.response.write("\n\n") - - self.list_bucket(bucket) - self.response.write("\n\n") - - self.list_bucket_directory_mode(bucket) - self.response.write("\n\n") - - self.delete_files() - self.response.write("\n\nThe demo ran successfully!\n") - - # [START gae_storage_write] - def create_file(self, filename): - """Create a file.""" - - self.response.write("Creating file {}\n".format(filename)) - - # The retry_params specified in the open call will override the default - # retry params for this particular file handle. - write_retry_params = cloudstorage.RetryParams(backoff_factor=1.1) - with cloudstorage.open( - filename, - "w", - content_type="text/plain", - options={"x-goog-meta-foo": "foo", "x-goog-meta-bar": "bar"}, - retry_params=write_retry_params, - ) as cloudstorage_file: - cloudstorage_file.write("abcde\n") - cloudstorage_file.write("f" * 1024 * 4 + "\n") - self.tmp_filenames_to_clean_up.append(filename) - # [END gae_storage_write] - - # [START gae_storage_read] - def read_file(self, filename): - self.response.write("Abbreviated file content (first line and last 1K):\n") - - with cloudstorage.open(filename) as cloudstorage_file: - self.response.write(cloudstorage_file.readline()) - cloudstorage_file.seek(-1024, os.SEEK_END) - self.response.write(cloudstorage_file.read()) - # [END gae_storage_read] - - def stat_file(self, filename): - self.response.write("File stat:\n") - - stat = cloudstorage.stat(filename) - self.response.write(repr(stat)) - - def create_files_for_list_bucket(self, bucket): - self.response.write("Creating more files for listbucket...\n") - filenames = [ - bucket + n for n in ["/foo1", "/foo2", "/bar", "/bar/1", "/bar/2", "/boo/"] - ] - for f in filenames: - self.create_file(f) - - # [START gae_storage_list_bucket] - def list_bucket(self, bucket): - """Create several files and paginate through them.""" - - self.response.write("Listbucket result:\n") - - # Production apps should set page_size to a practical value. - page_size = 1 - stats = cloudstorage.listbucket(bucket + "/foo", max_keys=page_size) - while True: - count = 0 - for stat in stats: - count += 1 - self.response.write(repr(stat)) - self.response.write("\n") - - if count != page_size or count == 0: - break - stats = cloudstorage.listbucket( - bucket + "/foo", max_keys=page_size, marker=stat.filename - ) - # [END gae_storage_list_bucket] - - def list_bucket_directory_mode(self, bucket): - self.response.write("Listbucket directory mode result:\n") - for stat in cloudstorage.listbucket(bucket + "/b", delimiter="/"): - self.response.write(stat) - self.response.write("\n") - if stat.is_dir: - for subdir_file in cloudstorage.listbucket( - stat.filename, delimiter="/" - ): - self.response.write(" {}".format(subdir_file)) - self.response.write("\n") - - def delete_files(self): - self.response.write("Deleting files...\n") - for filename in self.tmp_filenames_to_clean_up: - self.response.write("Deleting file {}\n".format(filename)) - try: - cloudstorage.delete(filename) - except cloudstorage.NotFoundError: - pass - - -app = webapp2.WSGIApplication([("/", MainPage)], debug=True) -# [END gae_storage_sample] diff --git a/appengine/standard/storage/appengine-client/main_test.py b/appengine/standard/storage/appengine-client/main_test.py deleted file mode 100644 index 48eb01ab194..00000000000 --- a/appengine/standard/storage/appengine-client/main_test.py +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright 2017 Google Inc. -# -# 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 os - -import webtest - -import main - -PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] - - -def test_get(testbed): - main.BUCKET_NAME = PROJECT - app = webtest.TestApp(main.app) - - response = app.get("/") - - assert response.status_int == 200 - assert "The demo ran successfully!" in response.body diff --git a/appengine/standard/storage/appengine-client/requirements-test.txt b/appengine/standard/storage/appengine-client/requirements-test.txt deleted file mode 100644 index b7e6a172e18..00000000000 --- a/appengine/standard/storage/appengine-client/requirements-test.txt +++ /dev/null @@ -1,8 +0,0 @@ -# pin pytest to 4.6.11 for Python2. -pytest==4.6.11; python_version < '3.0' -WebTest==2.0.35; python_version < '3.0' -# 2025-01-14 - Added support for Python 3 -pytest==8.3.2; python_version >= '3.0' -WebTest==3.0.1; python_version >= '3.0' -six==1.16.0 - diff --git a/appengine/standard/storage/appengine-client/requirements.txt b/appengine/standard/storage/appengine-client/requirements.txt deleted file mode 100644 index f2ec35f05f9..00000000000 --- a/appengine/standard/storage/appengine-client/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -GoogleAppEngineCloudStorageClient==1.9.22.1