Is there a way to set the api_token in code rather...
# prefect-server
l
Is there a way to set the api_token in code rather than relying on env or config file?
k
Hey @Lawrence Finn, I will double check this but I don’t think so. You can authenticate the
Client
, but that would but extend to
flow.register()
l
i had to do something like
Copy code
os.environ["PREFECT__CLOUD__AUTH_TOKEN"] = get_prefect_token()

from prefect import task, Flow, Parameter
from prefect.schedules import IntervalSchedule
from datetime import timedelta
from prefect.storage import S3
from prefect.executors import DaskExecutor
from prefect.run_configs import KubernetesRun
from prefect.tasks.prefect import StartFlowRun
import prefect
which is kinda ugly but 🤷
im writing an aws lambda and the api token is a secret in aws secret store
k
I went through the code and you might be able to do
Copy code
client = Client(api_key="...")
client.save_auth_to_disk()
which creates an
auth.toml
file and then future
Client()
calls would fetch that so when you do
flow.register()
, it would work as it creates a client under the hood. But this would persist a file which I guess is not what you want.
I see what you mean. Yeah I guess that’s what you have to do.
l
i guess your solution is fine, it’s on a lambda container so it is fine to write the file
k
Actually, if you do it this way, just use the
client.register()
function directly to register your Flow.
l
what params does that func take?
k
Very similar:
Copy code
prefect.client.client.Client.register(flow, project_name=None, build=True, set_schedule_active=True, version_group_id=None, compressed=True, no_url=False, idempotency_key=None)
l
oh cooool
thanks 🙏