Skip to content

Can not access SecretParam from on_document_created #127

Open
@arndtvoges

Description

@arndtvoges

This is on the emulator with v0.1.1. I have not tested this as a deployed function.

Not sure if this is my mistake, but I can't seem to access the secrets from within a Firestore function, although the secrets parameter looks like it is defined in _GLOBAL_OPTIONS?

from firebase_functions import firestore_fn
from firebase_admin import initialize_app, firestore
from firebase_functions.params import SecretParam

app = initialize_app()
db = firestore.client()

SECRET_KEY_ONE = SecretParam("SECRET_KEY_ONE")
SECRET_KEY_TWO = SecretParam("SECRET_KEY_TWO")

@firestore_fn.on_document_created(document="Chat/{chatId}", secrets=[SECRET_KEY_ONE, SECRET_KEY_TWO])
def onChatCreated(
    event: firestore_fn.Event[firestore_fn.DocumentSnapshot | None]
) -> None:
    print(SECRET_KEY_ONE.value())
    return

Gives me
TypeError: 'str' object is not callable

When I change the code to
print(SECRET_KEY_ONE) it gives me {{ params.SECRET_KEY_ONE }}

The secrets are defined in Cloud Secrets. When I change the secrets' names, it asks me to save a new value, indicating that it is aware of their existence of their original names in Cloud Secrets.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions