GoshDarnedHero
10/02/2023, 5:45 PMMarvin
10/02/2023, 5:45 PMpython
from prefect import Secret
# Load multiple secrets
secret1 = Secret("SECRET1").get()
secret2 = Secret("SECRET2").get()
In this example, SECRET1
and SECRET2
are the names of your secrets. Replace them with the actual names of your secrets. Each secret is loaded with a separate call to Secret().get()
, but they can be in the same Python script or function.
Remember, secrets are sensitive. Handle them with care, even if you're in a rush.GoshDarnedHero
10/02/2023, 5:46 PMMarvin
10/02/2023, 5:46 PMpython
from prefect import Secret
# Load multiple secrets
secret1 = Secret("SECRET1").get()
secret2 = Secret("SECRET2").get()
Replace SECRET1
and SECRET2
with the names of your secrets. It's a bit more typing, but it's a small price to pay for keeping your secrets, well, secret.GoshDarnedHero
10/02/2023, 5:47 PMMarvin
10/02/2023, 5:47 PMos
module. Here's how:
python
import os
# Get all environment variables
env_vars = os.environ
In this example, env_vars
is a dictionary that contains all environment variables. You can access individual variables like so:
python
var_value = env_vars.get('VAR_NAME')
Replace 'VAR_NAME'
with the name of your variable. Remember, though, with great power comes great responsibility. Be careful not to expose sensitive information when fetching all environment variables.GoshDarnedHero
10/02/2023, 5:48 PMMarvin
10/02/2023, 5:48 PMpython
from prefect import Client
# Initialize the client
client = Client()
# Get a variable
var_value = client.get_variables().get('VAR_NAME')
Replace 'VAR_NAME'
with the name of your variable. I know, it's a bit more work, but sometimes life doesn't give you shortcuts. Or at least, Prefect doesn't in this case.Nate
10/02/2023, 6:33 PMGoshDarnedHero
10/02/2023, 10:13 PMGoshDarnedHero
10/02/2023, 10:14 PMNate
10/02/2023, 10:29 PMBlockDocument
representations of the blocks in one go, but i assume you'd still have to loop over and cast them to your Secret
object that your code expects, so something like [Block.load(f"secret/{slug}") for slug in secret_slugs]
is still prob what id reach for, similar for variables