diff --git a/appengine/flexible/README.md b/appengine/flexible/README.md index 0cc851a437e..8f6a03a894f 100644 --- a/appengine/flexible/README.md +++ b/appengine/flexible/README.md @@ -7,8 +7,6 @@ These are samples for using Python on Google App Engine Flexible Environment. These samples are typically referenced from the [docs](https://cloud.google.com/appengine/docs). -For code samples of Python version 3.7 and earlier, please check -https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/appengine/flexible_python37_and_earlier See our other [Google Cloud Platform github repos](https://github.com/GoogleCloudPlatform) for sample applications and scaffolding for other frameworks and use cases. diff --git a/appengine/flexible_python37_and_earlier/README.md b/appengine/flexible_python37_and_earlier/README.md deleted file mode 100644 index 41927a35c3d..00000000000 --- a/appengine/flexible_python37_and_earlier/README.md +++ /dev/null @@ -1,70 +0,0 @@ -## Google App Engine Flexible Environment Python Samples - -[![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/flexible_python37_and_earlier/README.md - -These are samples for using Python on Google App Engine Flexible Environment. These samples are typically referenced from the [docs](https://cloud.google.com/appengine/docs). - -See our other [Google Cloud Platform github repos](https://github.com/GoogleCloudPlatform) for sample applications and -scaffolding for other frameworks and use cases. - -## Run Locally - -Some samples have specific instructions. If there is a README in the sample folder, please refer to it for any additional steps required to run the sample. - -In general, the samples typically require: - -1. Install the [Google Cloud SDK](https://cloud.google.com/sdk/), including the [gcloud tool](https://cloud.google.com/sdk/gcloud/), and [gcloud app component](https://cloud.google.com/sdk/gcloud-app). - -2. Setup the gcloud tool. This provides authentication to Google Cloud APIs and services. - - ``` - gcloud init - ``` - -3. Clone this repo. - - ``` - git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git - cd python-docs-samples/appengine/flexible_python37_and_earlier - ``` - -4. Follow https://cloud.google.com/python/docs/setup to set up a Python development environment. Then run: - - ``` - pip install -r requirements.txt - python main.py - ``` - -5. Visit the application at [http://localhost:8080](http://localhost:8080). - - -## Deploying - -Some samples in this repositories may have special deployment instructions. Refer to the readme in the sample directory. - -1. Use the [Google Developers Console](https://console.developer.google.com) to create a project/app id. (App id and project id are identical) - -2. Setup the gcloud tool, if you haven't already. - - ``` - gcloud init - ``` - -3. Use gcloud to deploy your app. - - ``` - gcloud app deploy - ``` - -4. Congratulations! Your application is now live at `your-app-id.appspot.com` - -## Contributing changes - -* See [CONTRIBUTING.md](../../CONTRIBUTING.md) - -## Licensing - -* See [LICENSE](../../LICENSE) diff --git a/appengine/flexible_python37_and_earlier/analytics/README.md b/appengine/flexible_python37_and_earlier/analytics/README.md deleted file mode 100644 index d4fa88bef8b..00000000000 --- a/appengine/flexible_python37_and_earlier/analytics/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# Google Analytics Measurement Protocol sample for Google App Engine Flexible - -[![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/flexible_python37_and_earlier/analytics/README.md - -This sample demonstrates how to use the [Google Analytics Measurement Protocol](https://developers.google.com/analytics/devguides/collection/protocol/v1/) (or any other SQL server) on [Google App Engine Flexible Environment](https://cloud.google.com/appengine). - -## Setup - -Before you can run or deploy the sample, you will need to do the following: - -1. Create a Google Analytics Property and obtain the Tracking ID. - -2. Update the environment variables in in ``app.yaml`` with your Tracking ID. - -## Running locally - -Refer to the [top-level README](../README.md) for instructions on running and deploying. - -You will need to set the following environment variables via your shell before running the sample: - - $ export GA_TRACKING_ID=[your Tracking ID] - $ python main.py diff --git a/appengine/flexible_python37_and_earlier/analytics/app.yaml b/appengine/flexible_python37_and_earlier/analytics/app.yaml deleted file mode 100644 index 0f5590d7058..00000000000 --- a/appengine/flexible_python37_and_earlier/analytics/app.yaml +++ /dev/null @@ -1,25 +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: python -env: flex -entrypoint: gunicorn -b :$PORT main:app - -runtime_config: - python_version: 3 - -#[START gae_flex_analytics_env_variables] -env_variables: - GA_TRACKING_ID: your-tracking-id -#[END gae_flex_analytics_env_variables] diff --git a/appengine/flexible_python37_and_earlier/analytics/main.py b/appengine/flexible_python37_and_earlier/analytics/main.py deleted file mode 100644 index c07ab9b4703..00000000000 --- a/appengine/flexible_python37_and_earlier/analytics/main.py +++ /dev/null @@ -1,77 +0,0 @@ -# Copyright 2015 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. - -# [START gae_flex_analytics_track_event] -import logging -import os - -from flask import Flask -import requests - - -app = Flask(__name__) - - -# Environment variables are defined in app.yaml. -GA_TRACKING_ID = os.environ["GA_TRACKING_ID"] - - -def track_event(category, action, label=None, value=0): - data = { - "v": "1", # API Version. - "tid": GA_TRACKING_ID, # Tracking ID / Property ID. - # Anonymous Client Identifier. Ideally, this should be a UUID that - # is associated with particular user, device, or browser instance. - "cid": "555", - "t": "event", # Event hit type. - "ec": category, # Event category. - "ea": action, # Event action. - "el": label, # Event label. - "ev": value, # Event value, must be an integer - "ua": "Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14", - } - - response = requests.post("https://www.google-analytics.com/collect", data=data) - - # If the request fails, this will raise a RequestException. Depending - # on your application's needs, this may be a non-error and can be caught - # by the caller. - response.raise_for_status() - - -@app.route("/") -def track_example(): - track_event(category="Example", action="test action") - return "Event tracked." - - -@app.errorhandler(500) -def server_error(e): - logging.exception("An error occurred during a request.") - return ( - """ - An internal error occurred:
{}
- See logs for full stacktrace.
- """.format(
- e
- ),
- 500,
- )
-
-
-if __name__ == "__main__":
- # This is used when running locally. Gunicorn is used to run the
- # application on Google App Engine. See entrypoint in app.yaml.
- app.run(host="127.0.0.1", port=8080, debug=True)
-# [END gae_flex_analytics_track_event]
diff --git a/appengine/flexible_python37_and_earlier/analytics/main_test.py b/appengine/flexible_python37_and_earlier/analytics/main_test.py
deleted file mode 100644
index 02914bda79d..00000000000
--- a/appengine/flexible_python37_and_earlier/analytics/main_test.py
+++ /dev/null
@@ -1,45 +0,0 @@
-# Copyright 2016 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.
-
-import re
-
-import pytest
-import responses
-
-
-@pytest.fixture
-def app(monkeypatch):
- monkeypatch.setenv("GA_TRACKING_ID", "1234")
-
- import main
-
- main.app.testing = True
- return main.app.test_client()
-
-
-@responses.activate
-def test_tracking(app):
- responses.add(
- responses.POST, re.compile(r".*"), body="{}", content_type="application/json"
- )
-
- r = app.get("/")
-
- assert r.status_code == 200
- assert "Event tracked" in r.data.decode("utf-8")
-
- assert len(responses.calls) == 1
- request_body = responses.calls[0].request.body
- assert "tid=1234" in request_body
- assert "ea=test+action" in request_body
diff --git a/appengine/flexible_python37_and_earlier/analytics/noxfile_config.py b/appengine/flexible_python37_and_earlier/analytics/noxfile_config.py
deleted file mode 100644
index 1665dd736f8..00000000000
--- a/appengine/flexible_python37_and_earlier/analytics/noxfile_config.py
+++ /dev/null
@@ -1,39 +0,0 @@
-# Copyright 2023 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.
-
-# Default TEST_CONFIG_OVERRIDE for python repos.
-
-# You can copy this file into your directory, then it will be imported from
-# the noxfile.py.
-
-# The source of truth:
-# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py
-
-TEST_CONFIG_OVERRIDE = {
- # You can opt out from the test for specific Python versions.
- # Skipping for Python 3.9 due to pyarrow compilation failure.
- "ignored_versions": ["2.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"],
- # Old samples are opted out of enforcing Python type hints
- # All new samples should feature them
- "enforce_type_hints": False,
- # An envvar key for determining the project id to use. Change it
- # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
- # build specific Cloud project. You can also use your own string
- # to use your own Cloud project.
- "gcloud_project_env": "GOOGLE_CLOUD_PROJECT",
- # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
- # A dictionary you want to inject into your test. Don't put any
- # secrets here. These values will override predefined values.
- "envs": {},
-}
diff --git a/appengine/flexible_python37_and_earlier/analytics/requirements-test.txt b/appengine/flexible_python37_and_earlier/analytics/requirements-test.txt
deleted file mode 100644
index e89f6031ad7..00000000000
--- a/appengine/flexible_python37_and_earlier/analytics/requirements-test.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-pytest==8.2.0
-responses==0.17.0; python_version < '3.7'
-responses==0.23.1; python_version > '3.6'
diff --git a/appengine/flexible_python37_and_earlier/analytics/requirements.txt b/appengine/flexible_python37_and_earlier/analytics/requirements.txt
deleted file mode 100644
index 9bfb6dcc546..00000000000
--- a/appengine/flexible_python37_and_earlier/analytics/requirements.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-Flask==3.0.3; python_version > '3.6'
-Flask==2.3.3; python_version < '3.7'
-gunicorn==23.0.0
-requests[security]==2.31.0
-Werkzeug==3.0.3
diff --git a/appengine/flexible_python37_and_earlier/hello_world/app.yaml b/appengine/flexible_python37_and_earlier/hello_world/app.yaml
deleted file mode 100644
index 7aa7a47e159..00000000000
--- a/appengine/flexible_python37_and_earlier/hello_world/app.yaml
+++ /dev/null
@@ -1,31 +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: python
-env: flex
-entrypoint: gunicorn -b :$PORT main:app
-
-runtime_config:
- python_version: 3
-
-# This sample incurs costs to run on the App Engine flexible environment.
-# The settings below are to reduce costs during testing and are not appropriate
-# for production use. For more information, see:
-# https://cloud.google.com/appengine/docs/flexible/python/configuring-your-app-with-app-yaml
-manual_scaling:
- instances: 1
-resources:
- cpu: 1
- memory_gb: 0.5
- disk_size_gb: 10
diff --git a/appengine/flexible_python37_and_earlier/hello_world/main.py b/appengine/flexible_python37_and_earlier/hello_world/main.py
deleted file mode 100644
index eba195ed4fd..00000000000
--- a/appengine/flexible_python37_and_earlier/hello_world/main.py
+++ /dev/null
@@ -1,35 +0,0 @@
-# Copyright 2015 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.
-
-# [START gae_flex_quickstart]
-from flask import Flask
-
-app = Flask(__name__)
-
-
-@app.route("/")
-def hello():
- """Return a friendly HTTP greeting.
-
- Returns:
- A string with the words 'Hello World!'.
- """
- return "Hello World!"
-
-
-if __name__ == "__main__":
- # This is used when running locally only. When deploying to Google App
- # Engine, a webserver process such as Gunicorn will serve the app.
- app.run(host="127.0.0.1", port=8080, debug=True)
-# [END gae_flex_quickstart]
diff --git a/appengine/flexible_python37_and_earlier/hello_world/main_test.py b/appengine/flexible_python37_and_earlier/hello_world/main_test.py
deleted file mode 100644
index a6049b094f9..00000000000
--- a/appengine/flexible_python37_and_earlier/hello_world/main_test.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# Copyright 2015 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.
-
-import main
-
-
-def test_index():
- main.app.testing = True
- client = main.app.test_client()
-
- r = client.get("/")
- assert r.status_code == 200
- assert "Hello World" in r.data.decode("utf-8")
diff --git a/appengine/flexible_python37_and_earlier/hello_world/noxfile_config.py b/appengine/flexible_python37_and_earlier/hello_world/noxfile_config.py
deleted file mode 100644
index 1665dd736f8..00000000000
--- a/appengine/flexible_python37_and_earlier/hello_world/noxfile_config.py
+++ /dev/null
@@ -1,39 +0,0 @@
-# Copyright 2023 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.
-
-# Default TEST_CONFIG_OVERRIDE for python repos.
-
-# You can copy this file into your directory, then it will be imported from
-# the noxfile.py.
-
-# The source of truth:
-# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py
-
-TEST_CONFIG_OVERRIDE = {
- # You can opt out from the test for specific Python versions.
- # Skipping for Python 3.9 due to pyarrow compilation failure.
- "ignored_versions": ["2.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"],
- # Old samples are opted out of enforcing Python type hints
- # All new samples should feature them
- "enforce_type_hints": False,
- # An envvar key for determining the project id to use. Change it
- # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
- # build specific Cloud project. You can also use your own string
- # to use your own Cloud project.
- "gcloud_project_env": "GOOGLE_CLOUD_PROJECT",
- # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
- # A dictionary you want to inject into your test. Don't put any
- # secrets here. These values will override predefined values.
- "envs": {},
-}
diff --git a/appengine/flexible_python37_and_earlier/hello_world/requirements-test.txt b/appengine/flexible_python37_and_earlier/hello_world/requirements-test.txt
deleted file mode 100644
index 15d066af319..00000000000
--- a/appengine/flexible_python37_and_earlier/hello_world/requirements-test.txt
+++ /dev/null
@@ -1 +0,0 @@
-pytest==8.2.0
diff --git a/appengine/flexible_python37_and_earlier/hello_world/requirements.txt b/appengine/flexible_python37_and_earlier/hello_world/requirements.txt
deleted file mode 100644
index 055e4c6a13d..00000000000
--- a/appengine/flexible_python37_and_earlier/hello_world/requirements.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-Flask==3.0.3; python_version > '3.6'
-Flask==3.0.3; python_version < '3.7'
-gunicorn==23.0.0
-Werkzeug==3.0.3
diff --git a/appengine/flexible_python37_and_earlier/hello_world_django/.gitignore b/appengine/flexible_python37_and_earlier/hello_world_django/.gitignore
deleted file mode 100644
index 49ef2557b16..00000000000
--- a/appengine/flexible_python37_and_earlier/hello_world_django/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-db.sqlite3
diff --git a/appengine/flexible_python37_and_earlier/hello_world_django/README.md b/appengine/flexible_python37_and_earlier/hello_world_django/README.md
deleted file mode 100644
index d6705b131a3..00000000000
--- a/appengine/flexible_python37_and_earlier/hello_world_django/README.md
+++ /dev/null
@@ -1,66 +0,0 @@
-# Django sample for Google App Engine Flexible Environment
-
-[![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/flexible_python37_and_earlier/hello_world_django/README.md
-
-This is a basic hello world [Django](https://www.djangoproject.com/) example
-for [Google App Engine Flexible Environment](https://cloud.google.com/appengine).
-
-## Running locally
-
-You can run locally using django's `manage.py`:
-
- $ python manage.py runserver
-
-## Deployment & how the application runs on Google App Engine.
-
-Follow the standard deployment instructions in
-[the top-level README](../README.md). Google App Engine runs the application
-using [gunicorn](http://gunicorn.org/) as defined by `entrypoint` in
-[`app.yaml`](app.yaml). You can use a different WSGI container if you want, as
-long as it listens for web traffic on port `$PORT` and is declared in
-[`requirements.txt`](requirements.txt).
-
-## How this was created
-
-To set up Python development environment, please follow
-https://cloud.google.com/python/docs/setup.
-
-This project was created using standard Django commands:
-
- $ virtualenv env
- $ source env/bin/activate
- $ pip install django gunicorn
- $ pip freeze > requirements.txt
- $ django-admin startproject project_name
- $ python manage.py startapp helloworld
-
-Then, we added a simple view in `hellworld.views`, added the app to
-`project_name.settings.INSTALLED_APPS`, and finally added a URL rule to
-`project_name.urls`.
-
-In order to deploy to Google App Engine, we created a simple
-[`app.yaml`](app.yaml).
-
-## Database notice
-
-This sample project uses Django's default sqlite database. This isn't suitable
-for production as your application can run multiple instances and each will
-have a different sqlite database. Additionally, instance disks are ephemeral,
-so data will not survive restarts.
-
-For production applications running on Google Cloud Platform, you have
-the following options:
-
-* Use [Cloud SQL](https://cloud.google.com/sql), a fully-managed MySQL database.
- There is a [Flask CloudSQL](../cloudsql) sample that should be straightforward
- to adapt to Django.
-* Use any database of your choice hosted on
- [Google Compute Engine](https://cloud.google.com/compute). The
- [Cloud Launcher](https://cloud.google.com/launcher/) can be used to easily
- deploy common databases.
-* Use third-party database services, or services hosted by other providers,
- provided you have configured access.
-
diff --git a/appengine/flexible_python37_and_earlier/hello_world_django/app.yaml b/appengine/flexible_python37_and_earlier/hello_world_django/app.yaml
deleted file mode 100644
index 62b74a9c27e..00000000000
--- a/appengine/flexible_python37_and_earlier/hello_world_django/app.yaml
+++ /dev/null
@@ -1,20 +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: python
-env: flex
-entrypoint: gunicorn -b :$PORT project_name.wsgi
-
-runtime_config:
- python_version: 3
diff --git a/appengine/flexible_python37_and_earlier/hello_world_django/helloworld/__init__.py b/appengine/flexible_python37_and_earlier/hello_world_django/helloworld/__init__.py
deleted file mode 100644
index e69de29bb2d..00000000000
diff --git a/appengine/flexible_python37_and_earlier/hello_world_django/helloworld/views.py b/appengine/flexible_python37_and_earlier/hello_world_django/helloworld/views.py
deleted file mode 100644
index 71c0106bda1..00000000000
--- a/appengine/flexible_python37_and_earlier/hello_world_django/helloworld/views.py
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2015 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 django.http import HttpResponse
-
-
-def index(request):
- return HttpResponse("Hello, World. This is Django running on Google App Engine")
diff --git a/appengine/flexible_python37_and_earlier/hello_world_django/manage.py b/appengine/flexible_python37_and_earlier/hello_world_django/manage.py
deleted file mode 100755
index c213c77eca6..00000000000
--- a/appengine/flexible_python37_and_earlier/hello_world_django/manage.py
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env python
-# 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.
-
-import os
-import sys
-
-if __name__ == "__main__":
- os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_name.settings")
-
- from django.core.management import execute_from_command_line
-
- execute_from_command_line(sys.argv)
diff --git a/appengine/flexible_python37_and_earlier/hello_world_django/noxfile_config.py b/appengine/flexible_python37_and_earlier/hello_world_django/noxfile_config.py
deleted file mode 100644
index 1665dd736f8..00000000000
--- a/appengine/flexible_python37_and_earlier/hello_world_django/noxfile_config.py
+++ /dev/null
@@ -1,39 +0,0 @@
-# Copyright 2023 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.
-
-# Default TEST_CONFIG_OVERRIDE for python repos.
-
-# You can copy this file into your directory, then it will be imported from
-# the noxfile.py.
-
-# The source of truth:
-# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py
-
-TEST_CONFIG_OVERRIDE = {
- # You can opt out from the test for specific Python versions.
- # Skipping for Python 3.9 due to pyarrow compilation failure.
- "ignored_versions": ["2.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"],
- # Old samples are opted out of enforcing Python type hints
- # All new samples should feature them
- "enforce_type_hints": False,
- # An envvar key for determining the project id to use. Change it
- # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
- # build specific Cloud project. You can also use your own string
- # to use your own Cloud project.
- "gcloud_project_env": "GOOGLE_CLOUD_PROJECT",
- # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
- # A dictionary you want to inject into your test. Don't put any
- # secrets here. These values will override predefined values.
- "envs": {},
-}
diff --git a/appengine/flexible_python37_and_earlier/hello_world_django/project_name/__init__.py b/appengine/flexible_python37_and_earlier/hello_world_django/project_name/__init__.py
deleted file mode 100644
index e69de29bb2d..00000000000
diff --git a/appengine/flexible_python37_and_earlier/hello_world_django/project_name/settings.py b/appengine/flexible_python37_and_earlier/hello_world_django/project_name/settings.py
deleted file mode 100644
index f8b93099d56..00000000000
--- a/appengine/flexible_python37_and_earlier/hello_world_django/project_name/settings.py
+++ /dev/null
@@ -1,116 +0,0 @@
-# Copyright 2015 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.
-
-"""
-Django settings for project_name project.
-
-Generated by 'django-admin startproject' using Django 1.8.4.
-
-For more information on this file, see
-https://docs.djangoproject.com/en/stable/topics/settings/
-
-For the full list of settings and their values, see
-https://docs.djangoproject.com/en/stable/ref/settings/
-"""
-
-# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
-import os
-
-BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
-
-
-# Quick-start development settings - unsuitable for production
-# See https://docs.djangoproject.com/en/stable/howto/deployment/checklist/
-
-# SECURITY WARNING: keep the secret key used in production secret!
-SECRET_KEY = "qgw!j*bpxo7g&o1ux-(2ph818ojfj(3c#-#*_8r^8&hq5jg$3@"
-
-# SECURITY WARNING: don't run with debug turned on in production!
-DEBUG = True
-
-ALLOWED_HOSTS = []
-
-
-# Application definition
-
-INSTALLED_APPS = (
- "django.contrib.admin",
- "django.contrib.auth",
- "django.contrib.contenttypes",
- "django.contrib.sessions",
- "django.contrib.messages",
- "django.contrib.staticfiles",
- "helloworld",
-)
-
-MIDDLEWARE = (
- "django.middleware.security.SecurityMiddleware",
- "django.contrib.sessions.middleware.SessionMiddleware",
- "django.middleware.common.CommonMiddleware",
- "django.middleware.csrf.CsrfViewMiddleware",
- "django.contrib.auth.middleware.AuthenticationMiddleware",
- "django.contrib.messages.middleware.MessageMiddleware",
- "django.middleware.clickjacking.XFrameOptionsMiddleware",
-)
-
-ROOT_URLCONF = "project_name.urls"
-
-TEMPLATES = [
- {
- "BACKEND": "django.template.backends.django.DjangoTemplates",
- "DIRS": [],
- "APP_DIRS": True,
- "OPTIONS": {
- "context_processors": [
- "django.template.context_processors.debug",
- "django.template.context_processors.request",
- "django.contrib.auth.context_processors.auth",
- "django.contrib.messages.context_processors.messages",
- ],
- },
- },
-]
-
-WSGI_APPLICATION = "project_name.wsgi.application"
-
-
-# Database
-# https://docs.djangoproject.com/en/stable/ref/settings/#databases
-
-DATABASES = {
- "default": {
- "ENGINE": "django.db.backends.sqlite3",
- "NAME": os.path.join(BASE_DIR, "db.sqlite3"),
- }
-}
-
-
-# Internationalization
-# https://docs.djangoproject.com/en/stable/topics/i18n/
-
-LANGUAGE_CODE = "en-us"
-
-TIME_ZONE = "UTC"
-
-USE_I18N = True
-
-USE_L10N = True
-
-USE_TZ = True
-
-
-# Static files (CSS, JavaScript, Images)
-# https://docs.djangoproject.com/en/stable/howto/static-files/
-
-STATIC_URL = "/static/"
diff --git a/appengine/flexible_python37_and_earlier/hello_world_django/project_name/urls.py b/appengine/flexible_python37_and_earlier/hello_world_django/project_name/urls.py
deleted file mode 100644
index 9a393bb42d2..00000000000
--- a/appengine/flexible_python37_and_earlier/hello_world_django/project_name/urls.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# Copyright 2015 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 django.contrib import admin
-from django.urls import include, path
-
-import helloworld.views
-
-
-urlpatterns = [
- path("admin/", include(admin.site.urls)),
- path("", helloworld.views.index),
-]
diff --git a/appengine/flexible_python37_and_earlier/hello_world_django/project_name/wsgi.py b/appengine/flexible_python37_and_earlier/hello_world_django/project_name/wsgi.py
deleted file mode 100644
index c069a496999..00000000000
--- a/appengine/flexible_python37_and_earlier/hello_world_django/project_name/wsgi.py
+++ /dev/null
@@ -1,30 +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.
-
-"""
-WSGI config for project_name project.
-
-It exposes the WSGI callable as a module-level variable named ``application``.
-
-For more information on this file, see
-https://docs.djangoproject.com/en/stable/howto/deployment/wsgi/
-"""
-
-import os
-
-from django.core.wsgi import get_wsgi_application
-
-os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_name.settings")
-
-application = get_wsgi_application()
diff --git a/appengine/flexible_python37_and_earlier/hello_world_django/requirements-test.txt b/appengine/flexible_python37_and_earlier/hello_world_django/requirements-test.txt
deleted file mode 100644
index 15d066af319..00000000000
--- a/appengine/flexible_python37_and_earlier/hello_world_django/requirements-test.txt
+++ /dev/null
@@ -1 +0,0 @@
-pytest==8.2.0
diff --git a/appengine/flexible_python37_and_earlier/hello_world_django/requirements.txt b/appengine/flexible_python37_and_earlier/hello_world_django/requirements.txt
deleted file mode 100644
index 435ef2cb8ee..00000000000
--- a/appengine/flexible_python37_and_earlier/hello_world_django/requirements.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-Django==5.2.9
-gunicorn==23.0.0
diff --git a/appengine/flexible_python37_and_earlier/metadata/app.yaml b/appengine/flexible_python37_and_earlier/metadata/app.yaml
deleted file mode 100644
index ca76f83fc3b..00000000000
--- a/appengine/flexible_python37_and_earlier/metadata/app.yaml
+++ /dev/null
@@ -1,20 +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: python
-env: flex
-entrypoint: gunicorn -b :$PORT main:app
-
-runtime_config:
- python_version: 3
diff --git a/appengine/flexible_python37_and_earlier/metadata/main.py b/appengine/flexible_python37_and_earlier/metadata/main.py
deleted file mode 100644
index 9d1e320865a..00000000000
--- a/appengine/flexible_python37_and_earlier/metadata/main.py
+++ /dev/null
@@ -1,87 +0,0 @@
-# Copyright 2015 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.
-
-import logging
-
-from flask import Flask
-import requests
-
-
-logging.basicConfig(level=logging.INFO)
-app = Flask(__name__)
-
-
-# [START gae_flex_metadata]
-METADATA_NETWORK_INTERFACE_URL = (
- "http://metadata/computeMetadata/v1/instance/network-interfaces/0/"
- "access-configs/0/external-ip"
-)
-
-
-def get_external_ip():
- """Gets the instance's external IP address from the Compute Engine metadata
- server.
-
- If the metadata server is unavailable, it assumes that the application is running locally.
-
- Returns:
- The instance's external IP address, or the string 'localhost' if the IP address
- is not available.
- """
- try:
- r = requests.get(
- METADATA_NETWORK_INTERFACE_URL,
- headers={"Metadata-Flavor": "Google"},
- timeout=2,
- )
- return r.text
- except requests.RequestException:
- logging.info("Metadata server could not be reached, assuming local.")
- return "localhost"
-
-
-# [END gae_flex_metadata]
-
-
-@app.route("/")
-def index():
- """Serves a string with the instance's external IP address.
-
- Websocket connections must be made directly to this instance.
-
- Returns:
- A formatted string containing the instance's external IP address.
- """
- external_ip = get_external_ip()
- return f"External IP: {external_ip}"
-
-
-@app.errorhandler(500)
-def server_error(e):
- """Serves a formatted message on-error.
-
- Returns:
- The error message and a code 500 status.
- """
- logging.exception("An error occurred during a request.")
- return (
- f"An internal error occurred: {e}Say hi to:
- - -{e}{}
- See logs for full stacktrace.
- """.format(
- e
- ),
- 500,
- )
-
-
-if __name__ == "__main__":
- # This is used when running locally. Gunicorn is used to run the
- # application on Google App Engine. See entrypoint in app.yaml.
- app.run(host="127.0.0.1", port=8080, debug=True)
diff --git a/appengine/flexible_python37_and_earlier/pubsub/main_test.py b/appengine/flexible_python37_and_earlier/pubsub/main_test.py
deleted file mode 100644
index 37abb0d6240..00000000000
--- a/appengine/flexible_python37_and_earlier/pubsub/main_test.py
+++ /dev/null
@@ -1,65 +0,0 @@
-# Copyright 2015 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.
-
-import base64
-import json
-import os
-
-import pytest
-
-import main
-
-
-@pytest.fixture
-def client():
- main.app.testing = True
- return main.app.test_client()
-
-
-def test_index(client):
- r = client.get("/")
- assert r.status_code == 200
-
-
-def test_post_index(client):
- r = client.post("/", data={"payload": "Test payload"})
- assert r.status_code == 200
-
-
-def test_push_endpoint(client):
- url = "/pubsub/push?token=" + os.environ["PUBSUB_VERIFICATION_TOKEN"]
-
- r = client.post(
- url,
- data=json.dumps(
- {"message": {"data": base64.b64encode(b"Test message").decode("utf-8")}}
- ),
- )
-
- assert r.status_code == 200
-
- # Make sure the message is visible on the home page.
- r = client.get("/")
- assert r.status_code == 200
- assert "Test message" in r.data.decode("utf-8")
-
-
-def test_push_endpoint_errors(client):
- # no token
- r = client.post("/pubsub/push")
- assert r.status_code == 400
-
- # invalid token
- r = client.post("/pubsub/push?token=bad")
- assert r.status_code == 400
diff --git a/appengine/flexible_python37_and_earlier/pubsub/noxfile_config.py b/appengine/flexible_python37_and_earlier/pubsub/noxfile_config.py
deleted file mode 100644
index 1665dd736f8..00000000000
--- a/appengine/flexible_python37_and_earlier/pubsub/noxfile_config.py
+++ /dev/null
@@ -1,39 +0,0 @@
-# Copyright 2023 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.
-
-# Default TEST_CONFIG_OVERRIDE for python repos.
-
-# You can copy this file into your directory, then it will be imported from
-# the noxfile.py.
-
-# The source of truth:
-# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py
-
-TEST_CONFIG_OVERRIDE = {
- # You can opt out from the test for specific Python versions.
- # Skipping for Python 3.9 due to pyarrow compilation failure.
- "ignored_versions": ["2.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"],
- # Old samples are opted out of enforcing Python type hints
- # All new samples should feature them
- "enforce_type_hints": False,
- # An envvar key for determining the project id to use. Change it
- # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
- # build specific Cloud project. You can also use your own string
- # to use your own Cloud project.
- "gcloud_project_env": "GOOGLE_CLOUD_PROJECT",
- # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
- # A dictionary you want to inject into your test. Don't put any
- # secrets here. These values will override predefined values.
- "envs": {},
-}
diff --git a/appengine/flexible_python37_and_earlier/pubsub/requirements-test.txt b/appengine/flexible_python37_and_earlier/pubsub/requirements-test.txt
deleted file mode 100644
index 15d066af319..00000000000
--- a/appengine/flexible_python37_and_earlier/pubsub/requirements-test.txt
+++ /dev/null
@@ -1 +0,0 @@
-pytest==8.2.0
diff --git a/appengine/flexible_python37_and_earlier/pubsub/requirements.txt b/appengine/flexible_python37_and_earlier/pubsub/requirements.txt
deleted file mode 100644
index d5b7ce68695..00000000000
--- a/appengine/flexible_python37_and_earlier/pubsub/requirements.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-Flask==3.0.3; python_version > '3.6'
-Flask==2.3.3; python_version < '3.7'
-google-cloud-pubsub==2.28.0
-gunicorn==23.0.0
-Werkzeug==3.0.3
diff --git a/appengine/flexible_python37_and_earlier/pubsub/sample_message.json b/appengine/flexible_python37_and_earlier/pubsub/sample_message.json
deleted file mode 100644
index 8fe62d23fb9..00000000000
--- a/appengine/flexible_python37_and_earlier/pubsub/sample_message.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "message": {
- "data": "SGVsbG8sIFdvcmxkIQ=="
- }
-}
diff --git a/appengine/flexible_python37_and_earlier/pubsub/templates/index.html b/appengine/flexible_python37_and_earlier/pubsub/templates/index.html
deleted file mode 100644
index 28449216c37..00000000000
--- a/appengine/flexible_python37_and_earlier/pubsub/templates/index.html
+++ /dev/null
@@ -1,36 +0,0 @@
-{#
-# Copyright 2015 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.
-#}
-
-
-
- Messages received by this instance:
-Note: because your application is likely running multiple instances, each instance will have a different list of messages.
-{e}{e}This is a static file serving example.
- - diff --git a/appengine/flexible_python37_and_earlier/twilio/README.md b/appengine/flexible_python37_and_earlier/twilio/README.md deleted file mode 100644 index 9a62b8400b5..00000000000 --- a/appengine/flexible_python37_and_earlier/twilio/README.md +++ /dev/null @@ -1,34 +0,0 @@ -# Python Twilio voice and SMS sample for Google App Engine Flexible Environment - -[![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/flexible_python37_and_earlier/twilio/README.md - -This sample demonstrates how to use [Twilio](https://www.twilio.com) on [Google App Engine Flexible Environment](https://cloud.google.com/appengine). - -For more information about Twilio, see their [Python quickstart tutorials](https://www.twilio.com/docs/quickstart/python). - -## Setup - -Before you can run or deploy the sample, you will need to do the following: - -1. [Create a Twilio Account](http://ahoy.twilio.com/googlecloudplatform). Google App Engine -customers receive a complimentary credit for SMS messages and inbound messages. - -2. Create a number on twilio, and configure the voice request URL to be ``https://your-app-id.appspot.com/call/receive`` -and the SMS request URL to be ``https://your-app-id.appspot.com/sms/receive``. - -3. Configure your Twilio settings in the environment variables section in ``app.yaml``. - -## Running locally - -Refer to the [top-level README](../README.md) for instructions on running and deploying. - -You can run the application locally to test the callbacks and SMS sending. You -will need to set environment variables before starting your application: - - $ export TWILIO_ACCOUNT_SID=[your-twilio-account-sid] - $ export TWILIO_AUTH_TOKEN=[your-twilio-auth-token] - $ export TWILIO_NUMBER=[your-twilio-number] - $ python main.py diff --git a/appengine/flexible_python37_and_earlier/twilio/app.yaml b/appengine/flexible_python37_and_earlier/twilio/app.yaml deleted file mode 100644 index 0e7de97eb19..00000000000 --- a/appengine/flexible_python37_and_earlier/twilio/app.yaml +++ /dev/null @@ -1,27 +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: python -env: flex -entrypoint: gunicorn -b :$PORT main:app - -runtime_config: - python_version: 3 - -# [START gae_flex_twilio_env] -env_variables: - TWILIO_ACCOUNT_SID: your-account-sid - TWILIO_AUTH_TOKEN: your-auth-token - TWILIO_NUMBER: your-twilio-number -# [END gae_flex_twilio_env] diff --git a/appengine/flexible_python37_and_earlier/twilio/main.py b/appengine/flexible_python37_and_earlier/twilio/main.py deleted file mode 100644 index 6f2a3a6830f..00000000000 --- a/appengine/flexible_python37_and_earlier/twilio/main.py +++ /dev/null @@ -1,96 +0,0 @@ -# Copyright 2015 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. - -import logging -import os - -from flask import Flask, request -from twilio import rest -from twilio.twiml import messaging_response, voice_response - - -TWILIO_ACCOUNT_SID = os.environ["TWILIO_ACCOUNT_SID"] -TWILIO_AUTH_TOKEN = os.environ["TWILIO_AUTH_TOKEN"] -TWILIO_NUMBER = os.environ["TWILIO_NUMBER"] - - -app = Flask(__name__) - - -# [START gae_flex_twilio_receive_call] -@app.route("/call/receive", methods=["POST"]) -def receive_call(): - """Answers a call and replies with a simple greeting.""" - response = voice_response.VoiceResponse() - response.say("Hello from Twilio!") - return str(response), 200, {"Content-Type": "application/xml"} - - -# [END gae_flex_twilio_receive_call] - - -# [START gae_flex_twilio_send_sms] -@app.route("/sms/send") -def send_sms(): - """Sends a simple SMS message.""" - to = request.args.get("to") - if not to: - return ( - 'Please provide the number to message in the "to" query string' - " parameter." - ), 400 - - client = rest.Client(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN) - rv = client.messages.create(to=to, from_=TWILIO_NUMBER, body="Hello from Twilio!") - return str(rv) - - -# [END gae_flex_twilio_send_sms] - - -# [START gae_flex_twilio_receive_sms] -@app.route("/sms/receive", methods=["POST"]) -def receive_sms(): - """Receives an SMS message and replies with a simple greeting.""" - sender = request.values.get("From") - body = request.values.get("Body") - - message = f"Hello, {sender}, you said: {body}" - - response = messaging_response.MessagingResponse() - response.message(message) - return str(response), 200, {"Content-Type": "application/xml"} - - -# [END gae_flex_twilio_receive_sms] - - -@app.errorhandler(500) -def server_error(e): - logging.exception("An error occurred during a request.") - return ( - """ - An internal error occurred:{}
- See logs for full stacktrace.
- """.format(
- e
- ),
- 500,
- )
-
-
-if __name__ == "__main__":
- # This is used when running locally. Gunicorn is used to run the
- # application on Google App Engine. See entrypoint in app.yaml.
- app.run(host="127.0.0.1", port=8080, debug=True)
diff --git a/appengine/flexible_python37_and_earlier/twilio/main_test.py b/appengine/flexible_python37_and_earlier/twilio/main_test.py
deleted file mode 100644
index 4878384f65a..00000000000
--- a/appengine/flexible_python37_and_earlier/twilio/main_test.py
+++ /dev/null
@@ -1,75 +0,0 @@
-# Copyright 2016 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.
-import re
-
-import pytest
-import responses
-
-
-@pytest.fixture
-def app(monkeypatch):
- monkeypatch.setenv("TWILIO_ACCOUNT_SID", "sid123")
- monkeypatch.setenv("TWILIO_AUTH_TOKEN", "auth123")
- monkeypatch.setenv("TWILIO_NUMBER", "0123456789")
-
- import main
-
- main.app.testing = True
- return main.app.test_client()
-
-
-def test_receive_call(app):
- r = app.post("/call/receive")
- assert "Hello from Twilio!" in r.data.decode("utf-8")
-
-
-@responses.activate
-def test_send_sms(app, monkeypatch):
- sample_response = {
- "sid": "sid",
- "date_created": "Wed, 20 Dec 2017 19:32:14 +0000",
- "date_updated": "Wed, 20 Dec 2017 19:32:14 +0000",
- "date_sent": None,
- "account_sid": "account_sid",
- "to": "+1234567890",
- "from": "+9876543210",
- "messaging_service_sid": None,
- "body": "Hello from Twilio!",
- "status": "queued",
- "num_segments": "1",
- "num_media": "0",
- "direction": "outbound-api",
- "api_version": "2010-04-01",
- "price": None,
- "price_unit": "USD",
- "error_code": None,
- "error_message": None,
- "uri": "/2010-04-01/Accounts/sample.json",
- "subresource_uris": {"media": "/2010-04-01/Accounts/sample/Media.json"},
- }
- responses.add(responses.POST, re.compile(".*"), json=sample_response, status=200)
-
- r = app.get("/sms/send")
- assert r.status_code == 400
-
- r = app.get("/sms/send?to=5558675309")
- assert r.status_code == 200
-
-
-def test_receive_sms(app):
- r = app.post(
- "/sms/receive", data={"From": "5558675309", "Body": "Jenny, I got your number."}
- )
- assert r.status_code == 200
- assert "Jenny, I got your number" in r.data.decode("utf-8")
diff --git a/appengine/flexible_python37_and_earlier/twilio/noxfile_config.py b/appengine/flexible_python37_and_earlier/twilio/noxfile_config.py
deleted file mode 100644
index 1665dd736f8..00000000000
--- a/appengine/flexible_python37_and_earlier/twilio/noxfile_config.py
+++ /dev/null
@@ -1,39 +0,0 @@
-# Copyright 2023 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.
-
-# Default TEST_CONFIG_OVERRIDE for python repos.
-
-# You can copy this file into your directory, then it will be imported from
-# the noxfile.py.
-
-# The source of truth:
-# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py
-
-TEST_CONFIG_OVERRIDE = {
- # You can opt out from the test for specific Python versions.
- # Skipping for Python 3.9 due to pyarrow compilation failure.
- "ignored_versions": ["2.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"],
- # Old samples are opted out of enforcing Python type hints
- # All new samples should feature them
- "enforce_type_hints": False,
- # An envvar key for determining the project id to use. Change it
- # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
- # build specific Cloud project. You can also use your own string
- # to use your own Cloud project.
- "gcloud_project_env": "GOOGLE_CLOUD_PROJECT",
- # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
- # A dictionary you want to inject into your test. Don't put any
- # secrets here. These values will override predefined values.
- "envs": {},
-}
diff --git a/appengine/flexible_python37_and_earlier/twilio/requirements-test.txt b/appengine/flexible_python37_and_earlier/twilio/requirements-test.txt
deleted file mode 100644
index e89f6031ad7..00000000000
--- a/appengine/flexible_python37_and_earlier/twilio/requirements-test.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-pytest==8.2.0
-responses==0.17.0; python_version < '3.7'
-responses==0.23.1; python_version > '3.6'
diff --git a/appengine/flexible_python37_and_earlier/twilio/requirements.txt b/appengine/flexible_python37_and_earlier/twilio/requirements.txt
deleted file mode 100644
index cfa80d12edf..00000000000
--- a/appengine/flexible_python37_and_earlier/twilio/requirements.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-Flask==3.0.3; python_version > '3.6'
-Flask==2.0.3; python_version < '3.7'
-gunicorn==23.0.0
-twilio==9.0.3
-Werkzeug==3.0.3; python_version >= '3.7'
-Werkzeug==2.3.8; python_version < '3.7'