Skip to content

Commit

Permalink
fix: modernize background app
Browse files Browse the repository at this point in the history
  • Loading branch information
iennae committed Aug 26, 2024
1 parent d9da8db commit 3a9e42e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion background/app/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
# limitations under the License.

# [START getting_started_background_config]
runtime: python37
runtime: python312
# [END getting_started_background_config]
12 changes: 4 additions & 8 deletions background/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ def translate():
to_language = request.form.get("lang", "")

if source_string == "":
error_message = "Empty value"
return error_message, 400
return f"Invalid request, you must provide a value.", 400

if to_language not in ACCEPTABLE_LANGUAGES:
error_message = "Unsupported language: {}".format(to_language)
return error_message, 400
return f"Unsupported language: {to_language}", 400

Check warning

Code scanning / CodeQL

Reflected server-side cross-site scripting Medium

Cross-site scripting vulnerability due to a
user-provided value
.

message = {
"Original": source_string,
Expand All @@ -78,11 +76,9 @@ def translate():
"OriginalLanguage": "",
}

topic_name = "projects/{}/topics/{}".format(
os.getenv("GOOGLE_CLOUD_PROJECT"), "translate"
)
topic_name = f"projects/{os.getenv('GOOGLE_CLOUD_PROJECT')}/topics/translate"
publisher.publish(
topic=topic_name, data=json.dumps(message).encode("utf8")
topic=topic_name, data=json.dumps(message).encode("utf-8")
)
return redirect("/")

Expand Down
6 changes: 3 additions & 3 deletions background/app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
google-cloud-firestore==2.11.1
google-cloud-pubsub==2.16.1
flask==2.2.5
google-cloud-firestore==2.18.0
google-cloud-pubsub==2.23.0
flask==3.0.3

0 comments on commit 3a9e42e

Please sign in to comment.