Laura Vaida
03/09/2021, 6:03 PMJim Crist-Harif
03/09/2021, 6:15 PMLaura Vaida
03/09/2021, 6:15 PMLaura Vaida
03/09/2021, 6:17 PMJim Crist-Harif
03/09/2021, 6:17 PMconfig.toml
).haf
03/09/2021, 6:17 PMdict
?Laura Vaida
03/09/2021, 6:17 PMJim Crist-Harif
03/09/2021, 6:18 PMhaf
03/09/2021, 6:19 PMfrom json import loads
@task
def mysterious():
raw = Secret("OH_VERY_SECRET").get() # e.g. {"hi":42}
v = loads(raw)
printf(v["hi"]) # => 42
Laura Vaida
03/09/2021, 6:20 PMCharles Liu
03/09/2021, 6:20 PMwith Flow("<flow name>") as flow:
client_secret = PrefectSecret("<your name for your secrets class")
on the front end, there is a feature to enter Secrets and it has to be valid nested JSON.Charles Liu
03/09/2021, 6:21 PMLaura Vaida
03/09/2021, 6:22 PMJim Crist-Harif
03/09/2021, 6:23 PMJim Crist-Harif
03/09/2021, 6:23 PMIn [1]: from prefect.client import Secret
In [2]: Secret("EXAMPLE").get()
Out[2]: {'key1': 'value1', 'key2': 'value2'}
Laura Vaida
03/09/2021, 6:26 PMsecret =
{"key" = "value"
}
that's my example and when i want to run
from prefect.client import Secret
it says
toml.decoder.TomlDecodeError: Found invalid character in key name: '"'. Try quoting the key name. (line 13 column 2 char 321)
haf
03/09/2021, 6:28 PM:
not =
Jim Crist-Harif
03/09/2021, 6:28 PM[context.secrets]
EXAMPLE = {key1 = "value1", key2 = "value2"}
Jim Crist-Harif
03/09/2021, 6:29 PMIn [1]: from prefect.client import Secret
In [2]: Secret("EXAMPLE").get()
Out[2]: <Box: {'key1': 'value1', 'key2': 'value2'}>
Laura Vaida
03/09/2021, 6:39 PMJim Crist-Harif
03/09/2021, 6:41 PMdef my_function(key1=None, key2=None):
...
@task
def my_task(secret):
return my_function(**secret)
with Flow("example") as flow:
secret = PrefectSecret("EXAMPLE")
my_task(secret)
Charles Liu
03/09/2021, 6:43 PMLaura Vaida
03/09/2021, 6:50 PMhaf
03/09/2021, 6:53 PMCharles Liu
03/09/2021, 6:53 PMCharles Liu
03/09/2021, 6:56 PMCharles Liu
03/09/2021, 6:56 PMJim Crist-Harif
03/09/2021, 6:58 PMprefect.client.Secret
is an internal api for loading secrets (this honestly should have been a function like prefect.secrets.get_secret
). prefect.tasks.secrets.PrefectSecret
is a task that uses prefect.client.Secret
internally for loading secrets. You usually want to use the latter (treat secrets as a task) rather than the former.Laura Vaida
03/09/2021, 7:28 PM