build/cloudfns
Dmitri Shuralyov 884a8debac cloudfns/wikiwebhook: set GCP_PROJECT env var explicitly
Prior to CL 230637, this cloud function was targeting the Go 1.11
runtime, which implicitly¹ set the GCP_PROJECT environment variable.
That no longer happens with the newer Go runtime², so set the same
variable explicitly, otherwise publishing to the topic fails.

Remove a defer r.Body.Close() line; the http.Request body is closed
by the http.Server, http.Handler does not need to.

Also update the version of pubsub package to the latest. It isn't
needed to fix the problem, but it has already been tested during
debugging, so it's inexpensive to include.

A future enhancement is to factor out the pubsub client creation
to happen once per function instance rather than per invocation³,
and use metadata.ProjectID instead of needing an explicit env var.

¹ https://cloud.google.com/functions/docs/env-var#nodejs_8_python_37_and_go_111
² https://cloud.google.com/functions/docs/env-var#newer_runtimes
³ https://cloud.google.com/functions/docs/concepts/go-runtime#one-time_initialization

Fixes golang/go#44948.

Change-Id: I03fd66c7fb784cef24c5759b45cb7c10ed17ee6a
Reviewed-on: https://go-review.googlesource.com/c/build/+/302549
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Trust: Alexander Rakoczy <alex@golang.org>
Reviewed-by: Alexander Rakoczy <alex@golang.org>
Reviewed-by: Carlos Amedee <carlos@golang.org>
2021-03-18 16:11:36 +00:00
..
issueswebhook cloudfns: fetch secrets from Secret Manager 2021-03-18 16:09:22 +00:00
sendwikidiff cloudfns: fetch secrets from Secret Manager 2021-03-18 16:09:22 +00:00
wikiwebhook cloudfns/wikiwebhook: set GCP_PROJECT env var explicitly 2021-03-18 16:11:36 +00:00