Ranu Goldan
04/08/2021, 2:18 AMPrefectSecret
Task
I want to pass the secret key via Parameter
. But it says that PrefectSecret argument should be statically defined so impossible to use parameter as secret key. Is that any workaround to solve that?
Thanks in advance!Jacob Blanco
04/08/2021, 4:45 AMJacob Blanco
04/08/2021, 4:45 AMRanu Goldan
04/08/2021, 4:56 AMfrom prefect import Flow, task, Parameter
from prefect.tasks.secrets import PrefectSecret
@task
def say_hello(secret=""):
print("hello {}".format(secret))
with Flow("hello_flowx") as flow:
secret_key = Parameter("secret_key")
secret = PrefectSecret(secret_key)
say_hellox = say_hello(secret)
flow.run(parameters={"secret_key": "secret_key"})
Ranu Goldan
04/08/2021, 4:56 AMA Task was passed as an argument to PrefectSecret, you likely want to first initialize PrefectSecret with any static (non-Task) arguments, then call the initialized task with any dynamic (Task) arguments instead. For example:
my_task = PrefectSecret(...) # static (non-Task) args go here
res = my_task(...) # dynamic (Task) args go here
Jay Shah
04/08/2021, 9:58 AMfrom prefect.client.secrets import Secret
val=Secret("secret")
val.get()
val.get() will display the secret valueJay Shah
04/08/2021, 10:00 AMfrom prefect import Flow, task, Parameter
from prefect.tasks.secrets import PrefectSecret
from prefect.client.secrets import Secret
@task
def say_hello(secret):
print("hello {}".format(secret))
with Flow("hello_flowx") as flow:
secret_key = Parameter("secret_key")
secret = Secret(secret_key)
say_hellox = say_hello(secret)
flow.run(parameters={"secret_key": "secret_key"})
The assumption is you've already set secret.Ranu Goldan
04/08/2021, 10:46 AMSecret
and pass it to task? Or should I just call it inside task func?Jay Shah
04/08/2021, 11:30 AMKevin Kho
Kevin Kho
Ranu Goldan
04/12/2021, 1:00 AMJay Shah
04/12/2021, 1:15 AM