Brian Roepke
01/04/2024, 11:35 PMMarvin
01/04/2024, 11:36 PMNate
01/04/2024, 11:36 PMNate
01/04/2024, 11:37 PMMarvin
01/04/2024, 11:37 PMpython
from prefect import flow
from prefect.blocks.system import Secret
# Assuming you have already created a Secret block via the Prefect UI or CLI with the name 'my-secret'
my_secret_block = Secret.load('my-secret')
@flow
def my_flow():
# To use the value of the secret within your flow:
secret_value = my_secret_block.get()
print(f"The secret value is: {secret_value}")
my_flow()
It's important to note that this code doesn't print the actual secret to any logs or output to help protect the secret's confidentiality. When you use the secret's value within your flow, it remains secret.
If you need to create a Secret String Block through code, here is a basic example:
python
from prefect.blocks.system import Secret
# Creating and saving a new Secret block with a name and secret value
my_secret_block = Secret(name="my-new-secret", value="super_secret_value")
my_secret_block.save("my-secret")
This example shows how to create a Secret block with a given value and save it with a name for later retrieval. Remember to replace "super_secret_value"
with your actual secret string, and use strong security practices to protect this information in your code.Brian Roepke
01/04/2024, 11:38 PM.get
the value. 😞Nate
01/04/2024, 11:39 PMSomeBlockInstance(...).value
its just that for Secret
it stores a SecretStr
so you'd have to do Secret.load(...).value.get_secret_value()
which is clunky so we have that .get()
convenience method which im not sure we have elsewhereBrian Roepke
01/04/2024, 11:40 PMBrian Roepke
01/04/2024, 11:40 PMNate
01/04/2024, 11:40 PM