Service Account Authentication via Secret Key JSON file (for Google Cloud Platform)

Off the top of my head, this should work:

import os.path

if not os.path.exists("/tmp/creds.json"):
  with open("/tmp/creds.json", "w") as f:
    f.write(anvil.secrets.get_secret("google_creds"))

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/tmp/creds.json"

…but the Google SDK almost certainly has a way to configure authentication more cleanly than writing it out to a file and then slurping it in. (I just had a look, but I didn’t find anything – Google developer documentation deeply painful to navigate, though, so I might have just missed something.)