https://prefect.io logo
Title
s

Scott Zelenka

06/04/2020, 6:04 PM
Is there a better way to dynamically configure which
PrefectSecret
to read from? Our use case is that we have different key/value pairs depending on the lifecycle the Flow is being executed in, so we split that up into two different Secrets, and use a Parameter to trigger which lifecyle it should attempt to process:
with Flow() as flow:
    lifecycle = Parameter("lifecycle", default='dev')
    secrets = PrefectSecret(f"SECRET_NAME_{lifecycle.run().upper()}")
That seems hacky, to have to call
.run()
on the Parameter though. Wondering if anyone found a cleaner approach.
n

nicholas

06/04/2020, 6:08 PM
Depending on how often you use the secret, I've found that getting the secret inside a task can be really helpful for dynamic secrets. Something like this:
@task
def my_task(x):
  some_secret = Secret("SECRET_NAME_{x}").get()