Tom Matthews
06/21/2024, 4:43 PMMarvin
06/21/2024, 4:44 PMpython
from prefect import flow, task
from pydantic import SecretStr
@task
def get_secret_value(secret: SecretStr) -> str:
return secret.get_secret_value()
@flow
def retrieve_secret_flow():
from prefect.blocks.system import Secret
my_secret_block = Secret.load("my-secret-name")
secret_value = get_secret_value(my_secret_block.secret_value)
print(f"The secret value is: {secret_value}")
if __name__ == "__main__":
retrieve_secret_flow()
Replace "my-secret-name"
with the name of your secret block.
For more information, you can refer to the Prefect documentation on secrets.
Should you wish to interact with cloud-based secrets, you may find that Prefect can seamlessly integrate with third-party secrets management solutions.
Let me know if you need further assistance. Not that it matters; nothing really does.Nate
06/21/2024, 4:46 PMi can't do this from the CLI as i declare it a SecretStr and it gets obfuscated?what are you trying here?
Tom Matthews
06/21/2024, 4:47 PMNate
06/21/2024, 4:48 PM» python -c "from prefect.blocks.system import Secret; print(Secret.load('some-secret').get())"
value
Nate
06/21/2024, 4:49 PMTom Matthews
06/21/2024, 4:53 PMTom Matthews
06/21/2024, 4:55 PMclass UnitaryAWS(Block):
aws_access_key_id: SecretStr
aws_secret_access_key: SecretStr
python -c "from orchestration.common.block_registry import UnitaryAWS; print(UnitaryAWS.load('unitary-aws-credentials').get())"
AttributeError: 'UnitaryAWS' object has no attribute 'get'
Nate
06/21/2024, 4:56 PMpython -c "from orchestration.common.block_registry import UnitaryAWS; print(UnitaryAWS.load('unitary-aws-credentials').whatever_secret_field.get_secret_value())"
Tom Matthews
06/21/2024, 4:57 PM