<@ULVA73B9P> how can i check the value of a secret...
# marvin-in-the-wild
t
@Marvin how can i check the value of a secret i have stored in prefect server? i can't do this from the CLI as i declare it a SecretStr and it gets obfuscated?
m
To check the value of a secret stored in Prefect Server, you have to retrieve it programmatically within your Prefect flow, as the CLI obfuscates SecretStr values. Here’s an example of how you might do that:
Copy code
python
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.
n
hi @Tom Matthews
i can't do this from the CLI as i declare it a SecretStr and it gets obfuscated?
what are you trying here?
t
i have an aws access key + secret stored as a secret and i want to check what it is to debug its permissions
n
Copy code
» python -c "from prefect.blocks.system import Secret; print(Secret.load('some-secret').get())"                                                                                        
value
does that work?
t
That does! Thank you!
But not for my custom block:
Copy code
class UnitaryAWS(Block):
    aws_access_key_id: SecretStr
    aws_secret_access_key: SecretStr
Copy code
python -c "from orchestration.common.block_registry import UnitaryAWS; print(UnitaryAWS.load('unitary-aws-credentials').get())"
AttributeError: 'UnitaryAWS' object has no attribute 'get'
n
.get() is not common to all blocks but you should be able to do
Copy code
python -c "from orchestration.common.block_registry import UnitaryAWS; print(UnitaryAWS.load('unitary-aws-credentials').whatever_secret_field.get_secret_value())"
t
works, thanks!
👍 1